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