author | wenzelm |
Fri, 26 Oct 2001 16:18:14 +0200 | |
changeset 11946 | adef41692ab0 |
parent 11945 | 1b540afebf4d |
child 11947 | 013d52bb0000 |
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 |
||
11935 | 96 |
subsection {* @{text n}-ary function types *} |
9622 | 97 |
|
9941
fe05af7ec816
renamed atts: rulify to rule_format, elimify to elim_format;
wenzelm
parents:
9906
diff
changeset
|
98 |
lemma list_app_typeD [rule_format]: |
11945 | 99 |
"\<forall>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)" |
9622 | 100 |
apply (induct_tac ts) |
101 |
apply simp |
|
102 |
apply (intro strip) |
|
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 |
||
9941
fe05af7ec816
renamed atts: rulify to rule_format, elimify to elim_format;
wenzelm
parents:
9906
diff
changeset
|
118 |
lemma list_app_typeI [rule_format]: |
11945 | 119 |
"\<forall>t T Ts. e \<turnstile> t : Ts \<Rrightarrow> T \<longrightarrow> e \<tturnstile> ts : Ts \<longrightarrow> e \<turnstile> t \<^sub>\<degree>\<^sub>\<degree> ts : T" |
9622 | 120 |
apply (induct_tac ts) |
121 |
apply (intro strip) |
|
122 |
apply simp |
|
123 |
apply (intro strip) |
|
124 |
apply (case_tac Ts) |
|
125 |
apply simp |
|
126 |
apply simp |
|
11943 | 127 |
apply (erule_tac x = "t \<^sub>\<degree> a" in allE) |
9622 | 128 |
apply (erule_tac x = T in allE) |
129 |
apply (erule_tac x = lista in allE) |
|
130 |
apply (erule impE) |
|
131 |
apply (erule conjE) |
|
132 |
apply (erule typing.App) |
|
133 |
apply assumption |
|
134 |
apply blast |
|
135 |
done |
|
136 |
||
11943 | 137 |
lemma lists_typings [rule_format]: |
138 |
"\<forall>Ts. e \<tturnstile> ts : Ts \<longrightarrow> ts \<in> lists {t. \<exists>T. e \<turnstile> t : T}" |
|
9622 | 139 |
apply (induct_tac ts) |
140 |
apply (intro strip) |
|
141 |
apply (case_tac Ts) |
|
142 |
apply simp |
|
143 |
apply (rule lists.Nil) |
|
144 |
apply simp |
|
145 |
apply (intro strip) |
|
146 |
apply (case_tac Ts) |
|
147 |
apply simp |
|
148 |
apply simp |
|
149 |
apply (rule lists.Cons) |
|
150 |
apply blast |
|
151 |
apply blast |
|
152 |
done |
|
153 |
||
154 |
||
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
155 |
subsection {* Lifting preserves termination and well-typedness *} |
9622 | 156 |
|
11935 | 157 |
lemma lift_map [simp]: |
11943 | 158 |
"\<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 | 159 |
by (induct ts) simp_all |
9622 | 160 |
|
11935 | 161 |
lemma subst_map [simp]: |
11943 | 162 |
"\<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 | 163 |
by (induct ts) simp_all |
9622 | 164 |
|
9941
fe05af7ec816
renamed atts: rulify to rule_format, elimify to elim_format;
wenzelm
parents:
9906
diff
changeset
|
165 |
lemma lift_IT [rule_format, intro!]: |
11943 | 166 |
"t \<in> IT \<Longrightarrow> \<forall>i. lift t i \<in> IT" |
9622 | 167 |
apply (erule IT.induct) |
168 |
apply (rule allI) |
|
169 |
apply (simp (no_asm)) |
|
170 |
apply (rule conjI) |
|
171 |
apply |
|
172 |
(rule impI, |
|
9716 | 173 |
rule IT.Var, |
9622 | 174 |
erule lists.induct, |
175 |
simp (no_asm), |
|
176 |
rule lists.Nil, |
|
177 |
simp (no_asm), |
|
178 |
erule IntE, |
|
179 |
rule lists.Cons, |
|
180 |
blast, |
|
181 |
assumption)+ |
|
182 |
apply auto |
|
183 |
done |
|
184 |
||
11935 | 185 |
lemma lifts_IT: |
186 |
"ts \<in> lists IT \<Longrightarrow> map (\<lambda>t. lift t 0) ts \<in> lists IT" |
|
187 |
by (induct ts) auto |
|
9622 | 188 |
|
11946 | 189 |
lemma lift_type [intro!]: "e \<turnstile> t : T \<Longrightarrow> e\<langle>i:U\<rangle> \<turnstile> lift t i : T" |
11935 | 190 |
proof - |
11943 | 191 |
assume "e \<turnstile> t : T" |
192 |
thus "\<And>i U. e\<langle>i:U\<rangle> \<turnstile> lift t i : T" |
|
11946 | 193 |
by induct auto |
11935 | 194 |
qed |
9622 | 195 |
|
11943 | 196 |
lemma lift_typings [rule_format]: |
197 |
"\<forall>Ts. e \<tturnstile> ts : Ts \<longrightarrow> (e\<langle>i:U\<rangle>) \<tturnstile> (map (\<lambda>t. lift t i) ts) : Ts" |
|
9622 | 198 |
apply (induct_tac ts) |
199 |
apply simp |
|
200 |
apply (intro strip) |
|
201 |
apply (case_tac Ts) |
|
11946 | 202 |
apply auto |
9622 | 203 |
done |
204 |
||
205 |
||
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
206 |
subsection {* Substitution lemmas *} |
9622 | 207 |
|
9941
fe05af7ec816
renamed atts: rulify to rule_format, elimify to elim_format;
wenzelm
parents:
9906
diff
changeset
|
208 |
lemma subst_lemma [rule_format]: |
11943 | 209 |
"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 | 210 |
apply (erule typing.induct) |
211 |
apply (intro strip) |
|
11946 | 212 |
apply (rule_tac x = x and y = i in linorder_cases) |
213 |
apply auto |
|
214 |
apply blast |
|
9622 | 215 |
done |
216 |
||
9941
fe05af7ec816
renamed atts: rulify to rule_format, elimify to elim_format;
wenzelm
parents:
9906
diff
changeset
|
217 |
lemma substs_lemma [rule_format]: |
11943 | 218 |
"e \<turnstile> u : T \<Longrightarrow> \<forall>Ts. (e\<langle>i:T\<rangle>) \<tturnstile> ts : Ts \<longrightarrow> |
219 |
e \<tturnstile> (map (\<lambda>t. t[u/i]) ts) : Ts" |
|
9622 | 220 |
apply (induct_tac ts) |
221 |
apply (intro strip) |
|
222 |
apply (case_tac Ts) |
|
223 |
apply simp |
|
224 |
apply simp |
|
225 |
apply (intro strip) |
|
226 |
apply (case_tac Ts) |
|
227 |
apply simp |
|
228 |
apply simp |
|
229 |
apply (erule conjE) |
|
230 |
apply (erule subst_lemma) |
|
11935 | 231 |
apply assumption |
232 |
apply (rule refl) |
|
9622 | 233 |
done |
234 |
||
235 |
||
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
236 |
subsection {* Subject reduction *} |
9622 | 237 |
|
9941
fe05af7ec816
renamed atts: rulify to rule_format, elimify to elim_format;
wenzelm
parents:
9906
diff
changeset
|
238 |
lemma subject_reduction [rule_format]: |
11943 | 239 |
"e \<turnstile> t : T \<Longrightarrow> \<forall>t'. t -> t' \<longrightarrow> e \<turnstile> t' : T" |
9622 | 240 |
apply (erule typing.induct) |
241 |
apply blast |
|
242 |
apply blast |
|
243 |
apply (intro strip) |
|
11943 | 244 |
apply (ind_cases "s \<^sub>\<degree> t -> t'") |
9622 | 245 |
apply hypsubst |
11945 | 246 |
apply (ind_cases "env \<turnstile> Abs t : T \<Rightarrow> U") |
9622 | 247 |
apply (rule subst_lemma) |
248 |
apply assumption |
|
249 |
apply assumption |
|
250 |
apply (rule ext) |
|
11935 | 251 |
apply (case_tac x) |
11946 | 252 |
apply auto |
9622 | 253 |
done |
254 |
||
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
255 |
|
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
256 |
subsection {* Additional lemmas *} |
9622 | 257 |
|
11943 | 258 |
lemma app_last: "(t \<^sub>\<degree>\<^sub>\<degree> ts) \<^sub>\<degree> u = t \<^sub>\<degree>\<^sub>\<degree> (ts @ [u])" |
11935 | 259 |
by simp |
9622 | 260 |
|
11943 | 261 |
lemma subst_Var_IT [rule_format]: "r \<in> IT \<Longrightarrow> \<forall>i j. r[Var i/j] \<in> IT" |
9622 | 262 |
apply (erule IT.induct) |
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
263 |
txt {* Case @{term Var}: *} |
9622 | 264 |
apply (intro strip) |
265 |
apply (simp (no_asm) add: subst_Var) |
|
266 |
apply |
|
267 |
((rule conjI impI)+, |
|
9716 | 268 |
rule IT.Var, |
9622 | 269 |
erule lists.induct, |
270 |
simp (no_asm), |
|
271 |
rule lists.Nil, |
|
272 |
simp (no_asm), |
|
273 |
erule IntE, |
|
274 |
erule CollectE, |
|
275 |
rule lists.Cons, |
|
276 |
fast, |
|
277 |
assumption)+ |
|
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
278 |
txt {* Case @{term Lambda}: *} |
9622 | 279 |
apply (intro strip) |
280 |
apply simp |
|
9716 | 281 |
apply (rule IT.Lambda) |
9622 | 282 |
apply fast |
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
283 |
txt {* Case @{term Beta}: *} |
9622 | 284 |
apply (intro strip) |
285 |
apply (simp (no_asm_use) add: subst_subst [symmetric]) |
|
9716 | 286 |
apply (rule IT.Beta) |
9622 | 287 |
apply auto |
288 |
done |
|
289 |
||
290 |
lemma Var_IT: "Var n \<in> IT" |
|
11943 | 291 |
apply (subgoal_tac "Var n \<^sub>\<degree>\<^sub>\<degree> [] \<in> IT") |
9622 | 292 |
apply simp |
9716 | 293 |
apply (rule IT.Var) |
9622 | 294 |
apply (rule lists.Nil) |
295 |
done |
|
296 |
||
11943 | 297 |
lemma app_Var_IT: "t \<in> IT \<Longrightarrow> t \<^sub>\<degree> Var i \<in> IT" |
9622 | 298 |
apply (erule IT.induct) |
299 |
apply (subst app_last) |
|
9716 | 300 |
apply (rule IT.Var) |
9622 | 301 |
apply simp |
302 |
apply (rule lists.Cons) |
|
303 |
apply (rule Var_IT) |
|
304 |
apply (rule lists.Nil) |
|
9906 | 305 |
apply (rule IT.Beta [where ?ss = "[]", unfolded foldl_Nil [THEN eq_reflection]]) |
9622 | 306 |
apply (erule subst_Var_IT) |
307 |
apply (rule Var_IT) |
|
308 |
apply (subst app_last) |
|
9716 | 309 |
apply (rule IT.Beta) |
9622 | 310 |
apply (subst app_last [symmetric]) |
311 |
apply assumption |
|
312 |
apply assumption |
|
313 |
done |
|
314 |
||
11935 | 315 |
lemma type_induct [induct type]: |
11945 | 316 |
"(\<And>T. (\<And>T1 T2. T = T1 \<Rightarrow> T2 \<Longrightarrow> P T1) \<Longrightarrow> |
317 |
(\<And>T1 T2. T = T1 \<Rightarrow> T2 \<Longrightarrow> P T2) \<Longrightarrow> P T) \<Longrightarrow> P T" |
|
11935 | 318 |
proof - |
319 |
case rule_context |
|
320 |
show ?thesis |
|
321 |
proof (induct T) |
|
322 |
case Atom |
|
323 |
show ?case by (rule rule_context) simp_all |
|
324 |
next |
|
325 |
case Fun |
|
326 |
show ?case by (rule rule_context) (insert Fun, simp_all) |
|
327 |
qed |
|
328 |
qed |
|
329 |
||
9622 | 330 |
|
9811
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
wenzelm
parents:
9771
diff
changeset
|
331 |
subsection {* Well-typed substitution preserves termination *} |
9622 | 332 |
|
11935 | 333 |
lemma subst_type_IT: |
11943 | 334 |
"\<And>t e T u i. t \<in> IT \<Longrightarrow> e\<langle>i:U\<rangle> \<turnstile> t : T \<Longrightarrow> |
335 |
u \<in> IT \<Longrightarrow> e \<turnstile> u : U \<Longrightarrow> t[u/i] \<in> IT" |
|
11935 | 336 |
(is "PROP ?P U" is "\<And>t e T u i. _ \<Longrightarrow> PROP ?Q t e T u i U") |
337 |
proof (induct U) |
|
338 |
fix T t |
|
11945 | 339 |
assume MI1: "\<And>T1 T2. T = T1 \<Rightarrow> T2 \<Longrightarrow> PROP ?P T1" |
340 |
assume MI2: "\<And>T1 T2. T = T1 \<Rightarrow> T2 \<Longrightarrow> PROP ?P T2" |
|
11935 | 341 |
assume "t \<in> IT" |
342 |
thus "\<And>e T' u i. PROP ?Q t e T' u i T" |
|
343 |
proof induct |
|
344 |
fix e T' u i |
|
11943 | 345 |
assume uIT: "u \<in> IT" |
346 |
assume uT: "e \<turnstile> u : T" |
|
11935 | 347 |
{ |
348 |
case (Var n rs) |
|
11943 | 349 |
assume nT: "e\<langle>i:T\<rangle> \<turnstile> Var n \<^sub>\<degree>\<^sub>\<degree> rs : T'" |
350 |
let ?ty = "{t. \<exists>T'. e\<langle>i:T\<rangle> \<turnstile> t : T'}" |
|
11935 | 351 |
let ?R = "\<lambda>t. \<forall>e T' u i. |
11943 | 352 |
e\<langle>i:T\<rangle> \<turnstile> t : T' \<longrightarrow> u \<in> IT \<longrightarrow> e \<turnstile> u : T \<longrightarrow> t[u/i] \<in> IT" |
353 |
show "(Var n \<^sub>\<degree>\<^sub>\<degree> rs)[u/i] \<in> IT" |
|
11935 | 354 |
proof (cases "n = i") |
11943 | 355 |
case True |
356 |
show ?thesis |
|
357 |
proof (cases rs) |
|
358 |
case Nil |
|
359 |
with uIT True show ?thesis by simp |
|
360 |
next |
|
361 |
case (Cons a as) |
|
362 |
with nT have "e\<langle>i:T\<rangle> \<turnstile> Var n \<^sub>\<degree> a \<^sub>\<degree>\<^sub>\<degree> as : T'" by simp |
|
363 |
then obtain Ts |
|
11945 | 364 |
where headT: "e\<langle>i:T\<rangle> \<turnstile> Var n \<^sub>\<degree> a : Ts \<Rrightarrow> T'" |
11943 | 365 |
and argsT: "(e\<langle>i:T\<rangle>) \<tturnstile> as : Ts" |
366 |
by (rule list_app_typeE) |
|
367 |
from headT obtain T'' |
|
11945 | 368 |
where varT: "e\<langle>i:T\<rangle> \<turnstile> Var n : T'' \<Rightarrow> Ts \<Rrightarrow> T'" |
11943 | 369 |
and argT: "e\<langle>i:T\<rangle> \<turnstile> a : T''" |
370 |
by cases simp_all |
|
11945 | 371 |
from varT True have T: "T = T'' \<Rightarrow> Ts \<Rrightarrow> T'" |
11946 | 372 |
by cases auto |
11945 | 373 |
with uT have uT': "e \<turnstile> u : T'' \<Rightarrow> Ts \<Rrightarrow> T'" by simp |
11943 | 374 |
from Var have SI: "?R a" by cases (simp_all add: Cons) |
375 |
from T have "(Var 0 \<^sub>\<degree>\<^sub>\<degree> map (\<lambda>t. lift t 0) |
|
376 |
(map (\<lambda>t. t[u/i]) as))[(u \<^sub>\<degree> a[u/i])/0] \<in> IT" |
|
377 |
proof (rule MI2) |
|
378 |
from T have "(lift u 0 \<^sub>\<degree> Var 0)[a[u/i]/0] \<in> IT" |
|
379 |
proof (rule MI1) |
|
380 |
have "lift u 0 \<in> IT" by (rule lift_IT) |
|
381 |
thus "lift u 0 \<^sub>\<degree> Var 0 \<in> IT" by (rule app_Var_IT) |
|
11945 | 382 |
show "e\<langle>0:T''\<rangle> \<turnstile> lift u 0 \<^sub>\<degree> Var 0 : Ts \<Rrightarrow> T'" |
11943 | 383 |
proof (rule typing.App) |
11945 | 384 |
show "e\<langle>0:T''\<rangle> \<turnstile> lift u 0 : T'' \<Rightarrow> Ts \<Rrightarrow> T'" |
11946 | 385 |
by (rule lift_type) (rule uT') |
11943 | 386 |
show "e\<langle>0:T''\<rangle> \<turnstile> Var 0 : T''" |
11946 | 387 |
by (rule typing.Var) simp |
11943 | 388 |
qed |
389 |
from argT uIT uT show "a[u/i] \<in> IT" |
|
390 |
by (rule SI[rule_format]) |
|
391 |
from argT uT show "e \<turnstile> a[u/i] : T''" |
|
11946 | 392 |
by (rule subst_lemma) simp |
11943 | 393 |
qed |
394 |
thus "u \<^sub>\<degree> a[u/i] \<in> IT" by simp |
|
395 |
from Var have "as \<in> lists {t. ?R t}" |
|
396 |
by cases (simp_all add: Cons) |
|
397 |
moreover from argsT have "as \<in> lists ?ty" |
|
398 |
by (rule lists_typings) |
|
399 |
ultimately have "as \<in> lists ({t. ?R t} \<inter> ?ty)" |
|
400 |
by (rule lists_IntI) |
|
401 |
hence "map (\<lambda>t. lift t 0) (map (\<lambda>t. t[u/i]) as) \<in> lists IT" |
|
402 |
(is "(?ls as) \<in> _") |
|
403 |
proof induct |
|
404 |
case Nil |
|
405 |
show ?case by fastsimp |
|
406 |
next |
|
407 |
case (Cons b bs) |
|
408 |
hence I: "?R b" by simp |
|
409 |
from Cons obtain U where "e\<langle>i:T\<rangle> \<turnstile> b : U" by fast |
|
410 |
with uT uIT I have "b[u/i] \<in> IT" by simp |
|
411 |
hence "lift (b[u/i]) 0 \<in> IT" by (rule lift_IT) |
|
412 |
hence "lift (b[u/i]) 0 # ?ls bs \<in> lists IT" |
|
413 |
by (rule lists.Cons) (rule Cons) |
|
414 |
thus ?case by simp |
|
415 |
qed |
|
416 |
thus "Var 0 \<^sub>\<degree>\<^sub>\<degree> ?ls as \<in> IT" by (rule IT.Var) |
|
11945 | 417 |
have "e\<langle>0:Ts \<Rrightarrow> T'\<rangle> \<turnstile> Var 0 : Ts \<Rrightarrow> T'" |
11946 | 418 |
by (rule typing.Var) simp |
11943 | 419 |
moreover from uT argsT have "e \<tturnstile> map (\<lambda>t. t[u/i]) as : Ts" |
420 |
by (rule substs_lemma) |
|
11945 | 421 |
hence "(e\<langle>0:Ts \<Rrightarrow> T'\<rangle>) \<tturnstile> ?ls as : Ts" |
11943 | 422 |
by (rule lift_typings) |
11945 | 423 |
ultimately show "e\<langle>0:Ts \<Rrightarrow> T'\<rangle> \<turnstile> Var 0 \<^sub>\<degree>\<^sub>\<degree> ?ls as : T'" |
11943 | 424 |
by (rule list_app_typeI) |
425 |
from argT uT have "e \<turnstile> a[u/i] : T''" |
|
426 |
by (rule subst_lemma) (rule refl) |
|
11945 | 427 |
with uT' show "e \<turnstile> u \<^sub>\<degree> a[u/i] : Ts \<Rrightarrow> T'" |
11943 | 428 |
by (rule typing.App) |
429 |
qed |
|
430 |
with Cons True show ?thesis |
|
431 |
by (simp add: map_compose [symmetric] o_def) |
|
432 |
qed |
|
11935 | 433 |
next |
11943 | 434 |
case False |
435 |
from Var have "rs \<in> lists {t. ?R t}" by simp |
|
436 |
moreover from nT obtain Ts where "(e\<langle>i:T\<rangle>) \<tturnstile> rs : Ts" |
|
437 |
by (rule list_app_typeE) |
|
438 |
hence "rs \<in> lists ?ty" by (rule lists_typings) |
|
439 |
ultimately have "rs \<in> lists ({t. ?R t} \<inter> ?ty)" |
|
440 |
by (rule lists_IntI) |
|
441 |
hence "map (\<lambda>x. x[u/i]) rs \<in> lists IT" |
|
442 |
proof induct |
|
443 |
case Nil |
|
444 |
show ?case by fastsimp |
|
445 |
next |
|
446 |
case (Cons a as) |
|
447 |
hence I: "?R a" by simp |
|
448 |
from Cons obtain U where "e\<langle>i:T\<rangle> \<turnstile> a : U" by fast |
|
449 |
with uT uIT I have "a[u/i] \<in> IT" by simp |
|
450 |
hence "(a[u/i] # map (\<lambda>t. t[u/i]) as) \<in> lists IT" |
|
451 |
by (rule lists.Cons) (rule Cons) |
|
452 |
thus ?case by simp |
|
453 |
qed |
|
454 |
with False show ?thesis by (auto simp add: subst_Var) |
|
11935 | 455 |
qed |
456 |
next |
|
457 |
case (Lambda r) |
|
11943 | 458 |
assume "e\<langle>i:T\<rangle> \<turnstile> Abs r : T'" |
459 |
and "\<And>e T' u i. PROP ?Q r e T' u i T" |
|
11935 | 460 |
with uIT uT show "Abs r[u/i] \<in> IT" |
11946 | 461 |
by fastsimp |
11935 | 462 |
next |
463 |
case (Beta r a as) |
|
11943 | 464 |
assume T: "e\<langle>i:T\<rangle> \<turnstile> Abs r \<^sub>\<degree> a \<^sub>\<degree>\<^sub>\<degree> as : T'" |
465 |
assume SI1: "\<And>e T' u i. PROP ?Q (r[a/0] \<^sub>\<degree>\<^sub>\<degree> as) e T' u i T" |
|
11935 | 466 |
assume SI2: "\<And>e T' u i. PROP ?Q a e T' u i T" |
11943 | 467 |
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 | 468 |
proof (rule IT.Beta) |
11943 | 469 |
have "Abs r \<^sub>\<degree> a \<^sub>\<degree>\<^sub>\<degree> as -> r[a/0] \<^sub>\<degree>\<^sub>\<degree> as" |
470 |
by (rule apps_preserves_beta) (rule beta.beta) |
|
471 |
with T have "e\<langle>i:T\<rangle> \<turnstile> r[a/0] \<^sub>\<degree>\<^sub>\<degree> as : T'" |
|
472 |
by (rule subject_reduction) |
|
473 |
hence "(r[a/0] \<^sub>\<degree>\<^sub>\<degree> as)[u/i] \<in> IT" |
|
474 |
by (rule SI1) |
|
475 |
thus "r[lift u 0/Suc i][a[u/i]/0] \<^sub>\<degree>\<^sub>\<degree> map (\<lambda>t. t[u/i]) as \<in> IT" |
|
476 |
by (simp del: subst_map add: subst_subst subst_map [symmetric]) |
|
477 |
from T obtain U where "e\<langle>i:T\<rangle> \<turnstile> Abs r \<^sub>\<degree> a : U" |
|
478 |
by (rule list_app_typeE) fast |
|
479 |
then obtain T'' where "e\<langle>i:T\<rangle> \<turnstile> a : T''" by cases simp_all |
|
480 |
thus "a[u/i] \<in> IT" by (rule SI2) |
|
11935 | 481 |
qed |
11943 | 482 |
thus "(Abs r \<^sub>\<degree> a \<^sub>\<degree>\<^sub>\<degree> as)[u/i] \<in> IT" by simp |
11935 | 483 |
} |
484 |
qed |
|
485 |
qed |
|
9622 | 486 |
|
11935 | 487 |
subsection {* Well-typed terms are strongly normalizing *} |
9622 | 488 |
|
11943 | 489 |
lemma type_implies_IT: "e \<turnstile> t : T \<Longrightarrow> t \<in> IT" |
11935 | 490 |
proof - |
11943 | 491 |
assume "e \<turnstile> t : T" |
11935 | 492 |
thus ?thesis |
493 |
proof induct |
|
494 |
case Var |
|
495 |
show ?case by (rule Var_IT) |
|
496 |
next |
|
497 |
case Abs |
|
498 |
show ?case by (rule IT.Lambda) |
|
499 |
next |
|
500 |
case (App T U e s t) |
|
11943 | 501 |
have "(Var 0 \<^sub>\<degree> lift t 0)[s/0] \<in> IT" |
11935 | 502 |
proof (rule subst_type_IT) |
11943 | 503 |
have "lift t 0 \<in> IT" by (rule lift_IT) |
504 |
hence "[lift t 0] \<in> lists IT" by (rule lists.Cons) (rule lists.Nil) |
|
505 |
hence "Var 0 \<^sub>\<degree>\<^sub>\<degree> [lift t 0] \<in> IT" by (rule IT.Var) |
|
11946 | 506 |
also have "Var 0 \<^sub>\<degree>\<^sub>\<degree> [lift t 0] = Var 0 \<^sub>\<degree> lift t 0" by simp |
11943 | 507 |
finally show "\<dots> \<in> IT" . |
11945 | 508 |
have "e\<langle>0:T \<Rightarrow> U\<rangle> \<turnstile> Var 0 : T \<Rightarrow> U" |
11946 | 509 |
by (rule typing.Var) simp |
11945 | 510 |
moreover have "e\<langle>0:T \<Rightarrow> U\<rangle> \<turnstile> lift t 0 : T" |
11946 | 511 |
by (rule lift_type) |
11945 | 512 |
ultimately show "e\<langle>0:T \<Rightarrow> U\<rangle> \<turnstile> Var 0 \<^sub>\<degree> lift t 0 : U" |
11943 | 513 |
by (rule typing.App) |
11935 | 514 |
qed |
515 |
thus ?case by simp |
|
516 |
qed |
|
517 |
qed |
|
9622 | 518 |
|
11943 | 519 |
theorem type_implies_termi: "e \<turnstile> t : T \<Longrightarrow> t \<in> termi beta" |
11935 | 520 |
proof - |
11943 | 521 |
assume "e \<turnstile> t : T" |
11935 | 522 |
hence "t \<in> IT" by (rule type_implies_IT) |
523 |
thus ?thesis by (rule IT_implies_termi) |
|
524 |
qed |
|
9622 | 525 |
|
11638 | 526 |
end |