author | wenzelm |
Sat, 17 Dec 2005 01:00:40 +0100 | |
changeset 18428 | 4059413acbc1 |
parent 18424 | a37f06555c07 |
child 18577 | a636846a02c7 |
permissions | -rw-r--r-- |
18266
55c201fe4c95
added an authors section (please let me know if somebody is left out or unhappy)
urbanc
parents:
18263
diff
changeset
|
1 |
(* $Id$ *) |
55c201fe4c95
added an authors section (please let me know if somebody is left out or unhappy)
urbanc
parents:
18263
diff
changeset
|
2 |
|
18269 | 3 |
theory fsub |
4 |
imports "../nominal" |
|
5 |
begin |
|
6 |
||
18424 | 7 |
text {* Authors: Christian Urban, |
8 |
Benjamin Pierce, |
|
9 |
Steve Zdancewic. |
|
10 |
Stephanie Weihrich and |
|
11 |
Dimitrios Vytiniotis; |
|
18266
55c201fe4c95
added an authors section (please let me know if somebody is left out or unhappy)
urbanc
parents:
18263
diff
changeset
|
12 |
|
18424 | 13 |
with help from Stefan Berghofer and Markus Wenzel. |
18266
55c201fe4c95
added an authors section (please let me know if somebody is left out or unhappy)
urbanc
parents:
18263
diff
changeset
|
14 |
*} |
55c201fe4c95
added an authors section (please let me know if somebody is left out or unhappy)
urbanc
parents:
18263
diff
changeset
|
15 |
|
18246 | 16 |
|
18424 | 17 |
section {* Atom Types, Types and Terms *} |
18 |
||
18246 | 19 |
atom_decl tyvrs vrs |
20 |
||
18424 | 21 |
nominal_datatype ty = |
22 |
TVar "tyvrs" |
|
23 |
| Top |
|
24 |
| Arrow "ty" "ty" ("_ \<rightarrow> _" [900,900] 900) |
|
25 |
| TAll "\<guillemotleft>tyvrs\<guillemotright>ty" "ty" |
|
18246 | 26 |
|
18424 | 27 |
nominal_datatype trm = |
28 |
Var "vrs" |
|
29 |
| Lam "\<guillemotleft>vrs\<guillemotright>trm" "ty" |
|
30 |
| TAbs "\<guillemotleft>tyvrs\<guillemotright>trm" "ty" |
|
31 |
| App "trm" "trm" |
|
32 |
| TApp "trm" "ty" |
|
18246 | 33 |
|
34 |
syntax |
|
35 |
TAll_syn :: "tyvrs \<Rightarrow> ty \<Rightarrow> ty \<Rightarrow> ty" ("\<forall> [_<:_]._" [900,900,900] 900) |
|
18424 | 36 |
Lam_syn :: "vrs \<Rightarrow> ty \<Rightarrow> trm \<Rightarrow> trm" ("Lam [_:_]._" [100,100,100] 100) |
37 |
TAbs_syn :: "tyvrs \<Rightarrow> ty \<Rightarrow> trm \<Rightarrow> trm" ("TAbs [_<:_]._" [100,100,100] 100) |
|
38 |
||
18246 | 39 |
translations |
18424 | 40 |
"\<forall>[a<:ty1].ty2" \<rightleftharpoons> "TAll a ty2 ty1" |
41 |
"Lam [a:tys].t" \<rightleftharpoons> "trm.Lam a t tys" |
|
42 |
"TAbs [a<:tys].t" \<rightleftharpoons> "trm.TAbs a t tys" |
|
18246 | 43 |
|
18424 | 44 |
subsection {* Typing contexts and Their Domains *} |
18246 | 45 |
|
46 |
types ty_context = "(tyvrs\<times>ty) list" |
|
47 |
||
48 |
consts |
|
49 |
"domain" :: "ty_context \<Rightarrow> tyvrs set" |
|
50 |
primrec |
|
51 |
"domain [] = {}" |
|
52 |
"domain (X#\<Gamma>) = {fst X}\<union>(domain \<Gamma>)" |
|
53 |
||
54 |
lemma domain_eqvt: |
|
55 |
fixes pi::"tyvrs prm" |
|
56 |
shows "pi\<bullet>(domain \<Gamma>) = domain (pi\<bullet>\<Gamma>)" |
|
57 |
by (induct \<Gamma>, auto simp add: perm_set_def) |
|
58 |
||
59 |
lemma finite_domain: |
|
60 |
fixes \<Gamma>::"ty_context" |
|
61 |
shows "finite (domain \<Gamma>)" |
|
62 |
by (induct \<Gamma>, auto) |
|
63 |
||
18424 | 64 |
lemma domain_inclusion: |
65 |
assumes a: "(X,T)\<in>set \<Gamma>" |
|
66 |
shows "X\<in>(domain \<Gamma>)" |
|
67 |
using a by (induct \<Gamma>, auto) |
|
18246 | 68 |
|
18424 | 69 |
lemma domain_existence: |
70 |
assumes a: "X\<in>(domain \<Gamma>)" |
|
71 |
shows "\<exists>T.(X,T)\<in>set \<Gamma>" |
|
72 |
using a by (induct \<Gamma>, auto) |
|
18246 | 73 |
|
74 |
lemma domain_append: |
|
75 |
shows "domain (\<Gamma>@\<Delta>) = ((domain \<Gamma>) \<union> (domain \<Delta>))" |
|
76 |
by (induct \<Gamma>, auto) |
|
77 |
||
18424 | 78 |
section {* Size Functions and Capture Avoiding Substitutiuon for Types *} |
18246 | 79 |
|
80 |
text {* they cannot yet be defined conveniently unless we have a recursion combinator *} |
|
81 |
||
82 |
consts size_ty :: "ty \<Rightarrow> nat" |
|
83 |
||
84 |
lemma size_ty[simp]: |
|
18424 | 85 |
shows "size_ty (TVar X) = 1" |
18246 | 86 |
and "size_ty (Top) = 1" |
87 |
and "\<lbrakk>size_ty t1 = m ; size_ty t2 = n\<rbrakk> \<Longrightarrow> size_ty (t1 \<rightarrow> t2) = m + n + 1" |
|
88 |
and "\<lbrakk>size_ty t1 = m ; size_ty t2 = n\<rbrakk> \<Longrightarrow> size_ty (\<forall> [a<:t1].t2) = m + n + 1" |
|
89 |
sorry |
|
90 |
||
91 |
consts subst_ty :: "ty \<Rightarrow> tyvrs \<Rightarrow> ty \<Rightarrow> ty" |
|
92 |
||
93 |
lemma subst_ty[simp]: |
|
18424 | 94 |
shows "subst_ty (TVar X) Y T = (if X=Y then T else (TVar X))" |
18246 | 95 |
and "subst_ty Top Y T = Top" |
96 |
and "subst_ty (T1 \<rightarrow> T2) Y T = (subst_ty T1 Y T) \<rightarrow> (subst_ty T2 Y T)" |
|
97 |
and "X\<sharp>(Y,T) \<Longrightarrow> subst_ty (\<forall>[X<:T1].T2) Y T = (\<forall>[X<:(subst_ty T1 Y T)].(subst_ty T2 Y T))" |
|
98 |
and "\<lbrakk>X\<sharp>Y; X\<sharp>T\<rbrakk> \<Longrightarrow> subst_ty (\<forall>[X<:T1].T2) Y T = (\<forall>[X<:(subst_ty T1 Y T)].(subst_ty T2 Y T))" |
|
99 |
sorry |
|
100 |
||
101 |
||
102 |
consts subst_ctxt :: "ty_context \<Rightarrow> tyvrs \<Rightarrow> ty \<Rightarrow> ty_context" |
|
103 |
primrec |
|
104 |
"subst_ctxt [] Y T = []" |
|
105 |
"subst_ctxt (XT#Xs) Y T = (fst XT, subst_ty (snd XT) Y T)#(subst_ctxt Xs Y T)" |
|
106 |
||
18424 | 107 |
subsection {* valid contexts *} |
18246 | 108 |
|
109 |
constdefs |
|
110 |
"closed_in" :: "ty \<Rightarrow> ty_context \<Rightarrow> bool" ("_ closed'_in _" [100,100] 100) |
|
111 |
"S closed_in \<Gamma> \<equiv> (supp S)\<subseteq>(domain \<Gamma>)" |
|
112 |
||
113 |
lemma closed_in_def2: |
|
114 |
shows "(S closed_in \<Gamma>) = ((supp S)\<subseteq>((supp (domain \<Gamma>)):: tyvrs set))" |
|
115 |
apply(simp add: closed_in_def) |
|
116 |
apply(simp add: at_fin_set_supp[OF at_tyvrs_inst, OF finite_domain]) |
|
117 |
done |
|
118 |
||
119 |
lemma closed_in_eqvt: |
|
120 |
fixes pi::"tyvrs prm" |
|
121 |
assumes a: "S closed_in \<Gamma>" |
|
122 |
shows "(pi\<bullet>S) closed_in (pi\<bullet>\<Gamma>)" |
|
123 |
using a |
|
124 |
proof (unfold "closed_in_def") |
|
18424 | 125 |
assume "supp S \<subseteq> (domain \<Gamma>)" |
18246 | 126 |
hence "pi\<bullet>(supp S) \<subseteq> pi\<bullet>(domain \<Gamma>)" |
127 |
by (simp add: pt_subseteq_eqvt[OF pt_tyvrs_inst, OF at_tyvrs_inst]) |
|
128 |
thus "(supp (pi\<bullet>S)) \<subseteq> (domain (pi\<bullet>\<Gamma>))" |
|
129 |
by (simp add: domain_eqvt pt_perm_supp[OF pt_tyvrs_inst, OF at_tyvrs_inst]) |
|
130 |
qed |
|
131 |
||
132 |
consts |
|
133 |
valid_rel :: "ty_context set" |
|
134 |
valid_sym :: "ty_context \<Rightarrow> bool" ("\<turnstile> _ ok" [100] 100) |
|
135 |
translations |
|
136 |
"\<turnstile> \<Gamma> ok" \<rightleftharpoons> "\<Gamma> \<in> valid_rel" |
|
137 |
inductive valid_rel |
|
138 |
intros |
|
139 |
v1[intro]: "\<turnstile> [] ok" |
|
140 |
v2[intro]: "\<lbrakk>\<turnstile> \<Gamma> ok; X\<sharp>\<Gamma>; T closed_in \<Gamma>\<rbrakk> \<Longrightarrow> \<turnstile> ((X,T)#\<Gamma>) ok" |
|
141 |
||
142 |
lemma valid_eqvt: |
|
143 |
fixes pi::"tyvrs prm" |
|
144 |
assumes a: "\<turnstile> \<Gamma> ok" |
|
145 |
shows "\<turnstile> (pi\<bullet>\<Gamma>) ok" |
|
146 |
using a |
|
147 |
proof (induct) |
|
148 |
case v1 |
|
149 |
show ?case by force |
|
150 |
next |
|
151 |
case (v2 T X \<Gamma>) |
|
152 |
have a1: "\<turnstile> (pi \<bullet> \<Gamma>) ok" by fact |
|
153 |
have a2: "X\<sharp>\<Gamma>" by fact |
|
154 |
have a3: "T closed_in \<Gamma>" by fact |
|
155 |
show ?case |
|
156 |
proof (simp, rule valid_rel.v2) |
|
157 |
show "\<turnstile> (pi \<bullet> \<Gamma>) ok" using a1 by simp |
|
158 |
next |
|
18424 | 159 |
show "(pi\<bullet>X)\<sharp>(pi\<bullet>\<Gamma>)" using a2 by (simp add: fresh_eqvt) |
18246 | 160 |
next |
161 |
show "(pi\<bullet>T) closed_in (pi\<bullet>\<Gamma>)" using a3 by (rule closed_in_eqvt) |
|
162 |
qed |
|
163 |
qed |
|
164 |
||
165 |
lemma validE: |
|
166 |
assumes a: "\<turnstile> ((X,T)#\<Gamma>) ok" |
|
167 |
shows "\<turnstile> \<Gamma> ok \<and> X\<sharp>\<Gamma> \<and> T closed_in \<Gamma>" |
|
168 |
using a by (cases, auto) |
|
169 |
||
18424 | 170 |
lemma validE_append: |
171 |
assumes a: "\<turnstile> (\<Delta>@\<Gamma>) ok" |
|
172 |
shows "\<turnstile> \<Gamma> ok" |
|
173 |
using a by (induct \<Delta>, auto dest: validE) |
|
18246 | 174 |
|
18424 | 175 |
lemma domain_fresh: |
18246 | 176 |
fixes X::"tyvrs" |
18424 | 177 |
assumes a: "\<turnstile> \<Gamma> ok" |
178 |
shows "X\<sharp>(domain \<Gamma>) = X\<sharp>\<Gamma>" |
|
179 |
using a |
|
18246 | 180 |
apply(induct \<Gamma>) |
18424 | 181 |
apply(auto simp add: fresh_list_nil fresh_list_cons fresh_set_empty fresh_prod fresh_atm |
182 |
fresh_fin_insert[OF pt_tyvrs_inst, OF at_tyvrs_inst, OF fs_tyvrs_inst, OF finite_domain]) |
|
183 |
apply(force simp add: closed_in_def2 fresh_def) |
|
18246 | 184 |
done |
185 |
||
186 |
lemma closed_in_fresh: |
|
187 |
fixes X::"tyvrs" |
|
188 |
assumes a1: "S closed_in \<Gamma>" |
|
189 |
and a2: "X\<sharp>\<Gamma>" |
|
190 |
and a3: "\<turnstile> \<Gamma> ok" |
|
191 |
shows "X\<sharp>S" |
|
192 |
using a1 a2 a3 |
|
193 |
apply(simp add: closed_in_def2) |
|
194 |
apply(simp add: domain_fresh[symmetric]) |
|
195 |
apply(simp add: fresh_def) |
|
196 |
apply(force) |
|
197 |
done |
|
198 |
||
18424 | 199 |
lemma replace_type: |
200 |
assumes a: "\<turnstile> (\<Delta>@(X,T)#\<Gamma>) ok" |
|
201 |
and b: "S closed_in \<Gamma>" |
|
202 |
shows "\<turnstile> (\<Delta>@(X,S)#\<Gamma>) ok" |
|
203 |
using a b |
|
18246 | 204 |
apply(induct \<Delta>) |
205 |
apply(auto dest!: validE intro!: v2 simp add: fresh_list_append fresh_list_cons fresh_prod) |
|
206 |
apply(drule validE_append) |
|
207 |
apply(drule validE) |
|
208 |
apply(drule_tac S="S" in closed_in_fresh) |
|
209 |
apply(simp) |
|
210 |
apply(force)+ |
|
211 |
apply(simp add: closed_in_def2) |
|
212 |
apply(simp add: domain_append) |
|
213 |
done |
|
214 |
||
18424 | 215 |
lemma fresh_implies_not_member: |
18246 | 216 |
fixes \<Gamma>::"ty_context" |
18424 | 217 |
assumes a: "X\<sharp>\<Gamma>" |
218 |
shows "\<not>(\<exists>T.(X,T)\<in>(set \<Gamma>))" |
|
219 |
using a |
|
18246 | 220 |
apply (induct \<Gamma>) |
221 |
apply (auto dest: validE simp add: fresh_list_cons fresh_prod fresh_atm) |
|
222 |
done |
|
223 |
||
224 |
lemma uniqueness_of_ctxt: |
|
225 |
fixes \<Gamma>::"ty_context" |
|
18412 | 226 |
assumes a: "\<turnstile> \<Gamma> ok" |
227 |
and b: "(X,T)\<in>set \<Gamma>" |
|
228 |
and c: "(X,S)\<in>set \<Gamma>" |
|
229 |
shows "T=S" |
|
230 |
using a b c |
|
231 |
apply (induct \<Gamma>) |
|
232 |
apply (auto dest!: validE fresh_implies_not_member) |
|
233 |
done |
|
18246 | 234 |
|
235 |
section {* Subtyping *} |
|
236 |
||
237 |
consts |
|
238 |
subtype_of_rel :: "(ty_context \<times> ty \<times> ty) set" |
|
239 |
subtype_of_sym :: "ty_context \<Rightarrow> ty \<Rightarrow> ty \<Rightarrow> bool" ("_ \<turnstile> _ <: _" [100,100,100] 100) |
|
240 |
translations |
|
241 |
"\<Gamma> \<turnstile> S <: T" \<rightleftharpoons> "(\<Gamma>,S,T) \<in> subtype_of_rel" |
|
242 |
inductive subtype_of_rel |
|
243 |
intros |
|
244 |
S_Top[intro]: "\<lbrakk>\<turnstile> \<Gamma> ok; S closed_in \<Gamma>\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> S <: Top" |
|
18424 | 245 |
S_Var[intro]: "\<lbrakk>\<turnstile> \<Gamma> ok; (X,S) \<in> set \<Gamma>; \<Gamma> \<turnstile> S <: T\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> (TVar X) <: T" |
246 |
S_Refl[intro]: "\<lbrakk>\<turnstile> \<Gamma> ok; X \<in> domain \<Gamma>\<rbrakk>\<Longrightarrow> \<Gamma> \<turnstile> TVar X <: TVar X" |
|
18246 | 247 |
S_Arrow[intro]: "\<lbrakk>\<Gamma> \<turnstile> T1 <: S1; \<Gamma> \<turnstile> S2 <: T2\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> (S1 \<rightarrow> S2) <: (T1 \<rightarrow> T2)" |
248 |
S_All[intro]: "\<lbrakk>\<Gamma> \<turnstile> T1 <: S1; X\<sharp>\<Gamma>; ((X,T1)#\<Gamma>) \<turnstile> S2 <: T2\<rbrakk> |
|
249 |
\<Longrightarrow> \<Gamma> \<turnstile> \<forall> [X<:S1].S2 <: \<forall> [X<:T1].T2" |
|
250 |
||
251 |
lemma subtype_implies_closed: |
|
252 |
assumes a: "\<Gamma> \<turnstile> S <: T" |
|
253 |
shows "S closed_in \<Gamma> \<and> T closed_in \<Gamma>" |
|
254 |
using a |
|
255 |
proof (induct) |
|
256 |
case (S_Top S \<Gamma>) |
|
18424 | 257 |
have "Top closed_in \<Gamma>" by (simp add: closed_in_def ty.supp) |
18246 | 258 |
moreover |
259 |
have "S closed_in \<Gamma>" by fact |
|
260 |
ultimately show "S closed_in \<Gamma> \<and> Top closed_in \<Gamma>" by simp |
|
261 |
next |
|
262 |
case (S_Var S T X \<Gamma>) |
|
263 |
have "(X,S)\<in>set \<Gamma>" by fact |
|
18424 | 264 |
hence "X \<in> domain \<Gamma>" by (rule domain_inclusion) |
265 |
hence "(TVar X) closed_in \<Gamma>" by (simp add: closed_in_def ty.supp supp_atm) |
|
18246 | 266 |
moreover |
267 |
have "S closed_in \<Gamma> \<and> T closed_in \<Gamma>" by fact |
|
268 |
hence "T closed_in \<Gamma>" by force |
|
18424 | 269 |
ultimately show "(TVar X) closed_in \<Gamma> \<and> T closed_in \<Gamma>" by simp |
270 |
qed (auto simp add: closed_in_def ty.supp supp_atm abs_supp) |
|
18246 | 271 |
|
272 |
||
273 |
lemma subtype_implies_ok: |
|
274 |
fixes X::"tyvrs" |
|
275 |
assumes a1: "\<Gamma> \<turnstile> S <: T" |
|
276 |
shows "\<turnstile> \<Gamma> ok" |
|
277 |
using a1 by (induct, auto) |
|
278 |
||
279 |
lemma subtype_implies_fresh: |
|
280 |
fixes X::"tyvrs" |
|
281 |
assumes a1: "\<Gamma> \<turnstile> S <: T" |
|
282 |
and a2: "X\<sharp>\<Gamma>" |
|
18424 | 283 |
shows "X\<sharp>S \<and> X\<sharp>T" |
18246 | 284 |
proof - |
285 |
from a1 have "\<turnstile> \<Gamma> ok" by (rule subtype_implies_ok) |
|
18424 | 286 |
with a2 have "X\<sharp>domain(\<Gamma>)" by (simp add: domain_fresh) |
287 |
moreover |
|
18246 | 288 |
from a1 have "S closed_in \<Gamma> \<and> T closed_in \<Gamma>" by (rule subtype_implies_closed) |
18424 | 289 |
hence "supp S \<subseteq> ((supp (domain \<Gamma>))::tyvrs set)" |
290 |
and "supp T \<subseteq> ((supp (domain \<Gamma>))::tyvrs set)" by (simp_all add: closed_in_def2) |
|
291 |
ultimately show "X\<sharp>S \<and> X\<sharp>T" by (force simp add: supp_prod fresh_def) |
|
18246 | 292 |
qed |
293 |
||
294 |
lemma silly_eqvt1: |
|
295 |
fixes X::"'a::pt_tyvrs" |
|
296 |
and S::"'b::pt_tyvrs" |
|
297 |
and pi::"tyvrs prm" |
|
298 |
shows "(X,S) \<in> set \<Gamma> \<Longrightarrow> (pi\<bullet>X,pi\<bullet>S) \<in> set (pi\<bullet>\<Gamma>)" |
|
299 |
apply(drule_tac pi="pi" in pt_set_bij2[OF pt_tyvrs_inst, OF at_tyvrs_inst]) |
|
300 |
apply(simp add: pt_list_set_pi[OF pt_tyvrs_inst]) |
|
301 |
done |
|
302 |
||
303 |
lemma silly_eqvt2: |
|
304 |
fixes X::"tyvrs" |
|
305 |
and pi::"tyvrs prm" |
|
306 |
shows "X \<in> (domain \<Gamma>) \<Longrightarrow> (pi\<bullet>X) \<in> (domain (pi\<bullet>\<Gamma>))" |
|
307 |
apply(drule_tac pi="pi" in pt_set_bij2[OF pt_tyvrs_inst, OF at_tyvrs_inst]) |
|
308 |
apply(simp add: domain_eqvt pt_list_set_pi[OF pt_tyvrs_inst] ) |
|
309 |
done |
|
310 |
||
311 |
lemma subtype_eqvt: |
|
312 |
fixes pi::"tyvrs prm" |
|
313 |
shows "\<Gamma> \<turnstile> S <: T \<Longrightarrow> (pi\<bullet>\<Gamma>) \<turnstile> (pi\<bullet>S) <: (pi\<bullet>T)" |
|
314 |
apply(erule subtype_of_rel.induct) |
|
315 |
apply(force intro: valid_eqvt closed_in_eqvt) |
|
316 |
apply(force intro: closed_in_eqvt valid_eqvt silly_eqvt1) |
|
317 |
apply(force intro: valid_eqvt silly_eqvt2) |
|
318 |
apply(force) |
|
319 |
apply(force intro!: S_All simp add: fresh_prod pt_fresh_bij1[OF pt_tyvrs_inst, OF at_tyvrs_inst]) |
|
320 |
done |
|
321 |
||
18305
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
322 |
lemma subtype_of_rel_induct[consumes 1, case_names S_Top S_Var S_Refl S_Arrow S_All]: |
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
323 |
fixes P :: "'a::fs_tyvrs\<Rightarrow>ty_context \<Rightarrow> ty \<Rightarrow> ty \<Rightarrow>bool" |
18246 | 324 |
assumes a: "\<Gamma> \<turnstile> S <: T" |
18424 | 325 |
and a1: "\<And>\<Gamma> S x. \<turnstile> \<Gamma> ok \<Longrightarrow> S closed_in \<Gamma> \<Longrightarrow> P x \<Gamma> S Top" |
326 |
and a2: "\<And>\<Gamma> X S T x. \<turnstile> \<Gamma> ok \<Longrightarrow> (X,S)\<in>set \<Gamma> \<Longrightarrow> \<Gamma> \<turnstile> S <: T \<Longrightarrow> (\<And>z. P z \<Gamma> S T) |
|
327 |
\<Longrightarrow> P x \<Gamma> (TVar X) T" |
|
328 |
and a3: "\<And>\<Gamma> X x. \<turnstile> \<Gamma> ok \<Longrightarrow> X\<in>domain \<Gamma> \<Longrightarrow> P x \<Gamma> (TVar X) (TVar X)" |
|
18305
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
329 |
and a4: "\<And>\<Gamma> S1 S2 T1 T2 x. \<Gamma> \<turnstile> T1 <: S1 \<Longrightarrow> (\<And>z. P z \<Gamma> T1 S1) \<Longrightarrow> \<Gamma> \<turnstile> S2 <: T2 \<Longrightarrow> |
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
330 |
(\<And>z. P z \<Gamma> S2 T2) \<Longrightarrow> P x \<Gamma> (S1 \<rightarrow> S2) (T1 \<rightarrow> T2)" |
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
331 |
and a5: "\<And>\<Gamma> X S1 S2 T1 T2 x. |
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
332 |
X\<sharp>x \<Longrightarrow> X\<sharp>(\<Gamma>,S1,T1) \<Longrightarrow> \<Gamma> \<turnstile> T1 <: S1 \<Longrightarrow> (\<And>z. P z \<Gamma> T1 S1) \<Longrightarrow> ((X,T1)#\<Gamma>) \<turnstile> S2 <: T2 |
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
333 |
\<Longrightarrow> (\<And>z. P z ((X,T1)#\<Gamma>) S2 T2) \<Longrightarrow> P x \<Gamma> (\<forall> [X<:S1].S2) (\<forall> [X<:T1].T2)" |
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
334 |
shows "P x \<Gamma> S T" |
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
335 |
proof - |
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
336 |
from a have "\<And>(pi::tyvrs prm) (x::'a::fs_tyvrs). P x (pi\<bullet>\<Gamma>) (pi\<bullet>S) (pi\<bullet>T)" |
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
337 |
proof (induct) |
18424 | 338 |
case (S_Top S \<Gamma>) |
339 |
thus "P x (pi\<bullet>\<Gamma>) (pi\<bullet>S) (pi\<bullet>Top)" by (force intro: valid_eqvt closed_in_eqvt a1) |
|
18305
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
340 |
next |
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
341 |
case (S_Var S T X \<Gamma>) |
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
342 |
have b1: "\<turnstile> \<Gamma> ok" by fact |
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
343 |
have b2: "(X,S) \<in> set \<Gamma>" by fact |
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
344 |
have b3: "\<Gamma> \<turnstile> S <: T" by fact |
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
345 |
have b4: "\<And>(pi::tyvrs prm) x. P x (pi\<bullet>\<Gamma>) (pi\<bullet>S) (pi\<bullet>T)" by fact |
18246 | 346 |
from b1 have "\<turnstile> (pi\<bullet>\<Gamma>) ok" by (rule valid_eqvt) |
347 |
moreover |
|
348 |
from b2 have "pi\<bullet>(X,S)\<in>pi\<bullet>(set \<Gamma>)" by (rule pt_set_bij2[OF pt_tyvrs_inst, OF at_tyvrs_inst]) |
|
349 |
hence "(pi\<bullet>X,pi\<bullet>S)\<in>set (pi\<bullet>\<Gamma>)" by (simp add: pt_list_set_pi[OF pt_tyvrs_inst]) |
|
350 |
moreover |
|
351 |
from b3 have "(pi\<bullet>\<Gamma>) \<turnstile> (pi\<bullet>S) <: (pi\<bullet>T)" by (rule subtype_eqvt) |
|
352 |
moreover |
|
18305
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
353 |
from b4 have "\<And>x. P x (pi\<bullet>\<Gamma>) (pi\<bullet>S) (pi\<bullet>T)" by simp |
18246 | 354 |
ultimately |
18424 | 355 |
show "P x (pi\<bullet>\<Gamma>) (pi\<bullet>(TVar X)) (pi\<bullet>T)" by (simp add: a2) |
18305
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
356 |
next |
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
357 |
case (S_Refl X \<Gamma>) |
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
358 |
have b1: "\<turnstile> \<Gamma> ok" by fact |
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
359 |
have b2: "X \<in> domain \<Gamma>" by fact |
18246 | 360 |
from b1 have "\<turnstile> (pi\<bullet>\<Gamma>) ok" by (rule valid_eqvt) |
361 |
moreover |
|
362 |
from b2 have "(pi\<bullet>X)\<in>pi\<bullet>domain \<Gamma>" by (rule pt_set_bij2[OF pt_tyvrs_inst, OF at_tyvrs_inst]) |
|
363 |
hence "(pi\<bullet>X)\<in>domain (pi\<bullet>\<Gamma>)" by (simp add: domain_eqvt pt_list_set_pi[OF pt_tyvrs_inst]) |
|
18424 | 364 |
ultimately show "P x (pi\<bullet>\<Gamma>) (pi\<bullet>(TVar X)) (pi\<bullet>(TVar X))" by (simp add: a3) |
18305
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
365 |
next |
18424 | 366 |
case S_Arrow thus ?case by (auto intro: a4 subtype_eqvt) |
18305
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
367 |
next |
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
368 |
case (S_All S1 S2 T1 T2 X \<Gamma>) |
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
369 |
have b1: "\<Gamma> \<turnstile> T1 <: S1" by fact |
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
370 |
have b2: "\<And>(pi::tyvrs prm) x. P x (pi\<bullet>\<Gamma>) (pi\<bullet>T1) (pi\<bullet>S1)" by fact |
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
371 |
have b4: "((X,T1)#\<Gamma>) \<turnstile> S2 <: T2" by fact |
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
372 |
have b5: "\<And>(pi::tyvrs prm) x. P x (pi\<bullet>((X,T1)#\<Gamma>)) (pi\<bullet>S2) (pi\<bullet>T2)" by fact |
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
373 |
have b3': "X\<sharp>\<Gamma>" by fact |
18424 | 374 |
have b3'': "X\<sharp>T1" "X\<sharp>S1" using b1 b3' by (simp_all add: subtype_implies_fresh) |
18305
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
375 |
have b3: "X\<sharp>(\<Gamma>,S1,T1)" using b3' b3'' by (simp add: fresh_prod) |
18246 | 376 |
have "\<exists>C::tyvrs. C\<sharp>(pi\<bullet>X,pi\<bullet>S2,pi\<bullet>T2,pi\<bullet>S1,pi\<bullet>T1,pi\<bullet>\<Gamma>,x)" |
377 |
by (rule at_exists_fresh[OF at_tyvrs_inst], simp add: fs_tyvrs1) |
|
378 |
then obtain C::"tyvrs" where f1: "C\<noteq>(pi\<bullet>X)" and f2: "C\<sharp>(pi\<bullet>S1)" and f3: "C\<sharp>(pi\<bullet>T1)" |
|
379 |
and f4: "C\<sharp>(pi\<bullet>S2)" and f5: "C\<sharp>(pi\<bullet>T2)" and f6: "C\<sharp>(pi\<bullet>\<Gamma>)" and f7: "C\<sharp>x" |
|
380 |
by (auto simp add: fresh_prod fresh_atm) |
|
381 |
let ?pi' = "[(C,pi\<bullet>X)]@pi" |
|
18305
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
382 |
from b2 have c1: "\<And>x. P x (?pi'\<bullet>\<Gamma>) (?pi'\<bullet>T1) (?pi'\<bullet>S1)" by simp |
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
383 |
from b5 have "\<And>x. P x (?pi'\<bullet>((X,T1)#\<Gamma>)) (?pi'\<bullet>S2) (?pi'\<bullet>T2)" by simp |
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
384 |
hence "\<And>x. P x ((?pi'\<bullet>X,?pi'\<bullet>T1)#(?pi'\<bullet>\<Gamma>)) (?pi'\<bullet>S2) (?pi'\<bullet>T2)" by simp |
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
385 |
hence c2: "\<And>x. P x ((C,?pi'\<bullet>T1)#(?pi'\<bullet>\<Gamma>)) (?pi'\<bullet>S2) (?pi'\<bullet>T2)" using f1 |
18246 | 386 |
by (simp only: pt_tyvrs2 calc_atm, simp) |
387 |
from b3 have "(pi\<bullet>X)\<sharp>(pi\<bullet>\<Gamma>)" |
|
388 |
by (simp add: fresh_prod pt_fresh_bij[OF pt_tyvrs_inst, OF at_tyvrs_inst]) |
|
389 |
with f6 have f6a: "?pi'\<bullet>\<Gamma>=pi\<bullet>\<Gamma>" |
|
390 |
by (simp only: pt_tyvrs2 pt_fresh_fresh[OF pt_tyvrs_inst, OF at_tyvrs_inst]) |
|
391 |
hence f6': "C\<sharp>(?pi'\<bullet>\<Gamma>)" using f6 by simp |
|
392 |
from b3 have "(pi\<bullet>X)\<sharp>(pi\<bullet>S1)" |
|
393 |
by (simp add: fresh_prod pt_fresh_bij[OF pt_tyvrs_inst, OF at_tyvrs_inst]) |
|
394 |
with f2 have f2a: "?pi'\<bullet>S1=pi\<bullet>S1" |
|
395 |
by (simp only: pt_tyvrs2 pt_fresh_fresh[OF pt_tyvrs_inst, OF at_tyvrs_inst]) |
|
396 |
hence f2': "C\<sharp>(?pi'\<bullet>S1)" using f2 by simp |
|
397 |
from b3 have "(pi\<bullet>X)\<sharp>(pi\<bullet>T1)" |
|
398 |
by (simp add: fresh_prod pt_fresh_bij[OF pt_tyvrs_inst, OF at_tyvrs_inst]) |
|
399 |
with f3 have f3a: "?pi'\<bullet>T1=pi\<bullet>T1" |
|
400 |
by (simp only: pt_tyvrs2 pt_fresh_fresh[OF pt_tyvrs_inst, OF at_tyvrs_inst]) |
|
401 |
hence f3': "C\<sharp>(?pi'\<bullet>T1)" using f3 by simp |
|
402 |
from b1 have e1: "(?pi'\<bullet>\<Gamma>) \<turnstile> (?pi'\<bullet>T1) <: (?pi'\<bullet>S1)" by (rule subtype_eqvt) |
|
403 |
from b4 have "(?pi'\<bullet>((X,T1)#\<Gamma>)) \<turnstile> (?pi'\<bullet>S2) <: (?pi'\<bullet>T2)" by (rule subtype_eqvt) |
|
404 |
hence "((?pi'\<bullet>X,?pi'\<bullet>T1)#(?pi'\<bullet>\<Gamma>)) \<turnstile> (?pi'\<bullet>S2) <: (?pi'\<bullet>T2)" by simp |
|
405 |
hence e2: "((C,?pi'\<bullet>T1)#(?pi'\<bullet>\<Gamma>)) \<turnstile> (?pi'\<bullet>S2) <: (?pi'\<bullet>T2)" using f1 |
|
406 |
by (simp only: pt_tyvrs2 calc_atm, simp) |
|
407 |
have fnew: "C\<sharp>(?pi'\<bullet>\<Gamma>,?pi'\<bullet>S1,?pi'\<bullet>T1)" using f6' f2' f3' by (simp add: fresh_prod) |
|
18305
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
408 |
have main: "P x (?pi'\<bullet>\<Gamma>) (\<forall> [C<:(?pi'\<bullet>S1)].(?pi'\<bullet>S2)) (\<forall> [C<:(?pi'\<bullet>T1)].(?pi'\<bullet>T2))" |
18246 | 409 |
using f7 fnew e1 c1 e2 c2 by (rule a5) |
410 |
have alpha1: "(\<forall> [C<:(?pi'\<bullet>S1)].(?pi'\<bullet>S2)) = (pi\<bullet>(\<forall> [X<:S1].S2))" |
|
411 |
using f1 f4 f2a[symmetric] by (simp add: ty.inject alpha pt_tyvrs2[symmetric]) |
|
412 |
have alpha2: "(\<forall> [C<:(?pi'\<bullet>T1)].(?pi'\<bullet>T2)) = (pi\<bullet>(\<forall> [X<:T1].T2))" |
|
413 |
using f1 f5 f3a[symmetric] by (simp add: ty.inject alpha pt_tyvrs2[symmetric]) |
|
18305
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
414 |
show "P x (pi\<bullet>\<Gamma>) (pi\<bullet>(\<forall> [X<:S1].S2)) (pi\<bullet>(\<forall> [X<:T1].T2))" |
18246 | 415 |
using alpha1 alpha2 f6a main by simp |
416 |
qed |
|
18305
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
417 |
hence "P x (([]::tyvrs prm)\<bullet>\<Gamma>) (([]::tyvrs prm)\<bullet>S) (([]::tyvrs prm)\<bullet>T)" by blast |
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
418 |
thus ?thesis by simp |
18246 | 419 |
qed |
420 |
||
18424 | 421 |
subsection {* Reflexivity of Subtyping *} |
18246 | 422 |
|
423 |
lemma subtype_reflexivity: |
|
18353
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
424 |
assumes a: "\<turnstile> \<Gamma> ok" |
18424 | 425 |
and b: "T closed_in \<Gamma>" |
18353
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
426 |
shows "\<Gamma> \<turnstile> T <: T" |
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
427 |
using a b |
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
428 |
proof(nominal_induct T avoiding: \<Gamma> rule: ty.induct_unsafe) |
18424 | 429 |
case (TAll X T\<^isub>1 T\<^isub>2) |
430 |
have ih_T\<^isub>1: "\<And>\<Gamma>. \<turnstile> \<Gamma> ok \<Longrightarrow> T\<^isub>1 closed_in \<Gamma> \<Longrightarrow> \<Gamma> \<turnstile> T\<^isub>1 <: T\<^isub>1" by fact |
|
431 |
have ih_T\<^isub>2: "\<And>\<Gamma>. \<turnstile> \<Gamma> ok \<Longrightarrow> T\<^isub>2 closed_in \<Gamma> \<Longrightarrow> \<Gamma> \<turnstile> T\<^isub>2 <: T\<^isub>2" by fact |
|
432 |
have fresh_cond: "X\<sharp>\<Gamma>" by fact |
|
433 |
have "(\<forall>[X<:T\<^isub>2].T\<^isub>1) closed_in \<Gamma>" by fact |
|
434 |
hence closed\<^isub>T\<^isub>2: "T\<^isub>2 closed_in \<Gamma>" and closed\<^isub>T\<^isub>1: "T\<^isub>1 closed_in ((X,T\<^isub>2)#\<Gamma>)" |
|
435 |
by (auto simp add: closed_in_def ty.supp abs_supp) |
|
436 |
have ok: "\<turnstile> \<Gamma> ok" by fact |
|
437 |
hence ok': "\<turnstile> ((X,T\<^isub>2)#\<Gamma>) ok" using closed\<^isub>T\<^isub>2 fresh_cond by force |
|
438 |
have "\<Gamma> \<turnstile> T\<^isub>2 <: T\<^isub>2" using ih_T\<^isub>2 closed\<^isub>T\<^isub>2 ok by simp |
|
18353
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
439 |
moreover |
18424 | 440 |
have "((X,T\<^isub>2)#\<Gamma>) \<turnstile> T\<^isub>1 <: T\<^isub>1" using ih_T\<^isub>1 closed\<^isub>T\<^isub>1 ok' by simp |
441 |
ultimately show "\<Gamma> \<turnstile> \<forall>[X<:T\<^isub>2].T\<^isub>1 <: \<forall>[X<:T\<^isub>2].T\<^isub>1" using fresh_cond |
|
442 |
by (simp add: subtype_of_rel.S_All) |
|
18246 | 443 |
qed (auto simp add: closed_in_def ty.supp supp_atm) |
444 |
||
18305
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
445 |
lemma subtype_reflexivity: |
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
446 |
assumes a: "\<turnstile> \<Gamma> ok" |
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
447 |
and b: "T closed_in \<Gamma>" |
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
448 |
shows "\<Gamma> \<turnstile> T <: T" |
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
449 |
using a b |
18353
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
450 |
apply(nominal_induct T avoiding: \<Gamma> rule: ty.induct_unsafe) |
18246 | 451 |
apply(auto simp add: ty.supp abs_supp closed_in_def supp_atm) |
18424 | 452 |
--{* Too bad that this instantiation cannot be found automatically. *} |
18305
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
453 |
apply(drule_tac x="(tyvrs, ty2)#\<Gamma>" in meta_spec) |
18246 | 454 |
apply(force simp add: closed_in_def) |
455 |
done |
|
456 |
||
18424 | 457 |
text {* Inversion lemmas *} |
18246 | 458 |
lemma S_TopE: |
18424 | 459 |
assumes a: "\<Gamma> \<turnstile> Top <: T" |
460 |
shows "T = Top" |
|
461 |
using a by (cases, auto) |
|
18246 | 462 |
|
463 |
lemma S_ArrowE_left: |
|
464 |
assumes a: "\<Gamma> \<turnstile> S1 \<rightarrow> S2 <: T" |
|
465 |
shows "T = Top \<or> (\<exists>T1 T2. T = T1 \<rightarrow> T2 \<and> \<Gamma> \<turnstile> T1 <: S1 \<and> \<Gamma> \<turnstile> S2 <: T2)" |
|
18424 | 466 |
using a by (cases, auto simp add: ty.inject) |
18246 | 467 |
|
468 |
lemma S_AllE_left: |
|
18424 | 469 |
shows "\<lbrakk>\<Gamma> \<turnstile> \<forall>[X<:S1].S2 <: T; X\<sharp>\<Gamma>; X\<sharp>S1\<rbrakk> |
18246 | 470 |
\<Longrightarrow> T = Top \<or> (\<exists>T1 T2. T = \<forall>[X<:T1].T2 \<and> \<Gamma> \<turnstile> T1 <: S1 \<and> ((X,T1)#\<Gamma>) \<turnstile> S2 <: T2)" |
471 |
apply(frule subtype_implies_ok) |
|
472 |
apply(ind_cases "\<Gamma> \<turnstile> \<forall>[X<:S1].S2 <: T") |
|
473 |
apply(auto simp add: ty.inject alpha) |
|
474 |
apply(rule_tac x="[(X,Xa)]\<bullet>T2" in exI) |
|
475 |
(* term *) |
|
476 |
apply(rule conjI) |
|
477 |
apply(rule sym) |
|
478 |
apply(rule pt_bij2[OF pt_tyvrs_inst, OF at_tyvrs_inst]) |
|
479 |
apply(rule pt_tyvrs3) |
|
480 |
apply(simp) |
|
481 |
apply(rule at_ds5[OF at_tyvrs_inst]) |
|
482 |
(* 1st conjunct *) |
|
483 |
apply(rule conjI) |
|
484 |
apply(simp add: pt_fresh_left[OF pt_tyvrs_inst, OF at_tyvrs_inst] calc_atm) |
|
485 |
apply(drule_tac \<Gamma>="((Xa,T1)#\<Gamma>)" in subtype_implies_closed)+ |
|
486 |
apply(simp add: closed_in_def) |
|
18424 | 487 |
apply(simp add: domain_fresh[of "\<Gamma>" "X", symmetric]) |
18246 | 488 |
apply(simp add: fresh_def) |
489 |
apply(subgoal_tac "X \<notin> (insert Xa (domain \<Gamma>))")(*A*) |
|
490 |
apply(force) |
|
491 |
(*A*) |
|
492 |
apply(simp add: at_fin_set_supp[OF at_tyvrs_inst, OF finite_domain]) |
|
493 |
(* 2nd conjunct *) |
|
494 |
apply(frule_tac X="X" in subtype_implies_fresh) |
|
18424 | 495 |
apply(assumption) |
18246 | 496 |
apply(drule_tac X="Xa" in subtype_implies_fresh) |
497 |
apply(assumption) |
|
498 |
apply(simp add: fresh_prod) |
|
499 |
apply(drule_tac pi="[(X,Xa)]" in subtype_eqvt) |
|
500 |
apply(simp add: calc_atm) |
|
501 |
apply(simp add: pt_fresh_fresh[OF pt_tyvrs_inst, OF at_tyvrs_inst]) |
|
502 |
done |
|
503 |
||
18424 | 504 |
section {* Type Substitution *} |
18246 | 505 |
|
18424 | 506 |
lemma subst_ty_fresh: |
507 |
fixes X :: "tyvrs" |
|
508 |
assumes a: "X\<sharp>(T,P)" |
|
509 |
shows "X\<sharp>(subst_ty T Y P)" |
|
510 |
using a |
|
18353
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
511 |
apply (nominal_induct T avoiding : T Y P rule: ty.induct_unsafe) |
18246 | 512 |
apply (auto simp add: fresh_prod abs_fresh) |
513 |
done |
|
514 |
||
18424 | 515 |
lemma subst_ctxt_fresh: |
18246 | 516 |
fixes X::"tyvrs" |
18424 | 517 |
assumes a: "X\<sharp>(\<Gamma>,P)" |
518 |
shows "X\<sharp>(subst_ctxt \<Gamma> Y P)" |
|
519 |
using a |
|
18246 | 520 |
apply (induct \<Gamma>) |
521 |
apply (auto intro: subst_ty_fresh simp add: fresh_prod fresh_list_cons) |
|
522 |
done |
|
523 |
||
524 |
(* |
|
525 |
lemma subst_ctxt_closed: |
|
526 |
shows "subst_ty b X P closed_in (subst_ctxt \<Delta> X P @ \<Gamma>)" |
|
527 |
||
528 |
||
529 |
lemma substitution_ok: |
|
530 |
shows "\<turnstile> (\<Delta>@(X,Q)#\<Gamma>) ok \<longrightarrow> \<Gamma> \<turnstile> P <: Q \<longrightarrow> \<turnstile> ((subst_ctxt \<Delta> X P)@\<Gamma>) ok" |
|
531 |
apply (induct \<Delta>) |
|
532 |
apply (auto dest: validE) |
|
533 |
apply (rule v2) |
|
534 |
apply assumption |
|
535 |
apply (drule validE) |
|
536 |
apply (auto simp add: fresh_list_append) |
|
537 |
apply (rule subst_ctxt_fresh) |
|
538 |
apply (simp add: fresh_prod) |
|
539 |
apply (drule_tac X = "a" in subtype_implies_fresh) |
|
540 |
apply (simp add: fresh_list_cons) |
|
541 |
apply (simp add: fresh_prod) |
|
542 |
apply (simp add: fresh_list_cons) |
|
543 |
apply (drule validE) |
|
544 |
||
545 |
done |
|
546 |
*) |
|
547 |
||
548 |
(* note: What should nominal induct do if the context is compound? *) |
|
549 |
(* |
|
550 |
lemma type_substitution: |
|
551 |
assumes a0: "(\<Delta>@(X,Q)#\<Gamma>) \<turnstile> S <: T" |
|
552 |
shows "\<turnstile> (\<Delta>@(X,Q)#\<Gamma>) ok \<longrightarrow> \<Gamma> \<turnstile> P <: Q |
|
553 |
\<longrightarrow> ((subst_ctxt \<Delta> X P)@\<Gamma>) \<turnstile> (subst_ty S X P) <: (subst_ty T X P)" |
|
554 |
using a0 |
|
555 |
thm subtype_of_rel_induct |
|
556 |
apply(rule subtype_of_rel_induct[of "\<Delta>@(X,Q)#\<Gamma>" "S" "T" _ "P"]) |
|
557 |
apply(auto) |
|
558 |
apply(rule S_Top) |
|
559 |
defer |
|
560 |
defer |
|
561 |
defer |
|
562 |
apply(rule S_Var) |
|
563 |
defer |
|
564 |
defer |
|
565 |
defer |
|
566 |
defer |
|
567 |
apply(rule S_Refl) |
|
568 |
defer |
|
569 |
defer |
|
570 |
||
571 |
||
572 |
apply (nominal_induct \<Delta> X Q \<Gamma> S T rule: subtype_of_rel_induct) |
|
573 |
*) |
|
574 |
||
575 |
section {* Weakening *} |
|
576 |
||
577 |
constdefs |
|
578 |
extends :: "ty_context \<Rightarrow> ty_context \<Rightarrow> bool" ("_ extends _" [100,100] 100) |
|
579 |
"\<Delta> extends \<Gamma> \<equiv> \<forall>X Q. (X,Q)\<in>set \<Gamma> \<longrightarrow> (X,Q)\<in>set \<Delta>" |
|
580 |
||
581 |
lemma extends_domain: |
|
582 |
assumes a: "\<Delta> extends \<Gamma>" |
|
583 |
shows "domain \<Gamma> \<subseteq> domain \<Delta>" |
|
584 |
using a |
|
585 |
apply (auto simp add: extends_def) |
|
586 |
apply (drule domain_existence) |
|
587 |
apply (force simp add: domain_inclusion) |
|
588 |
done |
|
589 |
||
590 |
lemma extends_closed: |
|
591 |
assumes a1: "T closed_in \<Gamma>" |
|
592 |
and a2: "\<Delta> extends \<Gamma>" |
|
593 |
shows "T closed_in \<Delta>" |
|
594 |
using a1 a2 |
|
595 |
by (auto dest: extends_domain simp add: closed_in_def) |
|
596 |
||
18424 | 597 |
lemma extends_memb: |
598 |
assumes a: "\<Delta> extends \<Gamma>" |
|
599 |
and b: "(X,T) \<in> set \<Gamma>" |
|
600 |
shows "(X,T) \<in> set \<Delta>" |
|
601 |
using a b by (simp add: extends_def) |
|
602 |
||
18246 | 603 |
lemma weakening: |
18353
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
604 |
assumes a: "\<Gamma> \<turnstile> S <: T" |
18424 | 605 |
and b: "\<turnstile> \<Delta> ok" |
606 |
and c: "\<Delta> extends \<Gamma>" |
|
18353
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
607 |
shows "\<Delta> \<turnstile> S <: T" |
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
608 |
using a b c |
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
609 |
proof (nominal_induct \<Gamma> S T avoiding: \<Delta> rule: subtype_of_rel_induct) |
18305
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
610 |
case (S_Top \<Gamma> S) |
18246 | 611 |
have lh_drv_prem: "S closed_in \<Gamma>" by fact |
18353
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
612 |
have "\<turnstile> \<Delta> ok" by fact |
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
613 |
moreover |
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
614 |
have "\<Delta> extends \<Gamma>" by fact |
18424 | 615 |
hence "S closed_in \<Delta>" using lh_drv_prem by (simp only: extends_closed) |
18353
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
616 |
ultimately show "\<Delta> \<turnstile> S <: Top" by force |
18246 | 617 |
next |
18305
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
618 |
case (S_Var \<Gamma> X S T) |
18246 | 619 |
have lh_drv_prem: "(X,S) \<in> set \<Gamma>" by fact |
18353
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
620 |
have ih: "\<And>\<Delta>. \<turnstile> \<Delta> ok \<Longrightarrow> \<Delta> extends \<Gamma> \<Longrightarrow> \<Delta> \<turnstile> S <: T" by fact |
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
621 |
have ok: "\<turnstile> \<Delta> ok" by fact |
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
622 |
have extends: "\<Delta> extends \<Gamma>" by fact |
18424 | 623 |
have "(X,S) \<in> set \<Delta>" using lh_drv_prem extends by (simp only: extends_memb) |
18353
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
624 |
moreover |
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
625 |
have "\<Delta> \<turnstile> S <: T" using ok extends ih by simp |
18424 | 626 |
ultimately show "\<Delta> \<turnstile> TVar X <: T" using ok by force |
18246 | 627 |
next |
18305
a780f9c1538b
changed everything until the interesting transitivity_narrowing
urbanc
parents:
18269
diff
changeset
|
628 |
case (S_Refl \<Gamma> X) |
18246 | 629 |
have lh_drv_prem: "X \<in> domain \<Gamma>" by fact |
18353
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
630 |
have "\<turnstile> \<Delta> ok" by fact |
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
631 |
moreover |
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
632 |
have "\<Delta> extends \<Gamma>" by fact |
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
633 |
hence "X \<in> domain \<Delta>" using lh_drv_prem by (force dest: extends_domain) |
18424 | 634 |
ultimately show "\<Delta> \<turnstile> TVar X <: TVar X" by force |
18246 | 635 |
next |
18424 | 636 |
case (S_Arrow \<Gamma> S\<^isub>1 S\<^isub>2 T\<^isub>1 T\<^isub>2) thus "\<Delta> \<turnstile> S\<^isub>1 \<rightarrow> S\<^isub>2 <: T\<^isub>1 \<rightarrow> T\<^isub>2" by blast |
18246 | 637 |
next |
18424 | 638 |
case (S_All \<Gamma> X S\<^isub>1 S\<^isub>2 T\<^isub>1 T\<^isub>2) |
639 |
have fresh_cond: "X\<sharp>\<Delta>" by fact |
|
640 |
have ih\<^isub>1: "\<And>\<Delta>. \<turnstile> \<Delta> ok \<Longrightarrow> \<Delta> extends \<Gamma> \<Longrightarrow> \<Delta> \<turnstile> T\<^isub>1 <: S\<^isub>1" by fact |
|
641 |
have ih\<^isub>2: "\<And>\<Delta>. \<turnstile> \<Delta> ok \<Longrightarrow> \<Delta> extends ((X,T\<^isub>1)#\<Gamma>) \<Longrightarrow> \<Delta> \<turnstile> S\<^isub>2 <: T\<^isub>2" by fact |
|
642 |
have lh_drv_prem: "\<Gamma> \<turnstile> T\<^isub>1 <: S\<^isub>1" by fact |
|
643 |
hence closed\<^isub>T\<^isub>1: "T\<^isub>1 closed_in \<Gamma>" by (simp add: subtype_implies_closed) |
|
18353
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
644 |
have ok: "\<turnstile> \<Delta> ok" by fact |
18424 | 645 |
have ext: "\<Delta> extends \<Gamma>" by fact |
646 |
have "T\<^isub>1 closed_in \<Delta>" using ext closed\<^isub>T\<^isub>1 by (simp only: extends_closed) |
|
647 |
hence "\<turnstile> ((X,T\<^isub>1)#\<Delta>) ok" using fresh_cond ok by force |
|
18353
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
648 |
moreover |
18424 | 649 |
have "((X,T\<^isub>1)#\<Delta>) extends ((X,T\<^isub>1)#\<Gamma>)" using ext by (force simp add: extends_def) |
650 |
ultimately have "((X,T\<^isub>1)#\<Delta>) \<turnstile> S\<^isub>2 <: T\<^isub>2" using ih\<^isub>2 by simp |
|
18353
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
651 |
moreover |
18424 | 652 |
have "\<Delta> \<turnstile> T\<^isub>1 <: S\<^isub>1" using ok ext ih\<^isub>1 by simp |
653 |
ultimately show "\<Delta> \<turnstile> \<forall> [X<:S\<^isub>1].S\<^isub>2 <: \<forall> [X<:T\<^isub>1].T\<^isub>2" using ok by (force intro: S_All) |
|
18246 | 654 |
qed |
655 |
||
18424 | 656 |
text {* In fact all "non-binding" cases can be solved automatically: *} |
18246 | 657 |
|
658 |
lemma weakening: |
|
18353
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
659 |
assumes a: "\<Gamma> \<turnstile> S <: T" |
18424 | 660 |
and b: "\<turnstile> \<Delta> ok" |
661 |
and c: "\<Delta> extends \<Gamma>" |
|
18353
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
662 |
shows "\<Delta> \<turnstile> S <: T" |
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
663 |
using a b c |
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
664 |
proof (nominal_induct \<Gamma> S T avoiding: \<Delta> rule: subtype_of_rel_induct) |
18424 | 665 |
case (S_All \<Gamma> X S\<^isub>1 S\<^isub>2 T\<^isub>1 T\<^isub>2) |
666 |
have fresh_cond: "X\<sharp>\<Delta>" by fact |
|
667 |
have ih\<^isub>1: "\<And>\<Delta>. \<turnstile> \<Delta> ok \<Longrightarrow> \<Delta> extends \<Gamma> \<Longrightarrow> \<Delta> \<turnstile> T\<^isub>1 <: S\<^isub>1" by fact |
|
668 |
have ih\<^isub>2: "\<And>\<Delta>. \<turnstile> \<Delta> ok \<Longrightarrow> \<Delta> extends ((X,T\<^isub>1)#\<Gamma>) \<Longrightarrow> \<Delta> \<turnstile> S\<^isub>2 <: T\<^isub>2" by fact |
|
669 |
have lh_drv_prem: "\<Gamma> \<turnstile> T\<^isub>1 <: S\<^isub>1" by fact |
|
670 |
hence closed\<^isub>T\<^isub>1: "T\<^isub>1 closed_in \<Gamma>" by (simp add: subtype_implies_closed) |
|
18353
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
671 |
have ok: "\<turnstile> \<Delta> ok" by fact |
18424 | 672 |
have ext: "\<Delta> extends \<Gamma>" by fact |
673 |
have "T\<^isub>1 closed_in \<Delta>" using ext closed\<^isub>T\<^isub>1 by (simp only: extends_closed) |
|
674 |
hence "\<turnstile> ((X,T\<^isub>1)#\<Delta>) ok" using fresh_cond ok by force |
|
18353
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
675 |
moreover |
18424 | 676 |
have "((X,T\<^isub>1)#\<Delta>) extends ((X,T\<^isub>1)#\<Gamma>)" using ext by (force simp add: extends_def) |
677 |
ultimately have "((X,T\<^isub>1)#\<Delta>) \<turnstile> S\<^isub>2 <: T\<^isub>2" using ih\<^isub>2 by simp |
|
18353
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
678 |
moreover |
18424 | 679 |
have "\<Delta> \<turnstile> T\<^isub>1 <: S\<^isub>1" using ok ext ih\<^isub>1 by simp |
680 |
ultimately show "\<Delta> \<turnstile> \<forall> [X<:S\<^isub>1].S\<^isub>2 <: \<forall> [X<:T\<^isub>1].T\<^isub>2" using ok by (force intro: S_All) |
|
681 |
qed (blast intro: extends_closed extends_memb dest: extends_domain)+ |
|
18246 | 682 |
|
18424 | 683 |
text {* our contexts grow from right to left *} |
18410 | 684 |
|
18246 | 685 |
lemma transitivity_and_narrowing: |
18416 | 686 |
shows "\<Gamma> \<turnstile> S <: Q \<Longrightarrow> \<Gamma> \<turnstile> Q <: T \<Longrightarrow> \<Gamma> \<turnstile> S <: T" |
18424 | 687 |
and "(\<Delta>@[(X,Q)]@\<Gamma>) \<turnstile> M <: N \<Longrightarrow> \<Gamma> \<turnstile> P <: Q \<Longrightarrow> (\<Delta>@[(X,P)]@\<Gamma>) \<turnstile> M <: N" |
18416 | 688 |
proof (induct Q fixing: \<Gamma> S T and \<Delta> \<Gamma> X P M N taking: "size_ty" rule: measure_induct_rule) |
18424 | 689 |
case (less Q) |
690 |
note IH_trans = prems[THEN conjunct1, rule_format] |
|
691 |
note IH_narrow = prems[THEN conjunct2, THEN spec, of _ "[]", simplified, rule_format] |
|
18353
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
692 |
|
18424 | 693 |
--{* The inner induction for transitivity over @{term "\<Gamma> \<turnstile> S <: Q"} *} |
18246 | 694 |
have transitivity: |
18353
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
695 |
"\<And>\<Gamma> S T. \<Gamma> \<turnstile> S <: Q \<Longrightarrow> \<Gamma> \<turnstile> Q <: T \<Longrightarrow> \<Gamma> \<turnstile> S <: T" |
18246 | 696 |
proof - |
18412 | 697 |
|
18424 | 698 |
-- {* We first handle the case where T = Top once and for all; this saves some |
699 |
repeated argument below (just like on paper :-). To do so we establish a little |
|
700 |
lemma that is invoked where needed in the induction for transitivity. *} |
|
18246 | 701 |
have top_case: |
18416 | 702 |
"\<And>\<Gamma> S T' P. \<lbrakk>\<turnstile> \<Gamma> ok; S closed_in \<Gamma>; P \<Longrightarrow> \<Gamma> \<turnstile> S <: T'; T'=Top \<or> P\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> S <: T'" |
18246 | 703 |
proof - |
704 |
fix \<Gamma> S T' P |
|
18424 | 705 |
assume S_Top_prm1: "S closed_in \<Gamma>" |
706 |
and S_Top_prm2: "\<turnstile> \<Gamma> ok" |
|
18416 | 707 |
and alternative: "P \<Longrightarrow> \<Gamma> \<turnstile> S <: T'" |
708 |
and "T'=Top \<or> P" |
|
18246 | 709 |
moreover |
710 |
{ assume "T'=Top" |
|
18424 | 711 |
hence "\<Gamma> \<turnstile> S <: T'" using S_Top_prm1 S_Top_prm2 by (simp add: S_Top) |
18246 | 712 |
} |
713 |
moreover |
|
714 |
{ assume P |
|
715 |
with alternative have "\<Gamma> \<turnstile> S <: T'" by simp |
|
716 |
} |
|
717 |
ultimately show "\<Gamma> \<turnstile> S <: T'" by blast |
|
718 |
qed |
|
719 |
||
18424 | 720 |
--{* Now proceed by the inner induction on the left-hand derivation *} |
721 |
fix \<Gamma>' S' T |
|
722 |
assume a: "\<Gamma>' \<turnstile> S' <: Q" --{* lh derivation *} |
|
723 |
assume b: "\<Gamma>' \<turnstile> Q <: T" --{* rh derivation *} |
|
724 |
from a b show "\<Gamma>' \<turnstile> S' <: T" |
|
725 |
proof(nominal_induct \<Gamma>' S' Q\<equiv>Q avoiding: \<Gamma>' S' T rule: subtype_of_rel_induct) |
|
726 |
case (S_Top \<Gamma> S) |
|
727 |
--{* in this case lh drv is @{term "\<Gamma> \<turnstile> S <: Top"} *} |
|
728 |
hence rh_drv: "\<Gamma> \<turnstile> Top <: T" by simp |
|
729 |
hence T_inst: "T = Top" by (simp add: S_TopE) |
|
730 |
have lh_drv_prm1: "\<turnstile> \<Gamma> ok" by fact |
|
731 |
have lh_drv_prm2: "S closed_in \<Gamma>" by fact |
|
732 |
from lh_drv_prm1 lh_drv_prm2 have "\<Gamma> \<turnstile> S <: Top" by (simp add: subtype_of_rel.S_Top) |
|
733 |
thus "\<Gamma> \<turnstile> S <: T" using T_inst by simp |
|
18246 | 734 |
next |
18424 | 735 |
case (S_Var \<Gamma> Y U Q) |
736 |
--{* in this case lh drv is @{term "\<Gamma> \<turnstile> TVar(Y) <: Q"} *} |
|
737 |
hence IH_inner: "\<Gamma> \<turnstile> U <: T" by simp |
|
738 |
have lh_drv_prm1: "\<turnstile> \<Gamma> ok" by fact |
|
739 |
have lh_drv_prm2: "(Y,U)\<in>set \<Gamma>" by fact |
|
740 |
from IH_inner show "\<Gamma> \<turnstile> TVar Y <: T" using lh_drv_prm1 lh_drv_prm2 |
|
741 |
by (simp add: subtype_of_rel.S_Var) |
|
18246 | 742 |
next |
18424 | 743 |
case (S_Refl \<Gamma> X) |
744 |
--{* in this case lh drv is @{term "\<Gamma> \<turnstile> TVar X <: TVar X"} *} |
|
745 |
thus "\<Gamma> \<turnstile> TVar X <: T" by simp |
|
18246 | 746 |
next |
18424 | 747 |
case (S_Arrow \<Gamma> S1 S2 Q1 Q2) |
748 |
--{* in this case lh drv is @{term "\<Gamma> \<turnstile> S1 \<rightarrow> S2 <: Q1 \<rightarrow> Q2"} *} |
|
749 |
hence rh_drv: "\<Gamma> \<turnstile> Q1 \<rightarrow> Q2 <: T" by simp |
|
750 |
have Q_inst: "Q1 \<rightarrow> Q2 = Q" by fact |
|
751 |
hence Q1_less: "size_ty Q1 < size_ty Q" |
|
752 |
and Q2_less: "size_ty Q2 < size_ty Q" by auto |
|
753 |
have lh_drv_prm1: "\<Gamma> \<turnstile> Q1 <: S1" by fact |
|
754 |
have lh_drv_prm2: "\<Gamma> \<turnstile> S2 <: Q2" by fact |
|
755 |
have "S1 closed_in \<Gamma>" and "S2 closed_in \<Gamma>" |
|
756 |
using lh_drv_prm1 lh_drv_prm2 by (simp_all add: subtype_implies_closed) |
|
757 |
hence "(S1 \<rightarrow> S2) closed_in \<Gamma>" by (simp add: closed_in_def ty.supp) |
|
18353
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
758 |
moreover |
18424 | 759 |
have "\<turnstile> \<Gamma> ok" using rh_drv by (rule subtype_implies_ok) |
18353
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
760 |
moreover |
18424 | 761 |
from rh_drv have "T = Top \<or> (\<exists>T1 T2. T = T1 \<rightarrow> T2 \<and> \<Gamma> \<turnstile> T1 <: Q1 \<and> \<Gamma> \<turnstile> Q2 <: T2)" |
762 |
by (simp add: S_ArrowE_left) |
|
18353
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
763 |
moreover |
18424 | 764 |
{ assume "\<exists>T1 T2. T = T1 \<rightarrow> T2 \<and> \<Gamma> \<turnstile> T1 <: Q1 \<and> \<Gamma> \<turnstile> Q2 <: T2" |
765 |
then obtain T1 T2 |
|
766 |
where T_inst: "T = T1 \<rightarrow> T2" |
|
767 |
and rh_drv_prm1: "\<Gamma> \<turnstile> T1 <: Q1" |
|
768 |
and rh_drv_prm2: "\<Gamma> \<turnstile> Q2 <: T2" by force |
|
769 |
from IH_trans[of "Q1"] have "\<Gamma> \<turnstile> T1 <: S1" using Q1_less rh_drv_prm1 lh_drv_prm1 by simp |
|
18246 | 770 |
moreover |
18424 | 771 |
from IH_trans[of "Q2"] have "\<Gamma> \<turnstile> S2 <: T2" using Q2_less rh_drv_prm2 lh_drv_prm2 by simp |
772 |
ultimately have "\<Gamma> \<turnstile> S1 \<rightarrow> S2 <: T1 \<rightarrow> T2" by (simp add: subtype_of_rel.S_Arrow) |
|
773 |
hence "\<Gamma> \<turnstile> S1 \<rightarrow> S2 <: T" using T_inst by simp |
|
18353
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
774 |
} |
18424 | 775 |
ultimately show "\<Gamma> \<turnstile> S1 \<rightarrow> S2 <: T" using top_case by blast |
18246 | 776 |
next |
18424 | 777 |
case (S_All \<Gamma> X S1 S2 Q1 Q2) |
778 |
--{* in this case lh drv is @{term "\<Gamma>\<turnstile>\<forall>[X<:S1].S2 <: \<forall>[X<:Q1].Q2"} *} |
|
779 |
hence rh_drv: "\<Gamma> \<turnstile> \<forall>[X<:Q1].Q2 <: T" by simp |
|
780 |
have lh_drv_prm1: "\<Gamma> \<turnstile> Q1 <: S1" by fact |
|
781 |
have lh_drv_prm2: "((X,Q1)#\<Gamma>) \<turnstile> S2 <: Q2" by fact |
|
782 |
have fresh_cond: "X\<sharp>\<Gamma>" "X\<sharp>Q1" by fact |
|
783 |
have Q_inst: "\<forall>[X<:Q1].Q2 = Q" by fact |
|
784 |
hence Q1_less: "size_ty Q1 < size_ty Q" |
|
785 |
and Q2_less: "size_ty Q2 < size_ty Q " by auto |
|
786 |
have "S1 closed_in \<Gamma>" and "S2 closed_in ((X,Q1)#\<Gamma>)" |
|
787 |
using lh_drv_prm1 lh_drv_prm2 by (simp_all add: subtype_implies_closed) |
|
788 |
hence "(\<forall>[X<:S1].S2) closed_in \<Gamma>" by (force simp add: closed_in_def ty.supp abs_supp) |
|
18353
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
789 |
moreover |
18424 | 790 |
have "\<turnstile> \<Gamma> ok" using rh_drv by (rule subtype_implies_ok) |
18353
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
791 |
moreover |
18424 | 792 |
from rh_drv have "T = Top \<or> (\<exists>T1 T2. T = \<forall>[X<:T1].T2 \<and> \<Gamma> \<turnstile> T1 <: Q1 \<and> ((X,T1)#\<Gamma>) \<turnstile> Q2 <: T2)" |
793 |
using fresh_cond by (simp add: S_AllE_left) |
|
18353
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
794 |
moreover |
18424 | 795 |
{ assume "\<exists>T1 T2. T = \<forall>[X<:T1].T2 \<and> \<Gamma> \<turnstile> T1 <: Q1 \<and> ((X,T1)#\<Gamma>) \<turnstile> Q2 <: T2" |
796 |
then obtain T1 T2 |
|
797 |
where T_inst: "T = \<forall>[X<:T1].T2" |
|
798 |
and rh_drv_prm1: "\<Gamma> \<turnstile> T1 <: Q1" |
|
799 |
and rh_drv_prm2:"((X,T1)#\<Gamma>) \<turnstile> Q2 <: T2" by force |
|
800 |
from IH_trans[of "Q1"] have "\<Gamma> \<turnstile> T1 <: S1" |
|
801 |
using lh_drv_prm1 rh_drv_prm1 Q1_less by blast |
|
18246 | 802 |
moreover |
18424 | 803 |
from IH_narrow[of "Q1"] have "((X,T1)#\<Gamma>) \<turnstile> S2 <: Q2" |
804 |
using Q1_less lh_drv_prm2 rh_drv_prm1 by blast |
|
805 |
with IH_trans[of "Q2"] have "((X,T1)#\<Gamma>) \<turnstile> S2 <: T2" |
|
806 |
using Q2_less rh_drv_prm2 by blast |
|
18353
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
807 |
moreover |
18424 | 808 |
ultimately have "\<Gamma> \<turnstile> \<forall>[X<:S1].S2 <: \<forall>[X<:T1].T2" |
809 |
using fresh_cond by (simp add: subtype_of_rel.S_All) |
|
810 |
hence "\<Gamma> \<turnstile> \<forall>[X<:S1].S2 <: T" using T_inst by simp |
|
18353
4dd468ccfdf7
transitivity should be now in a reasonable state. But
urbanc
parents:
18306
diff
changeset
|
811 |
} |
18424 | 812 |
ultimately show "\<Gamma> \<turnstile> \<forall>[X<:S1].S2 <: T" using top_case by blast |
18246 | 813 |
qed |
814 |
qed |
|
815 |
||
18424 | 816 |
--{* The inner induction for narrowing over @{term "(\<Delta>@[(X,Q)]@\<Gamma>) \<turnstile> M <: N"} *} |
18246 | 817 |
have narrowing: |
18424 | 818 |
"\<And>\<Delta> \<Gamma> X M N P. (\<Delta>@[(X,Q)]@\<Gamma>) \<turnstile> M <: N \<Longrightarrow> \<Gamma> \<turnstile> P<:Q \<Longrightarrow> (\<Delta>@[(X,P)]@\<Gamma>) \<turnstile> M <: N" |
18246 | 819 |
proof - |
18424 | 820 |
fix \<Delta>' \<Gamma>' X M N P |
821 |
assume a: "(\<Delta>'@[(X,Q)]@\<Gamma>') \<turnstile> M <: N" |
|
822 |
assume b: "\<Gamma>' \<turnstile> P<:Q" |
|
823 |
from a b show "(\<Delta>'@[(X,P)]@\<Gamma>') \<turnstile> M <: N" |
|
824 |
proof (nominal_induct \<Gamma>\<equiv>"\<Delta>'@[(X,Q)]@\<Gamma>'" M N avoiding: \<Delta>' \<Gamma>' X rule: subtype_of_rel_induct) |
|
825 |
case (S_Top _ S \<Delta> \<Gamma> X) |
|
826 |
--{* in this case lh drv is @{term "(\<Delta>@[(X,Q)]@\<Gamma>) \<turnstile> S <: Top"} *} |
|
827 |
hence lh_drv_prm1: "\<turnstile> (\<Delta>@[(X,Q)]@\<Gamma>) ok" |
|
828 |
and lh_drv_prm2: "S closed_in (\<Delta>@[(X,Q)]@\<Gamma>)" by simp_all |
|
829 |
have rh_drv: "\<Gamma> \<turnstile> P <: Q" by fact |
|
830 |
hence "P closed_in \<Gamma>" by (simp add: subtype_implies_closed) |
|
831 |
with lh_drv_prm1 have "\<turnstile> (\<Delta>@[(X,P)]@\<Gamma>) ok" by (simp add: replace_type) |
|
18412 | 832 |
moreover |
18424 | 833 |
from lh_drv_prm2 have "S closed_in (\<Delta>@[(X,P)]@\<Gamma>)" by (simp add: closed_in_def domain_append) |
834 |
ultimately show "(\<Delta>@[(X,P)]@\<Gamma>) \<turnstile> S <: Top" by (simp add: subtype_of_rel.S_Top) |
|
18246 | 835 |
next |
18424 | 836 |
case (S_Var _ Y S N \<Delta> \<Gamma> X) |
837 |
--{* in this case lh drv is @{term "(\<Delta>@[(X,Q)]@\<Gamma>) \<turnstile> TVar Y <: N"} *} |
|
838 |
hence IH_inner: "(\<Delta>@[(X,P)]@\<Gamma>) \<turnstile> S <: N" |
|
839 |
and lh_drv_prm1: "\<turnstile> (\<Delta>@[(X,Q)]@\<Gamma>) ok" |
|
840 |
and lh_drv_prm2: "(Y,S)\<in>set (\<Delta>@[(X,Q)]@\<Gamma>)" by simp_all |
|
841 |
have rh_drv: "\<Gamma> \<turnstile> P <: Q" by fact |
|
842 |
hence "P closed_in \<Gamma>" by (simp add: subtype_implies_closed) |
|
843 |
hence cntxt_ok: "\<turnstile> (\<Delta>@[(X,P)]@\<Gamma>) ok" using lh_drv_prm1 by (simp add: replace_type) |
|
844 |
-- {* we distinguishing the cases @{term "X\<noteq>Y"} and @{term "X=Y"} (the latter |
|
845 |
being the interesting one) *} |
|
846 |
{ assume "X\<noteq>Y" |
|
847 |
hence "(Y,S)\<in>set (\<Delta>@[(X,P)]@\<Gamma>)" using lh_drv_prm2 by simp |
|
848 |
with IH_inner have "(\<Delta>@[(X,P)]@\<Gamma>) \<turnstile> TVar Y <: N" |
|
849 |
using cntxt_ok by (simp add: subtype_of_rel.S_Var) |
|
850 |
} |
|
851 |
moreover |
|
852 |
{ have memb_XQ: "(X,Q)\<in>set (\<Delta>@[(X,Q)]@\<Gamma>)" by simp |
|
853 |
have memb_XP: "(X,P)\<in>set (\<Delta>@[(X,P)]@\<Gamma>)" by simp |
|
854 |
assume "X=Y" |
|
855 |
hence "S=Q" using lh_drv_prm1 lh_drv_prm2 memb_XQ by (simp only: uniqueness_of_ctxt) |
|
856 |
hence "(\<Delta>@[(X,P)]@\<Gamma>) \<turnstile> Q <: N" using IH_inner by simp |
|
857 |
moreover |
|
858 |
have "(\<Delta>@[(X,P)]@\<Gamma>) extends \<Gamma>" by (simp add: extends_def) |
|
859 |
hence "(\<Delta>@[(X,P)]@\<Gamma>) \<turnstile> P <: Q" using rh_drv cntxt_ok by (simp only: weakening) |
|
860 |
ultimately have "(\<Delta>@[(X,P)]@\<Gamma>) \<turnstile> P <: N" using transitivity by simp |
|
861 |
hence "(\<Delta>@[(X,P)]@\<Gamma>) \<turnstile> TVar X <: N" using memb_XP cntxt_ok |
|
862 |
by (simp only: subtype_of_rel.S_Var) |
|
863 |
} |
|
864 |
ultimately show "(\<Delta>@[(X,P)]@\<Gamma>) \<turnstile> TVar Y <: N" by blast |
|
18246 | 865 |
next |
18424 | 866 |
case (S_Refl _ Y \<Delta> \<Gamma> X) |
867 |
--{* in this case lh drv is @{term "(\<Delta>@[(X,Q)]@\<Gamma>) \<turnstile> TVar Y <: TVar Y"} *} |
|
868 |
hence lh_drv_prm1: "\<turnstile> (\<Delta>@[(X,Q)]@\<Gamma>) ok" |
|
869 |
and lh_drv_prm2: "Y \<in> domain (\<Delta>@[(X,Q)]@\<Gamma>)" by simp_all |
|
870 |
have "\<Gamma> \<turnstile> P <: Q" by fact |
|
871 |
hence "P closed_in \<Gamma>" by (simp add: subtype_implies_closed) |
|
872 |
with lh_drv_prm1 have "\<turnstile> (\<Delta>@[(X,P)]@\<Gamma>) ok" by (simp add: replace_type) |
|
873 |
moreover |
|
874 |
from lh_drv_prm2 have "Y \<in> domain (\<Delta>@[(X,P)]@\<Gamma>)" by (simp add: domain_append) |
|
875 |
ultimately show "(\<Delta>@[(X,P)]@\<Gamma>) \<turnstile> TVar Y <: TVar Y" by (simp add: subtype_of_rel.S_Refl) |
|
18246 | 876 |
next |
18424 | 877 |
case (S_Arrow _ Q1 Q2 S1 S2 \<Delta> \<Gamma> X) |
878 |
--{* in this case lh drv is @{term "(\<Delta>@[(X,Q)]@\<Gamma>) \<turnstile> Q1 \<rightarrow> Q2 <: S1 \<rightarrow> S2"} *} |
|
879 |
thus "(\<Delta>@[(X,P)]@\<Gamma>) \<turnstile> Q1 \<rightarrow> Q2 <: S1 \<rightarrow> S2" by blast |
|
880 |
next |
|
881 |
case (S_All _ Y S1 S2 T1 T2 \<Delta> \<Gamma> X) |
|
882 |
--{* in this case lh drv is @{term "(\<Delta>@[(X,Q)]@\<Gamma>) \<turnstile> \<forall>[Y<:S1].S2 <: \<forall>[Y<:T1].T2"} *} |
|
883 |
hence IH_inner1: "(\<Delta>@[(X,P)]@\<Gamma>) \<turnstile> T1 <: S1" |
|
884 |
and IH_inner2: "((Y,T1)#\<Delta>@[(X,P)]@\<Gamma>) \<turnstile> S2 <: T2" |
|
885 |
and lh_drv_prm2: "Y\<sharp>(\<Delta>@[(X,Q)]@\<Gamma>)" by force+ |
|
886 |
have rh_drv: "\<Gamma> \<turnstile> P <: Q" by fact |
|
887 |
hence "Y\<sharp>P" using lh_drv_prm2 by (simp only: fresh_list_append subtype_implies_fresh) |
|
888 |
hence "Y\<sharp>(\<Delta>@[(X,P)]@\<Gamma>)" using lh_drv_prm2 |
|
889 |
by (simp add: fresh_list_append fresh_list_cons fresh_prod) |
|
890 |
with IH_inner1 IH_inner2 |
|
891 |
show "(\<Delta>@[(X,P)]@\<Gamma>) \<turnstile> \<forall>[Y<:S1].S2 <: \<forall>[Y<:T1].T2" by (simp add: subtype_of_rel.S_All) |
|
18246 | 892 |
qed |
893 |
qed |
|
894 |
from transitivity narrowing show ?case by blast |
|
895 |
qed |
|
896 |
||
897 |
||
898 |
||
899 |
||
18416 | 900 |
end |