author | nipkow |
Mon, 30 Sep 2002 15:44:21 +0200 | |
changeset 13596 | ee5f79b210c1 |
parent 12171 | dc87f33db447 |
child 14064 | 35d36f43ba06 |
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 |
|
12171 | 185 |
lemma lift_type [intro!]: "e \<turnstile> t : T \<Longrightarrow> (\<And>i U. e\<langle>i:U\<rangle> \<turnstile> lift t i : T)" |
186 |
by (induct set: typing) auto |
|
187 |
||
9622 | 188 |
|
11987 | 189 |
lemma lift_typings: |
190 |
"\<And>Ts. e \<tturnstile> ts : Ts \<Longrightarrow> e\<langle>i:U\<rangle> \<tturnstile> (map (\<lambda>t. lift t i) ts) : Ts" |
|
191 |
apply (induct ts) |
|
9622 | 192 |
apply simp |
193 |
apply (case_tac Ts) |
|
11946 | 194 |
apply auto |
9622 | 195 |
done |
196 |
||
197 |
||
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
198 |
subsection {* Substitution lemmas *} |
9622 | 199 |
|
11994 | 200 |
lemma subst_lemma: |
201 |
"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)" |
|
202 |
apply (induct set: typing) |
|
11946 | 203 |
apply (rule_tac x = x and y = i in linorder_cases) |
204 |
apply auto |
|
205 |
apply blast |
|
9622 | 206 |
done |
207 |
||
12011 | 208 |
lemma substs_lemma: |
209 |
"\<And>Ts. e \<turnstile> u : T \<Longrightarrow> e\<langle>i:T\<rangle> \<tturnstile> ts : Ts \<Longrightarrow> |
|
11943 | 210 |
e \<tturnstile> (map (\<lambda>t. t[u/i]) ts) : Ts" |
12011 | 211 |
apply (induct ts) |
9622 | 212 |
apply (case_tac Ts) |
213 |
apply simp |
|
214 |
apply simp |
|
12011 | 215 |
apply atomize |
9622 | 216 |
apply (case_tac Ts) |
217 |
apply simp |
|
218 |
apply simp |
|
219 |
apply (erule conjE) |
|
12011 | 220 |
apply (erule (1) subst_lemma) |
11994 | 221 |
apply (rule refl) |
222 |
done |
|
223 |
||
9622 | 224 |
|
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
225 |
subsection {* Subject reduction *} |
9622 | 226 |
|
11994 | 227 |
lemma subject_reduction: "e \<turnstile> t : T \<Longrightarrow> (\<And>t'. t -> t' \<Longrightarrow> e \<turnstile> t' : T)" |
228 |
apply (induct set: typing) |
|
9622 | 229 |
apply blast |
230 |
apply blast |
|
11994 | 231 |
apply atomize |
12011 | 232 |
apply (ind_cases "s \<degree> t -> t'") |
9622 | 233 |
apply hypsubst |
11945 | 234 |
apply (ind_cases "env \<turnstile> Abs t : T \<Rightarrow> U") |
9622 | 235 |
apply (rule subst_lemma) |
236 |
apply assumption |
|
237 |
apply assumption |
|
238 |
apply (rule ext) |
|
11935 | 239 |
apply (case_tac x) |
11946 | 240 |
apply auto |
9622 | 241 |
done |
242 |
||
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
243 |
|
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
244 |
subsection {* Additional lemmas *} |
9622 | 245 |
|
12011 | 246 |
lemma app_last: "(t \<degree>\<degree> ts) \<degree> u = t \<degree>\<degree> (ts @ [u])" |
11935 | 247 |
by simp |
9622 | 248 |
|
11994 | 249 |
lemma subst_Var_IT: "r \<in> IT \<Longrightarrow> (\<And>i j. r[Var i/j] \<in> IT)" |
250 |
apply (induct set: IT) |
|
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
251 |
txt {* Case @{term Var}: *} |
9622 | 252 |
apply (simp (no_asm) add: subst_Var) |
253 |
apply |
|
254 |
((rule conjI impI)+, |
|
9716 | 255 |
rule IT.Var, |
9622 | 256 |
erule lists.induct, |
257 |
simp (no_asm), |
|
258 |
rule lists.Nil, |
|
259 |
simp (no_asm), |
|
260 |
erule IntE, |
|
261 |
erule CollectE, |
|
262 |
rule lists.Cons, |
|
263 |
fast, |
|
264 |
assumption)+ |
|
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
265 |
txt {* Case @{term Lambda}: *} |
11994 | 266 |
apply atomize |
9622 | 267 |
apply simp |
9716 | 268 |
apply (rule IT.Lambda) |
9622 | 269 |
apply fast |
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
270 |
txt {* Case @{term Beta}: *} |
11994 | 271 |
apply atomize |
9622 | 272 |
apply (simp (no_asm_use) add: subst_subst [symmetric]) |
9716 | 273 |
apply (rule IT.Beta) |
9622 | 274 |
apply auto |
275 |
done |
|
276 |
||
277 |
lemma Var_IT: "Var n \<in> IT" |
|
12011 | 278 |
apply (subgoal_tac "Var n \<degree>\<degree> [] \<in> IT") |
9622 | 279 |
apply simp |
9716 | 280 |
apply (rule IT.Var) |
9622 | 281 |
apply (rule lists.Nil) |
282 |
done |
|
283 |
||
12011 | 284 |
lemma app_Var_IT: "t \<in> IT \<Longrightarrow> t \<degree> Var i \<in> IT" |
11994 | 285 |
apply (induct set: IT) |
9622 | 286 |
apply (subst app_last) |
9716 | 287 |
apply (rule IT.Var) |
9622 | 288 |
apply simp |
289 |
apply (rule lists.Cons) |
|
290 |
apply (rule Var_IT) |
|
291 |
apply (rule lists.Nil) |
|
9906 | 292 |
apply (rule IT.Beta [where ?ss = "[]", unfolded foldl_Nil [THEN eq_reflection]]) |
9622 | 293 |
apply (erule subst_Var_IT) |
294 |
apply (rule Var_IT) |
|
295 |
apply (subst app_last) |
|
9716 | 296 |
apply (rule IT.Beta) |
9622 | 297 |
apply (subst app_last [symmetric]) |
298 |
apply assumption |
|
299 |
apply assumption |
|
300 |
done |
|
301 |
||
11935 | 302 |
lemma type_induct [induct type]: |
11945 | 303 |
"(\<And>T. (\<And>T1 T2. T = T1 \<Rightarrow> T2 \<Longrightarrow> P T1) \<Longrightarrow> |
304 |
(\<And>T1 T2. T = T1 \<Rightarrow> T2 \<Longrightarrow> P T2) \<Longrightarrow> P T) \<Longrightarrow> P T" |
|
11935 | 305 |
proof - |
306 |
case rule_context |
|
307 |
show ?thesis |
|
308 |
proof (induct T) |
|
309 |
case Atom |
|
310 |
show ?case by (rule rule_context) simp_all |
|
311 |
next |
|
312 |
case Fun |
|
313 |
show ?case by (rule rule_context) (insert Fun, simp_all) |
|
314 |
qed |
|
315 |
qed |
|
316 |
||
9622 | 317 |
|
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
318 |
subsection {* Well-typed substitution preserves termination *} |
9622 | 319 |
|
11935 | 320 |
lemma subst_type_IT: |
11943 | 321 |
"\<And>t e T u i. t \<in> IT \<Longrightarrow> e\<langle>i:U\<rangle> \<turnstile> t : T \<Longrightarrow> |
322 |
u \<in> IT \<Longrightarrow> e \<turnstile> u : U \<Longrightarrow> t[u/i] \<in> IT" |
|
11935 | 323 |
(is "PROP ?P U" is "\<And>t e T u i. _ \<Longrightarrow> PROP ?Q t e T u i U") |
324 |
proof (induct U) |
|
325 |
fix T t |
|
11945 | 326 |
assume MI1: "\<And>T1 T2. T = T1 \<Rightarrow> T2 \<Longrightarrow> PROP ?P T1" |
327 |
assume MI2: "\<And>T1 T2. T = T1 \<Rightarrow> T2 \<Longrightarrow> PROP ?P T2" |
|
11935 | 328 |
assume "t \<in> IT" |
329 |
thus "\<And>e T' u i. PROP ?Q t e T' u i T" |
|
330 |
proof induct |
|
331 |
fix e T' u i |
|
11943 | 332 |
assume uIT: "u \<in> IT" |
333 |
assume uT: "e \<turnstile> u : T" |
|
11935 | 334 |
{ |
13596 | 335 |
case (Var n rs e_ T'_ u_ i_) |
12011 | 336 |
assume nT: "e\<langle>i:T\<rangle> \<turnstile> Var n \<degree>\<degree> rs : T'" |
11943 | 337 |
let ?ty = "{t. \<exists>T'. e\<langle>i:T\<rangle> \<turnstile> t : T'}" |
11935 | 338 |
let ?R = "\<lambda>t. \<forall>e T' u i. |
11943 | 339 |
e\<langle>i:T\<rangle> \<turnstile> t : T' \<longrightarrow> u \<in> IT \<longrightarrow> e \<turnstile> u : T \<longrightarrow> t[u/i] \<in> IT" |
12011 | 340 |
show "(Var n \<degree>\<degree> rs)[u/i] \<in> IT" |
11935 | 341 |
proof (cases "n = i") |
11943 | 342 |
case True |
343 |
show ?thesis |
|
344 |
proof (cases rs) |
|
345 |
case Nil |
|
346 |
with uIT True show ?thesis by simp |
|
347 |
next |
|
348 |
case (Cons a as) |
|
12011 | 349 |
with nT have "e\<langle>i:T\<rangle> \<turnstile> Var n \<degree> a \<degree>\<degree> as : T'" by simp |
11943 | 350 |
then obtain Ts |
12011 | 351 |
where headT: "e\<langle>i:T\<rangle> \<turnstile> Var n \<degree> a : Ts \<Rrightarrow> T'" |
11947 | 352 |
and argsT: "e\<langle>i:T\<rangle> \<tturnstile> as : Ts" |
11943 | 353 |
by (rule list_app_typeE) |
354 |
from headT obtain T'' |
|
11945 | 355 |
where varT: "e\<langle>i:T\<rangle> \<turnstile> Var n : T'' \<Rightarrow> Ts \<Rrightarrow> T'" |
11943 | 356 |
and argT: "e\<langle>i:T\<rangle> \<turnstile> a : T''" |
357 |
by cases simp_all |
|
11945 | 358 |
from varT True have T: "T = T'' \<Rightarrow> Ts \<Rrightarrow> T'" |
11946 | 359 |
by cases auto |
11945 | 360 |
with uT have uT': "e \<turnstile> u : T'' \<Rightarrow> Ts \<Rrightarrow> T'" by simp |
12011 | 361 |
from T have "(Var 0 \<degree>\<degree> map (\<lambda>t. lift t 0) |
362 |
(map (\<lambda>t. t[u/i]) as))[(u \<degree> a[u/i])/0] \<in> IT" |
|
11943 | 363 |
proof (rule MI2) |
12011 | 364 |
from T have "(lift u 0 \<degree> Var 0)[a[u/i]/0] \<in> IT" |
11943 | 365 |
proof (rule MI1) |
366 |
have "lift u 0 \<in> IT" by (rule lift_IT) |
|
12011 | 367 |
thus "lift u 0 \<degree> Var 0 \<in> IT" by (rule app_Var_IT) |
368 |
show "e\<langle>0:T''\<rangle> \<turnstile> lift u 0 \<degree> Var 0 : Ts \<Rrightarrow> T'" |
|
11943 | 369 |
proof (rule typing.App) |
11945 | 370 |
show "e\<langle>0:T''\<rangle> \<turnstile> lift u 0 : T'' \<Rightarrow> Ts \<Rrightarrow> T'" |
11946 | 371 |
by (rule lift_type) (rule uT') |
11943 | 372 |
show "e\<langle>0:T''\<rangle> \<turnstile> Var 0 : T''" |
11946 | 373 |
by (rule typing.Var) simp |
11943 | 374 |
qed |
11950 | 375 |
from Var have "?R a" by cases (simp_all add: Cons) |
376 |
with argT uIT uT show "a[u/i] \<in> IT" by simp |
|
11943 | 377 |
from argT uT show "e \<turnstile> a[u/i] : T''" |
11946 | 378 |
by (rule subst_lemma) simp |
11943 | 379 |
qed |
12011 | 380 |
thus "u \<degree> a[u/i] \<in> IT" by simp |
11943 | 381 |
from Var have "as \<in> lists {t. ?R t}" |
382 |
by cases (simp_all add: Cons) |
|
383 |
moreover from argsT have "as \<in> lists ?ty" |
|
384 |
by (rule lists_typings) |
|
385 |
ultimately have "as \<in> lists ({t. ?R t} \<inter> ?ty)" |
|
386 |
by (rule lists_IntI) |
|
387 |
hence "map (\<lambda>t. lift t 0) (map (\<lambda>t. t[u/i]) as) \<in> lists IT" |
|
388 |
(is "(?ls as) \<in> _") |
|
389 |
proof induct |
|
390 |
case Nil |
|
391 |
show ?case by fastsimp |
|
392 |
next |
|
393 |
case (Cons b bs) |
|
394 |
hence I: "?R b" by simp |
|
395 |
from Cons obtain U where "e\<langle>i:T\<rangle> \<turnstile> b : U" by fast |
|
396 |
with uT uIT I have "b[u/i] \<in> IT" by simp |
|
397 |
hence "lift (b[u/i]) 0 \<in> IT" by (rule lift_IT) |
|
398 |
hence "lift (b[u/i]) 0 # ?ls bs \<in> lists IT" |
|
399 |
by (rule lists.Cons) (rule Cons) |
|
400 |
thus ?case by simp |
|
401 |
qed |
|
12011 | 402 |
thus "Var 0 \<degree>\<degree> ?ls as \<in> IT" by (rule IT.Var) |
11945 | 403 |
have "e\<langle>0:Ts \<Rrightarrow> T'\<rangle> \<turnstile> Var 0 : Ts \<Rrightarrow> T'" |
11946 | 404 |
by (rule typing.Var) simp |
11943 | 405 |
moreover from uT argsT have "e \<tturnstile> map (\<lambda>t. t[u/i]) as : Ts" |
406 |
by (rule substs_lemma) |
|
11947 | 407 |
hence "e\<langle>0:Ts \<Rrightarrow> T'\<rangle> \<tturnstile> ?ls as : Ts" |
11943 | 408 |
by (rule lift_typings) |
12011 | 409 |
ultimately show "e\<langle>0:Ts \<Rrightarrow> T'\<rangle> \<turnstile> Var 0 \<degree>\<degree> ?ls as : T'" |
11943 | 410 |
by (rule list_app_typeI) |
411 |
from argT uT have "e \<turnstile> a[u/i] : T''" |
|
412 |
by (rule subst_lemma) (rule refl) |
|
12011 | 413 |
with uT' show "e \<turnstile> u \<degree> a[u/i] : Ts \<Rrightarrow> T'" |
11943 | 414 |
by (rule typing.App) |
415 |
qed |
|
416 |
with Cons True show ?thesis |
|
417 |
by (simp add: map_compose [symmetric] o_def) |
|
418 |
qed |
|
11935 | 419 |
next |
11943 | 420 |
case False |
421 |
from Var have "rs \<in> lists {t. ?R t}" by simp |
|
11947 | 422 |
moreover from nT obtain Ts where "e\<langle>i:T\<rangle> \<tturnstile> rs : Ts" |
11943 | 423 |
by (rule list_app_typeE) |
424 |
hence "rs \<in> lists ?ty" by (rule lists_typings) |
|
425 |
ultimately have "rs \<in> lists ({t. ?R t} \<inter> ?ty)" |
|
426 |
by (rule lists_IntI) |
|
427 |
hence "map (\<lambda>x. x[u/i]) rs \<in> lists IT" |
|
428 |
proof induct |
|
429 |
case Nil |
|
430 |
show ?case by fastsimp |
|
431 |
next |
|
432 |
case (Cons a as) |
|
433 |
hence I: "?R a" by simp |
|
434 |
from Cons obtain U where "e\<langle>i:T\<rangle> \<turnstile> a : U" by fast |
|
435 |
with uT uIT I have "a[u/i] \<in> IT" by simp |
|
436 |
hence "(a[u/i] # map (\<lambda>t. t[u/i]) as) \<in> lists IT" |
|
437 |
by (rule lists.Cons) (rule Cons) |
|
438 |
thus ?case by simp |
|
439 |
qed |
|
440 |
with False show ?thesis by (auto simp add: subst_Var) |
|
11935 | 441 |
qed |
442 |
next |
|
13596 | 443 |
case (Lambda r e_ T'_ u_ i_) |
11943 | 444 |
assume "e\<langle>i:T\<rangle> \<turnstile> Abs r : T'" |
445 |
and "\<And>e T' u i. PROP ?Q r e T' u i T" |
|
11935 | 446 |
with uIT uT show "Abs r[u/i] \<in> IT" |
11946 | 447 |
by fastsimp |
11935 | 448 |
next |
13596 | 449 |
case (Beta r a as e_ T'_ u_ i_) |
12011 | 450 |
assume T: "e\<langle>i:T\<rangle> \<turnstile> Abs r \<degree> a \<degree>\<degree> as : T'" |
451 |
assume SI1: "\<And>e T' u i. PROP ?Q (r[a/0] \<degree>\<degree> as) e T' u i T" |
|
11935 | 452 |
assume SI2: "\<And>e T' u i. PROP ?Q a e T' u i T" |
12011 | 453 |
have "Abs (r[lift u 0/Suc i]) \<degree> a[u/i] \<degree>\<degree> map (\<lambda>t. t[u/i]) as \<in> IT" |
11935 | 454 |
proof (rule IT.Beta) |
12011 | 455 |
have "Abs r \<degree> a \<degree>\<degree> as -> r[a/0] \<degree>\<degree> as" |
11943 | 456 |
by (rule apps_preserves_beta) (rule beta.beta) |
12011 | 457 |
with T have "e\<langle>i:T\<rangle> \<turnstile> r[a/0] \<degree>\<degree> as : T'" |
11943 | 458 |
by (rule subject_reduction) |
12011 | 459 |
hence "(r[a/0] \<degree>\<degree> as)[u/i] \<in> IT" |
11943 | 460 |
by (rule SI1) |
12011 | 461 |
thus "r[lift u 0/Suc i][a[u/i]/0] \<degree>\<degree> map (\<lambda>t. t[u/i]) as \<in> IT" |
11943 | 462 |
by (simp del: subst_map add: subst_subst subst_map [symmetric]) |
12011 | 463 |
from T obtain U where "e\<langle>i:T\<rangle> \<turnstile> Abs r \<degree> a : U" |
11943 | 464 |
by (rule list_app_typeE) fast |
465 |
then obtain T'' where "e\<langle>i:T\<rangle> \<turnstile> a : T''" by cases simp_all |
|
466 |
thus "a[u/i] \<in> IT" by (rule SI2) |
|
11935 | 467 |
qed |
12011 | 468 |
thus "(Abs r \<degree> a \<degree>\<degree> as)[u/i] \<in> IT" by simp |
11935 | 469 |
} |
470 |
qed |
|
471 |
qed |
|
9622 | 472 |
|
12171 | 473 |
|
11935 | 474 |
subsection {* Well-typed terms are strongly normalizing *} |
9622 | 475 |
|
11943 | 476 |
lemma type_implies_IT: "e \<turnstile> t : T \<Longrightarrow> t \<in> IT" |
11935 | 477 |
proof - |
11943 | 478 |
assume "e \<turnstile> t : T" |
11935 | 479 |
thus ?thesis |
480 |
proof induct |
|
481 |
case Var |
|
482 |
show ?case by (rule Var_IT) |
|
483 |
next |
|
484 |
case Abs |
|
485 |
show ?case by (rule IT.Lambda) |
|
486 |
next |
|
487 |
case (App T U e s t) |
|
12011 | 488 |
have "(Var 0 \<degree> lift t 0)[s/0] \<in> IT" |
11935 | 489 |
proof (rule subst_type_IT) |
11943 | 490 |
have "lift t 0 \<in> IT" by (rule lift_IT) |
491 |
hence "[lift t 0] \<in> lists IT" by (rule lists.Cons) (rule lists.Nil) |
|
12011 | 492 |
hence "Var 0 \<degree>\<degree> [lift t 0] \<in> IT" by (rule IT.Var) |
493 |
also have "Var 0 \<degree>\<degree> [lift t 0] = Var 0 \<degree> lift t 0" by simp |
|
11943 | 494 |
finally show "\<dots> \<in> IT" . |
11945 | 495 |
have "e\<langle>0:T \<Rightarrow> U\<rangle> \<turnstile> Var 0 : T \<Rightarrow> U" |
11946 | 496 |
by (rule typing.Var) simp |
11945 | 497 |
moreover have "e\<langle>0:T \<Rightarrow> U\<rangle> \<turnstile> lift t 0 : T" |
11946 | 498 |
by (rule lift_type) |
12011 | 499 |
ultimately show "e\<langle>0:T \<Rightarrow> U\<rangle> \<turnstile> Var 0 \<degree> lift t 0 : U" |
11943 | 500 |
by (rule typing.App) |
11935 | 501 |
qed |
502 |
thus ?case by simp |
|
503 |
qed |
|
504 |
qed |
|
9622 | 505 |
|
11943 | 506 |
theorem type_implies_termi: "e \<turnstile> t : T \<Longrightarrow> t \<in> termi beta" |
11935 | 507 |
proof - |
11943 | 508 |
assume "e \<turnstile> t : T" |
11935 | 509 |
hence "t \<in> IT" by (rule type_implies_IT) |
510 |
thus ?thesis by (rule IT_implies_termi) |
|
511 |
qed |
|
9622 | 512 |
|
11638 | 513 |
end |