fact: Definition tmMatchCorrect (A : Type) : Core.TemplateMonad Prop := t <- (tmEval hnf A >>= tmQuote) ;; hs_num <- tmGetOption (split_head_symbol t) "no inductive";; let '(ind, Params) := hs_num in decl <- tmQuoteInductiveDecl (inductive_mind ind) ;; let '(mdecl,idecl) := decl in let params := firstn mdecl.(ind_npars) Params in num <- tmEval cbv (| ind_ctors idecl |) ;; x <- Core.tmFreshName "x" ;; mtch <- mkMatch t tTerm (tRel (2 * num)) (mk_predicate Instance.empty params (context_to_bcontext (ind_predicate_context ind mdecl idecl)) tTerm) (fun i ctr_types => args <- tmEval cbv (|ctr_types|);; C <- monad_map_i (encode_arguments t args) ctr_types ;; ret ( (((fun s => mkAppList s C) (tRel (args + 2 * (num - i) - 1))))) ) ;; E' <- Core.tmInferInstance None (encodable A);; E <- tmGetMyOption E' "failed" ;; t' <- ret (@enc A E);; l <- tmQuote t';; encn <- ret (tApp l [tRel (2*num) ]) ;; lhs <- ret (mkLApp encn ((fix f n := match n with 0 => [] | S n => tRel (2 * n + 1) :: f n end ) num)) ;; ter <- ret (tProd naAnon t (it (fun s : term => tProd naAnon tTerm (tProd naAnon (tApp (tConst (L_facts_mp, "proc") []) [tRel 0]) s)) num ((tApp (tConst (L_facts_mp, "redLe") []) [mkNat num; lhs; mtch]))));; ter <- tmEval cbv ter ;; tmUnquoteTyped Prop ter.
imports: Undecidability.L(L Tactics.Computable Tactics.ComputableTactics Tactics.Extract) MetaCoq(Template.All TemplateMonad.Core Template.Ast) List MetaCoq.Utils.bytestring