@@ -379,7 +379,7 @@ fun binder_inductive_cmd (((options, pred_name), binds_opt), perms_supps) no_def
379379 val goals = map (single o rpair []) (
380380 keep_perm perm_id0_goals @ keep_perm perm_comp_goals @ keep_both supp_seminat_goals
381381 @ keep_both perm_support_goals @ keep_supp supp_small_goals @ flat (keep_binders B_small_goals)
382- @ option No_Equiv [G_equiv_goal] [] @ [G_refresh_goal]
382+ @ option No_Equiv [G_equiv_goal] [] @ option No_Refresh [G_refresh_goal] [ ]
383383 );
384384 fun after_qed thmss lthy =
385385 let
@@ -430,15 +430,14 @@ fun binder_inductive_cmd (((options, pred_name), binds_opt), perms_supps) no_def
430430 val m2 = length (filter not one_specified);
431431 val m3 = length (filter not supps_specified);
432432 val m4 = length (filter not binders_specified);
433- val (((((((perm_id0s, perm_comps), supp_seminats), perm_supports), supp_smalls), B_smalls), G_equivs), G_refresh ) = map hd thmss
433+ val (((((((perm_id0s, perm_comps), supp_seminats), perm_supports), supp_smalls), B_smalls), G_equivs), G_refreshs ) = map hd thmss
434434 |> chop (n - m)
435435 ||>> chop (n - m)
436436 ||>> chop (n - m2)
437437 ||>> chop (n - m2)
438438 ||>> chop (num_vars * (n - m3))
439439 ||>> chop (length bind_ts - m4)
440- ||>> chop (option No_Equiv 1 0 )
441- ||> hd;
440+ ||>> chop (option No_Equiv 1 0 );
442441
443442 fun map_id0_of_mr_bnf (Inl mrbnf) = [MRBNF_Def.map_id0_of_mrbnf mrbnf]
444443 | map_id0_of_mr_bnf (Inr (Inl bnf)) = [BNF_Def.map_id0_of_bnf bnf]
@@ -586,18 +585,13 @@ fun binder_inductive_cmd (((options, pred_name), binds_opt), perms_supps) no_def
586585
587586 val perm_ids = map (fn thm => thm RS fun_cong RS @{thm trans[OF _ id_apply]}) perm_id0s;
588587
589- val _ = @{print} (map snd perms)
590588 val G_equiv = if member (op =) options No_Equiv then hd G_equivs else
591589 Goal.prove_sorry lthy [] [] G_equiv_goal (fn {context=ctxt, ...} => EVERY1 [
592590 K (Local_Defs.unfold0_tac ctxt [snd G]),
593591 REPEAT_DETERM o EVERY' [
594592 TRY o etac ctxt @{thm disj_forward},
595- SELECT_GOAL (print_tac ctxt " 0" ),
596593 REPEAT_DETERM o eresolve_tac ctxt [exE, conjE],
597- K (print_tac ctxt " 0.1" ),
598- (* hyp_subst_tac ctxt,*)
599594 REPEAT_DETERM_N (length param_Ts + 1 ) o etac ctxt @{thm subst[OF sym]},
600- K (print_tac ctxt " 0.2" ),
601595 Subgoal.FOCUS_PARAMS (fn {context=ctxt, params, ...} =>
602596 let
603597 val (fs, args) = map (Thm.term_of o snd) params
@@ -615,70 +609,114 @@ fun binder_inductive_cmd (((options, pred_name), binds_opt), perms_supps) no_def
615609 val equiv_simps = Named_Theorems.get ctxt " MRBNF_Recursor.equiv_simps"
616610 val monos = Inductive.get_monos ctxt
617611 val set_maps = maps set_map_of_mr_bnf mr_bnfs;
618- val _ = @{print} equiv
619- val _ = @{print} (map (Thm.cterm_of ctxt) ts)
620- val _ = @{print} set_maps
621- val _ = @{print} (flat (map_filter (Option.map #permute_simps) param_sugars))
622612 in EVERY1 [
623- K (print_tac ctxt " 1" ),
624613 EVERY' (map (fn t => rtac ctxt (
625614 infer_instantiate' ctxt [NONE , SOME (Thm.cterm_of ctxt t)] exI
626615 )) ts),
627- K (print_tac ctxt " 1.1" ),
628616 SELECT_GOAL (Local_Defs.unfold0_tac ctxt (map snd perms)),
629617 rtac ctxt conjI,
630-
631- K (print_tac ctxt " 1.2" ),
632618 SELECT_GOAL (Local_Defs.unfold0_tac ctxt (@{thms image_Un} @ equiv_simps)),
633619 REPEAT_DETERM o rtac ctxt @{thm arg_cong2[of _ _ _ _ " (\< union>)" ]},
634620 REPEAT_DETERM1 o EVERY' [
635- K (print_tac ctxt " 1.3" ),
636621 resolve_tac ctxt @{thms image_single[symmetric] image_empty refl} ORELSE' EVERY' [
637622 resolve_tac ctxt (map (fn thm => thm RS sym) (set_maps @ equiv_simps) @ equiv_simps),
638623 REPEAT_DETERM o assume_tac ctxt
639624 ]
640625 ],
641- K (print_tac ctxt " 2" ),
642626 K (Local_Defs.unfold0_tac ctxt @{thms id_apply}),
643627 K (Local_Defs.unfold0_tac ctxt @{thms id_def[symmetric]}),
644628 REPEAT_DETERM o EVERY' [
645629 TRY o rtac ctxt conjI,
646630 SELECT_GOAL (EVERY1 [
647- K (print_tac ctxt " foo" ),
648- REPEAT_DETERM1 o (K (print_tac ctxt " wat" ) THEN' FIRST' [
631+ REPEAT_DETERM1 o FIRST' [
649632 assume_tac ctxt,
650633 eresolve_tac ctxt [conjE],
651634 resolve_tac ctxt @{thms conjI refl TrueI bij_imp_bij_inv supp_inv_bound},
652635 rtac ctxt impI THEN' eresolve_tac ctxt @{thms injD[OF bij_is_inj, rotated -1 ]},
653636 EVERY' [
654- SELECT_GOAL (Local_Defs.unfold0_tac ctxt (@{print}( map_filter (try (fn thm => thm RS sym)) equiv_commute) )),
637+ SELECT_GOAL (Local_Defs.unfold0_tac ctxt (map_filter (try (fn thm => thm RS sym)) equiv_commute)),
655638 REPEAT_DETERM1 o EVERY' [
656639 EqSubst.eqsubst_tac ctxt [0 ] (map (Local_Defs.unfold0 ctxt (map snd perms)) perm_comps),
657- K (print_tac ctxt " comp" ),
658640 REPEAT_DETERM1 o (assume_tac ctxt ORELSE' resolve_tac ctxt @{thms supp_inv_bound bij_imp_bij_inv})
659641 ],
660642 K (Local_Defs.unfold0_tac ctxt @{thms inv_o_simp1 inv_o_simp2 inv_simp1 inv_simp2}),
661643 K (Local_Defs.unfold0_tac ctxt (map (Local_Defs.unfold0 ctxt (map snd perms)) perm_ids)),
662- K (print_tac ctxt " after_comp" ),
663644 assume_tac ctxt
664645 ],
665646 eresolve_tac ctxt (map_filter (try (fn thm => Drule.rotate_prems ~1 thm)) equiv),
666647 CHANGED o SELECT_GOAL (Local_Defs.unfold0_tac ctxt (equiv @ equiv_simps @ flat (map_filter (Option.map #permute_simps) param_sugars))),
667- (* EqSubst.eqsubst_tac ctxt [0] equiv,*)
668648 eresolve_tac ctxt (map (fn thm => Drule.rotate_prems ~1 (thm RS mp)) monos),
669649 resolve_tac ctxt monos,
670650 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)))
671- ])
651+ ]
672652 ])
673- ],
674- K (print_tac ctxt " 3" )
653+ ]
675654 ] end
676- ) ctxt,
677- K (print_tac ctxt " 4" )
655+ ) ctxt
678656 ]
679657 ]);
680658 val _ = @{print} G_equiv
681659
660+ val G_refresh = if member (op =) options No_Refresh then hd (G_refreshs) else
661+ let
662+ val var_rules = map (fn thm =>
663+ let val t = Logic.unvarify_global (Thm.prop_of thm)
664+ in (map Free (rev (Term.add_frees t [])), t) end
665+ ) intrs;
666+
667+ fun collect_permutes _ (Free _) = []
668+ | collect_permutes _ (Var _) = []
669+ | collect_permutes _ (Bound _) = []
670+ | collect_permutes _ (Const _) = []
671+ | collect_permutes vars (Abs (_, _, t)) = collect_permutes vars t
672+ | collect_permutes vars (t as (t1 $ t2)) = case try (dest_Type o Term.body_type o fastype_of) t of
673+ NONE => collect_permutes vars t1 @ collect_permutes vars t2
674+ | SOME (s, _) => (case MRBNF_Sugar.binder_sugar_of no_defs_lthy s of
675+ NONE => collect_permutes vars t1 @ collect_permutes vars t2
676+ | SOME sugar =>
677+ let val (ctor, args) = Term.strip_comb t
678+ in case (map_filter I (map_index (fn (i, (t, _)) =>
679+ if (op =) (apply2 (fst o dest_Const) (t, ctor)) then
680+ SOME i else NONE
681+ ) (#ctors sugar))) of
682+ [] => collect_permutes vars t1 @ collect_permutes vars t2
683+ | ctor_idx::_ => (case nth (hd (#bsetss sugar)) ctor_idx of
684+ NONE => maps (collect_permutes vars) args
685+ | SOME _ =>
686+ let
687+ val arg_Ts = Term.binder_types (fastype_of ctor);
688+ val permute_bounds = nth (#permute_bounds sugar) ctor_idx;
689+ val var_args = map (fn t => if member (op =) vars t then SOME t else NONE ) args;
690+ val result = map_filter I (map2 (fn NONE => K NONE
691+ | SOME perm => Option.map (fn x => (x, perm))
692+ ) permute_bounds var_args);
693+
694+ val tyenv = @{fold 2 } (fn NONE => K I | SOME perm => fn T =>
695+ Sign.typ_match (Proof_Context.theory_of no_defs_lthy) (body_type (fastype_of perm), T)
696+ ) permute_bounds arg_Ts Vartab.empty;
697+
698+ in map (apsnd (Envir.subst_term (tyenv, Vartab.empty))) result
699+ @ maps (collect_permutes vars) args
700+ end
701+ )
702+ end
703+ );
704+ fun isNONE NONE = true
705+ | isNONE _ = false
706+ val permute_bounds = map (distinct (op =) o uncurry collect_permutes) var_rules;
707+ val matrix = map2 (fn (vars, _) => fn perms =>
708+ let val inner = map (AList.lookup (op =) perms) vars;
709+ in if forall isNONE inner then NONE else SOME inner end
710+ ) var_rules permute_bounds;
711+ val _ = @{print} (map (Option.map (map (Option.map (Thm.cterm_of lthy)))) matrix)
712+ in Goal.prove_sorry lthy [] [] G_refresh_goal (fn {context=ctxt, ...} => EVERY1 [
713+ K (Local_Defs.unfold0_tac ctxt (snd G :: map snd perms)),
714+ Subgoal.FOCUS (fn {context=ctxt, prems, ...} =>
715+ refreshability_tac false (map fst supps) matrix (nth prems 2 ) (nth prems 1 ) supp_smalls (map snd supps) ctxt
716+ ) ctxt
717+ ]) end ;
718+ val _ = @{print} G_refresh
719+
682720 fun mk_induct mono = Drule.rotate_prems ~1 (
683721 apply_n @{thm le_funD} n (@{thm lfp_induct} OF [mono])
684722 RS @{thm le_boolD}
0 commit comments