author | wenzelm |
Wed, 04 Oct 2000 22:21:10 +0200 | |
changeset 10155 | 6263a4a60e38 |
parent 9941 | fe05af7ec816 |
child 10567 | e7c9900cca4d |
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 |
|
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
18 |
subsection {* Types and typing rules *} |
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
19 |
|
9641 | 20 |
datatype type = |
9622 | 21 |
Atom nat |
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
22 |
| Fun type type (infixr "=>" 200) |
9114
de99e37effda
Subject reduction and strong normalization of simply-typed lambda terms.
berghofe
parents:
diff
changeset
|
23 |
|
de99e37effda
Subject reduction and strong normalization of simply-typed lambda terms.
berghofe
parents:
diff
changeset
|
24 |
consts |
9641 | 25 |
typing :: "((nat => type) \<times> dB \<times> type) set" |
9114
de99e37effda
Subject reduction and strong normalization of simply-typed lambda terms.
berghofe
parents:
diff
changeset
|
26 |
|
de99e37effda
Subject reduction and strong normalization of simply-typed lambda terms.
berghofe
parents:
diff
changeset
|
27 |
syntax |
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
28 |
"_typing" :: "[nat => type, dB, type] => bool" ("_ |- _ : _" [50,50,50] 50) |
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
29 |
"_funs" :: "[type list, type] => type" (infixl "=>>" 150) |
9114
de99e37effda
Subject reduction and strong normalization of simply-typed lambda terms.
berghofe
parents:
diff
changeset
|
30 |
translations |
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
31 |
"env |- t : T" == "(env, t, T) \<in> typing" |
9114
de99e37effda
Subject reduction and strong normalization of simply-typed lambda terms.
berghofe
parents:
diff
changeset
|
32 |
"Ts =>> T" == "foldr Fun Ts T" |
de99e37effda
Subject reduction and strong normalization of simply-typed lambda terms.
berghofe
parents:
diff
changeset
|
33 |
|
de99e37effda
Subject reduction and strong normalization of simply-typed lambda terms.
berghofe
parents:
diff
changeset
|
34 |
inductive typing |
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
35 |
intros [intro!] |
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
36 |
Var: "env x = T ==> env |- Var x : T" |
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
37 |
Abs: "(nat_case T env) |- t : U ==> env |- Abs t : (T => U)" |
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
38 |
App: "env |- s : T => U ==> env |- t : T ==> env |- (s $ t) : U" |
9622 | 39 |
|
9641 | 40 |
inductive_cases [elim!]: |
41 |
"e |- Var i : T" |
|
42 |
"e |- t $ u : T" |
|
43 |
"e |- Abs t : T" |
|
9114
de99e37effda
Subject reduction and strong normalization of simply-typed lambda terms.
berghofe
parents:
diff
changeset
|
44 |
|
de99e37effda
Subject reduction and strong normalization of simply-typed lambda terms.
berghofe
parents:
diff
changeset
|
45 |
consts |
9641 | 46 |
"types" :: "[nat => type, dB list, type list] => bool" |
9114
de99e37effda
Subject reduction and strong normalization of simply-typed lambda terms.
berghofe
parents:
diff
changeset
|
47 |
primrec |
de99e37effda
Subject reduction and strong normalization of simply-typed lambda terms.
berghofe
parents:
diff
changeset
|
48 |
"types e [] Ts = (Ts = [])" |
9622 | 49 |
"types e (t # ts) Ts = |
50 |
(case Ts of |
|
9114
de99e37effda
Subject reduction and strong normalization of simply-typed lambda terms.
berghofe
parents:
diff
changeset
|
51 |
[] => False |
9641 | 52 |
| T # Ts => e |- t : T \<and> types e ts Ts)" |
9622 | 53 |
|
54 |
inductive_cases [elim!]: |
|
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
55 |
"x # xs \<in> lists S" |
9622 | 56 |
|
9641 | 57 |
declare IT.intros [intro!] |
58 |
||
9622 | 59 |
|
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
60 |
subsection {* Some examples *} |
9622 | 61 |
|
62 |
lemma "\<exists>T U. e |- Abs (Abs (Abs (Var 1 $ (Var 2 $ Var 1 $ Var 0)))) : T \<and> U = T" |
|
63 |
apply (intro exI conjI) |
|
9641 | 64 |
apply force |
9622 | 65 |
apply (rule refl) |
66 |
done |
|
67 |
||
68 |
lemma "\<exists>T U. e |- Abs (Abs (Abs (Var 2 $ Var 0 $ (Var 1 $ Var 0)))) : T \<and> U = T"; |
|
69 |
apply (intro exI conjI) |
|
9641 | 70 |
apply force |
9622 | 71 |
apply (rule refl) |
72 |
done |
|
73 |
||
74 |
||
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
75 |
text {* Iterated function types *} |
9622 | 76 |
|
9941
fe05af7ec816
renamed atts: rulify to rule_format, elimify to elim_format;
wenzelm
parents:
9906
diff
changeset
|
77 |
lemma list_app_typeD [rule_format]: |
9622 | 78 |
"\<forall>t T. e |- t $$ ts : T --> (\<exists>Ts. e |- t : Ts =>> T \<and> types e ts Ts)" |
79 |
apply (induct_tac ts) |
|
80 |
apply simp |
|
81 |
apply (intro strip) |
|
82 |
apply simp |
|
83 |
apply (erule_tac x = "t $ a" in allE) |
|
84 |
apply (erule_tac x = T in allE) |
|
85 |
apply (erule impE) |
|
86 |
apply assumption |
|
87 |
apply (elim exE conjE) |
|
88 |
apply (ind_cases "e |- t $ u : T") |
|
89 |
apply (rule_tac x = "Ta # Ts" in exI) |
|
90 |
apply simp |
|
91 |
done |
|
92 |
||
9941
fe05af7ec816
renamed atts: rulify to rule_format, elimify to elim_format;
wenzelm
parents:
9906
diff
changeset
|
93 |
lemma list_app_typeI [rule_format]: |
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
94 |
"\<forall>t T Ts. e |- t : Ts =>> T --> types e ts Ts --> e |- t $$ ts : T" |
9622 | 95 |
apply (induct_tac ts) |
96 |
apply (intro strip) |
|
97 |
apply simp |
|
98 |
apply (intro strip) |
|
99 |
apply (case_tac Ts) |
|
100 |
apply simp |
|
101 |
apply simp |
|
102 |
apply (erule_tac x = "t $ a" in allE) |
|
103 |
apply (erule_tac x = T in allE) |
|
104 |
apply (erule_tac x = lista in allE) |
|
105 |
apply (erule impE) |
|
106 |
apply (erule conjE) |
|
107 |
apply (erule typing.App) |
|
108 |
apply assumption |
|
109 |
apply blast |
|
110 |
done |
|
111 |
||
9941
fe05af7ec816
renamed atts: rulify to rule_format, elimify to elim_format;
wenzelm
parents:
9906
diff
changeset
|
112 |
lemma lists_types [rule_format]: |
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
113 |
"\<forall>Ts. types e ts Ts --> ts \<in> lists {t. \<exists>T. e |- t : T}" |
9622 | 114 |
apply (induct_tac ts) |
115 |
apply (intro strip) |
|
116 |
apply (case_tac Ts) |
|
117 |
apply simp |
|
118 |
apply (rule lists.Nil) |
|
119 |
apply simp |
|
120 |
apply (intro strip) |
|
121 |
apply (case_tac Ts) |
|
122 |
apply simp |
|
123 |
apply simp |
|
124 |
apply (rule lists.Cons) |
|
125 |
apply blast |
|
126 |
apply blast |
|
127 |
done |
|
128 |
||
129 |
||
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
130 |
subsection {* Lifting preserves termination and well-typedness *} |
9622 | 131 |
|
9941
fe05af7ec816
renamed atts: rulify to rule_format, elimify to elim_format;
wenzelm
parents:
9906
diff
changeset
|
132 |
lemma lift_map [rule_format, simp]: |
9622 | 133 |
"\<forall>t. lift (t $$ ts) i = lift t i $$ map (\<lambda>t. lift t i) ts" |
134 |
apply (induct_tac ts) |
|
9641 | 135 |
apply simp_all |
9622 | 136 |
done |
137 |
||
9941
fe05af7ec816
renamed atts: rulify to rule_format, elimify to elim_format;
wenzelm
parents:
9906
diff
changeset
|
138 |
lemma subst_map [rule_format, simp]: |
9622 | 139 |
"\<forall>t. subst (t $$ ts) u i = subst t u i $$ map (\<lambda>t. subst t u i) ts" |
140 |
apply (induct_tac ts) |
|
9641 | 141 |
apply simp_all |
9622 | 142 |
done |
143 |
||
9941
fe05af7ec816
renamed atts: rulify to rule_format, elimify to elim_format;
wenzelm
parents:
9906
diff
changeset
|
144 |
lemma lift_IT [rule_format, intro!]: |
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
145 |
"t \<in> IT ==> \<forall>i. lift t i \<in> IT" |
9622 | 146 |
apply (erule IT.induct) |
147 |
apply (rule allI) |
|
148 |
apply (simp (no_asm)) |
|
149 |
apply (rule conjI) |
|
150 |
apply |
|
151 |
(rule impI, |
|
9716 | 152 |
rule IT.Var, |
9622 | 153 |
erule lists.induct, |
154 |
simp (no_asm), |
|
155 |
rule lists.Nil, |
|
156 |
simp (no_asm), |
|
157 |
erule IntE, |
|
158 |
rule lists.Cons, |
|
159 |
blast, |
|
160 |
assumption)+ |
|
161 |
apply auto |
|
162 |
done |
|
163 |
||
9941
fe05af7ec816
renamed atts: rulify to rule_format, elimify to elim_format;
wenzelm
parents:
9906
diff
changeset
|
164 |
lemma lifts_IT [rule_format]: |
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
165 |
"ts \<in> lists IT --> map (\<lambda>t. lift t 0) ts \<in> lists IT" |
9622 | 166 |
apply (induct_tac ts) |
167 |
apply auto |
|
168 |
done |
|
169 |
||
170 |
||
171 |
lemma shift_env [simp]: |
|
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
172 |
"nat_case T |
9622 | 173 |
(\<lambda>j. if j < i then e j else if j = i then Ua else e (j - 1)) = |
174 |
(\<lambda>j. if j < Suc i then nat_case T e j else if j = Suc i then Ua |
|
175 |
else nat_case T e (j - 1))" |
|
176 |
apply (rule ext) |
|
177 |
apply (case_tac j) |
|
178 |
apply simp |
|
179 |
apply (case_tac nat) |
|
9641 | 180 |
apply simp_all |
9622 | 181 |
done |
182 |
||
9941
fe05af7ec816
renamed atts: rulify to rule_format, elimify to elim_format;
wenzelm
parents:
9906
diff
changeset
|
183 |
lemma lift_type' [rule_format]: |
9622 | 184 |
"e |- t : T ==> \<forall>i U. |
185 |
(\<lambda>j. if j < i then e j |
|
9641 | 186 |
else if j = i then U |
9622 | 187 |
else e (j - 1)) |- lift t i : T" |
188 |
apply (erule typing.induct) |
|
189 |
apply auto |
|
190 |
done |
|
191 |
||
192 |
lemma lift_type [intro!]: |
|
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
193 |
"e |- t : T ==> nat_case U e |- lift t 0 : T" |
9622 | 194 |
apply (subgoal_tac |
195 |
"nat_case U e = |
|
196 |
(\<lambda>j. if j < 0 then e j |
|
197 |
else if j = 0 then U else e (j - 1))") |
|
198 |
apply (erule ssubst) |
|
199 |
apply (erule lift_type') |
|
200 |
apply (rule ext) |
|
201 |
apply (case_tac j) |
|
202 |
apply simp_all |
|
203 |
done |
|
204 |
||
9941
fe05af7ec816
renamed atts: rulify to rule_format, elimify to elim_format;
wenzelm
parents:
9906
diff
changeset
|
205 |
lemma lift_types [rule_format]: |
9622 | 206 |
"\<forall>Ts. types e ts Ts --> |
207 |
types (\<lambda>j. if j < i then e j |
|
208 |
else if j = i then U |
|
209 |
else e (j - 1)) (map (\<lambda>t. lift t i) ts) Ts" |
|
210 |
apply (induct_tac ts) |
|
211 |
apply simp |
|
212 |
apply (intro strip) |
|
213 |
apply (case_tac Ts) |
|
214 |
apply simp_all |
|
215 |
apply (rule lift_type') |
|
216 |
apply (erule conjunct1) |
|
217 |
done |
|
218 |
||
219 |
||
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
220 |
subsection {* Substitution lemmas *} |
9622 | 221 |
|
9941
fe05af7ec816
renamed atts: rulify to rule_format, elimify to elim_format;
wenzelm
parents:
9906
diff
changeset
|
222 |
lemma subst_lemma [rule_format]: |
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
223 |
"e |- t : T ==> \<forall>e' i U u. |
9622 | 224 |
e = (\<lambda>j. if j < i then e' j |
225 |
else if j = i then U |
|
226 |
else e' (j-1)) --> |
|
227 |
e' |- u : U --> e' |- t[u/i] : T" |
|
228 |
apply (erule typing.induct) |
|
229 |
apply (intro strip) |
|
230 |
apply (case_tac "x = i") |
|
231 |
apply simp |
|
232 |
apply (frule linorder_neq_iff [THEN iffD1]) |
|
233 |
apply (erule disjE) |
|
234 |
apply simp |
|
235 |
apply (rule typing.Var) |
|
236 |
apply assumption |
|
237 |
apply (frule order_less_not_sym) |
|
238 |
apply (simp only: subst_gt split: split_if add: if_False) |
|
239 |
apply (rule typing.Var) |
|
240 |
apply assumption |
|
241 |
apply fastsimp |
|
242 |
apply fastsimp |
|
243 |
done |
|
244 |
||
9941
fe05af7ec816
renamed atts: rulify to rule_format, elimify to elim_format;
wenzelm
parents:
9906
diff
changeset
|
245 |
lemma substs_lemma [rule_format]: |
9622 | 246 |
"e |- u : T ==> |
247 |
\<forall>Ts. types (\<lambda>j. if j < i then e j |
|
248 |
else if j = i then T else e (j - 1)) ts Ts --> |
|
9641 | 249 |
types e (map (\<lambda>t. t[u/i]) ts) Ts" |
9622 | 250 |
apply (induct_tac ts) |
251 |
apply (intro strip) |
|
252 |
apply (case_tac Ts) |
|
253 |
apply simp |
|
254 |
apply simp |
|
255 |
apply (intro strip) |
|
256 |
apply (case_tac Ts) |
|
257 |
apply simp |
|
258 |
apply simp |
|
259 |
apply (erule conjE) |
|
260 |
apply (erule subst_lemma) |
|
9641 | 261 |
apply (rule refl) |
9622 | 262 |
apply assumption |
263 |
done |
|
264 |
||
265 |
||
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
266 |
subsection {* Subject reduction *} |
9622 | 267 |
|
9941
fe05af7ec816
renamed atts: rulify to rule_format, elimify to elim_format;
wenzelm
parents:
9906
diff
changeset
|
268 |
lemma subject_reduction [rule_format]: |
9622 | 269 |
"e |- t : T ==> \<forall>t'. t -> t' --> e |- t' : T" |
270 |
apply (erule typing.induct) |
|
271 |
apply blast |
|
272 |
apply blast |
|
273 |
apply (intro strip) |
|
274 |
apply (ind_cases "s $ t -> t'") |
|
275 |
apply hypsubst |
|
276 |
apply (ind_cases "env |- Abs t : T => U") |
|
277 |
apply (rule subst_lemma) |
|
278 |
apply assumption |
|
279 |
prefer 2 |
|
280 |
apply assumption |
|
281 |
apply (rule ext) |
|
282 |
apply (case_tac j) |
|
9641 | 283 |
apply auto |
9622 | 284 |
done |
285 |
||
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
286 |
|
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
287 |
subsection {* Additional lemmas *} |
9622 | 288 |
|
289 |
lemma app_last: "(t $$ ts) $ u = t $$ (ts @ [u])" |
|
290 |
apply simp |
|
291 |
done |
|
292 |
||
9941
fe05af7ec816
renamed atts: rulify to rule_format, elimify to elim_format;
wenzelm
parents:
9906
diff
changeset
|
293 |
lemma subst_Var_IT [rule_format]: "r \<in> IT ==> \<forall>i j. r[Var i/j] \<in> IT" |
9622 | 294 |
apply (erule IT.induct) |
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
295 |
txt {* Case @{term Var}: *} |
9622 | 296 |
apply (intro strip) |
297 |
apply (simp (no_asm) add: subst_Var) |
|
298 |
apply |
|
299 |
((rule conjI impI)+, |
|
9716 | 300 |
rule IT.Var, |
9622 | 301 |
erule lists.induct, |
302 |
simp (no_asm), |
|
303 |
rule lists.Nil, |
|
304 |
simp (no_asm), |
|
305 |
erule IntE, |
|
306 |
erule CollectE, |
|
307 |
rule lists.Cons, |
|
308 |
fast, |
|
309 |
assumption)+ |
|
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
310 |
txt {* Case @{term Lambda}: *} |
9622 | 311 |
apply (intro strip) |
312 |
apply simp |
|
9716 | 313 |
apply (rule IT.Lambda) |
9622 | 314 |
apply fast |
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
315 |
txt {* Case @{term Beta}: *} |
9622 | 316 |
apply (intro strip) |
317 |
apply (simp (no_asm_use) add: subst_subst [symmetric]) |
|
9716 | 318 |
apply (rule IT.Beta) |
9622 | 319 |
apply auto |
320 |
done |
|
321 |
||
322 |
lemma Var_IT: "Var n \<in> IT" |
|
323 |
apply (subgoal_tac "Var n $$ [] \<in> IT") |
|
324 |
apply simp |
|
9716 | 325 |
apply (rule IT.Var) |
9622 | 326 |
apply (rule lists.Nil) |
327 |
done |
|
328 |
||
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
329 |
lemma app_Var_IT: "t \<in> IT ==> t $ Var i \<in> IT" |
9622 | 330 |
apply (erule IT.induct) |
331 |
apply (subst app_last) |
|
9716 | 332 |
apply (rule IT.Var) |
9622 | 333 |
apply simp |
334 |
apply (rule lists.Cons) |
|
335 |
apply (rule Var_IT) |
|
336 |
apply (rule lists.Nil) |
|
9906 | 337 |
apply (rule IT.Beta [where ?ss = "[]", unfolded foldl_Nil [THEN eq_reflection]]) |
9622 | 338 |
apply (erule subst_Var_IT) |
339 |
apply (rule Var_IT) |
|
340 |
apply (subst app_last) |
|
9716 | 341 |
apply (rule IT.Beta) |
9622 | 342 |
apply (subst app_last [symmetric]) |
343 |
apply assumption |
|
344 |
apply assumption |
|
345 |
done |
|
346 |
||
347 |
||
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
348 |
subsection {* Well-typed substitution preserves termination *} |
9622 | 349 |
|
9941
fe05af7ec816
renamed atts: rulify to rule_format, elimify to elim_format;
wenzelm
parents:
9906
diff
changeset
|
350 |
lemma subst_type_IT [rule_format]: |
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
351 |
"\<forall>t. t \<in> IT --> (\<forall>e T u i. |
9622 | 352 |
(\<lambda>j. if j < i then e j |
353 |
else if j = i then U |
|
354 |
else e (j - 1)) |- t : T --> |
|
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
355 |
u \<in> IT --> e |- u : U --> t[u/i] \<in> IT)" |
9622 | 356 |
apply (rule_tac f = size and a = U in measure_induct) |
357 |
apply (rule allI) |
|
358 |
apply (rule impI) |
|
359 |
apply (erule IT.induct) |
|
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
360 |
txt {* Case @{term Var}: *} |
9622 | 361 |
apply (intro strip) |
362 |
apply (case_tac "n = i") |
|
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
363 |
txt {* Case @{term "n = i"}: *} |
9622 | 364 |
apply (case_tac rs) |
365 |
apply simp |
|
366 |
apply simp |
|
367 |
apply (drule list_app_typeD) |
|
368 |
apply (elim exE conjE) |
|
369 |
apply (ind_cases "e |- t $ u : T") |
|
370 |
apply (ind_cases "e |- Var i : T") |
|
9641 | 371 |
apply (drule_tac s = "(?T::type) => ?U" in sym) |
9622 | 372 |
apply simp |
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
373 |
apply (subgoal_tac "lift u 0 $ Var 0 \<in> IT") |
9622 | 374 |
prefer 2 |
375 |
apply (rule app_Var_IT) |
|
376 |
apply (erule lift_IT) |
|
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
377 |
apply (subgoal_tac "(lift u 0 $ Var 0)[a[u/i]/0] \<in> IT") |
9622 | 378 |
apply (simp (no_asm_use)) |
9641 | 379 |
apply (subgoal_tac "(Var 0 $$ map (\<lambda>t. lift t 0) |
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
380 |
(map (\<lambda>t. t[u/i]) list))[(u $ a[u/i])/0] \<in> IT") |
9771 | 381 |
apply (simp (no_asm_use) del: map_compose |
382 |
add: map_compose [symmetric] o_def) |
|
9622 | 383 |
apply (erule_tac x = "Ts =>> T" in allE) |
384 |
apply (erule impE) |
|
385 |
apply simp |
|
386 |
apply (erule_tac x = "Var 0 $$ |
|
9641 | 387 |
map (\<lambda>t. lift t 0) (map (\<lambda>t. t[u/i]) list)" in allE) |
9622 | 388 |
apply (erule impE) |
9716 | 389 |
apply (rule IT.Var) |
9622 | 390 |
apply (rule lifts_IT) |
391 |
apply (drule lists_types) |
|
392 |
apply |
|
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
393 |
(ind_cases "x # xs \<in> lists (Collect P)", |
9641 | 394 |
erule lists_IntI [THEN lists.induct], |
395 |
assumption) |
|
396 |
apply fastsimp |
|
9622 | 397 |
apply fastsimp |
398 |
apply (erule_tac x = e in allE) |
|
399 |
apply (erule_tac x = T in allE) |
|
400 |
apply (erule_tac x = "u $ a[u/i]" in allE) |
|
401 |
apply (erule_tac x = 0 in allE) |
|
402 |
apply (fastsimp intro!: list_app_typeI lift_types subst_lemma substs_lemma) |
|
403 |
apply (erule_tac x = Ta in allE) |
|
404 |
apply (erule impE) |
|
405 |
apply simp |
|
406 |
apply (erule_tac x = "lift u 0 $ Var 0" in allE) |
|
407 |
apply (erule impE) |
|
408 |
apply assumption |
|
409 |
apply (erule_tac x = e in allE) |
|
410 |
apply (erule_tac x = "Ts =>> T" in allE) |
|
411 |
apply (erule_tac x = "a[u/i]" in allE) |
|
412 |
apply (erule_tac x = 0 in allE) |
|
413 |
apply (erule impE) |
|
414 |
apply (rule typing.App) |
|
415 |
apply (erule lift_type') |
|
416 |
apply (rule typing.Var) |
|
417 |
apply simp |
|
418 |
apply (fast intro!: subst_lemma) |
|
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
419 |
txt {* Case @{term "n ~= i"}: *} |
9622 | 420 |
apply (drule list_app_typeD) |
421 |
apply (erule exE) |
|
422 |
apply (erule conjE) |
|
423 |
apply (drule lists_types) |
|
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
424 |
apply (subgoal_tac "map (\<lambda>x. x[u/i]) rs \<in> lists IT") |
9622 | 425 |
apply (simp add: subst_Var) |
426 |
apply fast |
|
427 |
apply (erule lists_IntI [THEN lists.induct]) |
|
428 |
apply assumption |
|
429 |
apply fastsimp |
|
430 |
apply fastsimp |
|
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
431 |
txt {* Case @{term Lambda}: *} |
9622 | 432 |
apply fastsimp |
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
433 |
txt {* Case @{term Beta}: *} |
9622 | 434 |
apply (intro strip) |
435 |
apply (simp (no_asm)) |
|
9716 | 436 |
apply (rule IT.Beta) |
9622 | 437 |
apply (simp (no_asm) del: subst_map add: subst_subst subst_map [symmetric]) |
438 |
apply (drule subject_reduction) |
|
439 |
apply (rule apps_preserves_beta) |
|
440 |
apply (rule beta.beta) |
|
441 |
apply fast |
|
442 |
apply (drule list_app_typeD) |
|
443 |
apply fast |
|
444 |
done |
|
445 |
||
446 |
||
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
447 |
subsection {* Main theorem: well-typed terms are strongly normalizing *} |
9622 | 448 |
|
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
449 |
lemma type_implies_IT: "e |- t : T ==> t \<in> IT" |
9622 | 450 |
apply (erule typing.induct) |
451 |
apply (rule Var_IT) |
|
9716 | 452 |
apply (erule IT.Lambda) |
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
453 |
apply (subgoal_tac "(Var 0 $ lift t 0)[s/0] \<in> IT") |
9622 | 454 |
apply simp |
455 |
apply (rule subst_type_IT) |
|
9771 | 456 |
apply (rule lists.Nil |
10155 | 457 |
[THEN [2] lists.Cons [THEN IT.Var], unfolded foldl_Nil [THEN eq_reflection] |
9771 | 458 |
foldl_Cons [THEN eq_reflection]]) |
9622 | 459 |
apply (erule lift_IT) |
460 |
apply (rule typing.App) |
|
461 |
apply (rule typing.Var) |
|
462 |
apply simp |
|
463 |
apply (erule lift_type') |
|
464 |
apply assumption |
|
465 |
apply assumption |
|
466 |
done |
|
467 |
||
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
468 |
theorem type_implies_termi: "e |- t : T ==> t \<in> termi beta" |
9622 | 469 |
apply (rule IT_implies_termi) |
470 |
apply (erule type_implies_IT) |
|
471 |
done |
|
472 |
||
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
473 |
end |