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