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