fact: Definition autoinduct (p : program) : term := let (Σ, t) := p in let (hd, args) := decompose_app t in let hd' := match hd with | tConst kn _ => match lookup_constant Σ kn with | Some b => match b.(cst_body) with | Some b => b | None => tVar "error: constant has no body" end | None => tVar "error: constant not declared" end | x => x end in let (lambdas, rhd) := decompose_lam_assum [] hd' in let n := List.length lambdas in match rhd with | tFix mfix idx => match nth_error mfix idx with | Some f => match nth_error args (n + f.(rarg)) with | Some x => x | None => tVar "not enough arguments for induction" end | None => tVar "ill-typed fixpoint" end | _ => tVar "passed term does not unfold to a fixpoint" end.
imports: MetaCoq.Template(All) MetaCoq.Utils(bytestring) List