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