1 theory LFex |
1 theory LFex |
2 imports "Nominal2_Atoms" "Nominal2_Eqvt" "Nominal2_Supp" "Abs" "Perm" "Fv" "Rsp" |
2 imports "Parser" |
3 begin |
3 begin |
4 |
4 |
5 atom_decl name |
5 atom_decl name |
6 atom_decl ident |
6 atom_decl ident |
7 |
7 |
8 datatype rkind = |
8 ML {* restricted_nominal := false *} |
|
9 |
|
10 nominal_datatype kind = |
9 Type |
11 Type |
10 | KPi "rty" "name" "rkind" |
12 | KPi "ty" n::"name" k::"kind" bind n in k |
11 and rty = |
13 and ty = |
12 TConst "ident" |
14 TConst "ident" |
13 | TApp "rty" "rtrm" |
15 | TApp "ty" "trm" |
14 | TPi "rty" "name" "rty" |
16 | TPi "ty" n::"name" t::"ty" bind n in t |
15 and rtrm = |
17 and trm = |
16 Const "ident" |
18 Const "ident" |
17 | Var "name" |
19 | Var "name" |
18 | App "rtrm" "rtrm" |
20 | App "trm" "trm" |
19 | Lam "rty" "name" "rtrm" |
21 | Lam "ty" n::"name" t::"trm" bind n in t |
20 |
|
21 |
|
22 setup {* snd o define_raw_perms (Datatype.the_info @{theory} "LFex.rkind") 3 *} |
|
23 print_theorems |
|
24 |
|
25 local_setup {* |
|
26 snd o define_fv_alpha (Datatype.the_info @{theory} "LFex.rkind") |
|
27 [[ [], [(NONE, 1, 2)]], |
|
28 [ [], [], [(NONE, 1, 2)] ], |
|
29 [ [], [], [], [(NONE, 1, 2)]]] *} |
|
30 notation |
|
31 alpha_rkind ("_ \<approx>ki _" [100, 100] 100) |
|
32 and alpha_rty ("_ \<approx>ty _" [100, 100] 100) |
|
33 and alpha_rtrm ("_ \<approx>tr _" [100, 100] 100) |
|
34 thm fv_rkind_fv_rty_fv_rtrm.simps alpha_rkind_alpha_rty_alpha_rtrm.intros |
|
35 local_setup {* (fn ctxt => snd (Local_Theory.note ((@{binding alpha_rkind_alpha_rty_alpha_rtrm_inj}, []), (build_alpha_inj @{thms alpha_rkind_alpha_rty_alpha_rtrm.intros} @{thms rkind.distinct rty.distinct rtrm.distinct rkind.inject rty.inject rtrm.inject} @{thms alpha_rkind.cases alpha_rty.cases alpha_rtrm.cases} ctxt)) ctxt)) *} |
|
36 thm alpha_rkind_alpha_rty_alpha_rtrm_inj |
|
37 |
|
38 lemma rfv_eqvt[eqvt]: |
|
39 "((pi\<bullet>fv_rkind t1) = fv_rkind (pi\<bullet>t1))" |
|
40 "((pi\<bullet>fv_rty t2) = fv_rty (pi\<bullet>t2))" |
|
41 "((pi\<bullet>fv_rtrm t3) = fv_rtrm (pi\<bullet>t3))" |
|
42 apply(induct t1 and t2 and t3 rule: rkind_rty_rtrm.inducts) |
|
43 apply(simp_all add: union_eqvt Diff_eqvt) |
|
44 apply(simp_all add: permute_set_eq atom_eqvt) |
|
45 done |
|
46 |
|
47 lemma alpha_eqvt: |
|
48 "(t1 \<approx>ki s1 \<longrightarrow> (p \<bullet> t1) \<approx>ki (p \<bullet> s1)) \<and> |
|
49 (t2 \<approx>ty s2 \<longrightarrow> (p \<bullet> t2) \<approx>ty (p \<bullet> s2)) \<and> |
|
50 (t3 \<approx>tr s3 \<longrightarrow> (p \<bullet> t3) \<approx>tr (p \<bullet> s3))" |
|
51 apply(rule alpha_rkind_alpha_rty_alpha_rtrm.induct) |
|
52 apply (simp_all add: alpha_rkind_alpha_rty_alpha_rtrm_inj) |
|
53 apply (erule_tac [!] conjE)+ |
|
54 apply (erule_tac [!] exi[of _ _ "p"]) |
|
55 apply (erule_tac [!] alpha_gen_compose_eqvt) |
|
56 apply (simp_all add: rfv_eqvt eqvts atom_eqvt) |
|
57 done |
|
58 |
|
59 local_setup {* (fn ctxt => snd (Local_Theory.note ((@{binding alpha_equivps}, []), |
|
60 (build_equivps [@{term alpha_rkind}, @{term alpha_rty}, @{term alpha_rtrm}] |
|
61 @{thm rkind_rty_rtrm.induct} @{thm alpha_rkind_alpha_rty_alpha_rtrm.induct} |
|
62 @{thms rkind.inject rty.inject rtrm.inject} @{thms alpha_rkind_alpha_rty_alpha_rtrm_inj} |
|
63 @{thms rkind.distinct rty.distinct rtrm.distinct} |
|
64 @{thms alpha_rkind.cases alpha_rty.cases alpha_rtrm.cases} |
|
65 @{thms alpha_eqvt} ctxt)) ctxt)) *} |
|
66 thm alpha_equivps |
|
67 |
|
68 local_setup {* define_quotient_type |
|
69 [(([], @{binding kind}, NoSyn), (@{typ rkind}, @{term alpha_rkind})), |
|
70 (([], @{binding ty}, NoSyn), (@{typ rty}, @{term alpha_rty} )), |
|
71 (([], @{binding trm}, NoSyn), (@{typ rtrm}, @{term alpha_rtrm} ))] |
|
72 (ALLGOALS (resolve_tac @{thms alpha_equivps})) |
|
73 *} |
|
74 |
|
75 local_setup {* |
|
76 (fn ctxt => ctxt |
|
77 |> snd o (Quotient_Def.quotient_lift_const ("TYP", @{term Type})) |
|
78 |> snd o (Quotient_Def.quotient_lift_const ("KPI", @{term KPi})) |
|
79 |> snd o (Quotient_Def.quotient_lift_const ("TCONST", @{term TConst})) |
|
80 |> snd o (Quotient_Def.quotient_lift_const ("TAPP", @{term TApp})) |
|
81 |> snd o (Quotient_Def.quotient_lift_const ("TPI", @{term TPi})) |
|
82 |> snd o (Quotient_Def.quotient_lift_const ("CONS", @{term Const})) |
|
83 |> snd o (Quotient_Def.quotient_lift_const ("VAR", @{term Var})) |
|
84 |> snd o (Quotient_Def.quotient_lift_const ("APP", @{term App})) |
|
85 |> snd o (Quotient_Def.quotient_lift_const ("LAM", @{term Lam})) |
|
86 |> snd o (Quotient_Def.quotient_lift_const ("fv_kind", @{term fv_rkind})) |
|
87 |> snd o (Quotient_Def.quotient_lift_const ("fv_ty", @{term fv_rty})) |
|
88 |> snd o (Quotient_Def.quotient_lift_const ("fv_trm", @{term fv_rtrm}))) *} |
|
89 print_theorems |
|
90 |
|
91 local_setup {* snd o prove_const_rsp @{binding rfv_rsp} [@{term fv_rkind}, @{term fv_rty}, @{term fv_rtrm}] |
|
92 (fn _ => fvbv_rsp_tac @{thm alpha_rkind_alpha_rty_alpha_rtrm.induct} @{thms fv_rkind_fv_rty_fv_rtrm.simps} 1) *} |
|
93 local_setup {* snd o prove_const_rsp Binding.empty [@{term "permute :: perm \<Rightarrow> rkind \<Rightarrow> rkind"}, @{term "permute :: perm \<Rightarrow> rty \<Rightarrow> rty"}, @{term "permute :: perm \<Rightarrow> rtrm \<Rightarrow> rtrm"}] |
|
94 (fn _ => asm_simp_tac (HOL_ss addsimps @{thms alpha_eqvt}) 1) *} |
|
95 ML {* fun const_rsp_tac _ = constr_rsp_tac @{thms alpha_rkind_alpha_rty_alpha_rtrm_inj} |
|
96 @{thms rfv_rsp} @{thms alpha_equivps} 1 *} |
|
97 local_setup {* snd o prove_const_rsp Binding.empty [@{term TConst}] const_rsp_tac *} |
|
98 local_setup {* snd o prove_const_rsp Binding.empty [@{term TApp}] const_rsp_tac *} |
|
99 local_setup {* snd o prove_const_rsp Binding.empty [@{term Var}] const_rsp_tac *} |
|
100 local_setup {* snd o prove_const_rsp Binding.empty [@{term App}] const_rsp_tac *} |
|
101 local_setup {* snd o prove_const_rsp Binding.empty [@{term Const}] const_rsp_tac *} |
|
102 local_setup {* snd o prove_const_rsp Binding.empty [@{term KPi}] const_rsp_tac *} |
|
103 local_setup {* snd o prove_const_rsp Binding.empty [@{term TPi}] const_rsp_tac *} |
|
104 local_setup {* snd o prove_const_rsp Binding.empty [@{term Lam}] const_rsp_tac *} |
|
105 |
|
106 lemmas kind_ty_trm_induct = rkind_rty_rtrm.induct[quot_lifted] |
|
107 |
|
108 thm rkind_rty_rtrm.inducts |
|
109 lemmas kind_ty_trm_inducts = rkind_rty_rtrm.inducts[quot_lifted] |
|
110 |
|
111 setup {* define_lifted_perms ["LFex.kind", "LFex.ty", "LFex.trm"] |
|
112 [("permute_kind", @{term "permute :: perm \<Rightarrow> rkind \<Rightarrow> rkind"}), |
|
113 ("permute_ty", @{term "permute :: perm \<Rightarrow> rty \<Rightarrow> rty"}), |
|
114 ("permute_trm", @{term "permute :: perm \<Rightarrow> rtrm \<Rightarrow> rtrm"})] |
|
115 @{thms permute_rkind_permute_rty_permute_rtrm_zero permute_rkind_permute_rty_permute_rtrm_append} *} |
|
116 |
|
117 (* |
|
118 Lifts, but slow and not needed?. |
|
119 lemmas alpha_kind_alpha_ty_alpha_trm_induct = alpha_rkind_alpha_rty_alpha_rtrm.induct[unfolded alpha_gen, quot_lifted, folded alpha_gen] |
|
120 *) |
|
121 |
|
122 lemmas permute_ktt[simp] = permute_rkind_permute_rty_permute_rtrm.simps[quot_lifted] |
|
123 |
|
124 lemmas kind_ty_trm_inj = alpha_rkind_alpha_rty_alpha_rtrm_inj[unfolded alpha_gen, quot_lifted, folded alpha_gen] |
|
125 |
|
126 lemmas fv_kind_ty_trm = fv_rkind_fv_rty_fv_rtrm.simps[quot_lifted] |
|
127 |
|
128 lemmas fv_eqvt = rfv_eqvt[quot_lifted] |
|
129 |
22 |
130 lemma supports: |
23 lemma supports: |
131 "{} supports TYP" |
24 "{} supports Type" |
132 "(supp (atom i)) supports (TCONST i)" |
25 "(supp (atom i)) supports (TConst i)" |
133 "(supp A \<union> supp M) supports (TAPP A M)" |
26 "(supp A \<union> supp M) supports (TApp A M)" |
134 "(supp (atom i)) supports (CONS i)" |
27 "(supp (atom i)) supports (Const i)" |
135 "(supp (atom x)) supports (VAR x)" |
28 "(supp (atom x)) supports (Var x)" |
136 "(supp M \<union> supp N) supports (APP M N)" |
29 "(supp M \<union> supp N) supports (App M N)" |
137 "(supp ty \<union> supp (atom na) \<union> supp ki) supports (KPI ty na ki)" |
30 "(supp ty \<union> supp (atom na) \<union> supp ki) supports (KPi ty na ki)" |
138 "(supp ty \<union> supp (atom na) \<union> supp ty2) supports (TPI ty na ty2)" |
31 "(supp ty \<union> supp (atom na) \<union> supp ty2) supports (TPi ty na ty2)" |
139 "(supp ty \<union> supp (atom na) \<union> supp trm) supports (LAM ty na trm)" |
32 "(supp ty \<union> supp (atom na) \<union> supp trm) supports (Lam ty na trm)" |
140 apply(simp_all add: supports_def fresh_def[symmetric] swap_fresh_fresh) |
33 apply(simp_all add: supports_def fresh_def[symmetric] swap_fresh_fresh kind_ty_trm_perm) |
141 apply(rule_tac [!] allI)+ |
34 apply(rule_tac [!] allI)+ |
142 apply(rule_tac [!] impI) |
35 apply(rule_tac [!] impI) |
143 apply(tactic {* ALLGOALS (REPEAT o etac conjE) *}) |
36 apply(tactic {* ALLGOALS (REPEAT o etac conjE) *}) |
144 apply(simp_all add: fresh_atom) |
37 apply(simp_all add: fresh_atom) |
145 done |
38 done |
146 |
39 |
147 lemma kind_ty_trm_fs: |
40 lemma kind_ty_trm_fs: |
148 "finite (supp (x\<Colon>kind))" |
41 "finite (supp (x\<Colon>kind)) \<and> finite (supp (y\<Colon>ty)) \<and> finite (supp (z\<Colon>trm))" |
149 "finite (supp (y\<Colon>ty))" |
42 apply(induct rule: kind_ty_trm_induct) |
150 "finite (supp (z\<Colon>trm))" |
|
151 apply(induct x and y and z rule: kind_ty_trm_inducts) |
|
152 apply(tactic {* ALLGOALS (rtac @{thm supports_finite} THEN' resolve_tac @{thms supports}) *}) |
43 apply(tactic {* ALLGOALS (rtac @{thm supports_finite} THEN' resolve_tac @{thms supports}) *}) |
153 apply(simp_all add: supp_atom) |
44 apply(simp_all add: supp_atom) |
154 done |
45 done |
155 |
46 |
156 instance kind and ty and trm :: fs |
47 instance kind and ty and trm :: fs |
164 "(\<exists>x. P x \<and> Q \<and> Z x) = (Q \<and> (\<exists>x. P x \<and> Z x))" |
55 "(\<exists>x. P x \<and> Q \<and> Z x) = (Q \<and> (\<exists>x. P x \<and> Z x))" |
165 "(\<exists>x. Q \<and> P x \<and> Z x) = (Q \<and> (\<exists>x. P x \<and> Z x))" |
56 "(\<exists>x. Q \<and> P x \<and> Z x) = (Q \<and> (\<exists>x. P x \<and> Z x))" |
166 apply (blast)+ |
57 apply (blast)+ |
167 done |
58 done |
168 |
59 |
|
60 lemma Collect_neg_conj: "{x. \<not>(P x \<and> Q x)} = {x. \<not>(P x)} \<union> {x. \<not>(Q x)}" |
|
61 by (simp add: Collect_imp_eq Collect_neg_eq[symmetric]) |
|
62 |
169 lemma supp_eqs: |
63 lemma supp_eqs: |
170 "supp TYP = {}" |
64 "supp Type = {}" |
171 "supp rkind = fv_kind rkind \<Longrightarrow> supp (KPI rty name rkind) = supp rty \<union> supp (Abs {atom name} rkind)" |
65 "supp rkind = fv_kind rkind \<Longrightarrow> supp (KPi rty name rkind) = supp rty \<union> supp (Abs {atom name} rkind)" |
172 "supp (TCONST i) = {atom i}" |
66 "supp (TConst i) = {atom i}" |
173 "supp (TAPP A M) = supp A \<union> supp M" |
67 "supp (TApp A M) = supp A \<union> supp M" |
174 "supp rty2 = fv_ty rty2 \<Longrightarrow> supp (TPI rty1 name rty2) = supp rty1 \<union> supp (Abs {atom name} rty2)" |
68 "supp rty2 = fv_ty rty2 \<Longrightarrow> supp (TPi rty1 name rty2) = supp rty1 \<union> supp (Abs {atom name} rty2)" |
175 "supp (CONS i) = {atom i}" |
69 "supp (Const i) = {atom i}" |
176 "supp (VAR x) = {atom x}" |
70 "supp (Var x) = {atom x}" |
177 "supp (APP M N) = supp M \<union> supp N" |
71 "supp (App M N) = supp M \<union> supp N" |
178 "supp rtrm = fv_trm rtrm \<Longrightarrow> supp (LAM rty name rtrm) = supp rty \<union> supp (Abs {atom name} rtrm)" |
72 "supp rtrm = fv_trm rtrm \<Longrightarrow> supp (Lam rty name rtrm) = supp rty \<union> supp (Abs {atom name} rtrm)" |
179 apply(simp_all (no_asm) add: supp_def permute_set_eq atom_eqvt) |
73 apply(simp_all (no_asm) add: supp_def permute_set_eq atom_eqvt kind_ty_trm_perm) |
180 apply(simp_all only: kind_ty_trm_inj Abs_eq_iff alpha_gen) |
74 apply(simp_all only: kind_ty_trm_inject Abs_eq_iff alpha_gen) |
181 apply(simp_all only:ex_out) |
75 apply(simp_all only: ex_out) |
182 apply(simp_all only: supp_eqvt[symmetric] fv_eqvt[symmetric] eqvts[symmetric]) |
76 apply(simp_all only: eqvts[symmetric]) |
183 apply(simp_all add: Collect_imp_eq Collect_neg_eq[symmetric]) |
77 apply(simp_all only: Collect_neg_conj) |
184 apply(simp_all add: supp_at_base[simplified supp_def] Un_commute) |
78 apply(simp_all only: supp_at_base[simplified supp_def] Un_commute Un_assoc) |
|
79 apply(simp_all add: Collect_imp_eq Collect_neg_eq[symmetric] Un_commute Un_assoc) |
|
80 apply(simp_all add: Un_left_commute) |
185 done |
81 done |
186 |
82 |
187 |
|
188 lemma supp_fv: |
83 lemma supp_fv: |
189 "supp t1 = fv_kind t1" |
84 "supp t1 = fv_kind t1 \<and> supp t2 = fv_ty t2 \<and> supp t3 = fv_trm t3" |
190 "supp t2 = fv_ty t2" |
85 apply(induct rule: kind_ty_trm_induct) |
191 "supp t3 = fv_trm t3" |
86 apply(simp_all (no_asm) only: supp_eqs kind_ty_trm_fv) |
192 apply(induct t1 and t2 and t3 rule: kind_ty_trm_inducts) |
|
193 apply(simp_all (no_asm) only: supp_eqs fv_kind_ty_trm) |
|
194 apply(simp_all) |
87 apply(simp_all) |
195 apply(subst supp_eqs) |
88 apply(simp_all add: supp_eqs) |
196 apply(simp_all add: supp_Abs) |
|
197 apply(subst supp_eqs) |
|
198 apply(simp_all add: supp_Abs) |
|
199 apply(subst supp_eqs) |
|
200 apply(simp_all add: supp_Abs) |
89 apply(simp_all add: supp_Abs) |
201 done |
90 done |
202 |
91 |
203 lemma supp_rkind_rty_rtrm: |
92 lemma supp_rkind_rty_rtrm: |
204 "supp TYP = {}" |
93 "supp Type = {}" |
205 "supp (KPI A x K) = supp A \<union> (supp K - {atom x})" |
94 "supp (KPi A x K) = supp A \<union> (supp K - {atom x})" |
206 "supp (TCONST i) = {atom i}" |
95 "supp (TConst i) = {atom i}" |
207 "supp (TAPP A M) = supp A \<union> supp M" |
96 "supp (TApp A M) = supp A \<union> supp M" |
208 "supp (TPI A x B) = supp A \<union> (supp B - {atom x})" |
97 "supp (TPi A x B) = supp A \<union> (supp B - {atom x})" |
209 "supp (CONS i) = {atom i}" |
98 "supp (Const i) = {atom i}" |
210 "supp (VAR x) = {atom x}" |
99 "supp (Var x) = {atom x}" |
211 "supp (APP M N) = supp M \<union> supp N" |
100 "supp (App M N) = supp M \<union> supp N" |
212 "supp (LAM A x M) = supp A \<union> (supp M - {atom x})" |
101 "supp (Lam A x M) = supp A \<union> (supp M - {atom x})" |
213 by (simp_all only: supp_fv fv_kind_ty_trm) |
102 apply (simp_all add: supp_fv kind_ty_trm_fv) |
214 |
103 |
215 end |
104 end |
216 |
105 |
217 |
106 |
218 |
107 |