author | wenzelm |
Fri, 09 Nov 2001 00:09:47 +0100 | |
changeset 12114 | a8e860c86252 |
parent 12011 | 1a3a7b3cd9bb |
child 12171 | dc87f33db447 |
permissions | -rw-r--r-- |
9114
de99e37effda
Subject reduction and strong normalization of simply-typed lambda terms.
berghofe
parents:
diff
changeset
|
1 |
(* Title: HOL/Lambda/Type.thy |
de99e37effda
Subject reduction and strong normalization of simply-typed lambda terms.
berghofe
parents:
diff
changeset
|
2 |
ID: $Id$ |
de99e37effda
Subject reduction and strong normalization of simply-typed lambda terms.
berghofe
parents:
diff
changeset
|
3 |
Author: Stefan Berghofer |
de99e37effda
Subject reduction and strong normalization of simply-typed lambda terms.
berghofe
parents:
diff
changeset
|
4 |
Copyright 2000 TU Muenchen |
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
5 |
*) |
9114
de99e37effda
Subject reduction and strong normalization of simply-typed lambda terms.
berghofe
parents:
diff
changeset
|
6 |
|
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
7 |
header {* Simply-typed lambda terms: subject reduction and strong |
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
8 |
normalization *} |
9114
de99e37effda
Subject reduction and strong normalization of simply-typed lambda terms.
berghofe
parents:
diff
changeset
|
9 |
|
9622 | 10 |
theory Type = InductTermi: |
9114
de99e37effda
Subject reduction and strong normalization of simply-typed lambda terms.
berghofe
parents:
diff
changeset
|
11 |
|
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
12 |
text_raw {* |
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
13 |
\footnote{Formalization by Stefan Berghofer. Partly based on a |
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
14 |
paper proof by Ralph Matthes.} |
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
15 |
*} |
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
16 |
|
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
17 |
|
11946 | 18 |
subsection {* Environments *} |
19 |
||
20 |
constdefs |
|
12011 | 21 |
shift :: "(nat \<Rightarrow> 'a) \<Rightarrow> nat \<Rightarrow> 'a \<Rightarrow> nat \<Rightarrow> 'a" ("_<_:_>" [90, 0, 0] 91) |
22 |
"e<i:a> \<equiv> \<lambda>j. if j < i then e j else if j = i then a else e (j - 1)" |
|
12114
a8e860c86252
eliminated old "symbols" syntax, use "xsymbols" instead;
wenzelm
parents:
12011
diff
changeset
|
23 |
syntax (xsymbols) |
11946 | 24 |
shift :: "(nat \<Rightarrow> 'a) \<Rightarrow> nat \<Rightarrow> 'a \<Rightarrow> nat \<Rightarrow> 'a" ("_\<langle>_:_\<rangle>" [90, 0, 0] 91) |
25 |
||
26 |
lemma shift_eq [simp]: "i = j \<Longrightarrow> (e\<langle>i:T\<rangle>) j = T" |
|
27 |
by (simp add: shift_def) |
|
28 |
||
29 |
lemma shift_gt [simp]: "j < i \<Longrightarrow> (e\<langle>i:T\<rangle>) j = e j" |
|
30 |
by (simp add: shift_def) |
|
31 |
||
32 |
lemma shift_lt [simp]: "i < j \<Longrightarrow> (e\<langle>i:T\<rangle>) j = e (j - 1)" |
|
33 |
by (simp add: shift_def) |
|
34 |
||
35 |
lemma shift_commute [simp]: "e\<langle>i:U\<rangle>\<langle>0:T\<rangle> = e\<langle>0:T\<rangle>\<langle>Suc i:U\<rangle>" |
|
36 |
apply (rule ext) |
|
37 |
apply (case_tac x) |
|
38 |
apply simp |
|
39 |
apply (case_tac nat) |
|
40 |
apply (simp_all add: shift_def) |
|
41 |
done |
|
42 |
||
43 |
||
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
44 |
subsection {* Types and typing rules *} |
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
45 |
|
9641 | 46 |
datatype type = |
9622 | 47 |
Atom nat |
11945 | 48 |
| Fun type type (infixr "\<Rightarrow>" 200) |
9114
de99e37effda
Subject reduction and strong normalization of simply-typed lambda terms.
berghofe
parents:
diff
changeset
|
49 |
|
de99e37effda
Subject reduction and strong normalization of simply-typed lambda terms.
berghofe
parents:
diff
changeset
|
50 |
consts |
11943 | 51 |
typing :: "((nat \<Rightarrow> type) \<times> dB \<times> type) set" |
52 |
typings :: "(nat \<Rightarrow> type) \<Rightarrow> dB list \<Rightarrow> type list \<Rightarrow> bool" |
|
9114
de99e37effda
Subject reduction and strong normalization of simply-typed lambda terms.
berghofe
parents:
diff
changeset
|
53 |
|
de99e37effda
Subject reduction and strong normalization of simply-typed lambda terms.
berghofe
parents:
diff
changeset
|
54 |
syntax |
11945 | 55 |
"_funs" :: "type list \<Rightarrow> type \<Rightarrow> type" (infixr "=>>" 200) |
11943 | 56 |
"_typing" :: "(nat \<Rightarrow> type) \<Rightarrow> dB \<Rightarrow> type \<Rightarrow> bool" ("_ |- _ : _" [50, 50, 50] 50) |
57 |
"_typings" :: "(nat \<Rightarrow> type) \<Rightarrow> dB list \<Rightarrow> type list \<Rightarrow> bool" |
|
58 |
("_ ||- _ : _" [50, 50, 50] 50) |
|
12114
a8e860c86252
eliminated old "symbols" syntax, use "xsymbols" instead;
wenzelm
parents:
12011
diff
changeset
|
59 |
syntax (xsymbols) |
11943 | 60 |
"_typing" :: "(nat \<Rightarrow> type) \<Rightarrow> dB \<Rightarrow> type \<Rightarrow> bool" ("_ \<turnstile> _ : _" [50, 50, 50] 50) |
61 |
syntax (latex) |
|
11945 | 62 |
"_funs" :: "type list \<Rightarrow> type \<Rightarrow> type" (infixr "\<Rrightarrow>" 200) |
11943 | 63 |
"_typings" :: "(nat \<Rightarrow> type) \<Rightarrow> dB list \<Rightarrow> type list \<Rightarrow> bool" |
64 |
("_ \<tturnstile> _ : _" [50, 50, 50] 50) |
|
9114
de99e37effda
Subject reduction and strong normalization of simply-typed lambda terms.
berghofe
parents:
diff
changeset
|
65 |
translations |
11945 | 66 |
"Ts \<Rrightarrow> T" \<rightleftharpoons> "foldr Fun Ts T" |
11943 | 67 |
"env \<turnstile> t : T" \<rightleftharpoons> "(env, t, T) \<in> typing" |
68 |
"env \<tturnstile> ts : Ts" \<rightleftharpoons> "typings env ts Ts" |
|
9114
de99e37effda
Subject reduction and strong normalization of simply-typed lambda terms.
berghofe
parents:
diff
changeset
|
69 |
|
de99e37effda
Subject reduction and strong normalization of simply-typed lambda terms.
berghofe
parents:
diff
changeset
|
70 |
inductive typing |
11638 | 71 |
intros |
11943 | 72 |
Var [intro!]: "env x = T \<Longrightarrow> env \<turnstile> Var x : T" |
11946 | 73 |
Abs [intro!]: "env\<langle>0:T\<rangle> \<turnstile> t : U \<Longrightarrow> env \<turnstile> Abs t : (T \<Rightarrow> U)" |
12011 | 74 |
App [intro!]: "env \<turnstile> s : T \<Rightarrow> U \<Longrightarrow> env \<turnstile> t : T \<Longrightarrow> env \<turnstile> (s \<degree> t) : U" |
9622 | 75 |
|
11943 | 76 |
inductive_cases typing_elims [elim!]: |
77 |
"e \<turnstile> Var i : T" |
|
12011 | 78 |
"e \<turnstile> t \<degree> u : T" |
11943 | 79 |
"e \<turnstile> Abs t : T" |
11935 | 80 |
|
11943 | 81 |
primrec |
82 |
"(e \<tturnstile> [] : Ts) = (Ts = [])" |
|
83 |
"(e \<tturnstile> (t # ts) : Ts) = |
|
84 |
(case Ts of |
|
85 |
[] \<Rightarrow> False |
|
86 |
| T # Ts \<Rightarrow> e \<turnstile> t : T \<and> e \<tturnstile> ts : Ts)" |
|
9114
de99e37effda
Subject reduction and strong normalization of simply-typed lambda terms.
berghofe
parents:
diff
changeset
|
87 |
|
9622 | 88 |
|
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
89 |
subsection {* Some examples *} |
9622 | 90 |
|
12011 | 91 |
lemma "e \<turnstile> Abs (Abs (Abs (Var 1 \<degree> (Var 2 \<degree> Var 1 \<degree> Var 0)))) : ?T" |
11935 | 92 |
by force |
9622 | 93 |
|
12011 | 94 |
lemma "e \<turnstile> Abs (Abs (Abs (Var 2 \<degree> Var 0 \<degree> (Var 1 \<degree> Var 0)))) : ?T" |
11935 | 95 |
by force |
9622 | 96 |
|
97 |
||
11950 | 98 |
subsection {* n-ary function types *} |
9622 | 99 |
|
11987 | 100 |
lemma list_app_typeD: |
12011 | 101 |
"\<And>t T. e \<turnstile> t \<degree>\<degree> ts : T \<Longrightarrow> \<exists>Ts. e \<turnstile> t : Ts \<Rrightarrow> T \<and> e \<tturnstile> ts : Ts" |
11987 | 102 |
apply (induct ts) |
9622 | 103 |
apply simp |
11987 | 104 |
apply atomize |
9622 | 105 |
apply simp |
12011 | 106 |
apply (erule_tac x = "t \<degree> a" in allE) |
9622 | 107 |
apply (erule_tac x = T in allE) |
108 |
apply (erule impE) |
|
109 |
apply assumption |
|
110 |
apply (elim exE conjE) |
|
12011 | 111 |
apply (ind_cases "e \<turnstile> t \<degree> u : T") |
9622 | 112 |
apply (rule_tac x = "Ta # Ts" in exI) |
113 |
apply simp |
|
114 |
done |
|
115 |
||
11935 | 116 |
lemma list_app_typeE: |
12011 | 117 |
"e \<turnstile> t \<degree>\<degree> ts : T \<Longrightarrow> (\<And>Ts. e \<turnstile> t : Ts \<Rrightarrow> T \<Longrightarrow> e \<tturnstile> ts : Ts \<Longrightarrow> C) \<Longrightarrow> C" |
11935 | 118 |
by (insert list_app_typeD) fast |
119 |
||
11987 | 120 |
lemma list_app_typeI: |
12011 | 121 |
"\<And>t T Ts. e \<turnstile> t : Ts \<Rrightarrow> T \<Longrightarrow> e \<tturnstile> ts : Ts \<Longrightarrow> e \<turnstile> t \<degree>\<degree> ts : T" |
11987 | 122 |
apply (induct ts) |
9622 | 123 |
apply simp |
11987 | 124 |
apply atomize |
9622 | 125 |
apply (case_tac Ts) |
126 |
apply simp |
|
127 |
apply simp |
|
12011 | 128 |
apply (erule_tac x = "t \<degree> a" in allE) |
9622 | 129 |
apply (erule_tac x = T in allE) |
130 |
apply (erule_tac x = lista in allE) |
|
131 |
apply (erule impE) |
|
132 |
apply (erule conjE) |
|
133 |
apply (erule typing.App) |
|
134 |
apply assumption |
|
135 |
apply blast |
|
136 |
done |
|
137 |
||
11987 | 138 |
lemma lists_typings: |
139 |
"\<And>Ts. e \<tturnstile> ts : Ts \<Longrightarrow> ts \<in> lists {t. \<exists>T. e \<turnstile> t : T}" |
|
140 |
apply (induct ts) |
|
9622 | 141 |
apply (case_tac Ts) |
142 |
apply simp |
|
143 |
apply (rule lists.Nil) |
|
144 |
apply simp |
|
145 |
apply (case_tac Ts) |
|
146 |
apply simp |
|
147 |
apply simp |
|
148 |
apply (rule lists.Cons) |
|
149 |
apply blast |
|
150 |
apply blast |
|
151 |
done |
|
152 |
||
153 |
||
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
154 |
subsection {* Lifting preserves termination and well-typedness *} |
9622 | 155 |
|
11935 | 156 |
lemma lift_map [simp]: |
12011 | 157 |
"\<And>t. lift (t \<degree>\<degree> ts) i = lift t i \<degree>\<degree> map (\<lambda>t. lift t i) ts" |
11935 | 158 |
by (induct ts) simp_all |
9622 | 159 |
|
11935 | 160 |
lemma subst_map [simp]: |
12011 | 161 |
"\<And>t. subst (t \<degree>\<degree> ts) u i = subst t u i \<degree>\<degree> map (\<lambda>t. subst t u i) ts" |
11935 | 162 |
by (induct ts) simp_all |
9622 | 163 |
|
11994 | 164 |
lemma lift_IT [intro!]: "t \<in> IT \<Longrightarrow> (\<And>i. lift t i \<in> IT)" |
165 |
apply (induct set: IT) |
|
9622 | 166 |
apply (simp (no_asm)) |
167 |
apply (rule conjI) |
|
168 |
apply |
|
169 |
(rule impI, |
|
9716 | 170 |
rule IT.Var, |
9622 | 171 |
erule lists.induct, |
172 |
simp (no_asm), |
|
173 |
rule lists.Nil, |
|
174 |
simp (no_asm), |
|
175 |
erule IntE, |
|
176 |
rule lists.Cons, |
|
177 |
blast, |
|
178 |
assumption)+ |
|
179 |
apply auto |
|
180 |
done |
|
181 |
||
11947 | 182 |
lemma lifts_IT: "ts \<in> lists IT \<Longrightarrow> map (\<lambda>t. lift t 0) ts \<in> lists IT" |
11935 | 183 |
by (induct ts) auto |
9622 | 184 |
|
11946 | 185 |
lemma lift_type [intro!]: "e \<turnstile> t : T \<Longrightarrow> e\<langle>i:U\<rangle> \<turnstile> lift t i : T" |
11935 | 186 |
proof - |
11943 | 187 |
assume "e \<turnstile> t : T" |
188 |
thus "\<And>i U. e\<langle>i:U\<rangle> \<turnstile> lift t i : T" |
|
11946 | 189 |
by induct auto |
11935 | 190 |
qed |
9622 | 191 |
|
11987 | 192 |
lemma lift_typings: |
193 |
"\<And>Ts. e \<tturnstile> ts : Ts \<Longrightarrow> e\<langle>i:U\<rangle> \<tturnstile> (map (\<lambda>t. lift t i) ts) : Ts" |
|
194 |
apply (induct ts) |
|
9622 | 195 |
apply simp |
196 |
apply (case_tac Ts) |
|
11946 | 197 |
apply auto |
9622 | 198 |
done |
199 |
||
200 |
||
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
201 |
subsection {* Substitution lemmas *} |
9622 | 202 |
|
11994 | 203 |
lemma subst_lemma: |
204 |
"e \<turnstile> t : T \<Longrightarrow> (\<And>e' i U u. e' \<turnstile> u : U \<Longrightarrow> e = e'\<langle>i:U\<rangle> \<Longrightarrow> e' \<turnstile> t[u/i] : T)" |
|
205 |
apply (induct set: typing) |
|
11946 | 206 |
apply (rule_tac x = x and y = i in linorder_cases) |
207 |
apply auto |
|
208 |
apply blast |
|
9622 | 209 |
done |
210 |
||
12011 | 211 |
lemma substs_lemma: |
212 |
"\<And>Ts. e \<turnstile> u : T \<Longrightarrow> e\<langle>i:T\<rangle> \<tturnstile> ts : Ts \<Longrightarrow> |
|
11943 | 213 |
e \<tturnstile> (map (\<lambda>t. t[u/i]) ts) : Ts" |
12011 | 214 |
apply (induct ts) |
9622 | 215 |
apply (case_tac Ts) |
216 |
apply simp |
|
217 |
apply simp |
|
12011 | 218 |
apply atomize |
9622 | 219 |
apply (case_tac Ts) |
220 |
apply simp |
|
221 |
apply simp |
|
222 |
apply (erule conjE) |
|
12011 | 223 |
apply (erule (1) subst_lemma) |
11994 | 224 |
apply (rule refl) |
225 |
done |
|
226 |
||
9622 | 227 |
|
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
228 |
subsection {* Subject reduction *} |
9622 | 229 |
|
11994 | 230 |
lemma subject_reduction: "e \<turnstile> t : T \<Longrightarrow> (\<And>t'. t -> t' \<Longrightarrow> e \<turnstile> t' : T)" |
231 |
apply (induct set: typing) |
|
9622 | 232 |
apply blast |
233 |
apply blast |
|
11994 | 234 |
apply atomize |
12011 | 235 |
apply (ind_cases "s \<degree> t -> t'") |
9622 | 236 |
apply hypsubst |
11945 | 237 |
apply (ind_cases "env \<turnstile> Abs t : T \<Rightarrow> U") |
9622 | 238 |
apply (rule subst_lemma) |
239 |
apply assumption |
|
240 |
apply assumption |
|
241 |
apply (rule ext) |
|
11935 | 242 |
apply (case_tac x) |
11946 | 243 |
apply auto |
9622 | 244 |
done |
245 |
||
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
246 |
|
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
247 |
subsection {* Additional lemmas *} |
9622 | 248 |
|
12011 | 249 |
lemma app_last: "(t \<degree>\<degree> ts) \<degree> u = t \<degree>\<degree> (ts @ [u])" |
11935 | 250 |
by simp |
9622 | 251 |
|
11994 | 252 |
lemma subst_Var_IT: "r \<in> IT \<Longrightarrow> (\<And>i j. r[Var i/j] \<in> IT)" |
253 |
apply (induct set: IT) |
|
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
254 |
txt {* Case @{term Var}: *} |
9622 | 255 |
apply (simp (no_asm) add: subst_Var) |
256 |
apply |
|
257 |
((rule conjI impI)+, |
|
9716 | 258 |
rule IT.Var, |
9622 | 259 |
erule lists.induct, |
260 |
simp (no_asm), |
|
261 |
rule lists.Nil, |
|
262 |
simp (no_asm), |
|
263 |
erule IntE, |
|
264 |
erule CollectE, |
|
265 |
rule lists.Cons, |
|
266 |
fast, |
|
267 |
assumption)+ |
|
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
268 |
txt {* Case @{term Lambda}: *} |
11994 | 269 |
apply atomize |
9622 | 270 |
apply simp |
9716 | 271 |
apply (rule IT.Lambda) |
9622 | 272 |
apply fast |
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
273 |
txt {* Case @{term Beta}: *} |
11994 | 274 |
apply atomize |
9622 | 275 |
apply (simp (no_asm_use) add: subst_subst [symmetric]) |
9716 | 276 |
apply (rule IT.Beta) |
9622 | 277 |
apply auto |
278 |
done |
|
279 |
||
280 |
lemma Var_IT: "Var n \<in> IT" |
|
12011 | 281 |
apply (subgoal_tac "Var n \<degree>\<degree> [] \<in> IT") |
9622 | 282 |
apply simp |
9716 | 283 |
apply (rule IT.Var) |
9622 | 284 |
apply (rule lists.Nil) |
285 |
done |
|
286 |
||
12011 | 287 |
lemma app_Var_IT: "t \<in> IT \<Longrightarrow> t \<degree> Var i \<in> IT" |
11994 | 288 |
apply (induct set: IT) |
9622 | 289 |
apply (subst app_last) |
9716 | 290 |
apply (rule IT.Var) |
9622 | 291 |
apply simp |
292 |
apply (rule lists.Cons) |
|
293 |
apply (rule Var_IT) |
|
294 |
apply (rule lists.Nil) |
|
9906 | 295 |
apply (rule IT.Beta [where ?ss = "[]", unfolded foldl_Nil [THEN eq_reflection]]) |
9622 | 296 |
apply (erule subst_Var_IT) |
297 |
apply (rule Var_IT) |
|
298 |
apply (subst app_last) |
|
9716 | 299 |
apply (rule IT.Beta) |
9622 | 300 |
apply (subst app_last [symmetric]) |
301 |
apply assumption |
|
302 |
apply assumption |
|
303 |
done |
|
304 |
||
11935 | 305 |
lemma type_induct [induct type]: |
11945 | 306 |
"(\<And>T. (\<And>T1 T2. T = T1 \<Rightarrow> T2 \<Longrightarrow> P T1) \<Longrightarrow> |
307 |
(\<And>T1 T2. T = T1 \<Rightarrow> T2 \<Longrightarrow> P T2) \<Longrightarrow> P T) \<Longrightarrow> P T" |
|
11935 | 308 |
proof - |
309 |
case rule_context |
|
310 |
show ?thesis |
|
311 |
proof (induct T) |
|
312 |
case Atom |
|
313 |
show ?case by (rule rule_context) simp_all |
|
314 |
next |
|
315 |
case Fun |
|
316 |
show ?case by (rule rule_context) (insert Fun, simp_all) |
|
317 |
qed |
|
318 |
qed |
|
319 |
||
9622 | 320 |
|
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
321 |
subsection {* Well-typed substitution preserves termination *} |
9622 | 322 |
|
11935 | 323 |
lemma subst_type_IT: |
11943 | 324 |
"\<And>t e T u i. t \<in> IT \<Longrightarrow> e\<langle>i:U\<rangle> \<turnstile> t : T \<Longrightarrow> |
325 |
u \<in> IT \<Longrightarrow> e \<turnstile> u : U \<Longrightarrow> t[u/i] \<in> IT" |
|
11935 | 326 |
(is "PROP ?P U" is "\<And>t e T u i. _ \<Longrightarrow> PROP ?Q t e T u i U") |
327 |
proof (induct U) |
|
328 |
fix T t |
|
11945 | 329 |
assume MI1: "\<And>T1 T2. T = T1 \<Rightarrow> T2 \<Longrightarrow> PROP ?P T1" |
330 |
assume MI2: "\<And>T1 T2. T = T1 \<Rightarrow> T2 \<Longrightarrow> PROP ?P T2" |
|
11935 | 331 |
assume "t \<in> IT" |
332 |
thus "\<And>e T' u i. PROP ?Q t e T' u i T" |
|
333 |
proof induct |
|
334 |
fix e T' u i |
|
11943 | 335 |
assume uIT: "u \<in> IT" |
336 |
assume uT: "e \<turnstile> u : T" |
|
11935 | 337 |
{ |
338 |
case (Var n rs) |
|
12011 | 339 |
assume nT: "e\<langle>i:T\<rangle> \<turnstile> Var n \<degree>\<degree> rs : T'" |
11943 | 340 |
let ?ty = "{t. \<exists>T'. e\<langle>i:T\<rangle> \<turnstile> t : T'}" |
11935 | 341 |
let ?R = "\<lambda>t. \<forall>e T' u i. |
11943 | 342 |
e\<langle>i:T\<rangle> \<turnstile> t : T' \<longrightarrow> u \<in> IT \<longrightarrow> e \<turnstile> u : T \<longrightarrow> t[u/i] \<in> IT" |
12011 | 343 |
show "(Var n \<degree>\<degree> rs)[u/i] \<in> IT" |
11935 | 344 |
proof (cases "n = i") |
11943 | 345 |
case True |
346 |
show ?thesis |
|
347 |
proof (cases rs) |
|
348 |
case Nil |
|
349 |
with uIT True show ?thesis by simp |
|
350 |
next |
|
351 |
case (Cons a as) |
|
12011 | 352 |
with nT have "e\<langle>i:T\<rangle> \<turnstile> Var n \<degree> a \<degree>\<degree> as : T'" by simp |
11943 | 353 |
then obtain Ts |
12011 | 354 |
where headT: "e\<langle>i:T\<rangle> \<turnstile> Var n \<degree> a : Ts \<Rrightarrow> T'" |
11947 | 355 |
and argsT: "e\<langle>i:T\<rangle> \<tturnstile> as : Ts" |
11943 | 356 |
by (rule list_app_typeE) |
357 |
from headT obtain T'' |
|
11945 | 358 |
where varT: "e\<langle>i:T\<rangle> \<turnstile> Var n : T'' \<Rightarrow> Ts \<Rrightarrow> T'" |
11943 | 359 |
and argT: "e\<langle>i:T\<rangle> \<turnstile> a : T''" |
360 |
by cases simp_all |
|
11945 | 361 |
from varT True have T: "T = T'' \<Rightarrow> Ts \<Rrightarrow> T'" |
11946 | 362 |
by cases auto |
11945 | 363 |
with uT have uT': "e \<turnstile> u : T'' \<Rightarrow> Ts \<Rrightarrow> T'" by simp |
12011 | 364 |
from T have "(Var 0 \<degree>\<degree> map (\<lambda>t. lift t 0) |
365 |
(map (\<lambda>t. t[u/i]) as))[(u \<degree> a[u/i])/0] \<in> IT" |
|
11943 | 366 |
proof (rule MI2) |
12011 | 367 |
from T have "(lift u 0 \<degree> Var 0)[a[u/i]/0] \<in> IT" |
11943 | 368 |
proof (rule MI1) |
369 |
have "lift u 0 \<in> IT" by (rule lift_IT) |
|
12011 | 370 |
thus "lift u 0 \<degree> Var 0 \<in> IT" by (rule app_Var_IT) |
371 |
show "e\<langle>0:T''\<rangle> \<turnstile> lift u 0 \<degree> Var 0 : Ts \<Rrightarrow> T'" |
|
11943 | 372 |
proof (rule typing.App) |
11945 | 373 |
show "e\<langle>0:T''\<rangle> \<turnstile> lift u 0 : T'' \<Rightarrow> Ts \<Rrightarrow> T'" |
11946 | 374 |
by (rule lift_type) (rule uT') |
11943 | 375 |
show "e\<langle>0:T''\<rangle> \<turnstile> Var 0 : T''" |
11946 | 376 |
by (rule typing.Var) simp |
11943 | 377 |
qed |
11950 | 378 |
from Var have "?R a" by cases (simp_all add: Cons) |
379 |
with argT uIT uT show "a[u/i] \<in> IT" by simp |
|
11943 | 380 |
from argT uT show "e \<turnstile> a[u/i] : T''" |
11946 | 381 |
by (rule subst_lemma) simp |
11943 | 382 |
qed |
12011 | 383 |
thus "u \<degree> a[u/i] \<in> IT" by simp |
11943 | 384 |
from Var have "as \<in> lists {t. ?R t}" |
385 |
by cases (simp_all add: Cons) |
|
386 |
moreover from argsT have "as \<in> lists ?ty" |
|
387 |
by (rule lists_typings) |
|
388 |
ultimately have "as \<in> lists ({t. ?R t} \<inter> ?ty)" |
|
389 |
by (rule lists_IntI) |
|
390 |
hence "map (\<lambda>t. lift t 0) (map (\<lambda>t. t[u/i]) as) \<in> lists IT" |
|
391 |
(is "(?ls as) \<in> _") |
|
392 |
proof induct |
|
393 |
case Nil |
|
394 |
show ?case by fastsimp |
|
395 |
next |
|
396 |
case (Cons b bs) |
|
397 |
hence I: "?R b" by simp |
|
398 |
from Cons obtain U where "e\<langle>i:T\<rangle> \<turnstile> b : U" by fast |
|
399 |
with uT uIT I have "b[u/i] \<in> IT" by simp |
|
400 |
hence "lift (b[u/i]) 0 \<in> IT" by (rule lift_IT) |
|
401 |
hence "lift (b[u/i]) 0 # ?ls bs \<in> lists IT" |
|
402 |
by (rule lists.Cons) (rule Cons) |
|
403 |
thus ?case by simp |
|
404 |
qed |
|
12011 | 405 |
thus "Var 0 \<degree>\<degree> ?ls as \<in> IT" by (rule IT.Var) |
11945 | 406 |
have "e\<langle>0:Ts \<Rrightarrow> T'\<rangle> \<turnstile> Var 0 : Ts \<Rrightarrow> T'" |
11946 | 407 |
by (rule typing.Var) simp |
11943 | 408 |
moreover from uT argsT have "e \<tturnstile> map (\<lambda>t. t[u/i]) as : Ts" |
409 |
by (rule substs_lemma) |
|
11947 | 410 |
hence "e\<langle>0:Ts \<Rrightarrow> T'\<rangle> \<tturnstile> ?ls as : Ts" |
11943 | 411 |
by (rule lift_typings) |
12011 | 412 |
ultimately show "e\<langle>0:Ts \<Rrightarrow> T'\<rangle> \<turnstile> Var 0 \<degree>\<degree> ?ls as : T'" |
11943 | 413 |
by (rule list_app_typeI) |
414 |
from argT uT have "e \<turnstile> a[u/i] : T''" |
|
415 |
by (rule subst_lemma) (rule refl) |
|
12011 | 416 |
with uT' show "e \<turnstile> u \<degree> a[u/i] : Ts \<Rrightarrow> T'" |
11943 | 417 |
by (rule typing.App) |
418 |
qed |
|
419 |
with Cons True show ?thesis |
|
420 |
by (simp add: map_compose [symmetric] o_def) |
|
421 |
qed |
|
11935 | 422 |
next |
11943 | 423 |
case False |
424 |
from Var have "rs \<in> lists {t. ?R t}" by simp |
|
11947 | 425 |
moreover from nT obtain Ts where "e\<langle>i:T\<rangle> \<tturnstile> rs : Ts" |
11943 | 426 |
by (rule list_app_typeE) |
427 |
hence "rs \<in> lists ?ty" by (rule lists_typings) |
|
428 |
ultimately have "rs \<in> lists ({t. ?R t} \<inter> ?ty)" |
|
429 |
by (rule lists_IntI) |
|
430 |
hence "map (\<lambda>x. x[u/i]) rs \<in> lists IT" |
|
431 |
proof induct |
|
432 |
case Nil |
|
433 |
show ?case by fastsimp |
|
434 |
next |
|
435 |
case (Cons a as) |
|
436 |
hence I: "?R a" by simp |
|
437 |
from Cons obtain U where "e\<langle>i:T\<rangle> \<turnstile> a : U" by fast |
|
438 |
with uT uIT I have "a[u/i] \<in> IT" by simp |
|
439 |
hence "(a[u/i] # map (\<lambda>t. t[u/i]) as) \<in> lists IT" |
|
440 |
by (rule lists.Cons) (rule Cons) |
|
441 |
thus ?case by simp |
|
442 |
qed |
|
443 |
with False show ?thesis by (auto simp add: subst_Var) |
|
11935 | 444 |
qed |
445 |
next |
|
446 |
case (Lambda r) |
|
11943 | 447 |
assume "e\<langle>i:T\<rangle> \<turnstile> Abs r : T'" |
448 |
and "\<And>e T' u i. PROP ?Q r e T' u i T" |
|
11935 | 449 |
with uIT uT show "Abs r[u/i] \<in> IT" |
11946 | 450 |
by fastsimp |
11935 | 451 |
next |
452 |
case (Beta r a as) |
|
12011 | 453 |
assume T: "e\<langle>i:T\<rangle> \<turnstile> Abs r \<degree> a \<degree>\<degree> as : T'" |
454 |
assume SI1: "\<And>e T' u i. PROP ?Q (r[a/0] \<degree>\<degree> as) e T' u i T" |
|
11935 | 455 |
assume SI2: "\<And>e T' u i. PROP ?Q a e T' u i T" |
12011 | 456 |
have "Abs (r[lift u 0/Suc i]) \<degree> a[u/i] \<degree>\<degree> map (\<lambda>t. t[u/i]) as \<in> IT" |
11935 | 457 |
proof (rule IT.Beta) |
12011 | 458 |
have "Abs r \<degree> a \<degree>\<degree> as -> r[a/0] \<degree>\<degree> as" |
11943 | 459 |
by (rule apps_preserves_beta) (rule beta.beta) |
12011 | 460 |
with T have "e\<langle>i:T\<rangle> \<turnstile> r[a/0] \<degree>\<degree> as : T'" |
11943 | 461 |
by (rule subject_reduction) |
12011 | 462 |
hence "(r[a/0] \<degree>\<degree> as)[u/i] \<in> IT" |
11943 | 463 |
by (rule SI1) |
12011 | 464 |
thus "r[lift u 0/Suc i][a[u/i]/0] \<degree>\<degree> map (\<lambda>t. t[u/i]) as \<in> IT" |
11943 | 465 |
by (simp del: subst_map add: subst_subst subst_map [symmetric]) |
12011 | 466 |
from T obtain U where "e\<langle>i:T\<rangle> \<turnstile> Abs r \<degree> a : U" |
11943 | 467 |
by (rule list_app_typeE) fast |
468 |
then obtain T'' where "e\<langle>i:T\<rangle> \<turnstile> a : T''" by cases simp_all |
|
469 |
thus "a[u/i] \<in> IT" by (rule SI2) |
|
11935 | 470 |
qed |
12011 | 471 |
thus "(Abs r \<degree> a \<degree>\<degree> as)[u/i] \<in> IT" by simp |
11935 | 472 |
} |
473 |
qed |
|
474 |
qed |
|
9622 | 475 |
|
11935 | 476 |
subsection {* Well-typed terms are strongly normalizing *} |
9622 | 477 |
|
11943 | 478 |
lemma type_implies_IT: "e \<turnstile> t : T \<Longrightarrow> t \<in> IT" |
11935 | 479 |
proof - |
11943 | 480 |
assume "e \<turnstile> t : T" |
11935 | 481 |
thus ?thesis |
482 |
proof induct |
|
483 |
case Var |
|
484 |
show ?case by (rule Var_IT) |
|
485 |
next |
|
486 |
case Abs |
|
487 |
show ?case by (rule IT.Lambda) |
|
488 |
next |
|
489 |
case (App T U e s t) |
|
12011 | 490 |
have "(Var 0 \<degree> lift t 0)[s/0] \<in> IT" |
11935 | 491 |
proof (rule subst_type_IT) |
11943 | 492 |
have "lift t 0 \<in> IT" by (rule lift_IT) |
493 |
hence "[lift t 0] \<in> lists IT" by (rule lists.Cons) (rule lists.Nil) |
|
12011 | 494 |
hence "Var 0 \<degree>\<degree> [lift t 0] \<in> IT" by (rule IT.Var) |
495 |
also have "Var 0 \<degree>\<degree> [lift t 0] = Var 0 \<degree> lift t 0" by simp |
|
11943 | 496 |
finally show "\<dots> \<in> IT" . |
11945 | 497 |
have "e\<langle>0:T \<Rightarrow> U\<rangle> \<turnstile> Var 0 : T \<Rightarrow> U" |
11946 | 498 |
by (rule typing.Var) simp |
11945 | 499 |
moreover have "e\<langle>0:T \<Rightarrow> U\<rangle> \<turnstile> lift t 0 : T" |
11946 | 500 |
by (rule lift_type) |
12011 | 501 |
ultimately show "e\<langle>0:T \<Rightarrow> U\<rangle> \<turnstile> Var 0 \<degree> lift t 0 : U" |
11943 | 502 |
by (rule typing.App) |
11935 | 503 |
qed |
504 |
thus ?case by simp |
|
505 |
qed |
|
506 |
qed |
|
9622 | 507 |
|
11943 | 508 |
theorem type_implies_termi: "e \<turnstile> t : T \<Longrightarrow> t \<in> termi beta" |
11935 | 509 |
proof - |
11943 | 510 |
assume "e \<turnstile> t : T" |
11935 | 511 |
hence "t \<in> IT" by (rule type_implies_IT) |
512 |
thus ?thesis by (rule IT_implies_termi) |
|
513 |
qed |
|
9622 | 514 |
|
11638 | 515 |
end |