Skip to content

Commit 60c5b35

Browse files
committed
Automate initial version of equivariance proof
Works for all cases except InfFOL and Mazza
1 parent 59cbbdb commit 60c5b35

File tree

18 files changed

+425
-324
lines changed

18 files changed

+425
-324
lines changed

Tools/binder_inductive.ML

Lines changed: 100 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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}

Tools/mrbnf_sugar.ML

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ fun create_binder_datatype (spec : spec) lthy =
427427
])] end
428428
) ctors_tys) ctors_tys));
429429

430-
(* TODO: map_bij (rename simps); injection *)
430+
(* TODO: injection *)
431431

432432
(* Term for variable substitution *)
433433
val x = length replace - #rec_vars spec;

thys/Infinitary_FOL/InfFOL.thy

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,7 @@ unfolding kmember_def map_fun_def id_o o_id map_set\<^sub>k_def
231231
unfolding comp_def Abs_set\<^sub>k_inverse[OF UNIV_I]
232232
apply transfer apply transfer by blast
233233

234-
lemma in_k_equiv: "isPerm \<sigma> \<Longrightarrow> rrename_ifol' \<sigma> f \<in>\<^sub>k map_set\<^sub>k (rrename_ifol' \<sigma>) \<Delta> = f \<in>\<^sub>k \<Delta>"
235-
unfolding isPerm_def
236-
apply (erule conjE)
234+
lemma in_k_equiv[equiv]: "bij (\<sigma>::'a::var_ifol'_pre \<Rightarrow> 'a) \<Longrightarrow> |supp \<sigma>| <o |UNIV::'a set| \<Longrightarrow> rrename_ifol' \<sigma> f \<in>\<^sub>k map_set\<^sub>k (rrename_ifol' \<sigma>) \<Delta> = f \<in>\<^sub>k \<Delta>"
237235
apply (rule iffI)
238236
apply (drule in_k_equiv'[rotated])
239237
apply (rule bij_imp_bij_inv)
@@ -251,13 +249,11 @@ lemma in_k_equiv: "isPerm \<sigma> \<Longrightarrow> rrename_ifol' \<sigma> f \<
251249
apply assumption
252250
done
253251

254-
lemma in_k1_equiv': "bij \<sigma> \<Longrightarrow> f \<in>\<^sub>k\<^sub>1 F \<Longrightarrow> rrename_ifol' \<sigma> f \<in>\<^sub>k\<^sub>1 map_set\<^sub>k\<^sub>1 (rrename_ifol' \<sigma>) F"
252+
lemma in_k1_equiv'[equiv]: "bij \<sigma> \<Longrightarrow> f \<in>\<^sub>k\<^sub>1 F \<Longrightarrow> rrename_ifol' \<sigma> f \<in>\<^sub>k\<^sub>1 map_set\<^sub>k\<^sub>1 (rrename_ifol' \<sigma>) F"
255253
apply (unfold k1member_def map_fun_def comp_def id_def map_set\<^sub>k\<^sub>1_def Abs_set\<^sub>k\<^sub>1_inverse[OF UNIV_I])
256254
apply transfer apply transfer by blast
257255

258-
lemma in_k1_equiv: "isPerm \<sigma> \<Longrightarrow> rrename_ifol' \<sigma> f \<in>\<^sub>k\<^sub>1 map_set\<^sub>k\<^sub>1 (rrename_ifol' \<sigma>) \<Delta> = f \<in>\<^sub>k\<^sub>1 \<Delta>"
259-
unfolding isPerm_def
260-
apply (erule conjE)
256+
lemma in_k1_equiv[equiv]: "bij (\<sigma>::'a::var_ifol'_pre \<Rightarrow> 'a) \<Longrightarrow> |supp \<sigma>| <o |UNIV::'a set| \<Longrightarrow> rrename_ifol' \<sigma> f \<in>\<^sub>k\<^sub>1 map_set\<^sub>k\<^sub>1 (rrename_ifol' \<sigma>) \<Delta> = f \<in>\<^sub>k\<^sub>1 \<Delta>"
261257
apply (rule iffI)
262258
apply (drule in_k1_equiv'[rotated])
263259
apply (rule bij_imp_bij_inv)
@@ -340,7 +336,7 @@ inductive deduct :: "ifol set\<^sub>k \<Rightarrow> ifol \<Rightarrow> bool" (in
340336
| AllE: "\<lbrakk> \<Delta> \<turnstile> All V f ; supp \<rho> \<subseteq> set\<^sub>k\<^sub>2 V \<rbrakk> \<Longrightarrow> \<Delta> \<turnstile> f\<lbrakk>\<rho>\<rbrakk>"
341337

342338
binder_inductive deduct
343-
subgoal for R B \<sigma> x1 x2
339+
(* subgoal for R B \<sigma> x1 x2
344340
unfolding induct_rulify_fallback split_beta
345341
apply (elim disj_forward exE)
346342
apply (auto simp: ifol'.rrename_comps in_k_equiv in_k_equiv' isPerm_def ifol'.rrename_ids supp_inv_bound)
@@ -412,8 +408,8 @@ binder_inductive deduct
412408
apply (metis ifol'.rrename_bijs ifol'.rrename_inv_simps inv_simp1 set\<^sub>k.map_ident_strong)
413409
apply (erule image_mono)
414410
done
415-
done
416-
subgoal premises prems for R B \<Delta> x2
411+
done*)
412+
(* subgoal premises prems for R B \<Delta> x2
417413
using prems(2-) unfolding induct_rulify_fallback split_beta
418414
unfolding ex_push_inwards conj_disj_distribL ex_disj_distrib
419415
apply (elim disj_forward)
@@ -602,7 +598,12 @@ binder_inductive deduct
602598
by (smt (verit) Int_iff Un_Int_eq(1) X_def \<sigma>_def bij_betw_apply disjoint_iff image_iff)
603599
qed
604600
done
605-
done
601+
done*)
602+
sorry
603+
604+
lemma all_mono_bij:
605+
"bij f \<Longrightarrow> (\<And>x. P x \<longrightarrow> Q (f x)) \<Longrightarrow> (\<forall>x. P x) \<longrightarrow> (\<forall>x. Q x)"
606+
by (metis bij_pointE)
606607

607608
thm deduct.strong_induct
608609
thm deduct.equiv

thys/Infinitary_Lambda_Calculus/ILC.thy

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ lemma inj_embed: "inj embed"
7171
unfolding embed_def
7272
by (rule someI_ex[OF ex_inj_infinite_regular_var_iterm_pre[where 'a='a]])
7373

74-
7574
(****************************)
7675
(* DATATYPE-SPECIFIC CUSTOMIZATION *)
7776

@@ -831,11 +830,11 @@ unfolding imkSubst_def by auto
831830
lemma card_dsset_ivar: "|dsset xs| <o |UNIV::ivar set|"
832831
using countable_card_ivar countable_card_le_natLeq dsset_natLeq by auto
833832

834-
lemma SSupp_imkSubst[simp,intro]: "|SSupp (imkSubst xs es)| <o |UNIV::ivar set|"
833+
lemma SSupp_imkSubst[simp,intro]: "|SSupp (imkSubst xs es)| <o |UNIV::'a::var_iterm_pre set|"
835834
proof-
836835
have "SSupp (imkSubst xs es) \<subseteq> dsset xs"
837836
unfolding SSupp_def by auto (metis imkSubst_idle)
838-
thus ?thesis by (simp add: card_of_subset_bound card_dsset_ivar)
837+
thus ?thesis by (simp add: card_of_subset_bound dsset_card_ls)
839838
qed
840839

841840
lemma imkSubst_smap_irrename:
@@ -947,7 +946,16 @@ proof-
947946
imkSubst_idle imkSubst_smap iterm.set(3) not_imageI) . . .
948947
qed
949948

950-
949+
lemma irrename_itvsubst[equiv_commute]:
950+
fixes \<sigma>::"ivar \<Rightarrow> ivar"
951+
shows "bij \<sigma> \<Longrightarrow> |supp \<sigma>| <o |UNIV::ivar set|
952+
\<Longrightarrow> irrename \<sigma> (itvsubst (imkSubst xs es2) e1) = itvsubst (imkSubst (dsmap \<sigma> xs) (smap (irrename \<sigma>) es2)) (irrename \<sigma> e1)"
953+
apply (rule trans)
954+
apply (rule box_equals[OF iterm.rrename_tvsubst[THEN fun_cong] comp_apply comp_apply])
955+
apply assumption+
956+
apply (rule SSupp_imkSubst)
957+
apply (rule arg_cong2[OF _ refl, of _ _ itvsubst])
958+
using imkSubst_smap_irrename[symmetric, of \<sigma>] by auto
951959

952960
(* RECURSOR PREPARATIONS: *)
953961

thys/Infinitary_Lambda_Calculus/ILC_Beta.thy

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -25,41 +25,6 @@ inductive istep :: "itrm \<Rightarrow> itrm \<Rightarrow> bool" where
2525
| Xi: "istep e e' \<Longrightarrow> istep (iLam xs e) (iLam xs e')"
2626

2727
binder_inductive istep
28-
subgoal for R B \<sigma> x1 x2
29-
apply (elim disj_forward exE conjE)
30-
subgoal for xs e1 es2
31-
apply(rule exI[of _ "dsmap \<sigma> xs"])
32-
apply(rule exI[of _ "irrename \<sigma> e1"])
33-
apply(rule exI[of _ "smap (irrename \<sigma>) es2"])
34-
apply (simp add: iterm.rrename_comps) apply(subst irrename_itvsubst_comp) apply auto
35-
apply(subst imkSubst_smap_irrename_inv) unfolding isPerm_def apply auto
36-
apply(subst irrename_eq_itvsubst_iVar'[of _ e1]) unfolding isPerm_def apply auto
37-
apply(subst itvsubst_comp)
38-
subgoal by (metis SSupp_imkSubst imkSubst_smap_irrename_inv)
39-
subgoal by (smt (verit, best) SSupp_def VVr_eq_Var card_of_subset_bound mem_Collect_eq not_in_supp_alt o_apply subsetI)
40-
subgoal apply(rule itvsubst_cong)
41-
subgoal using SSupp_irrename_bound by blast
42-
subgoal using card_SSupp_itvsubst_imkSubst_irrename_inv isPerm_def by auto
43-
subgoal for x apply simp apply(subst iterm.subst(1))
44-
subgoal using card_SSupp_imkSubst_irrename_inv[unfolded isPerm_def] by auto
45-
subgoal by simp . . .
46-
(* *)
47-
subgoal for e1 e1' es2
48-
apply(rule exI[of _ "irrename \<sigma> e1"]) apply(rule exI[of _ "irrename \<sigma> e1'"])
49-
apply(rule exI[of _ "smap (irrename \<sigma>) es2"])
50-
by (simp add: iterm.rrename_comps)
51-
(* *)
52-
subgoal for es2 i e2' e1
53-
apply(rule exI[of _ "smap (irrename \<sigma>) es2"])
54-
apply(rule exI[of _ i])
55-
apply(rule exI[of _ "irrename \<sigma> e2'"])
56-
apply(rule exI[of _ "irrename \<sigma> e1"])
57-
apply (simp add: iterm.rrename_comps) .
58-
(* *)
59-
subgoal for e e' xs
60-
apply(rule exI[of _ "irrename \<sigma> e"]) apply(rule exI[of _ "irrename \<sigma> e'"])
61-
apply(rule exI[of _ "dsmap \<sigma> xs"])
62-
by (simp add: iterm.rrename_comps) .
6328
subgoal premises prems for R B x1 x2
6429
using prems(2-) apply safe
6530
subgoal for xs e1 es2

thys/Infinitary_Lambda_Calculus/ILC_affine.thy

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ inductive affine :: "itrm \<Rightarrow> bool" where
2222
affine (iApp e1 es2)"
2323

2424
binder_inductive affine
25-
unfolding isPerm_def induct_rulify_fallback
25+
26+
(*unfolding isPerm_def induct_rulify_fallback
2627
subgoal for R B \<sigma> t
2728
apply(elim disjE)
2829
subgoal apply(rule disjI3_1)
@@ -50,7 +51,7 @@ binder_inductive affine
5051
done
5152
done
5253
done
53-
done
54+
done*)
5455
subgoal premises prems for R B t
5556
using prems(2-)
5657
apply safe

thys/MRBNF_Recursor.thy

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ ML_file \<open>../Tools/mrbnf_vvsubst.ML\<close>
1010
ML_file \<open>../Tools/mrbnf_tvsubst.ML\<close>
1111
ML_file \<open>../Tools/mrbnf_sugar.ML\<close>
1212

13+
named_theorems equiv
14+
named_theorems equiv_commute
15+
named_theorems equiv_simps
16+
17+
declare Un_iff[equiv_simps] de_Morgan_disj[equiv_simps]
18+
inj_image_mem_iff[OF bij_is_inj, equiv_simps]
19+
singleton_iff[equiv_simps] image_empty[equiv_simps]
20+
Int_Un_distrib[equiv_simps] Un_empty[equiv_simps]
21+
image_is_empty[equiv_simps] image_Int[OF bij_is_inj, symmetric, equiv_simps]
22+
inj_eq[OF bij_is_inj, equiv_simps] inj_eq[OF bij_is_inj, equiv_simps]
23+
image_insert[equiv_simps] insert_iff[equiv_simps] notin_empty_eq_True[equiv_simps]
24+
1325
context begin
1426
ML_file \<open>../Tools/binder_induction.ML\<close>
1527
end

0 commit comments

Comments
 (0)