@@ -61,6 +61,10 @@ fun binder_inductive_cmd ((pred_name, binds_opt), perms_supps) no_defs_lthy =
6161
6262 val param_Ts = map (Term.typ_subst_TVars subst) param_Ts;
6363
64+ val param_sugars = map (fn T => Option.mapPartial (fn s =>
65+ MRBNF_Sugar.binder_sugar_of no_defs_lthy s
66+ ) (try (fn () => fst (dest_Type T)) ())) param_Ts;
67+
6468 fun collect_binders (Free _) = []
6569 | collect_binders (Var _) = []
6670 | collect_binders (Bound _) = []
@@ -230,7 +234,6 @@ fun binder_inductive_cmd ((pred_name, binds_opt), perms_supps) no_defs_lthy =
230234 val thy = Proof_Context.theory_of no_defs_lthy;
231235 fun mk_match mk_T ts = map2 (fn t => fn T =>
232236 let
233- val _ = @{print} (Thm.cterm_of no_defs_lthy t, T, mk_T T)
234237 val t = Logic.varify_types_global t;
235238 val tyenv = Sign.typ_match thy (fastype_of t, mk_T T) Vartab.empty;
236239 in Envir.subst_term (tyenv, Vartab.empty) t end
@@ -361,6 +364,7 @@ fun binder_inductive_cmd ((pred_name, binds_opt), perms_supps) no_defs_lthy =
361364 val perms_specified = map (fn Inl _ => false | _ => true ) raw_perms;
362365 val supps_specified = map (fn Inl _ => false | _ => true ) raw_supps;
363366 val one_specified = map2 (fn a => fn b => a orelse b) perms_specified supps_specified;
367+
364368 fun keep_perm xs = cond_keep xs perms_specified;
365369 fun keep_supp xs = cond_keep xs supps_specified;
366370 fun keep_both xs = cond_keep xs one_specified;
@@ -371,7 +375,7 @@ fun binder_inductive_cmd ((pred_name, binds_opt), perms_supps) no_defs_lthy =
371375 val goals = map (single o rpair []) (
372376 keep_perm perm_id0_goals @ keep_perm perm_comp_goals @ keep_both supp_seminat_goals
373377 @ keep_both perm_support_goals @ keep_supp supp_small_goals @ flat (keep_binders B_small_goals)
374- @ [G_equiv_goal, G_refresh_goal]
378+ @ [G_refresh_goal]
375379 );
376380 fun after_qed thmss lthy =
377381 let
@@ -422,14 +426,13 @@ fun binder_inductive_cmd ((pred_name, binds_opt), perms_supps) no_defs_lthy =
422426 val m2 = length (filter not one_specified);
423427 val m3 = length (filter not supps_specified);
424428 val m4 = length (filter not binders_specified);
425- val ((((((( perm_id0s, perm_comps), supp_seminats), perm_supports), supp_smalls), B_smalls), G_equiv ), G_refresh) = map hd thmss
429+ val ((((((perm_id0s, perm_comps), supp_seminats), perm_supports), supp_smalls), B_smalls), G_refresh) = map hd thmss
426430 |> chop (n - m)
427431 ||>> chop (n - m)
428432 ||>> chop (n - m2)
429433 ||>> chop (n - m2)
430434 ||>> chop (num_vars * (n - m3))
431435 ||>> chop (length bind_ts - m4)
432- ||>> apfst hd o chop 1
433436 ||> hd;
434437
435438 fun map_id0_of_mr_bnf (Inl mrbnf) = [MRBNF_Def.map_id0_of_mrbnf mrbnf]
@@ -578,6 +581,99 @@ fun binder_inductive_cmd ((pred_name, binds_opt), perms_supps) no_defs_lthy =
578581
579582 val perm_ids = map (fn thm => thm RS fun_cong RS @{thm trans[OF _ id_apply]}) perm_id0s;
580583
584+ val _ = @{print} (map snd perms)
585+ val G_equiv =
586+ Goal.prove_sorry lthy [] [] G_equiv_goal (fn {context=ctxt, ...} => EVERY1 [
587+ K (Local_Defs.unfold0_tac ctxt [snd G]),
588+ REPEAT_DETERM o EVERY' [
589+ TRY o etac ctxt @{thm disj_forward},
590+ SELECT_GOAL (print_tac ctxt " 0" ),
591+ REPEAT_DETERM o eresolve_tac ctxt [exE, conjE],
592+ K (print_tac ctxt " 0.1" ),
593+ (* hyp_subst_tac ctxt,*)
594+ REPEAT_DETERM_N (length param_Ts + 1 ) o etac ctxt @{thm subst[OF sym]},
595+ K (print_tac ctxt " 0.2" ),
596+ Subgoal.FOCUS_PARAMS (fn {context=ctxt, params, ...} =>
597+ let
598+ val (fs, args) = map (Thm.term_of o snd) params
599+ |> drop 2
600+ |> chop 1
601+ ||> drop (length param_Ts);
602+ val (mr_bnfs, ts) = apfst (map snd o flat) (split_list (map (fn x => case find_index (curry (op =) (fastype_of x)) param_Ts of
603+ ~1 => (case find_index (curry (op =) (fastype_of x)) var_Ts of
604+ ~1 => apsnd (fn t => t $ x) (build_permute_for fs var_Ts (fastype_of x))
605+ | n => ([], nth fs n $ x))
606+ | n => ([], Term.list_comb (fst (nth perms n), fs) $ x)
607+ ) args));
608+ val equiv_commute = Named_Theorems.get ctxt " MRBNF_Recursor.equiv_commute" ;
609+ val equiv = Named_Theorems.get ctxt " MRBNF_Recursor.equiv" @ equiv_commute;
610+ val equiv_simps = Named_Theorems.get ctxt " MRBNF_Recursor.equiv_simps"
611+ val monos = Inductive.get_monos ctxt
612+ val set_maps = maps set_map_of_mr_bnf mr_bnfs;
613+ val _ = @{print} equiv
614+ val _ = @{print} (map (Thm.cterm_of ctxt) ts)
615+ val _ = @{print} set_maps
616+ val _ = @{print} (flat (map_filter (Option.map #permute_simps) param_sugars))
617+ in EVERY1 [
618+ K (print_tac ctxt " 1" ),
619+ EVERY' (map (fn t => rtac ctxt (
620+ infer_instantiate' ctxt [NONE , SOME (Thm.cterm_of ctxt t)] exI
621+ )) ts),
622+ K (print_tac ctxt " 1.1" ),
623+ SELECT_GOAL (Local_Defs.unfold0_tac ctxt (map snd perms)),
624+ rtac ctxt conjI,
625+
626+ K (print_tac ctxt " 1.2" ),
627+ SELECT_GOAL (Local_Defs.unfold0_tac ctxt (@{thms image_Un} @ equiv_simps)),
628+ REPEAT_DETERM o rtac ctxt @{thm arg_cong2[of _ _ _ _ " (\< union>)" ]},
629+ REPEAT_DETERM1 o EVERY' [
630+ K (print_tac ctxt " 1.3" ),
631+ resolve_tac ctxt @{thms image_single[symmetric] image_empty refl} ORELSE' EVERY' [
632+ resolve_tac ctxt (map (fn thm => thm RS sym) (set_maps @ equiv_simps) @ equiv_simps),
633+ REPEAT_DETERM o assume_tac ctxt
634+ ]
635+ ],
636+ K (print_tac ctxt " 2" ),
637+ K (Local_Defs.unfold0_tac ctxt @{thms id_apply}),
638+ K (Local_Defs.unfold0_tac ctxt @{thms id_def[symmetric]}),
639+ REPEAT_DETERM o EVERY' [
640+ TRY o rtac ctxt conjI,
641+ SELECT_GOAL (EVERY1 [
642+ K (print_tac ctxt " foo" ),
643+ REPEAT_DETERM1 o (K (print_tac ctxt " wat" ) THEN' FIRST' [
644+ assume_tac ctxt,
645+ eresolve_tac ctxt [conjE],
646+ resolve_tac ctxt @{thms conjI refl TrueI bij_imp_bij_inv supp_inv_bound},
647+ rtac ctxt impI THEN' eresolve_tac ctxt @{thms injD[OF bij_is_inj, rotated -1 ]},
648+ EVERY' [
649+ SELECT_GOAL (Local_Defs.unfold0_tac ctxt (@{print}(map_filter (try (fn thm => thm RS sym)) equiv_commute))),
650+ REPEAT_DETERM1 o EVERY' [
651+ EqSubst.eqsubst_tac ctxt [0 ] (map (Local_Defs.unfold0 ctxt (map snd perms)) perm_comps),
652+ K (print_tac ctxt " comp" ),
653+ REPEAT_DETERM1 o (assume_tac ctxt ORELSE' resolve_tac ctxt @{thms supp_inv_bound bij_imp_bij_inv})
654+ ],
655+ K (Local_Defs.unfold0_tac ctxt @{thms inv_o_simp1 inv_o_simp2 inv_simp1 inv_simp2}),
656+ K (Local_Defs.unfold0_tac ctxt (map (Local_Defs.unfold0 ctxt (map snd perms)) perm_ids)),
657+ K (print_tac ctxt " after_comp" ),
658+ assume_tac ctxt
659+ ],
660+ eresolve_tac ctxt (map_filter (try (fn thm => Drule.rotate_prems ~1 thm)) equiv),
661+ CHANGED o SELECT_GOAL (Local_Defs.unfold0_tac ctxt (equiv @ equiv_simps @ flat (map_filter (Option.map #permute_simps) param_sugars))),
662+ (* EqSubst.eqsubst_tac ctxt [0] equiv,*)
663+ eresolve_tac ctxt (map (fn thm => Drule.rotate_prems ~1 (thm RS mp)) monos),
664+ resolve_tac ctxt monos,
665+ CHANGED o SELECT_GOAL (Local_Defs.unfold0_tac ctxt (flat (map_filter (Option.map (map (fn thm => thm RS sym) o #permute_simps)) param_sugars)))
666+ ])
667+ ])
668+ ],
669+ K (print_tac ctxt " 3" )
670+ ] end
671+ ) ctxt,
672+ K (print_tac ctxt " 4" )
673+ ]
674+ ]);
675+ val _ = @{print} G_equiv
676+
581677 fun mk_induct mono = Drule.rotate_prems ~1 (
582678 apply_n @{thm le_funD} n (@{thm lfp_induct} OF [mono])
583679 RS @{thm le_boolD}
0 commit comments