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