author | urbanc |
Thu, 12 Apr 2007 15:46:12 +0200 | |
changeset 22650 | 0c5b22076fb3 |
parent 22609 | 40ade470e319 |
child 22730 | 8bcc8809ed3b |
permissions | -rw-r--r-- |
22073 | 1 |
(* "$Id$" *) |
2 |
(* *) |
|
22082 | 3 |
(* Formalisation of the chapter on Logical Relations *) |
4 |
(* and a Case Study in Equivalence Checking *) |
|
5 |
(* by Karl Crary from the book on Advanced Topics in *) |
|
6 |
(* Types and Programming Languages, MIT Press 2005 *) |
|
7 |
||
8 |
(* The formalisation was done by Julien Narboux and *) |
|
22594
33a690455f88
add a few details in the Fst and Snd cases of unicity proof
narboux
parents:
22542
diff
changeset
|
9 |
(* Christian Urban. *) |
22073 | 10 |
|
11 |
theory Crary |
|
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
12 |
imports "../Nominal" |
22073 | 13 |
begin |
14 |
||
15 |
atom_decl name |
|
16 |
||
17 |
nominal_datatype ty = TBase |
|
18 |
| TUnit |
|
19 |
| Arrow "ty" "ty" ("_\<rightarrow>_" [100,100] 100) |
|
20 |
||
21 |
nominal_datatype trm = Unit |
|
22 |
| Var "name" |
|
23 |
| Lam "\<guillemotleft>name\<guillemotright>trm" ("Lam [_]._" [100,100] 100) |
|
24 |
| App "trm" "trm" |
|
25 |
| Const "nat" |
|
26 |
||
22494 | 27 |
types Ctxt = "(name\<times>ty) list" |
28 |
types Subst = "(name\<times>trm) list" |
|
29 |
||
22073 | 30 |
|
31 |
lemma perm_ty[simp]: |
|
32 |
fixes T::"ty" |
|
33 |
and pi::"name prm" |
|
34 |
shows "pi\<bullet>T = T" |
|
22542 | 35 |
by (induct T rule: ty.weak_induct) (simp_all) |
22073 | 36 |
|
37 |
lemma fresh_ty[simp]: |
|
38 |
fixes x::"name" |
|
39 |
and T::"ty" |
|
40 |
shows "x\<sharp>T" |
|
41 |
by (simp add: fresh_def supp_def) |
|
42 |
||
43 |
lemma ty_cases: |
|
44 |
fixes T::ty |
|
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
45 |
shows "(\<exists> T\<^isub>1 T\<^isub>2. T=T\<^isub>1\<rightarrow>T\<^isub>2) \<or> T=TUnit \<or> T=TBase" |
22542 | 46 |
by (induct T rule:ty.weak_induct) (auto) |
22073 | 47 |
|
48 |
instance ty :: size .. |
|
49 |
||
50 |
nominal_primrec |
|
51 |
"size (TBase) = 1" |
|
52 |
"size (TUnit) = 1" |
|
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
53 |
"size (T\<^isub>1\<rightarrow>T\<^isub>2) = size T\<^isub>1 + size T\<^isub>2" |
22073 | 54 |
by (rule TrueI)+ |
55 |
||
56 |
lemma ty_size_greater_zero[simp]: |
|
57 |
fixes T::"ty" |
|
58 |
shows "size T > 0" |
|
59 |
by (nominal_induct rule:ty.induct) (simp_all) |
|
60 |
||
22494 | 61 |
section {* Substitutions *} |
62 |
||
63 |
fun |
|
64 |
lookup :: "Subst \<Rightarrow> name \<Rightarrow> trm" |
|
65 |
where |
|
66 |
"lookup [] x = Var x" |
|
22501 | 67 |
| "lookup ((y,T)#\<theta>) x = (if x=y then T else lookup \<theta> x)" |
22494 | 68 |
|
69 |
lemma lookup_eqvt[eqvt]: |
|
70 |
fixes pi::"name prm" |
|
71 |
shows "pi\<bullet>(lookup \<theta> x) = lookup (pi\<bullet>\<theta>) (pi\<bullet>x)" |
|
72 |
by (induct \<theta>) (auto simp add: perm_bij) |
|
73 |
||
74 |
lemma lookup_fresh: |
|
75 |
fixes z::"name" |
|
76 |
assumes a: "z\<sharp>\<theta>" "z\<sharp>x" |
|
77 |
shows "z\<sharp> lookup \<theta> x" |
|
78 |
using a |
|
79 |
by (induct rule: lookup.induct) |
|
80 |
(auto simp add: fresh_list_cons) |
|
81 |
||
82 |
lemma lookup_fresh': |
|
83 |
assumes a: "z\<sharp>\<theta>" |
|
84 |
shows "lookup \<theta> z = Var z" |
|
85 |
using a |
|
86 |
by (induct rule: lookup.induct) |
|
87 |
(auto simp add: fresh_list_cons fresh_prod fresh_atm) |
|
88 |
||
89 |
consts |
|
90 |
psubst :: "Subst \<Rightarrow> trm \<Rightarrow> trm" ("_<_>" [60,100] 100) |
|
91 |
||
92 |
nominal_primrec |
|
93 |
"\<theta><(Var x)> = (lookup \<theta> x)" |
|
94 |
"\<theta><(App t\<^isub>1 t\<^isub>2)> = App (\<theta><t\<^isub>1>) (\<theta><t\<^isub>2>)" |
|
95 |
"x\<sharp>\<theta> \<Longrightarrow> \<theta><(Lam [x].t)> = Lam [x].(\<theta><t>)" |
|
96 |
"\<theta><(Const n)> = Const n" |
|
97 |
"\<theta><(Unit)> = Unit" |
|
98 |
apply(finite_guess)+ |
|
99 |
apply(rule TrueI)+ |
|
100 |
apply(simp add: abs_fresh)+ |
|
101 |
apply(fresh_guess)+ |
|
102 |
done |
|
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
103 |
|
22494 | 104 |
abbreviation |
105 |
subst :: "trm \<Rightarrow> name \<Rightarrow> trm \<Rightarrow> trm" ("_[_::=_]" [100,100,100] 100) |
|
106 |
where |
|
107 |
"t[x::=t'] \<equiv> ([(x,t')])<t>" |
|
108 |
||
109 |
lemma subst[simp]: |
|
110 |
shows "(Var x)[y::=t'] = (if x=y then t' else (Var x))" |
|
111 |
and "(App t\<^isub>1 t\<^isub>2)[y::=t'] = App (t\<^isub>1[y::=t']) (t\<^isub>2[y::=t'])" |
|
112 |
and "x\<sharp>(y,t') \<Longrightarrow> (Lam [x].t)[y::=t'] = Lam [x].(t[y::=t'])" |
|
113 |
and "Const n[y::=t'] = Const n" |
|
114 |
and "Unit [y::=t'] = Unit" |
|
115 |
by (simp_all add: fresh_list_cons fresh_list_nil) |
|
116 |
||
117 |
lemma subst_eqvt[eqvt]: |
|
118 |
fixes pi::"name prm" |
|
119 |
shows "pi\<bullet>(t[x::=t']) = (pi\<bullet>t)[(pi\<bullet>x)::=(pi\<bullet>t')]" |
|
120 |
by (nominal_induct t avoiding: x t' rule: trm.induct) |
|
121 |
(perm_simp add: fresh_bij)+ |
|
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
122 |
|
22494 | 123 |
lemma subst_rename: |
124 |
fixes c::"name" |
|
125 |
assumes a: "c\<sharp>t\<^isub>1" |
|
126 |
shows "t\<^isub>1[a::=t\<^isub>2] = ([(c,a)]\<bullet>t\<^isub>1)[c::=t\<^isub>2]" |
|
127 |
using a |
|
128 |
apply(nominal_induct t\<^isub>1 avoiding: a c t\<^isub>2 rule: trm.induct) |
|
129 |
apply(simp add: trm.inject calc_atm fresh_atm abs_fresh perm_nat_def)+ |
|
130 |
done |
|
131 |
||
132 |
lemma fresh_psubst: |
|
133 |
fixes z::"name" |
|
134 |
assumes a: "z\<sharp>t" "z\<sharp>\<theta>" |
|
135 |
shows "z\<sharp>(\<theta><t>)" |
|
136 |
using a |
|
137 |
by (nominal_induct t avoiding: z \<theta> t rule: trm.induct) |
|
138 |
(auto simp add: abs_fresh lookup_fresh) |
|
139 |
||
140 |
lemma fresh_subst'': |
|
141 |
fixes z::"name" |
|
142 |
assumes "z\<sharp>t\<^isub>2" |
|
143 |
shows "z\<sharp>t\<^isub>1[z::=t\<^isub>2]" |
|
144 |
using assms |
|
145 |
by (nominal_induct t\<^isub>1 avoiding: t\<^isub>2 z rule: trm.induct) |
|
146 |
(auto simp add: abs_fresh fresh_nat fresh_atm) |
|
147 |
||
148 |
lemma fresh_subst': |
|
149 |
fixes z::"name" |
|
150 |
assumes "z\<sharp>[y].t\<^isub>1" "z\<sharp>t\<^isub>2" |
|
151 |
shows "z\<sharp>t\<^isub>1[y::=t\<^isub>2]" |
|
152 |
using assms |
|
153 |
by (nominal_induct t\<^isub>1 avoiding: y t\<^isub>2 z rule: trm.induct) |
|
154 |
(auto simp add: abs_fresh fresh_nat fresh_atm) |
|
22073 | 155 |
|
22494 | 156 |
lemma fresh_subst: |
157 |
fixes z::"name" |
|
158 |
assumes a: "z\<sharp>t\<^isub>1" "z\<sharp>t\<^isub>2" |
|
159 |
shows "z\<sharp>t\<^isub>1[y::=t\<^isub>2]" |
|
160 |
using a |
|
161 |
by (auto simp add: fresh_subst' abs_fresh) |
|
162 |
||
163 |
lemma fresh_psubst_simp: |
|
164 |
assumes "x\<sharp>t" |
|
165 |
shows "(x,u)#\<theta><t> = \<theta><t>" |
|
166 |
using assms |
|
167 |
proof (nominal_induct t avoiding: x u \<theta> rule: trm.induct) |
|
168 |
case (Lam y t x u) |
|
169 |
have fs: "y\<sharp>\<theta>" "y\<sharp>x" "y\<sharp>u" by fact |
|
170 |
moreover have "x\<sharp> Lam [y].t" by fact |
|
171 |
ultimately have "x\<sharp>t" by (simp add: abs_fresh fresh_atm) |
|
172 |
moreover have ih:"\<And>n T. n\<sharp>t \<Longrightarrow> ((n,T)#\<theta>)<t> = \<theta><t>" by fact |
|
173 |
ultimately have "(x,u)#\<theta><t> = \<theta><t>" by auto |
|
174 |
moreover have "(x,u)#\<theta><Lam [y].t> = Lam [y]. ((x,u)#\<theta><t>)" using fs |
|
175 |
by (simp add: fresh_list_cons fresh_prod) |
|
176 |
moreover have " \<theta><Lam [y].t> = Lam [y]. (\<theta><t>)" using fs by simp |
|
177 |
ultimately show "(x,u)#\<theta><Lam [y].t> = \<theta><Lam [y].t>" by auto |
|
178 |
qed (auto simp add: fresh_atm abs_fresh) |
|
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
179 |
|
22494 | 180 |
lemma forget: |
181 |
fixes x::"name" |
|
182 |
assumes a: "x\<sharp>t" |
|
183 |
shows "t[x::=t'] = t" |
|
184 |
using a |
|
185 |
by (nominal_induct t avoiding: x t' rule: trm.induct) |
|
186 |
(auto simp add: fresh_atm abs_fresh) |
|
187 |
||
188 |
lemma subst_fun_eq: |
|
189 |
fixes u::trm |
|
190 |
assumes h:"[x].t\<^isub>1 = [y].t\<^isub>2" |
|
191 |
shows "t\<^isub>1[x::=u] = t\<^isub>2[y::=u]" |
|
192 |
proof - |
|
193 |
{ |
|
194 |
assume "x=y" and "t\<^isub>1=t\<^isub>2" |
|
195 |
then have ?thesis using h by simp |
|
196 |
} |
|
197 |
moreover |
|
198 |
{ |
|
199 |
assume h1:"x \<noteq> y" and h2:"t\<^isub>1=[(x,y)] \<bullet> t\<^isub>2" and h3:"x \<sharp> t\<^isub>2" |
|
200 |
then have "([(x,y)] \<bullet> t\<^isub>2)[x::=u] = t\<^isub>2[y::=u]" by (simp add: subst_rename) |
|
201 |
then have ?thesis using h2 by simp |
|
202 |
} |
|
203 |
ultimately show ?thesis using alpha h by blast |
|
204 |
qed |
|
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
205 |
|
22494 | 206 |
lemma psubst_empty[simp]: |
207 |
shows "[]<t> = t" |
|
208 |
by (nominal_induct t rule: trm.induct) |
|
209 |
(auto simp add: fresh_list_nil) |
|
210 |
||
211 |
lemma psubst_subst_psubst: |
|
212 |
assumes h:"c\<sharp>\<theta>" |
|
213 |
shows "\<theta><t>[c::=s] = (c,s)#\<theta><t>" |
|
214 |
using h |
|
215 |
by (nominal_induct t avoiding: \<theta> c s rule: trm.induct) |
|
216 |
(auto simp add: fresh_list_cons fresh_atm forget lookup_fresh lookup_fresh' fresh_psubst) |
|
217 |
||
218 |
lemma subst_fresh_simp: |
|
219 |
assumes a: "x\<sharp>\<theta>" |
|
220 |
shows "\<theta><Var x> = Var x" |
|
221 |
using a |
|
222 |
by (induct \<theta> arbitrary: x, auto simp add:fresh_list_cons fresh_prod fresh_atm) |
|
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
223 |
|
22494 | 224 |
lemma psubst_subst_propagate: |
225 |
assumes "x\<sharp>\<theta>" |
|
226 |
shows "\<theta><t[x::=u]> = \<theta><t>[x::=\<theta><u>]" |
|
227 |
using assms |
|
228 |
proof (nominal_induct t avoiding: x u \<theta> rule: trm.induct) |
|
229 |
case (Var n x u \<theta>) |
|
230 |
{ assume "x=n" |
|
231 |
moreover have "x\<sharp>\<theta>" by fact |
|
232 |
ultimately have "\<theta><Var n[x::=u]> = \<theta><Var n>[x::=\<theta><u>]" using subst_fresh_simp by auto |
|
233 |
} |
|
234 |
moreover |
|
235 |
{ assume h:"x\<noteq>n" |
|
236 |
then have "x\<sharp>Var n" by (auto simp add: fresh_atm) |
|
237 |
moreover have "x\<sharp>\<theta>" by fact |
|
238 |
ultimately have "x\<sharp>\<theta><Var n>" using fresh_psubst by blast |
|
239 |
then have " \<theta><Var n>[x::=\<theta><u>] = \<theta><Var n>" using forget by auto |
|
240 |
then have "\<theta><Var n[x::=u]> = \<theta><Var n>[x::=\<theta><u>]" using h by auto |
|
241 |
} |
|
242 |
ultimately show ?case by auto |
|
243 |
next |
|
244 |
case (Lam n t x u \<theta>) |
|
245 |
have fs:"n\<sharp>x" "n\<sharp>u" "n\<sharp>\<theta>" "x\<sharp>\<theta>" by fact |
|
246 |
have ih:"\<And> y s \<theta>. y\<sharp>\<theta> \<Longrightarrow> ((\<theta><(t[y::=s])>) = ((\<theta><t>)[y::=(\<theta><s>)]))" by fact |
|
247 |
have "\<theta> <(Lam [n].t)[x::=u]> = \<theta><Lam [n]. (t [x::=u])>" using fs by auto |
|
248 |
then have "\<theta> <(Lam [n].t)[x::=u]> = Lam [n]. \<theta><t [x::=u]>" using fs by auto |
|
249 |
moreover have "\<theta><t[x::=u]> = \<theta><t>[x::=\<theta><u>]" using ih fs by blast |
|
250 |
ultimately have "\<theta> <(Lam [n].t)[x::=u]> = Lam [n].(\<theta><t>[x::=\<theta><u>])" by auto |
|
251 |
moreover have "Lam [n].(\<theta><t>[x::=\<theta><u>]) = (Lam [n].\<theta><t>)[x::=\<theta><u>]" using fs fresh_psubst by auto |
|
252 |
ultimately have "\<theta><(Lam [n].t)[x::=u]> = (Lam [n].\<theta><t>)[x::=\<theta><u>]" using fs by auto |
|
253 |
then show "\<theta><(Lam [n].t)[x::=u]> = \<theta><Lam [n].t>[x::=\<theta><u>]" using fs by auto |
|
254 |
qed (auto) |
|
255 |
||
256 |
section {* Typing *} |
|
257 |
||
22073 | 258 |
inductive2 |
22494 | 259 |
valid :: "Ctxt \<Rightarrow> bool" |
22073 | 260 |
where |
22494 | 261 |
v_nil[intro]: "valid []" |
262 |
| v_cons[intro]: "\<lbrakk>valid \<Gamma>;a\<sharp>\<Gamma>\<rbrakk> \<Longrightarrow> valid ((a,T)#\<Gamma>)" |
|
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
263 |
|
22538
3ccb92dfb5e9
tuned proofs (taking full advantage of nominal_inductive)
urbanc
parents:
22531
diff
changeset
|
264 |
equivariance valid |
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
265 |
|
22073 | 266 |
inductive_cases2 |
267 |
valid_cons_elim_auto[elim]:"valid ((x,T)#\<Gamma>)" |
|
268 |
||
22494 | 269 |
abbreviation |
22650
0c5b22076fb3
tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents:
22609
diff
changeset
|
270 |
"sub_context" :: "Ctxt \<Rightarrow> Ctxt \<Rightarrow> bool" (" _ \<subseteq> _ " [55,55] 55) |
22494 | 271 |
where |
22650
0c5b22076fb3
tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents:
22609
diff
changeset
|
272 |
"\<Gamma>\<^isub>1 \<subseteq> \<Gamma>\<^isub>2 \<equiv> \<forall>a T. (a,T)\<in>set \<Gamma>\<^isub>1 \<longrightarrow> (a,T)\<in>set \<Gamma>\<^isub>2" |
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
273 |
|
22494 | 274 |
lemma valid_monotonicity[elim]: |
22650
0c5b22076fb3
tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents:
22609
diff
changeset
|
275 |
assumes a: "\<Gamma> \<subseteq> \<Gamma>'" |
22494 | 276 |
and b: "x\<sharp>\<Gamma>'" |
22650
0c5b22076fb3
tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents:
22609
diff
changeset
|
277 |
shows "(x,T\<^isub>1)#\<Gamma> \<subseteq> (x,T\<^isub>1)#\<Gamma>'" |
22494 | 278 |
using a b by auto |
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
279 |
|
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
280 |
lemma fresh_context: |
22494 | 281 |
fixes \<Gamma> :: "Ctxt" |
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
282 |
and a :: "name" |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
283 |
assumes "a\<sharp>\<Gamma>" |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
284 |
shows "\<not>(\<exists>\<tau>::ty. (a,\<tau>)\<in>set \<Gamma>)" |
22494 | 285 |
using assms |
286 |
by (induct \<Gamma>) |
|
287 |
(auto simp add: fresh_prod fresh_list_cons fresh_atm) |
|
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
288 |
|
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
289 |
lemma type_unicity_in_context: |
22494 | 290 |
assumes a: "valid \<Gamma>" |
291 |
and b: "(x,T\<^isub>1) \<in> set \<Gamma>" |
|
292 |
and c: "(x,T\<^isub>2) \<in> set \<Gamma>" |
|
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
293 |
shows "T\<^isub>1=T\<^isub>2" |
22494 | 294 |
using a b c |
295 |
by (induct \<Gamma>) |
|
296 |
(auto dest!: fresh_context) |
|
22073 | 297 |
|
298 |
inductive2 |
|
22494 | 299 |
typing :: "Ctxt\<Rightarrow>trm\<Rightarrow>ty\<Rightarrow>bool" (" _ \<turnstile> _ : _ " [60,60,60] 60) |
22073 | 300 |
where |
22650
0c5b22076fb3
tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents:
22609
diff
changeset
|
301 |
t_Var[intro]: "\<lbrakk>valid \<Gamma>; (x,T)\<in>set \<Gamma>\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> Var x : T" |
0c5b22076fb3
tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents:
22609
diff
changeset
|
302 |
| t_App[intro]: "\<lbrakk>\<Gamma> \<turnstile> e\<^isub>1 : T\<^isub>1\<rightarrow>T\<^isub>2; \<Gamma> \<turnstile> e\<^isub>2 : T\<^isub>1\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> App e\<^isub>1 e\<^isub>2 : T\<^isub>2" |
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
303 |
| t_Lam[intro]: "\<lbrakk>x\<sharp>\<Gamma>; (x,T\<^isub>1)#\<Gamma> \<turnstile> t : T\<^isub>2\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> Lam [x].t : T\<^isub>1\<rightarrow>T\<^isub>2" |
22073 | 304 |
| t_Const[intro]: "valid \<Gamma> \<Longrightarrow> \<Gamma> \<turnstile> Const n : TBase" |
305 |
| t_Unit[intro]: "valid \<Gamma> \<Longrightarrow> \<Gamma> \<turnstile> Unit : TUnit" |
|
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
306 |
|
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
307 |
nominal_inductive typing |
22531 | 308 |
by (simp_all add: abs_fresh) |
22073 | 309 |
|
22494 | 310 |
lemma typing_implies_valid: |
311 |
assumes a: "\<Gamma> \<turnstile> t : T" |
|
312 |
shows "valid \<Gamma>" |
|
313 |
using a by (induct) (auto) |
|
22073 | 314 |
|
315 |
declare trm.inject [simp add] |
|
316 |
declare ty.inject [simp add] |
|
317 |
||
318 |
inductive_cases2 t_Lam_elim_auto[elim]: "\<Gamma> \<turnstile> Lam [x].t : T" |
|
319 |
inductive_cases2 t_Var_elim_auto[elim]: "\<Gamma> \<turnstile> Var x : T" |
|
320 |
inductive_cases2 t_App_elim_auto[elim]: "\<Gamma> \<turnstile> App x y : T" |
|
22609
40ade470e319
perm_simp can now simplify using the rules (a,b) o a = b and (a,b) o b = a
narboux
parents:
22594
diff
changeset
|
321 |
inductive_cases2 t_Const_elim_auto[elim]: "\<Gamma> \<turnstile> Const n : T" |
40ade470e319
perm_simp can now simplify using the rules (a,b) o a = b and (a,b) o b = a
narboux
parents:
22594
diff
changeset
|
322 |
inductive_cases2 t_Unit_elim_auto[elim]: "\<Gamma> \<turnstile> Unit : TUnit" |
40ade470e319
perm_simp can now simplify using the rules (a,b) o a = b and (a,b) o b = a
narboux
parents:
22594
diff
changeset
|
323 |
inductive_cases2 t_Unit_elim_auto'[elim]: "\<Gamma> \<turnstile> s : TUnit" |
22073 | 324 |
|
325 |
declare trm.inject [simp del] |
|
326 |
declare ty.inject [simp del] |
|
327 |
||
22494 | 328 |
section {* Definitional Equivalence *} |
22073 | 329 |
|
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
330 |
inductive2 |
22494 | 331 |
def_equiv :: "Ctxt\<Rightarrow>trm\<Rightarrow>trm\<Rightarrow>ty\<Rightarrow>bool" ("_ \<turnstile> _ \<equiv> _ : _" [60,60] 60) |
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
332 |
where |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
333 |
Q_Refl[intro]: "\<Gamma> \<turnstile> t : T \<Longrightarrow> \<Gamma> \<turnstile> t \<equiv> t : T" |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
334 |
| Q_Symm[intro]: "\<Gamma> \<turnstile> t \<equiv> s : T \<Longrightarrow> \<Gamma> \<turnstile> s \<equiv> t : T" |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
335 |
| Q_Trans[intro]: "\<lbrakk>\<Gamma> \<turnstile> s \<equiv> t : T; \<Gamma> \<turnstile> t \<equiv> u : T\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> s \<equiv> u : T" |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
336 |
| Q_Abs[intro]: "\<lbrakk>x\<sharp>\<Gamma>; (x,T\<^isub>1)#\<Gamma> \<turnstile> s\<^isub>2 \<equiv> t\<^isub>2 : T\<^isub>2\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> Lam [x]. s\<^isub>2 \<equiv> Lam [x]. t\<^isub>2 : T\<^isub>1 \<rightarrow> T\<^isub>2" |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
337 |
| Q_App[intro]: "\<lbrakk>\<Gamma> \<turnstile> s\<^isub>1 \<equiv> t\<^isub>1 : T\<^isub>1 \<rightarrow> T\<^isub>2 ; \<Gamma> \<turnstile> s\<^isub>2 \<equiv> t\<^isub>2 : T\<^isub>1\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> App s\<^isub>1 s\<^isub>2 \<equiv> App t\<^isub>1 t\<^isub>2 : T\<^isub>2" |
22494 | 338 |
| Q_Beta[intro]: "\<lbrakk>x\<sharp>(\<Gamma>,s\<^isub>2,t\<^isub>2); (x,T\<^isub>1)#\<Gamma> \<turnstile> s\<^isub>1 \<equiv> t\<^isub>1 : T\<^isub>2 ; \<Gamma> \<turnstile> s\<^isub>2 \<equiv> t\<^isub>2 : T\<^isub>1\<rbrakk> |
339 |
\<Longrightarrow> \<Gamma> \<turnstile> App (Lam [x]. s\<^isub>1) s\<^isub>2 \<equiv> t\<^isub>1[x::=t\<^isub>2] : T\<^isub>2" |
|
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
340 |
| Q_Ext[intro]: "\<lbrakk>x\<sharp>(\<Gamma>,s,t); (x,T\<^isub>1)#\<Gamma> \<turnstile> App s (Var x) \<equiv> App t (Var x) : T\<^isub>2\<rbrakk> |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
341 |
\<Longrightarrow> \<Gamma> \<turnstile> s \<equiv> t : T\<^isub>1 \<rightarrow> T\<^isub>2" |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
342 |
|
22494 | 343 |
nominal_inductive def_equiv |
22531 | 344 |
by (simp_all add: abs_fresh fresh_subst'') |
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
345 |
|
22494 | 346 |
lemma def_equiv_implies_valid: |
347 |
assumes a: "\<Gamma> \<turnstile> t \<equiv> s : T" |
|
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
348 |
shows "valid \<Gamma>" |
22494 | 349 |
using a by (induct) (auto elim: typing_implies_valid) |
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
350 |
|
22494 | 351 |
section {* Weak Head Reduction *} |
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
352 |
|
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
353 |
inductive2 |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
354 |
whr_def :: "trm\<Rightarrow>trm\<Rightarrow>bool" ("_ \<leadsto> _" [80,80] 80) |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
355 |
where |
22494 | 356 |
QAR_Beta[intro]: "App (Lam [x]. t\<^isub>1) t\<^isub>2 \<leadsto> t\<^isub>1[x::=t\<^isub>2]" |
357 |
| QAR_App[intro]: "t\<^isub>1 \<leadsto> t\<^isub>1' \<Longrightarrow> App t\<^isub>1 t\<^isub>2 \<leadsto> App t\<^isub>1' t\<^isub>2" |
|
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
358 |
|
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
359 |
declare trm.inject [simp add] |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
360 |
declare ty.inject [simp add] |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
361 |
|
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
362 |
inductive_cases2 whr_Gen[elim]: "t \<leadsto> t'" |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
363 |
inductive_cases2 whr_Lam[elim]: "Lam [x].t \<leadsto> t'" |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
364 |
inductive_cases2 whr_App_Lam[elim]: "App (Lam [x].t12) t2 \<leadsto> t" |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
365 |
inductive_cases2 whr_Var[elim]: "Var x \<leadsto> t" |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
366 |
inductive_cases2 whr_Const[elim]: "Const n \<leadsto> t" |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
367 |
inductive_cases2 whr_App[elim]: "App p q \<leadsto> t" |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
368 |
inductive_cases2 whr_Const_Right[elim]: "t \<leadsto> Const n" |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
369 |
inductive_cases2 whr_Var_Right[elim]: "t \<leadsto> Var x" |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
370 |
inductive_cases2 whr_App_Right[elim]: "t \<leadsto> App p q" |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
371 |
|
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
372 |
declare trm.inject [simp del] |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
373 |
declare ty.inject [simp del] |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
374 |
|
22531 | 375 |
equivariance whr_def |
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
376 |
|
22494 | 377 |
section {* Weak Head Normalisation *} |
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
378 |
|
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
379 |
abbreviation |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
380 |
nf :: "trm \<Rightarrow> bool" ("_ \<leadsto>|" [100] 100) |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
381 |
where |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
382 |
"t\<leadsto>| \<equiv> \<not>(\<exists> u. t \<leadsto> u)" |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
383 |
|
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
384 |
inductive2 |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
385 |
whn_def :: "trm\<Rightarrow>trm\<Rightarrow>bool" ("_ \<Down> _" [80,80] 80) |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
386 |
where |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
387 |
QAN_Reduce[intro]: "\<lbrakk>s \<leadsto> t; t \<Down> u\<rbrakk> \<Longrightarrow> s \<Down> u" |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
388 |
| QAN_Normal[intro]: "t\<leadsto>| \<Longrightarrow> t \<Down> t" |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
389 |
|
22494 | 390 |
declare trm.inject[simp] |
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
391 |
|
22494 | 392 |
inductive_cases2 whn_inv_auto[elim]: "t \<Down> t'" |
393 |
||
394 |
declare trm.inject[simp del] |
|
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
395 |
|
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
396 |
lemma whn_eqvt[eqvt]: |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
397 |
fixes pi::"name prm" |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
398 |
assumes a: "t \<Down> t'" |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
399 |
shows "(pi\<bullet>t) \<Down> (pi\<bullet>t')" |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
400 |
using a |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
401 |
apply(induct) |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
402 |
apply(rule QAN_Reduce) |
22542 | 403 |
apply(rule whr_def.eqvt) |
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
404 |
apply(assumption)+ |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
405 |
apply(rule QAN_Normal) |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
406 |
apply(auto) |
22542 | 407 |
apply(drule_tac pi="rev pi" in whr_def.eqvt) |
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
408 |
apply(perm_simp) |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
409 |
done |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
410 |
|
22494 | 411 |
lemma red_unicity : |
412 |
assumes a: "x \<leadsto> a" |
|
413 |
and b: "x \<leadsto> b" |
|
414 |
shows "a=b" |
|
415 |
using a b |
|
416 |
apply (induct arbitrary: b) |
|
417 |
apply (erule whr_App_Lam) |
|
418 |
apply (clarify) |
|
419 |
apply (rule subst_fun_eq) |
|
420 |
apply (simp) |
|
421 |
apply (force) |
|
422 |
apply (erule whr_App) |
|
423 |
apply (blast)+ |
|
424 |
done |
|
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
425 |
|
22494 | 426 |
lemma nf_unicity : |
427 |
assumes "x \<Down> a" and "x \<Down> b" |
|
428 |
shows "a=b" |
|
429 |
using assms |
|
430 |
proof (induct arbitrary: b) |
|
431 |
case (QAN_Reduce x t a b) |
|
432 |
have h:"x \<leadsto> t" "t \<Down> a" by fact |
|
433 |
have ih:"\<And>b. t \<Down> b \<Longrightarrow> a = b" by fact |
|
434 |
have "x \<Down> b" by fact |
|
435 |
then obtain t' where "x \<leadsto> t'" and hl:"t' \<Down> b" using h by auto |
|
436 |
then have "t=t'" using h red_unicity by auto |
|
437 |
then show "a=b" using ih hl by auto |
|
438 |
qed (auto) |
|
439 |
||
440 |
section {* Algorithmic Term Equivalence and Algorithmic Path Equivalence *} |
|
441 |
||
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
442 |
inductive2 |
22650
0c5b22076fb3
tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents:
22609
diff
changeset
|
443 |
alg_equiv :: "Ctxt\<Rightarrow>trm\<Rightarrow>trm\<Rightarrow>ty\<Rightarrow>bool" ("_ \<turnstile> _ \<Leftrightarrow> _ : _" [60,60,60,60] 60) |
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
444 |
and |
22650
0c5b22076fb3
tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents:
22609
diff
changeset
|
445 |
alg_path_equiv :: "Ctxt\<Rightarrow>trm\<Rightarrow>trm\<Rightarrow>ty\<Rightarrow>bool" ("_ \<turnstile> _ \<leftrightarrow> _ : _" [60,60,60,60] 60) |
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
446 |
where |
22650
0c5b22076fb3
tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents:
22609
diff
changeset
|
447 |
QAT_Base[intro]: "\<lbrakk>s \<Down> p; t \<Down> q; \<Gamma> \<turnstile> p \<leftrightarrow> q : TBase\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> s \<Leftrightarrow> t : TBase" |
22494 | 448 |
| QAT_Arrow[intro]: "\<lbrakk>x\<sharp>(\<Gamma>,s,t); (x,T\<^isub>1)#\<Gamma> \<turnstile> App s (Var x) \<Leftrightarrow> App t (Var x) : T\<^isub>2\<rbrakk> |
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
449 |
\<Longrightarrow> \<Gamma> \<turnstile> s \<Leftrightarrow> t : T\<^isub>1 \<rightarrow> T\<^isub>2" |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
450 |
| QAT_One[intro]: "valid \<Gamma> \<Longrightarrow> \<Gamma> \<turnstile> s \<Leftrightarrow> t : TUnit" |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
451 |
| QAP_Var[intro]: "\<lbrakk>valid \<Gamma>;(x,T) \<in> set \<Gamma>\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> Var x \<leftrightarrow> Var x : T" |
22650
0c5b22076fb3
tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents:
22609
diff
changeset
|
452 |
| QAP_App[intro]: "\<lbrakk>\<Gamma> \<turnstile> p \<leftrightarrow> q : T\<^isub>1 \<rightarrow> T\<^isub>2; \<Gamma> \<turnstile> s \<Leftrightarrow> t : T\<^isub>1\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> App p s \<leftrightarrow> App q t : T\<^isub>2" |
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
453 |
| QAP_Const[intro]: "valid \<Gamma> \<Longrightarrow> \<Gamma> \<turnstile> Const n \<leftrightarrow> Const n : TBase" |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
454 |
|
22531 | 455 |
nominal_inductive alg_equiv |
456 |
avoids QAT_Arrow: x |
|
457 |
by simp_all |
|
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
458 |
|
22494 | 459 |
declare trm.inject [simp add] |
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
460 |
declare ty.inject [simp add] |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
461 |
|
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
462 |
inductive_cases2 alg_equiv_Base_inv_auto[elim]: "\<Gamma> \<turnstile> s\<Leftrightarrow>t : TBase" |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
463 |
inductive_cases2 alg_equiv_Arrow_inv_auto[elim]: "\<Gamma> \<turnstile> s\<Leftrightarrow>t : T\<^isub>1 \<rightarrow> T\<^isub>2" |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
464 |
|
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
465 |
inductive_cases2 alg_path_equiv_Base_inv_auto[elim]: "\<Gamma> \<turnstile> s\<leftrightarrow>t : TBase" |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
466 |
inductive_cases2 alg_path_equiv_Unit_inv_auto[elim]: "\<Gamma> \<turnstile> s\<leftrightarrow>t : TUnit" |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
467 |
inductive_cases2 alg_path_equiv_Arrow_inv_auto[elim]: "\<Gamma> \<turnstile> s\<leftrightarrow>t : T\<^isub>1 \<rightarrow> T\<^isub>2" |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
468 |
|
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
469 |
inductive_cases2 alg_path_equiv_Var_left_inv_auto[elim]: "\<Gamma> \<turnstile> Var x \<leftrightarrow> t : T" |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
470 |
inductive_cases2 alg_path_equiv_Var_left_inv_auto'[elim]: "\<Gamma> \<turnstile> Var x \<leftrightarrow> t : T'" |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
471 |
inductive_cases2 alg_path_equiv_Var_right_inv_auto[elim]: "\<Gamma> \<turnstile> s \<leftrightarrow> Var x : T" |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
472 |
inductive_cases2 alg_path_equiv_Var_right_inv_auto'[elim]: "\<Gamma> \<turnstile> s \<leftrightarrow> Var x : T'" |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
473 |
inductive_cases2 alg_path_equiv_Const_left_inv_auto[elim]: "\<Gamma> \<turnstile> Const n \<leftrightarrow> t : T" |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
474 |
inductive_cases2 alg_path_equiv_Const_right_inv_auto[elim]: "\<Gamma> \<turnstile> s \<leftrightarrow> Const n : T" |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
475 |
inductive_cases2 alg_path_equiv_App_left_inv_auto[elim]: "\<Gamma> \<turnstile> App p s \<leftrightarrow> t : T" |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
476 |
inductive_cases2 alg_path_equiv_App_right_inv_auto[elim]: "\<Gamma> \<turnstile> s \<leftrightarrow> App q t : T" |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
477 |
inductive_cases2 alg_path_equiv_Lam_left_inv_auto[elim]: "\<Gamma> \<turnstile> Lam[x].s \<leftrightarrow> t : T" |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
478 |
inductive_cases2 alg_path_equiv_Lam_right_inv_auto[elim]: "\<Gamma> \<turnstile> t \<leftrightarrow> Lam[x].s : T" |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
479 |
|
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
480 |
declare trm.inject [simp del] |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
481 |
declare ty.inject [simp del] |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
482 |
|
22073 | 483 |
lemma Q_Arrow_strong_inversion: |
22494 | 484 |
assumes fs: "x\<sharp>\<Gamma>" "x\<sharp>t" "x\<sharp>u" |
485 |
and h: "\<Gamma> \<turnstile> t \<Leftrightarrow> u : T\<^isub>1\<rightarrow>T\<^isub>2" |
|
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
486 |
shows "(x,T\<^isub>1)#\<Gamma> \<turnstile> App t (Var x) \<Leftrightarrow> App u (Var x) : T\<^isub>2" |
22073 | 487 |
proof - |
22494 | 488 |
obtain y where fs2: "y\<sharp>(\<Gamma>,t,u)" and "(y,T\<^isub>1)#\<Gamma> \<turnstile> App t (Var y) \<Leftrightarrow> App u (Var y) : T\<^isub>2" |
22082 | 489 |
using h by auto |
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
490 |
then have "([(x,y)]\<bullet>((y,T\<^isub>1)#\<Gamma>)) \<turnstile> [(x,y)]\<bullet> App t (Var y) \<Leftrightarrow> [(x,y)]\<bullet> App u (Var y) : T\<^isub>2" |
22542 | 491 |
using alg_equiv.eqvt[simplified] by blast |
22082 | 492 |
then show ?thesis using fs fs2 by (perm_simp) |
22073 | 493 |
qed |
494 |
||
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
495 |
(* |
22594
33a690455f88
add a few details in the Fst and Snd cases of unicity proof
narboux
parents:
22542
diff
changeset
|
496 |
Warning this lemma is false: |
33a690455f88
add a few details in the Fst and Snd cases of unicity proof
narboux
parents:
22542
diff
changeset
|
497 |
|
22073 | 498 |
lemma algorithmic_type_unicity: |
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
499 |
shows "\<lbrakk> \<Gamma> \<turnstile> s \<Leftrightarrow> t : T ; \<Gamma> \<turnstile> s \<Leftrightarrow> u : T' \<rbrakk> \<Longrightarrow> T = T'" |
22073 | 500 |
and "\<lbrakk> \<Gamma> \<turnstile> s \<leftrightarrow> t : T ; \<Gamma> \<turnstile> s \<leftrightarrow> u : T' \<rbrakk> \<Longrightarrow> T = T'" |
501 |
||
502 |
Here is the counter example : |
|
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
503 |
\<Gamma> \<turnstile> Const n \<Leftrightarrow> Const n : Tbase and \<Gamma> \<turnstile> Const n \<Leftrightarrow> Const n : TUnit |
22073 | 504 |
*) |
505 |
||
506 |
lemma algorithmic_path_type_unicity: |
|
22494 | 507 |
shows "\<Gamma> \<turnstile> s \<leftrightarrow> t : T \<Longrightarrow> \<Gamma> \<turnstile> s \<leftrightarrow> u : T' \<Longrightarrow> T = T'" |
22082 | 508 |
proof (induct arbitrary: u T' |
509 |
rule: alg_equiv_alg_path_equiv.inducts(2) [of _ _ _ _ _ "%a b c d . True" ]) |
|
22073 | 510 |
case (QAP_Var \<Gamma> x T u T') |
511 |
have "\<Gamma> \<turnstile> Var x \<leftrightarrow> u : T'" by fact |
|
512 |
then have "u=Var x" and "(x,T') \<in> set \<Gamma>" by auto |
|
513 |
moreover have "valid \<Gamma>" "(x,T) \<in> set \<Gamma>" by fact |
|
514 |
ultimately show "T=T'" using type_unicity_in_context by auto |
|
515 |
next |
|
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
516 |
case (QAP_App \<Gamma> p q T\<^isub>1 T\<^isub>2 s t u T\<^isub>2') |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
517 |
have ih:"\<And>u T. \<Gamma> \<turnstile> p \<leftrightarrow> u : T \<Longrightarrow> T\<^isub>1\<rightarrow>T\<^isub>2 = T" by fact |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
518 |
have "\<Gamma> \<turnstile> App p s \<leftrightarrow> u : T\<^isub>2'" by fact |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
519 |
then obtain r t T\<^isub>1' where "u = App r t" "\<Gamma> \<turnstile> p \<leftrightarrow> r : T\<^isub>1' \<rightarrow> T\<^isub>2'" by auto |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
520 |
then have "T\<^isub>1\<rightarrow>T\<^isub>2 = T\<^isub>1' \<rightarrow> T\<^isub>2'" by auto |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
521 |
then show "T\<^isub>2=T\<^isub>2'" using ty.inject by auto |
22073 | 522 |
qed (auto) |
523 |
||
22494 | 524 |
lemma alg_path_equiv_implies_valid: |
525 |
shows "\<Gamma> \<turnstile> s \<Leftrightarrow> t : T \<Longrightarrow> valid \<Gamma>" |
|
526 |
and "\<Gamma> \<turnstile> s \<leftrightarrow> t : T \<Longrightarrow> valid \<Gamma>" |
|
527 |
by (induct rule : alg_equiv_alg_path_equiv.inducts, auto) |
|
528 |
||
529 |
lemma algorithmic_symmetry: |
|
530 |
shows "\<Gamma> \<turnstile> s \<Leftrightarrow> t : T \<Longrightarrow> \<Gamma> \<turnstile> t \<Leftrightarrow> s : T" |
|
531 |
and "\<Gamma> \<turnstile> s \<leftrightarrow> t : T \<Longrightarrow> \<Gamma> \<turnstile> t \<leftrightarrow> s : T" |
|
532 |
by (induct rule: alg_equiv_alg_path_equiv.inducts) |
|
533 |
(auto simp add: fresh_prod) |
|
534 |
||
22073 | 535 |
lemma algorithmic_transitivity: |
22494 | 536 |
shows "\<Gamma> \<turnstile> s \<Leftrightarrow> t : T \<Longrightarrow> \<Gamma> \<turnstile> t \<Leftrightarrow> u : T \<Longrightarrow> \<Gamma> \<turnstile> s \<Leftrightarrow> u : T" |
537 |
and "\<Gamma> \<turnstile> s \<leftrightarrow> t : T \<Longrightarrow> \<Gamma> \<turnstile> t \<leftrightarrow> u : T \<Longrightarrow> \<Gamma> \<turnstile> s \<leftrightarrow> u : T" |
|
22531 | 538 |
proof (nominal_induct \<Gamma> s t T and \<Gamma> s t T avoiding: u rule: alg_equiv_alg_path_equiv.strong_inducts) |
22073 | 539 |
case (QAT_Base s p t q \<Gamma> u) |
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
540 |
have "\<Gamma> \<turnstile> t \<Leftrightarrow> u : TBase" by fact |
22494 | 541 |
then obtain r' q' where b1: "t \<Down> q'" and b2: "u \<Down> r'" and b3: "\<Gamma> \<turnstile> q' \<leftrightarrow> r' : TBase" by auto |
542 |
have ih: "\<Gamma> \<turnstile> q \<leftrightarrow> r' : TBase \<Longrightarrow> \<Gamma> \<turnstile> p \<leftrightarrow> r' : TBase" by fact |
|
543 |
have "t \<Down> q" by fact |
|
544 |
with b1 have eq: "q=q'" by (simp add: nf_unicity) |
|
545 |
with ih b3 have "\<Gamma> \<turnstile> p \<leftrightarrow> r' : TBase" by simp |
|
546 |
moreover |
|
547 |
have "s \<Down> p" by fact |
|
548 |
ultimately show "\<Gamma> \<turnstile> s \<Leftrightarrow> u : TBase" using b2 by auto |
|
22073 | 549 |
next |
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
550 |
case (QAT_Arrow x \<Gamma> s t T\<^isub>1 T\<^isub>2 u) |
22494 | 551 |
have ih:"(x,T\<^isub>1)#\<Gamma> \<turnstile> App t (Var x) \<Leftrightarrow> App u (Var x) : T\<^isub>2 |
552 |
\<Longrightarrow> (x,T\<^isub>1)#\<Gamma> \<turnstile> App s (Var x) \<Leftrightarrow> App u (Var x) : T\<^isub>2" by fact |
|
553 |
have fs: "x\<sharp>\<Gamma>" "x\<sharp>s" "x\<sharp>t" "x\<sharp>u" by fact |
|
554 |
have "\<Gamma> \<turnstile> t \<Leftrightarrow> u : T\<^isub>1\<rightarrow>T\<^isub>2" by fact |
|
555 |
then have "(x,T\<^isub>1)#\<Gamma> \<turnstile> App t (Var x) \<Leftrightarrow> App u (Var x) : T\<^isub>2" using fs |
|
556 |
by (simp add: Q_Arrow_strong_inversion) |
|
557 |
with ih have "(x,T\<^isub>1)#\<Gamma> \<turnstile> App s (Var x) \<Leftrightarrow> App u (Var x) : T\<^isub>2" by simp |
|
558 |
then show "\<Gamma> \<turnstile> s \<Leftrightarrow> u : T\<^isub>1\<rightarrow>T\<^isub>2" using fs by (auto simp add: fresh_prod) |
|
22073 | 559 |
next |
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
560 |
case (QAP_App \<Gamma> p q T\<^isub>1 T\<^isub>2 s t u) |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
561 |
have "\<Gamma> \<turnstile> App q t \<leftrightarrow> u : T\<^isub>2" by fact |
22494 | 562 |
then obtain r T\<^isub>1' v where ha: "\<Gamma> \<turnstile> q \<leftrightarrow> r : T\<^isub>1'\<rightarrow>T\<^isub>2" and hb: "\<Gamma> \<turnstile> t \<Leftrightarrow> v : T\<^isub>1'" and eq: "u = App r v" |
22082 | 563 |
by auto |
22494 | 564 |
have ih1: "\<Gamma> \<turnstile> q \<leftrightarrow> r : T\<^isub>1\<rightarrow>T\<^isub>2 \<Longrightarrow> \<Gamma> \<turnstile> p \<leftrightarrow> r : T\<^isub>1\<rightarrow>T\<^isub>2" by fact |
565 |
have ih2:"\<Gamma> \<turnstile> t \<Leftrightarrow> v : T\<^isub>1 \<Longrightarrow> \<Gamma> \<turnstile> s \<Leftrightarrow> v : T\<^isub>1" by fact |
|
566 |
have "\<Gamma> \<turnstile> p \<leftrightarrow> q : T\<^isub>1\<rightarrow>T\<^isub>2" by fact |
|
567 |
then have "\<Gamma> \<turnstile> q \<leftrightarrow> p : T\<^isub>1\<rightarrow>T\<^isub>2" by (simp add: algorithmic_symmetry) |
|
568 |
with ha have "T\<^isub>1'\<rightarrow>T\<^isub>2 = T\<^isub>1\<rightarrow>T\<^isub>2" using algorithmic_path_type_unicity by simp |
|
569 |
then have "T\<^isub>1' = T\<^isub>1" by (simp add: ty.inject) |
|
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
570 |
then have "\<Gamma> \<turnstile> s \<Leftrightarrow> v : T\<^isub>1" "\<Gamma> \<turnstile> p \<leftrightarrow> r : T\<^isub>1\<rightarrow>T\<^isub>2" using ih1 ih2 ha hb by auto |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
571 |
then show "\<Gamma> \<turnstile> App p s \<leftrightarrow> u : T\<^isub>2" using eq by auto |
22073 | 572 |
qed (auto) |
573 |
||
574 |
lemma algorithmic_weak_head_closure: |
|
22494 | 575 |
shows "\<Gamma> \<turnstile> s \<Leftrightarrow> t : T \<Longrightarrow> s' \<leadsto> s \<Longrightarrow> t' \<leadsto> t \<Longrightarrow> \<Gamma> \<turnstile> s' \<Leftrightarrow> t' : T" |
576 |
apply (nominal_induct \<Gamma> s t T avoiding: s' t' |
|
22531 | 577 |
rule: alg_equiv_alg_path_equiv.strong_inducts(1) [of _ _ _ _ "%a b c d e. True"]) |
22494 | 578 |
apply(auto intro!: QAT_Arrow) |
579 |
done |
|
580 |
||
581 |
lemma algorithmic_monotonicity: |
|
22650
0c5b22076fb3
tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents:
22609
diff
changeset
|
582 |
shows "\<Gamma> \<turnstile> s \<Leftrightarrow> t : T \<Longrightarrow> \<Gamma> \<subseteq> \<Gamma>' \<Longrightarrow> valid \<Gamma>' \<Longrightarrow> \<Gamma>' \<turnstile> s \<Leftrightarrow> t : T" |
0c5b22076fb3
tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents:
22609
diff
changeset
|
583 |
and "\<Gamma> \<turnstile> s \<leftrightarrow> t : T \<Longrightarrow> \<Gamma> \<subseteq> \<Gamma>' \<Longrightarrow> valid \<Gamma>' \<Longrightarrow> \<Gamma>' \<turnstile> s \<leftrightarrow> t : T" |
22531 | 584 |
proof (nominal_induct \<Gamma> s t T and \<Gamma> s t T avoiding: \<Gamma>' rule: alg_equiv_alg_path_equiv.strong_inducts) |
22494 | 585 |
case (QAT_Arrow x \<Gamma> s t T\<^isub>1 T\<^isub>2 \<Gamma>') |
586 |
have fs:"x\<sharp>\<Gamma>" "x\<sharp>s" "x\<sharp>t" "x\<sharp>\<Gamma>'"by fact |
|
22650
0c5b22076fb3
tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents:
22609
diff
changeset
|
587 |
have h2:"\<Gamma> \<subseteq> \<Gamma>'" by fact |
0c5b22076fb3
tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents:
22609
diff
changeset
|
588 |
have ih:"\<And>\<Gamma>'. \<lbrakk>(x,T\<^isub>1)#\<Gamma> \<subseteq> \<Gamma>'; valid \<Gamma>'\<rbrakk> \<Longrightarrow> \<Gamma>' \<turnstile> App s (Var x) \<Leftrightarrow> App t (Var x) : T\<^isub>2" by fact |
22494 | 589 |
have "valid \<Gamma>'" by fact |
590 |
then have "valid ((x,T\<^isub>1)#\<Gamma>')" using fs by auto |
|
591 |
moreover |
|
22650
0c5b22076fb3
tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents:
22609
diff
changeset
|
592 |
have sub: "(x,T\<^isub>1)#\<Gamma> \<subseteq> (x,T\<^isub>1)#\<Gamma>'" using h2 by auto |
22494 | 593 |
ultimately have "(x,T\<^isub>1)#\<Gamma>' \<turnstile> App s (Var x) \<Leftrightarrow> App t (Var x) : T\<^isub>2" using ih by simp |
594 |
then show "\<Gamma>' \<turnstile> s \<Leftrightarrow> t : T\<^isub>1\<rightarrow>T\<^isub>2" using fs by (auto simp add: fresh_prod) |
|
595 |
qed (auto) |
|
596 |
||
597 |
lemma path_equiv_implies_nf: |
|
598 |
assumes "\<Gamma> \<turnstile> s \<leftrightarrow> t : T" |
|
599 |
shows "s \<leadsto>|" and "t \<leadsto>|" |
|
600 |
using assms |
|
601 |
by (induct rule: alg_equiv_alg_path_equiv.inducts(2)) (simp, auto) |
|
602 |
||
603 |
section {* Logical Equivalence *} |
|
604 |
||
605 |
function log_equiv :: "(Ctxt \<Rightarrow> trm \<Rightarrow> trm \<Rightarrow> ty \<Rightarrow> bool)" ("_ \<turnstile> _ is _ : _" [60,60,60,60] 60) |
|
606 |
where |
|
607 |
"\<Gamma> \<turnstile> s is t : TUnit = True" |
|
608 |
| "\<Gamma> \<turnstile> s is t : TBase = \<Gamma> \<turnstile> s \<Leftrightarrow> t : TBase" |
|
609 |
| "\<Gamma> \<turnstile> s is t : (T\<^isub>1 \<rightarrow> T\<^isub>2) = |
|
22650
0c5b22076fb3
tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents:
22609
diff
changeset
|
610 |
(\<forall>\<Gamma>' s' t'. \<Gamma>\<subseteq>\<Gamma>' \<longrightarrow> valid \<Gamma>' \<longrightarrow> \<Gamma>' \<turnstile> s' is t' : T\<^isub>1 \<longrightarrow> (\<Gamma>' \<turnstile> (App s s') is (App t t') : T\<^isub>2))" |
22494 | 611 |
apply (auto simp add: ty.inject) |
612 |
apply (subgoal_tac "(\<exists>T\<^isub>1 T\<^isub>2. b=T\<^isub>1 \<rightarrow> T\<^isub>2) \<or> b=TUnit \<or> b=TBase" ) |
|
613 |
apply (force) |
|
614 |
apply (rule ty_cases) |
|
615 |
done |
|
616 |
||
617 |
termination |
|
618 |
apply(relation "measure (\<lambda>(_,_,_,T). size T)") |
|
619 |
apply(auto) |
|
620 |
done |
|
621 |
||
622 |
lemma logical_monotonicity : |
|
623 |
assumes a1: "\<Gamma> \<turnstile> s is t : T" |
|
22650
0c5b22076fb3
tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents:
22609
diff
changeset
|
624 |
and a2: "\<Gamma> \<subseteq> \<Gamma>'" |
22494 | 625 |
and a3: "valid \<Gamma>'" |
626 |
shows "\<Gamma>' \<turnstile> s is t : T" |
|
627 |
using a1 a2 a3 |
|
628 |
proof (induct arbitrary: \<Gamma>' rule: log_equiv.induct) |
|
629 |
case (2 \<Gamma> s t \<Gamma>') |
|
630 |
then show "\<Gamma>' \<turnstile> s is t : TBase" using algorithmic_monotonicity by auto |
|
631 |
next |
|
632 |
case (3 \<Gamma> s t T\<^isub>1 T\<^isub>2 \<Gamma>') |
|
633 |
have "\<Gamma> \<turnstile> s is t : T\<^isub>1\<rightarrow>T\<^isub>2" |
|
22650
0c5b22076fb3
tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents:
22609
diff
changeset
|
634 |
and "\<Gamma> \<subseteq> \<Gamma>'" |
22494 | 635 |
and "valid \<Gamma>'" by fact |
636 |
then show "\<Gamma>' \<turnstile> s is t : T\<^isub>1\<rightarrow>T\<^isub>2" by simp |
|
637 |
qed (auto) |
|
638 |
||
639 |
lemma main_lemma: |
|
640 |
shows "\<Gamma> \<turnstile> s is t : T \<Longrightarrow> valid \<Gamma> \<Longrightarrow> \<Gamma> \<turnstile> s \<Leftrightarrow> t : T" |
|
641 |
and "\<Gamma> \<turnstile> p \<leftrightarrow> q : T \<Longrightarrow> \<Gamma> \<turnstile> p is q : T" |
|
642 |
proof (nominal_induct T arbitrary: \<Gamma> s t p q rule: ty.induct) |
|
643 |
case (Arrow T\<^isub>1 T\<^isub>2) |
|
644 |
{ |
|
645 |
case (1 \<Gamma> s t) |
|
646 |
have ih1:"\<And>\<Gamma> s t. \<lbrakk>\<Gamma> \<turnstile> s is t : T\<^isub>2; valid \<Gamma>\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> s \<Leftrightarrow> t : T\<^isub>2" by fact |
|
647 |
have ih2:"\<And>\<Gamma> s t. \<Gamma> \<turnstile> s \<leftrightarrow> t : T\<^isub>1 \<Longrightarrow> \<Gamma> \<turnstile> s is t : T\<^isub>1" by fact |
|
648 |
have h:"\<Gamma> \<turnstile> s is t : T\<^isub>1\<rightarrow>T\<^isub>2" by fact |
|
649 |
obtain x::name where fs:"x\<sharp>(\<Gamma>,s,t)" by (erule exists_fresh[OF fs_name1]) |
|
650 |
have "valid \<Gamma>" by fact |
|
651 |
then have v: "valid ((x,T\<^isub>1)#\<Gamma>)" using fs by auto |
|
652 |
then have "(x,T\<^isub>1)#\<Gamma> \<turnstile> Var x \<leftrightarrow> Var x : T\<^isub>1" by auto |
|
653 |
then have "(x,T\<^isub>1)#\<Gamma> \<turnstile> Var x is Var x : T\<^isub>1" using ih2 by auto |
|
654 |
then have "(x,T\<^isub>1)#\<Gamma> \<turnstile> App s (Var x) is App t (Var x) : T\<^isub>2" using h v by auto |
|
655 |
then have "(x,T\<^isub>1)#\<Gamma> \<turnstile> App s (Var x) \<Leftrightarrow> App t (Var x) : T\<^isub>2" using ih1 v by auto |
|
656 |
then show "\<Gamma> \<turnstile> s \<Leftrightarrow> t : T\<^isub>1\<rightarrow>T\<^isub>2" using fs by (auto simp add: fresh_prod) |
|
657 |
next |
|
658 |
case (2 \<Gamma> p q) |
|
659 |
have h: "\<Gamma> \<turnstile> p \<leftrightarrow> q : T\<^isub>1\<rightarrow>T\<^isub>2" by fact |
|
660 |
have ih1:"\<And>\<Gamma> s t. \<Gamma> \<turnstile> s \<leftrightarrow> t : T\<^isub>2 \<Longrightarrow> \<Gamma> \<turnstile> s is t : T\<^isub>2" by fact |
|
661 |
have ih2:"\<And>\<Gamma> s t. \<lbrakk>\<Gamma> \<turnstile> s is t : T\<^isub>1; valid \<Gamma>\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> s \<Leftrightarrow> t : T\<^isub>1" by fact |
|
662 |
{ |
|
663 |
fix \<Gamma>' s t |
|
22650
0c5b22076fb3
tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents:
22609
diff
changeset
|
664 |
assume "\<Gamma> \<subseteq> \<Gamma>'" and hl:"\<Gamma>' \<turnstile> s is t : T\<^isub>1" and hk: "valid \<Gamma>'" |
22494 | 665 |
then have "\<Gamma>' \<turnstile> p \<leftrightarrow> q : T\<^isub>1 \<rightarrow> T\<^isub>2" using h algorithmic_monotonicity by auto |
666 |
moreover have "\<Gamma>' \<turnstile> s \<Leftrightarrow> t : T\<^isub>1" using ih2 hl hk by auto |
|
667 |
ultimately have "\<Gamma>' \<turnstile> App p s \<leftrightarrow> App q t : T\<^isub>2" by auto |
|
668 |
then have "\<Gamma>' \<turnstile> App p s is App q t : T\<^isub>2" using ih1 by auto |
|
669 |
} |
|
670 |
then show "\<Gamma> \<turnstile> p is q : T\<^isub>1\<rightarrow>T\<^isub>2" by simp |
|
671 |
} |
|
672 |
next |
|
673 |
case TBase |
|
674 |
{ case 2 |
|
675 |
have h:"\<Gamma> \<turnstile> s \<leftrightarrow> t : TBase" by fact |
|
676 |
then have "s \<leadsto>|" and "t \<leadsto>|" using path_equiv_implies_nf by auto |
|
677 |
then have "s \<Down> s" and "t \<Down> t" by auto |
|
678 |
then have "\<Gamma> \<turnstile> s \<Leftrightarrow> t : TBase" using h by auto |
|
679 |
then show "\<Gamma> \<turnstile> s is t : TBase" by auto |
|
680 |
} |
|
681 |
qed (auto elim: alg_path_equiv_implies_valid) |
|
682 |
||
683 |
corollary corollary_main: |
|
684 |
assumes a: "\<Gamma> \<turnstile> s \<leftrightarrow> t : T" |
|
685 |
shows "\<Gamma> \<turnstile> s \<Leftrightarrow> t : T" |
|
686 |
using a main_lemma alg_path_equiv_implies_valid by blast |
|
22073 | 687 |
|
688 |
lemma logical_symmetry: |
|
22082 | 689 |
assumes a: "\<Gamma> \<turnstile> s is t : T" |
22073 | 690 |
shows "\<Gamma> \<turnstile> t is s : T" |
22082 | 691 |
using a |
22494 | 692 |
by (nominal_induct arbitrary: \<Gamma> s t rule: ty.induct) |
693 |
(auto simp add: algorithmic_symmetry) |
|
22073 | 694 |
|
695 |
lemma logical_transitivity: |
|
696 |
assumes "\<Gamma> \<turnstile> s is t : T" "\<Gamma> \<turnstile> t is u : T" |
|
697 |
shows "\<Gamma> \<turnstile> s is u : T" |
|
698 |
using assms |
|
699 |
proof (nominal_induct arbitrary: \<Gamma> s t u rule:ty.induct) |
|
700 |
case TBase |
|
701 |
then show "\<Gamma> \<turnstile> s is u : TBase" by (auto elim: algorithmic_transitivity) |
|
702 |
next |
|
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
703 |
case (Arrow T\<^isub>1 T\<^isub>2 \<Gamma> s t u) |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
704 |
have h1:"\<Gamma> \<turnstile> s is t : T\<^isub>1 \<rightarrow> T\<^isub>2" by fact |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
705 |
have h2:"\<Gamma> \<turnstile> t is u : T\<^isub>1 \<rightarrow> T\<^isub>2" by fact |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
706 |
have ih1:"\<And>\<Gamma> s t u. \<lbrakk>\<Gamma> \<turnstile> s is t : T\<^isub>1; \<Gamma> \<turnstile> t is u : T\<^isub>1\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> s is u : T\<^isub>1" by fact |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
707 |
have ih2:"\<And>\<Gamma> s t u. \<lbrakk>\<Gamma> \<turnstile> s is t : T\<^isub>2; \<Gamma> \<turnstile> t is u : T\<^isub>2\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> s is u : T\<^isub>2" by fact |
22073 | 708 |
{ |
709 |
fix \<Gamma>' s' u' |
|
22650
0c5b22076fb3
tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents:
22609
diff
changeset
|
710 |
assume hsub:"\<Gamma> \<subseteq> \<Gamma>'" and hl:"\<Gamma>' \<turnstile> s' is u' : T\<^isub>1" and hk: "valid \<Gamma>'" |
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
711 |
then have "\<Gamma>' \<turnstile> u' is s' : T\<^isub>1" using logical_symmetry by blast |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
712 |
then have "\<Gamma>' \<turnstile> u' is u' : T\<^isub>1" using ih1 hl by blast |
22494 | 713 |
then have "\<Gamma>' \<turnstile> App t u' is App u u' : T\<^isub>2" using h2 hsub hk by auto |
714 |
moreover have "\<Gamma>' \<turnstile> App s s' is App t u' : T\<^isub>2" using h1 hsub hl hk by auto |
|
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
715 |
ultimately have "\<Gamma>' \<turnstile> App s s' is App u u' : T\<^isub>2" using ih2 by blast |
22073 | 716 |
} |
22494 | 717 |
then show "\<Gamma> \<turnstile> s is u : T\<^isub>1 \<rightarrow> T\<^isub>2" by auto |
22073 | 718 |
qed (auto) |
719 |
||
720 |
lemma logical_weak_head_closure: |
|
22494 | 721 |
assumes a: "\<Gamma> \<turnstile> s is t : T" |
722 |
and b: "s' \<leadsto> s" |
|
723 |
and c: "t' \<leadsto> t" |
|
22073 | 724 |
shows "\<Gamma> \<turnstile> s' is t' : T" |
22494 | 725 |
using a b c algorithmic_weak_head_closure |
726 |
by (nominal_induct arbitrary: \<Gamma> s t s' t' rule: ty.induct) |
|
727 |
(auto, blast) |
|
22073 | 728 |
|
729 |
lemma logical_weak_head_closure': |
|
22494 | 730 |
assumes "\<Gamma> \<turnstile> s is t : T" and "s' \<leadsto> s" |
22073 | 731 |
shows "\<Gamma> \<turnstile> s' is t : T" |
732 |
using assms |
|
22082 | 733 |
proof (nominal_induct arbitrary: \<Gamma> s t s' rule: ty.induct) |
22073 | 734 |
case (TBase \<Gamma> s t s') |
735 |
then show ?case by force |
|
736 |
next |
|
737 |
case (TUnit \<Gamma> s t s') |
|
738 |
then show ?case by auto |
|
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
739 |
next |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
740 |
case (Arrow T\<^isub>1 T\<^isub>2 \<Gamma> s t s') |
22073 | 741 |
have h1:"s' \<leadsto> s" by fact |
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
742 |
have ih:"\<And>\<Gamma> s t s'. \<lbrakk>\<Gamma> \<turnstile> s is t : T\<^isub>2; s' \<leadsto> s\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> s' is t : T\<^isub>2" by fact |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
743 |
have h2:"\<Gamma> \<turnstile> s is t : T\<^isub>1\<rightarrow>T\<^isub>2" by fact |
22494 | 744 |
then |
22650
0c5b22076fb3
tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents:
22609
diff
changeset
|
745 |
have hb:"\<forall>\<Gamma>' s' t'. \<Gamma>\<subseteq>\<Gamma>' \<longrightarrow> valid \<Gamma>' \<longrightarrow> \<Gamma>' \<turnstile> s' is t' : T\<^isub>1 \<longrightarrow> (\<Gamma>' \<turnstile> (App s s') is (App t t') : T\<^isub>2)" |
22494 | 746 |
by auto |
22073 | 747 |
{ |
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
748 |
fix \<Gamma>' s\<^isub>2 t\<^isub>2 |
22650
0c5b22076fb3
tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents:
22609
diff
changeset
|
749 |
assume "\<Gamma> \<subseteq> \<Gamma>'" and "\<Gamma>' \<turnstile> s\<^isub>2 is t\<^isub>2 : T\<^isub>1" and "valid \<Gamma>'" |
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
750 |
then have "\<Gamma>' \<turnstile> (App s s\<^isub>2) is (App t t\<^isub>2) : T\<^isub>2" using hb by auto |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
751 |
moreover have "(App s' s\<^isub>2) \<leadsto> (App s s\<^isub>2)" using h1 by auto |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
752 |
ultimately have "\<Gamma>' \<turnstile> App s' s\<^isub>2 is App t t\<^isub>2 : T\<^isub>2" using ih by auto |
22073 | 753 |
} |
22494 | 754 |
then show "\<Gamma> \<turnstile> s' is t : T\<^isub>1\<rightarrow>T\<^isub>2" by auto |
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
755 |
qed |
22073 | 756 |
|
757 |
abbreviation |
|
22494 | 758 |
log_equiv_for_psubsts :: "Ctxt \<Rightarrow> Subst \<Rightarrow> Subst \<Rightarrow> Ctxt \<Rightarrow> bool" ("_ \<turnstile> _ is _ over _" [60,60] 60) |
22073 | 759 |
where |
22494 | 760 |
"\<Gamma>' \<turnstile> \<theta> is \<theta>' over \<Gamma> \<equiv> \<forall>x T. (x,T) \<in> set \<Gamma> \<longrightarrow> \<Gamma>' \<turnstile> \<theta><Var x> is \<theta>'<Var x> : T" |
22073 | 761 |
|
762 |
lemma logical_pseudo_reflexivity: |
|
763 |
assumes "\<Gamma>' \<turnstile> t is s over \<Gamma>" |
|
764 |
shows "\<Gamma>' \<turnstile> s is s over \<Gamma>" |
|
765 |
proof - |
|
766 |
have "\<Gamma>' \<turnstile> t is s over \<Gamma>" by fact |
|
767 |
moreover then have "\<Gamma>' \<turnstile> s is t over \<Gamma>" using logical_symmetry by blast |
|
768 |
ultimately show "\<Gamma>' \<turnstile> s is s over \<Gamma>" using logical_transitivity by blast |
|
769 |
qed |
|
770 |
||
771 |
lemma logical_subst_monotonicity : |
|
22494 | 772 |
assumes a: "\<Gamma>' \<turnstile> s is t over \<Gamma>" |
22650
0c5b22076fb3
tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents:
22609
diff
changeset
|
773 |
and b: "\<Gamma>' \<subseteq> \<Gamma>''" |
22494 | 774 |
and c: "valid \<Gamma>''" |
22073 | 775 |
shows "\<Gamma>'' \<turnstile> s is t over \<Gamma>" |
22494 | 776 |
using a b c logical_monotonicity by blast |
22073 | 777 |
|
778 |
lemma equiv_subst_ext : |
|
22494 | 779 |
assumes h1: "\<Gamma>' \<turnstile> \<theta> is \<theta>' over \<Gamma>" |
780 |
and h2: "\<Gamma>' \<turnstile> s is t : T" |
|
781 |
and fs: "x\<sharp>\<Gamma>" |
|
782 |
shows "\<Gamma>' \<turnstile> (x,s)#\<theta> is (x,t)#\<theta>' over (x,T)#\<Gamma>" |
|
22073 | 783 |
using assms |
784 |
proof - |
|
22494 | 785 |
{ |
786 |
fix y U |
|
787 |
assume "(y,U) \<in> set ((x,T)#\<Gamma>)" |
|
788 |
moreover |
|
789 |
{ |
|
790 |
assume "(y,U) \<in> set [(x,T)]" |
|
791 |
then have "\<Gamma>' \<turnstile> (x,s)#\<theta><Var y> is (x,t)#\<theta>'<Var y> : U" by auto |
|
792 |
} |
|
793 |
moreover |
|
794 |
{ |
|
795 |
assume hl:"(y,U) \<in> set \<Gamma>" |
|
796 |
then have "\<not> y\<sharp>\<Gamma>" by (induct \<Gamma>) (auto simp add: fresh_list_cons fresh_atm fresh_prod) |
|
797 |
then have hf:"x\<sharp> Var y" using fs by (auto simp add: fresh_atm) |
|
798 |
then have "(x,s)#\<theta><Var y> = \<theta><Var y>" "(x,t)#\<theta>'<Var y> = \<theta>'<Var y>" using fresh_psubst_simp by blast+ |
|
799 |
moreover have "\<Gamma>' \<turnstile> \<theta><Var y> is \<theta>'<Var y> : U" using h1 hl by auto |
|
800 |
ultimately have "\<Gamma>' \<turnstile> (x,s)#\<theta><Var y> is (x,t)#\<theta>'<Var y> : U" by auto |
|
801 |
} |
|
802 |
ultimately have "\<Gamma>' \<turnstile> (x,s)#\<theta><Var y> is (x,t)#\<theta>'<Var y> : U" by auto |
|
22073 | 803 |
} |
22494 | 804 |
then show "\<Gamma>' \<turnstile> (x,s)#\<theta> is (x,t)#\<theta>' over (x,T)#\<Gamma>" by auto |
22073 | 805 |
qed |
806 |
||
22494 | 807 |
theorem fundamental_theorem_1: |
808 |
assumes h1: "\<Gamma> \<turnstile> t : T" |
|
809 |
and h2: "\<Gamma>' \<turnstile> \<theta> is \<theta>' over \<Gamma>" |
|
810 |
and h3: "valid \<Gamma>'" |
|
811 |
shows "\<Gamma>' \<turnstile> \<theta><t> is \<theta>'<t> : T" |
|
812 |
using h1 h2 h3 |
|
22531 | 813 |
proof (nominal_induct \<Gamma> t T avoiding: \<Gamma>' \<theta> \<theta>' rule: typing.strong_induct) |
22494 | 814 |
case (t_Lam x \<Gamma> T\<^isub>1 t\<^isub>2 T\<^isub>2 \<Gamma>' \<theta> \<theta>') |
815 |
have fs:"x\<sharp>\<theta>" "x\<sharp>\<theta>'" "x\<sharp>\<Gamma>" by fact |
|
816 |
have h:"\<Gamma>' \<turnstile> \<theta> is \<theta>' over \<Gamma>" by fact |
|
817 |
have ih:"\<And> \<Gamma>' \<theta> \<theta>'. \<lbrakk>\<Gamma>' \<turnstile> \<theta> is \<theta>' over (x,T\<^isub>1)#\<Gamma>; valid \<Gamma>'\<rbrakk> \<Longrightarrow> \<Gamma>' \<turnstile> \<theta><t\<^isub>2> is \<theta>'<t\<^isub>2> : T\<^isub>2" by fact |
|
818 |
{ |
|
819 |
fix \<Gamma>'' s' t' |
|
22650
0c5b22076fb3
tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents:
22609
diff
changeset
|
820 |
assume "\<Gamma>' \<subseteq> \<Gamma>''" and hl:"\<Gamma>''\<turnstile> s' is t' : T\<^isub>1" and v: "valid \<Gamma>''" |
22494 | 821 |
then have "\<Gamma>'' \<turnstile> \<theta> is \<theta>' over \<Gamma>" using logical_subst_monotonicity h by blast |
822 |
then have "\<Gamma>'' \<turnstile> (x,s')#\<theta> is (x,t')#\<theta>' over (x,T\<^isub>1)#\<Gamma>" using equiv_subst_ext hl fs by blast |
|
823 |
then have "\<Gamma>'' \<turnstile> (x,s')#\<theta><t\<^isub>2> is (x,t')#\<theta>'<t\<^isub>2> : T\<^isub>2" using ih v by auto |
|
824 |
then have "\<Gamma>''\<turnstile>\<theta><t\<^isub>2>[x::=s'] is \<theta>'<t\<^isub>2>[x::=t'] : T\<^isub>2" using psubst_subst_psubst fs by simp |
|
825 |
moreover have "App (Lam [x].\<theta><t\<^isub>2>) s' \<leadsto> \<theta><t\<^isub>2>[x::=s']" by auto |
|
826 |
moreover have "App (Lam [x].\<theta>'<t\<^isub>2>) t' \<leadsto> \<theta>'<t\<^isub>2>[x::=t']" by auto |
|
827 |
ultimately have "\<Gamma>''\<turnstile> App (Lam [x].\<theta><t\<^isub>2>) s' is App (Lam [x].\<theta>'<t\<^isub>2>) t' : T\<^isub>2" |
|
828 |
using logical_weak_head_closure by auto |
|
829 |
} |
|
830 |
then show "\<Gamma>' \<turnstile> \<theta><Lam [x].t\<^isub>2> is \<theta>'<Lam [x].t\<^isub>2> : T\<^isub>1\<rightarrow>T\<^isub>2" using fs by simp |
|
22073 | 831 |
qed (auto) |
832 |
||
833 |
theorem fundamental_theorem_2: |
|
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
834 |
assumes h1: "\<Gamma> \<turnstile> s \<equiv> t : T" |
22494 | 835 |
and h2: "\<Gamma>' \<turnstile> \<theta> is \<theta>' over \<Gamma>" |
836 |
and h3: "valid \<Gamma>'" |
|
837 |
shows "\<Gamma>' \<turnstile> \<theta><s> is \<theta>'<t> : T" |
|
838 |
using h1 h2 h3 |
|
22531 | 839 |
proof (nominal_induct \<Gamma> s t T avoiding: \<Gamma>' \<theta> \<theta>' rule: def_equiv.strong_induct) |
22494 | 840 |
case (Q_Refl \<Gamma> t T \<Gamma>' \<theta> \<theta>') |
841 |
have "\<Gamma> \<turnstile> t : T" |
|
842 |
and "valid \<Gamma>'" by fact |
|
843 |
moreover |
|
844 |
have "\<Gamma>' \<turnstile> \<theta> is \<theta>' over \<Gamma>" by fact |
|
845 |
ultimately show "\<Gamma>' \<turnstile> \<theta><t> is \<theta>'<t> : T" using fundamental_theorem_1 by blast |
|
22073 | 846 |
next |
22494 | 847 |
case (Q_Symm \<Gamma> t s T \<Gamma>' \<theta> \<theta>') |
848 |
have "\<Gamma>' \<turnstile> \<theta> is \<theta>' over \<Gamma>" |
|
849 |
and "valid \<Gamma>'" by fact |
|
850 |
moreover |
|
851 |
have ih: "\<And> \<Gamma>' \<theta> \<theta>'. \<lbrakk>\<Gamma>' \<turnstile> \<theta> is \<theta>' over \<Gamma>; valid \<Gamma>'\<rbrakk> \<Longrightarrow> \<Gamma>' \<turnstile> \<theta><t> is \<theta>'<s> : T" by fact |
|
852 |
ultimately show "\<Gamma>' \<turnstile> \<theta><s> is \<theta>'<t> : T" using logical_symmetry by blast |
|
22073 | 853 |
next |
22494 | 854 |
case (Q_Trans \<Gamma> s t T u \<Gamma>' \<theta> \<theta>') |
855 |
have ih1: "\<And> \<Gamma>' \<theta> \<theta>'. \<lbrakk>\<Gamma>' \<turnstile> \<theta> is \<theta>' over \<Gamma>; valid \<Gamma>'\<rbrakk> \<Longrightarrow> \<Gamma>' \<turnstile> \<theta><s> is \<theta>'<t> : T" by fact |
|
856 |
have ih2: "\<And> \<Gamma>' \<theta> \<theta>'. \<lbrakk>\<Gamma>' \<turnstile> \<theta> is \<theta>' over \<Gamma>; valid \<Gamma>'\<rbrakk> \<Longrightarrow> \<Gamma>' \<turnstile> \<theta><t> is \<theta>'<u> : T" by fact |
|
857 |
have h: "\<Gamma>' \<turnstile> \<theta> is \<theta>' over \<Gamma>" |
|
858 |
and v: "valid \<Gamma>'" by fact |
|
859 |
then have "\<Gamma>' \<turnstile> \<theta>' is \<theta>' over \<Gamma>" using logical_pseudo_reflexivity by auto |
|
860 |
then have "\<Gamma>' \<turnstile> \<theta>'<t> is \<theta>'<u> : T" using ih2 v by auto |
|
861 |
moreover have "\<Gamma>' \<turnstile> \<theta><s> is \<theta>'<t> : T" using ih1 h v by auto |
|
862 |
ultimately show "\<Gamma>' \<turnstile> \<theta><s> is \<theta>'<u> : T" using logical_transitivity by blast |
|
863 |
next |
|
864 |
case (Q_Abs x \<Gamma> T\<^isub>1 s\<^isub>2 t\<^isub>2 T\<^isub>2 \<Gamma>' \<theta> \<theta>') |
|
22073 | 865 |
have fs:"x\<sharp>\<Gamma>" by fact |
22494 | 866 |
have fs2: "x\<sharp>\<theta>" "x\<sharp>\<theta>'" by fact |
867 |
have h2: "\<Gamma>' \<turnstile> \<theta> is \<theta>' over \<Gamma>" |
|
868 |
and h3: "valid \<Gamma>'" by fact |
|
869 |
have ih:"\<And>\<Gamma>' \<theta> \<theta>'. \<lbrakk>\<Gamma>' \<turnstile> \<theta> is \<theta>' over (x,T\<^isub>1)#\<Gamma>; valid \<Gamma>'\<rbrakk> \<Longrightarrow> \<Gamma>' \<turnstile> \<theta><s\<^isub>2> is \<theta>'<t\<^isub>2> : T\<^isub>2" by fact |
|
22073 | 870 |
{ |
871 |
fix \<Gamma>'' s' t' |
|
22650
0c5b22076fb3
tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents:
22609
diff
changeset
|
872 |
assume "\<Gamma>' \<subseteq> \<Gamma>''" and hl:"\<Gamma>''\<turnstile> s' is t' : T\<^isub>1" and hk: "valid \<Gamma>''" |
22494 | 873 |
then have "\<Gamma>'' \<turnstile> \<theta> is \<theta>' over \<Gamma>" using h2 logical_subst_monotonicity by blast |
874 |
then have "\<Gamma>'' \<turnstile> (x,s')#\<theta> is (x,t')#\<theta>' over (x,T\<^isub>1)#\<Gamma>" using equiv_subst_ext hl fs by blast |
|
875 |
then have "\<Gamma>'' \<turnstile> (x,s')#\<theta><s\<^isub>2> is (x,t')#\<theta>'<t\<^isub>2> : T\<^isub>2" using ih hk by blast |
|
876 |
then have "\<Gamma>''\<turnstile> \<theta><s\<^isub>2>[x::=s'] is \<theta>'<t\<^isub>2>[x::=t'] : T\<^isub>2" using fs2 psubst_subst_psubst by auto |
|
877 |
moreover have "App (Lam [x]. \<theta><s\<^isub>2>) s' \<leadsto> \<theta><s\<^isub>2>[x::=s']" |
|
878 |
and "App (Lam [x].\<theta>'<t\<^isub>2>) t' \<leadsto> \<theta>'<t\<^isub>2>[x::=t']" by auto |
|
879 |
ultimately have "\<Gamma>'' \<turnstile> App (Lam [x]. \<theta><s\<^isub>2>) s' is App (Lam [x].\<theta>'<t\<^isub>2>) t' : T\<^isub>2" |
|
22073 | 880 |
using logical_weak_head_closure by auto |
881 |
} |
|
882 |
moreover have "valid \<Gamma>'" using h2 by auto |
|
22494 | 883 |
ultimately have "\<Gamma>' \<turnstile> Lam [x].\<theta><s\<^isub>2> is Lam [x].\<theta>'<t\<^isub>2> : T\<^isub>1\<rightarrow>T\<^isub>2" by auto |
884 |
then show "\<Gamma>' \<turnstile> \<theta><Lam [x].s\<^isub>2> is \<theta>'<Lam [x].t\<^isub>2> : T\<^isub>1\<rightarrow>T\<^isub>2" using fs2 by auto |
|
22073 | 885 |
next |
22494 | 886 |
case (Q_App \<Gamma> s\<^isub>1 t\<^isub>1 T\<^isub>1 T\<^isub>2 s\<^isub>2 t\<^isub>2 \<Gamma>' \<theta> \<theta>') |
887 |
then show "\<Gamma>' \<turnstile> \<theta><App s\<^isub>1 s\<^isub>2> is \<theta>'<App t\<^isub>1 t\<^isub>2> : T\<^isub>2" by auto |
|
22073 | 888 |
next |
22531 | 889 |
case (Q_Beta x \<Gamma> s\<^isub>2 t\<^isub>2 T\<^isub>1 s12 t12 T\<^isub>2 \<Gamma>' \<theta> \<theta>') |
22494 | 890 |
have h: "\<Gamma>' \<turnstile> \<theta> is \<theta>' over \<Gamma>" |
891 |
and h': "valid \<Gamma>'" by fact |
|
892 |
have fs: "x\<sharp>\<Gamma>" by fact |
|
893 |
have fs2: " x\<sharp>\<theta>" "x\<sharp>\<theta>'" by fact |
|
894 |
have ih1: "\<And>\<Gamma>' \<theta> \<theta>'. \<lbrakk>\<Gamma>' \<turnstile> \<theta> is \<theta>' over \<Gamma>; valid \<Gamma>'\<rbrakk> \<Longrightarrow> \<Gamma>' \<turnstile> \<theta><s\<^isub>2> is \<theta>'<t\<^isub>2> : T\<^isub>1" by fact |
|
895 |
have ih2: "\<And>\<Gamma>' \<theta> \<theta>'. \<lbrakk>\<Gamma>' \<turnstile> \<theta> is \<theta>' over (x,T\<^isub>1)#\<Gamma>; valid \<Gamma>'\<rbrakk> \<Longrightarrow> \<Gamma>' \<turnstile> \<theta><s12> is \<theta>'<t12> : T\<^isub>2" by fact |
|
896 |
have "\<Gamma>' \<turnstile> \<theta><s\<^isub>2> is \<theta>'<t\<^isub>2> : T\<^isub>1" using ih1 h' h by auto |
|
897 |
then have "\<Gamma>' \<turnstile> (x,\<theta><s\<^isub>2>)#\<theta> is (x,\<theta>'<t\<^isub>2>)#\<theta>' over (x,T\<^isub>1)#\<Gamma>" using equiv_subst_ext h fs by blast |
|
898 |
then have "\<Gamma>' \<turnstile> (x,\<theta><s\<^isub>2>)#\<theta><s12> is (x,\<theta>'<t\<^isub>2>)#\<theta>'<t12> : T\<^isub>2" using ih2 h' by auto |
|
899 |
then have "\<Gamma>' \<turnstile> \<theta><s12>[x::=\<theta><s\<^isub>2>] is \<theta>'<t12>[x::=\<theta>'<t\<^isub>2>] : T\<^isub>2" using fs2 psubst_subst_psubst by auto |
|
900 |
then have "\<Gamma>' \<turnstile> \<theta><s12>[x::=\<theta><s\<^isub>2>] is \<theta>'<t12[x::=t\<^isub>2]> : T\<^isub>2" using fs2 psubst_subst_propagate by auto |
|
901 |
moreover have "App (Lam [x].\<theta><s12>) (\<theta><s\<^isub>2>) \<leadsto> \<theta><s12>[x::=\<theta><s\<^isub>2>]" by auto |
|
902 |
ultimately have "\<Gamma>' \<turnstile> App (Lam [x].\<theta><s12>) (\<theta><s\<^isub>2>) is \<theta>'<t12[x::=t\<^isub>2]> : T\<^isub>2" |
|
22073 | 903 |
using logical_weak_head_closure' by auto |
22494 | 904 |
then show "\<Gamma>' \<turnstile> \<theta><App (Lam [x].s12) s\<^isub>2> is \<theta>'<t12[x::=t\<^isub>2]> : T\<^isub>2" using fs2 by simp |
22073 | 905 |
next |
22494 | 906 |
case (Q_Ext x \<Gamma> s t T\<^isub>1 T\<^isub>2 \<Gamma>' \<theta> \<theta>') |
907 |
have h2: "\<Gamma>' \<turnstile> \<theta> is \<theta>' over \<Gamma>" |
|
908 |
and h2': "valid \<Gamma>'" by fact |
|
22073 | 909 |
have fs:"x\<sharp>\<Gamma>" "x\<sharp>s" "x\<sharp>t" by fact |
22494 | 910 |
have ih:"\<And>\<Gamma>' \<theta> \<theta>'. \<lbrakk>\<Gamma>' \<turnstile> \<theta> is \<theta>' over (x,T\<^isub>1)#\<Gamma>; valid \<Gamma>'\<rbrakk> |
911 |
\<Longrightarrow> \<Gamma>' \<turnstile> \<theta><App s (Var x)> is \<theta>'<App t (Var x)> : T\<^isub>2" by fact |
|
22073 | 912 |
{ |
913 |
fix \<Gamma>'' s' t' |
|
22650
0c5b22076fb3
tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents:
22609
diff
changeset
|
914 |
assume hsub: "\<Gamma>' \<subseteq> \<Gamma>''" and hl: "\<Gamma>''\<turnstile> s' is t' : T\<^isub>1" and hk: "valid \<Gamma>''" |
22494 | 915 |
then have "\<Gamma>'' \<turnstile> \<theta> is \<theta>' over \<Gamma>" using h2 logical_subst_monotonicity by blast |
916 |
then have "\<Gamma>'' \<turnstile> (x,s')#\<theta> is (x,t')#\<theta>' over (x,T\<^isub>1)#\<Gamma>" using equiv_subst_ext hl fs by blast |
|
917 |
then have "\<Gamma>'' \<turnstile> (x,s')#\<theta><App s (Var x)> is (x,t')#\<theta>'<App t (Var x)> : T\<^isub>2" using ih hk by blast |
|
918 |
then |
|
919 |
have "\<Gamma>'' \<turnstile> App (((x,s')#\<theta>)<s>) (((x,s')#\<theta>)<(Var x)>) is App ((x,t')#\<theta>'<t>) ((x,t')#\<theta>'<(Var x)>) : T\<^isub>2" |
|
22082 | 920 |
by auto |
22494 | 921 |
then have "\<Gamma>'' \<turnstile> App ((x,s')#\<theta><s>) s' is App ((x,t')#\<theta>'<t>) t' : T\<^isub>2" by auto |
922 |
then have "\<Gamma>'' \<turnstile> App (\<theta><s>) s' is App (\<theta>'<t>) t' : T\<^isub>2" using fs fresh_psubst_simp by auto |
|
22073 | 923 |
} |
924 |
moreover have "valid \<Gamma>'" using h2 by auto |
|
22494 | 925 |
ultimately show "\<Gamma>' \<turnstile> \<theta><s> is \<theta>'<t> : T\<^isub>1\<rightarrow>T\<^isub>2" by auto |
22073 | 926 |
qed |
927 |
||
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
928 |
|
22073 | 929 |
theorem completeness: |
22494 | 930 |
assumes asm: "\<Gamma> \<turnstile> s \<equiv> t : T" |
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
931 |
shows "\<Gamma> \<turnstile> s \<Leftrightarrow> t : T" |
22073 | 932 |
proof - |
22494 | 933 |
have val: "valid \<Gamma>" using def_equiv_implies_valid asm by simp |
934 |
moreover |
|
22073 | 935 |
{ |
936 |
fix x T |
|
937 |
assume "(x,T) \<in> set \<Gamma>" "valid \<Gamma>" |
|
22494 | 938 |
then have "\<Gamma> \<turnstile> Var x is Var x : T" using main_lemma(2) by blast |
22073 | 939 |
} |
940 |
ultimately have "\<Gamma> \<turnstile> [] is [] over \<Gamma>" by auto |
|
22494 | 941 |
then have "\<Gamma> \<turnstile> []<s> is []<t> : T" using fundamental_theorem_2 val asm by blast |
22073 | 942 |
then have "\<Gamma> \<turnstile> s is t : T" by simp |
22494 | 943 |
then show "\<Gamma> \<turnstile> s \<Leftrightarrow> t : T" using main_lemma(1) val by simp |
22073 | 944 |
qed |
945 |
||
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
946 |
text {* We leave soundness as an exercise - like in the book :-) \\ |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
947 |
@{prop[mode=IfThen] "\<lbrakk>\<Gamma> \<turnstile> s \<Leftrightarrow> t : T; \<Gamma> \<turnstile> t : T; \<Gamma> \<turnstile> s : T\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> s \<equiv> t : T"} \\ |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
948 |
@{prop "\<lbrakk>\<Gamma> \<turnstile> s \<leftrightarrow> t : T; \<Gamma> \<turnstile> t : T; \<Gamma> \<turnstile> s : T\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> s \<equiv> t : T"} |
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
22231
diff
changeset
|
949 |
*} |
22073 | 950 |
|
951 |
end |
|
952 |