| author | wenzelm | 
| Thu, 20 Sep 2007 20:56:33 +0200 | |
| changeset 24665 | e5bea50b9b89 | 
| parent 23750 | a1db5f819d00 | 
| child 25974 | 0cb35fa9c6fa | 
| 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: 
9771diff
changeset | 5 | *) | 
| 9114 
de99e37effda
Subject reduction and strong normalization of simply-typed lambda terms.
 berghofe parents: diff
changeset | 6 | |
| 14064 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 7 | header {* Simply-typed lambda terms *}
 | 
| 9114 
de99e37effda
Subject reduction and strong normalization of simply-typed lambda terms.
 berghofe parents: diff
changeset | 8 | |
| 16417 | 9 | theory Type imports ListApplication begin | 
| 9811 
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
 wenzelm parents: 
9771diff
changeset | 10 | |
| 
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
 wenzelm parents: 
9771diff
changeset | 11 | |
| 11946 | 12 | subsection {* Environments *}
 | 
| 13 | ||
| 19086 | 14 | definition | 
| 21404 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 wenzelm parents: 
21210diff
changeset | 15 |   shift :: "(nat \<Rightarrow> 'a) \<Rightarrow> nat \<Rightarrow> 'a \<Rightarrow> nat \<Rightarrow> 'a"  ("_<_:_>" [90, 0, 0] 91) where
 | 
| 19086 | 16 | "e<i:a> = (\<lambda>j. if j < i then e j else if j = i then a else e (j - 1))" | 
| 19363 | 17 | |
| 21210 | 18 | notation (xsymbols) | 
| 19656 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 wenzelm parents: 
19380diff
changeset | 19 |   shift  ("_\<langle>_:_\<rangle>" [90, 0, 0] 91)
 | 
| 19363 | 20 | |
| 21210 | 21 | notation (HTML output) | 
| 19656 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 wenzelm parents: 
19380diff
changeset | 22 |   shift  ("_\<langle>_:_\<rangle>" [90, 0, 0] 91)
 | 
| 11946 | 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: 
9771diff
changeset | 42 | subsection {* Types and typing rules *}
 | 
| 
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
 wenzelm parents: 
9771diff
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 | |
| 23750 | 48 | inductive typing :: "(nat \<Rightarrow> type) \<Rightarrow> dB \<Rightarrow> type \<Rightarrow> bool"  ("_ \<turnstile> _ : _" [50, 50, 50] 50)
 | 
| 22271 | 49 | where | 
| 50 | Var [intro!]: "env x = T \<Longrightarrow> env \<turnstile> Var x : T" | |
| 51 | | Abs [intro!]: "env\<langle>0:T\<rangle> \<turnstile> t : U \<Longrightarrow> env \<turnstile> Abs t : (T \<Rightarrow> U)" | |
| 52 | | App [intro!]: "env \<turnstile> s : T \<Rightarrow> U \<Longrightarrow> env \<turnstile> t : T \<Longrightarrow> env \<turnstile> (s \<degree> t) : U" | |
| 53 | ||
| 23750 | 54 | inductive_cases typing_elims [elim!]: | 
| 22271 | 55 | "e \<turnstile> Var i : T" | 
| 56 | "e \<turnstile> t \<degree> u : T" | |
| 57 | "e \<turnstile> Abs t : T" | |
| 58 | ||
| 9114 
de99e37effda
Subject reduction and strong normalization of simply-typed lambda terms.
 berghofe parents: diff
changeset | 59 | consts | 
| 11943 | 60 | 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 | 61 | |
| 19363 | 62 | abbreviation | 
| 21404 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 wenzelm parents: 
21210diff
changeset | 63 | funs :: "type list \<Rightarrow> type \<Rightarrow> type" (infixr "=>>" 200) where | 
| 19363 | 64 | "Ts =>> T == foldr Fun Ts T" | 
| 19086 | 65 | |
| 21404 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 wenzelm parents: 
21210diff
changeset | 66 | abbreviation | 
| 19086 | 67 | typings_rel :: "(nat \<Rightarrow> type) \<Rightarrow> dB list \<Rightarrow> type list \<Rightarrow> bool" | 
| 21404 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 wenzelm parents: 
21210diff
changeset | 68 |     ("_ ||- _ : _" [50, 50, 50] 50) where
 | 
| 19363 | 69 | "env ||- ts : Ts == typings env ts Ts" | 
| 19086 | 70 | |
| 21210 | 71 | notation (latex) | 
| 21404 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 wenzelm parents: 
21210diff
changeset | 72 | funs (infixr "\<Rrightarrow>" 200) and | 
| 19656 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 wenzelm parents: 
19380diff
changeset | 73 |   typings_rel  ("_ \<tturnstile> _ : _" [50, 50, 50] 50)
 | 
| 9114 
de99e37effda
Subject reduction and strong normalization of simply-typed lambda terms.
 berghofe parents: diff
changeset | 74 | |
| 11943 | 75 | primrec | 
| 76 | "(e \<tturnstile> [] : Ts) = (Ts = [])" | |
| 77 | "(e \<tturnstile> (t # ts) : Ts) = | |
| 78 | (case Ts of | |
| 79 | [] \<Rightarrow> False | |
| 80 | | 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 | 81 | |
| 9622 | 82 | |
| 9811 
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
 wenzelm parents: 
9771diff
changeset | 83 | subsection {* Some examples *}
 | 
| 9622 | 84 | |
| 12011 | 85 | lemma "e \<turnstile> Abs (Abs (Abs (Var 1 \<degree> (Var 2 \<degree> Var 1 \<degree> Var 0)))) : ?T" | 
| 11935 | 86 | by force | 
| 9622 | 87 | |
| 12011 | 88 | lemma "e \<turnstile> Abs (Abs (Abs (Var 2 \<degree> Var 0 \<degree> (Var 1 \<degree> Var 0)))) : ?T" | 
| 11935 | 89 | by force | 
| 9622 | 90 | |
| 91 | ||
| 14064 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 92 | subsection {* Lists of types *}
 | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 93 | |
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 94 | lemma lists_typings: | 
| 22271 | 95 | "e \<tturnstile> ts : Ts \<Longrightarrow> listsp (\<lambda>t. \<exists>T. e \<turnstile> t : T) ts" | 
| 20503 | 96 | apply (induct ts arbitrary: Ts) | 
| 14064 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 97 | apply (case_tac Ts) | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 98 | apply simp | 
| 22271 | 99 | apply (rule listsp.Nil) | 
| 14064 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 100 | apply simp | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 101 | apply (case_tac Ts) | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 102 | apply simp | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 103 | apply simp | 
| 22271 | 104 | apply (rule listsp.Cons) | 
| 14064 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 105 | apply blast | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 106 | apply blast | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 107 | done | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 108 | |
| 18241 | 109 | lemma types_snoc: "e \<tturnstile> ts : Ts \<Longrightarrow> e \<turnstile> t : T \<Longrightarrow> e \<tturnstile> ts @ [t] : Ts @ [T]" | 
| 20503 | 110 | apply (induct ts arbitrary: Ts) | 
| 14064 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 111 | apply simp | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 112 | apply (case_tac Ts) | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 113 | apply simp+ | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 114 | done | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 115 | |
| 18241 | 116 | lemma types_snoc_eq: "e \<tturnstile> ts @ [t] : Ts @ [T] = | 
| 14064 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 117 | (e \<tturnstile> ts : Ts \<and> e \<turnstile> t : T)" | 
| 20503 | 118 | apply (induct ts arbitrary: Ts) | 
| 14064 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 119 | apply (case_tac Ts) | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 120 | apply simp+ | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 121 | apply (case_tac Ts) | 
| 15236 
f289e8ba2bb3
Proofs needed to be updated because induction now preserves name of
 nipkow parents: 
14565diff
changeset | 122 | apply (case_tac "ts @ [t]") | 
| 14064 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 123 | apply simp+ | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 124 | done | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 125 | |
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 126 | lemma rev_exhaust2 [case_names Nil snoc, extraction_expand]: | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 127 | "(xs = [] \<Longrightarrow> P) \<Longrightarrow> (\<And>ys y. xs = ys @ [y] \<Longrightarrow> P) \<Longrightarrow> P" | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 128 |   -- {* Cannot use @{text rev_exhaust} from the @{text List}
 | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 129 | theory, since it is not constructive *} | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 130 | apply (subgoal_tac "\<forall>ys. xs = rev ys \<longrightarrow> P") | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 131 | apply (erule_tac x="rev xs" in allE) | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 132 | apply simp | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 133 | apply (rule allI) | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 134 | apply (rule impI) | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 135 | apply (case_tac ys) | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 136 | apply simp | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 137 | apply simp | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 138 | apply atomize | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 139 | apply (erule allE)+ | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 140 | apply (erule mp, rule conjI) | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 141 | apply (rule refl)+ | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 142 | done | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 143 | |
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 144 | lemma types_snocE: "e \<tturnstile> ts @ [t] : Ts \<Longrightarrow> | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 145 | (\<And>Us U. Ts = Us @ [U] \<Longrightarrow> e \<tturnstile> ts : Us \<Longrightarrow> e \<turnstile> t : U \<Longrightarrow> P) \<Longrightarrow> P" | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 146 | apply (cases Ts rule: rev_exhaust2) | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 147 | apply simp | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 148 | apply (case_tac "ts @ [t]") | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 149 | apply (simp add: types_snoc_eq)+ | 
| 17589 | 150 | apply iprover | 
| 14064 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 151 | done | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 152 | |
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 153 | |
| 11950 | 154 | subsection {* n-ary function types *}
 | 
| 9622 | 155 | |
| 11987 | 156 | lemma list_app_typeD: | 
| 18241 | 157 | "e \<turnstile> t \<degree>\<degree> ts : T \<Longrightarrow> \<exists>Ts. e \<turnstile> t : Ts \<Rrightarrow> T \<and> e \<tturnstile> ts : Ts" | 
| 20503 | 158 | apply (induct ts arbitrary: t T) | 
| 9622 | 159 | apply simp | 
| 11987 | 160 | apply atomize | 
| 9622 | 161 | apply simp | 
| 12011 | 162 | apply (erule_tac x = "t \<degree> a" in allE) | 
| 9622 | 163 | apply (erule_tac x = T in allE) | 
| 164 | apply (erule impE) | |
| 165 | apply assumption | |
| 166 | apply (elim exE conjE) | |
| 23750 | 167 | apply (ind_cases "e \<turnstile> t \<degree> u : T" for t u T) | 
| 9622 | 168 | apply (rule_tac x = "Ta # Ts" in exI) | 
| 169 | apply simp | |
| 170 | done | |
| 171 | ||
| 11935 | 172 | lemma list_app_typeE: | 
| 12011 | 173 | "e \<turnstile> t \<degree>\<degree> ts : T \<Longrightarrow> (\<And>Ts. e \<turnstile> t : Ts \<Rrightarrow> T \<Longrightarrow> e \<tturnstile> ts : Ts \<Longrightarrow> C) \<Longrightarrow> C" | 
| 11935 | 174 | by (insert list_app_typeD) fast | 
| 175 | ||
| 11987 | 176 | lemma list_app_typeI: | 
| 18241 | 177 | "e \<turnstile> t : Ts \<Rrightarrow> T \<Longrightarrow> e \<tturnstile> ts : Ts \<Longrightarrow> e \<turnstile> t \<degree>\<degree> ts : T" | 
| 20503 | 178 | apply (induct ts arbitrary: t T Ts) | 
| 9622 | 179 | apply simp | 
| 11987 | 180 | apply atomize | 
| 9622 | 181 | apply (case_tac Ts) | 
| 182 | apply simp | |
| 183 | apply simp | |
| 12011 | 184 | apply (erule_tac x = "t \<degree> a" in allE) | 
| 9622 | 185 | apply (erule_tac x = T in allE) | 
| 15236 
f289e8ba2bb3
Proofs needed to be updated because induction now preserves name of
 nipkow parents: 
14565diff
changeset | 186 | apply (erule_tac x = list in allE) | 
| 9622 | 187 | apply (erule impE) | 
| 188 | apply (erule conjE) | |
| 189 | apply (erule typing.App) | |
| 190 | apply assumption | |
| 191 | apply blast | |
| 192 | done | |
| 193 | ||
| 14064 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 194 | text {*
 | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 195 | For the specific case where the head of the term is a variable, | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 196 | the following theorems allow to infer the types of the arguments | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 197 | without analyzing the typing derivation. This is crucial | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 198 | for program extraction. | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 199 | *} | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 200 | |
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 201 | theorem var_app_type_eq: | 
| 18241 | 202 | "e \<turnstile> Var i \<degree>\<degree> ts : T \<Longrightarrow> e \<turnstile> Var i \<degree>\<degree> ts : U \<Longrightarrow> T = U" | 
| 20503 | 203 | apply (induct ts arbitrary: T U rule: rev_induct) | 
| 14064 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 204 | apply simp | 
| 23750 | 205 | apply (ind_cases "e \<turnstile> Var i : T" for T) | 
| 206 | apply (ind_cases "e \<turnstile> Var i : T" for T) | |
| 14064 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 207 | apply simp | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 208 | apply simp | 
| 23750 | 209 | apply (ind_cases "e \<turnstile> t \<degree> u : T" for t u T) | 
| 210 | apply (ind_cases "e \<turnstile> t \<degree> u : T" for t u T) | |
| 14064 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 211 | apply atomize | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 212 | apply (erule_tac x="Ta \<Rightarrow> T" in allE) | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 213 | apply (erule_tac x="Tb \<Rightarrow> U" in allE) | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 214 | apply (erule impE) | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 215 | apply assumption | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 216 | apply (erule impE) | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 217 | apply assumption | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 218 | apply simp | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 219 | done | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 220 | |
| 18241 | 221 | lemma var_app_types: "e \<turnstile> Var i \<degree>\<degree> ts \<degree>\<degree> us : T \<Longrightarrow> e \<tturnstile> ts : Ts \<Longrightarrow> | 
| 14064 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 222 | e \<turnstile> Var i \<degree>\<degree> ts : U \<Longrightarrow> \<exists>Us. U = Us \<Rrightarrow> T \<and> e \<tturnstile> us : Us" | 
| 20503 | 223 | apply (induct us arbitrary: ts Ts U) | 
| 14064 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 224 | apply simp | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 225 | apply (erule var_app_type_eq) | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 226 | apply assumption | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 227 | apply simp | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 228 | apply atomize | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 229 | apply (case_tac U) | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 230 | apply (rule FalseE) | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 231 | apply simp | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 232 | apply (erule list_app_typeE) | 
| 23750 | 233 | apply (ind_cases "e \<turnstile> t \<degree> u : T" for t u T) | 
| 14064 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 234 | apply (drule_tac T="Atom nat" and U="Ta \<Rightarrow> Tsa \<Rrightarrow> T" in var_app_type_eq) | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 235 | apply assumption | 
| 9622 | 236 | apply simp | 
| 14064 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 237 | apply (erule_tac x="ts @ [a]" in allE) | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 238 | apply (erule_tac x="Ts @ [type1]" in allE) | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 239 | apply (erule_tac x="type2" in allE) | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 240 | apply simp | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 241 | apply (erule impE) | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 242 | apply (rule types_snoc) | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 243 | apply assumption | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 244 | apply (erule list_app_typeE) | 
| 23750 | 245 | apply (ind_cases "e \<turnstile> t \<degree> u : T" for t u T) | 
| 14064 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 246 | apply (drule_tac T="type1 \<Rightarrow> type2" and U="Ta \<Rightarrow> Tsa \<Rrightarrow> T" in var_app_type_eq) | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 247 | apply assumption | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 248 | apply simp | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 249 | apply (erule impE) | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 250 | apply (rule typing.App) | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 251 | apply assumption | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 252 | apply (erule list_app_typeE) | 
| 23750 | 253 | apply (ind_cases "e \<turnstile> t \<degree> u : T" for t u T) | 
| 14064 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 254 | apply (frule_tac T="type1 \<Rightarrow> type2" and U="Ta \<Rightarrow> Tsa \<Rrightarrow> T" in var_app_type_eq) | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 255 | apply assumption | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 256 | apply simp | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 257 | apply (erule exE) | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 258 | apply (rule_tac x="type1 # Us" in exI) | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 259 | apply simp | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 260 | apply (erule list_app_typeE) | 
| 23750 | 261 | apply (ind_cases "e \<turnstile> t \<degree> u : T" for t u T) | 
| 14064 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 262 | apply (frule_tac T="type1 \<Rightarrow> Us \<Rrightarrow> T" and U="Ta \<Rightarrow> Tsa \<Rrightarrow> T" in var_app_type_eq) | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 263 | apply assumption | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 264 | apply simp | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 265 | done | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 266 | |
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 267 | lemma var_app_typesE: "e \<turnstile> Var i \<degree>\<degree> ts : T \<Longrightarrow> | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 268 | (\<And>Ts. e \<turnstile> Var i : Ts \<Rrightarrow> T \<Longrightarrow> e \<tturnstile> ts : Ts \<Longrightarrow> P) \<Longrightarrow> P" | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 269 | apply (drule var_app_types [of _ _ "[]", simplified]) | 
| 17589 | 270 | apply (iprover intro: typing.Var)+ | 
| 14064 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 271 | done | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 272 | |
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 273 | lemma abs_typeE: "e \<turnstile> Abs t : T \<Longrightarrow> (\<And>U V. e\<langle>0:U\<rangle> \<turnstile> t : V \<Longrightarrow> P) \<Longrightarrow> P" | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 274 | apply (cases T) | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 275 | apply (rule FalseE) | 
| 22271 | 276 | apply (erule typing.cases) | 
| 14064 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 277 | apply simp_all | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 278 | apply atomize | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 279 | apply (erule_tac x="type1" in allE) | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 280 | apply (erule_tac x="type2" in allE) | 
| 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 281 | apply (erule mp) | 
| 22271 | 282 | apply (erule typing.cases) | 
| 14064 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 283 | apply simp_all | 
| 9622 | 284 | done | 
| 285 | ||
| 286 | ||
| 14064 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 287 | subsection {* Lifting preserves well-typedness *}
 | 
| 9622 | 288 | |
| 18257 | 289 | lemma lift_type [intro!]: "e \<turnstile> t : T \<Longrightarrow> e\<langle>i:U\<rangle> \<turnstile> lift t i : T" | 
| 20503 | 290 | by (induct arbitrary: i U set: typing) auto | 
| 12171 | 291 | |
| 14064 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 292 | lemma lift_types: | 
| 18241 | 293 | "e \<tturnstile> ts : Ts \<Longrightarrow> e\<langle>i:U\<rangle> \<tturnstile> (map (\<lambda>t. lift t i) ts) : Ts" | 
| 20503 | 294 | apply (induct ts arbitrary: Ts) | 
| 9622 | 295 | apply simp | 
| 296 | apply (case_tac Ts) | |
| 11946 | 297 | apply auto | 
| 9622 | 298 | done | 
| 299 | ||
| 300 | ||
| 9811 
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
 wenzelm parents: 
9771diff
changeset | 301 | subsection {* Substitution lemmas *}
 | 
| 9622 | 302 | |
| 11994 | 303 | lemma subst_lemma: | 
| 18257 | 304 | "e \<turnstile> t : T \<Longrightarrow> e' \<turnstile> u : U \<Longrightarrow> e = e'\<langle>i:U\<rangle> \<Longrightarrow> e' \<turnstile> t[u/i] : T" | 
| 20503 | 305 | apply (induct arbitrary: e' i U u set: typing) | 
| 11946 | 306 | apply (rule_tac x = x and y = i in linorder_cases) | 
| 307 | apply auto | |
| 308 | apply blast | |
| 9622 | 309 | done | 
| 310 | ||
| 12011 | 311 | lemma substs_lemma: | 
| 18241 | 312 | "e \<turnstile> u : T \<Longrightarrow> e\<langle>i:T\<rangle> \<tturnstile> ts : Ts \<Longrightarrow> | 
| 11943 | 313 | e \<tturnstile> (map (\<lambda>t. t[u/i]) ts) : Ts" | 
| 20503 | 314 | apply (induct ts arbitrary: Ts) | 
| 9622 | 315 | apply (case_tac Ts) | 
| 316 | apply simp | |
| 317 | apply simp | |
| 12011 | 318 | apply atomize | 
| 9622 | 319 | apply (case_tac Ts) | 
| 320 | apply simp | |
| 321 | apply simp | |
| 322 | apply (erule conjE) | |
| 12011 | 323 | apply (erule (1) subst_lemma) | 
| 11994 | 324 | apply (rule refl) | 
| 325 | done | |
| 326 | ||
| 9622 | 327 | |
| 9811 
39ffdb8cab03
HOL/Lambda: converted into new-style theory and document;
 wenzelm parents: 
9771diff
changeset | 328 | subsection {* Subject reduction *}
 | 
| 9622 | 329 | |
| 22271 | 330 | lemma subject_reduction: "e \<turnstile> t : T \<Longrightarrow> t \<rightarrow>\<^sub>\<beta> t' \<Longrightarrow> e \<turnstile> t' : T" | 
| 20503 | 331 | apply (induct arbitrary: t' set: typing) | 
| 9622 | 332 | apply blast | 
| 333 | apply blast | |
| 11994 | 334 | apply atomize | 
| 23750 | 335 | apply (ind_cases "s \<degree> t \<rightarrow>\<^sub>\<beta> t'" for s t t') | 
| 9622 | 336 | apply hypsubst | 
| 23750 | 337 | apply (ind_cases "env \<turnstile> Abs t : T \<Rightarrow> U" for env t T U) | 
| 9622 | 338 | apply (rule subst_lemma) | 
| 339 | apply assumption | |
| 340 | apply assumption | |
| 341 | apply (rule ext) | |
| 11935 | 342 | apply (case_tac x) | 
| 11946 | 343 | apply auto | 
| 9622 | 344 | done | 
| 345 | ||
| 14064 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 346 | theorem subject_reduction': "t \<rightarrow>\<^sub>\<beta>\<^sup>* t' \<Longrightarrow> e \<turnstile> t : T \<Longrightarrow> e \<turnstile> t' : T" | 
| 23750 | 347 | by (induct set: rtranclp) (iprover intro: subject_reduction)+ | 
| 9622 | 348 | |
| 349 | ||
| 14064 
35d36f43ba06
Moved strong normalization proof to StrongNorm.thy
 berghofe parents: 
13596diff
changeset | 350 | subsection {* Alternative induction rule for types *}
 | 
| 9622 | 351 | |
| 11935 | 352 | lemma type_induct [induct type]: | 
| 18241 | 353 | assumes | 
| 11945 | 354 | "(\<And>T. (\<And>T1 T2. T = T1 \<Rightarrow> T2 \<Longrightarrow> P T1) \<Longrightarrow> | 
| 18241 | 355 | (\<And>T1 T2. T = T1 \<Rightarrow> T2 \<Longrightarrow> P T2) \<Longrightarrow> P T)" | 
| 356 | shows "P T" | |
| 357 | proof (induct T) | |
| 358 | case Atom | |
| 23464 | 359 | show ?case by (rule assms) simp_all | 
| 18241 | 360 | next | 
| 361 | case Fun | |
| 23464 | 362 | show ?case by (rule assms) (insert Fun, simp_all) | 
| 11935 | 363 | qed | 
| 364 | ||
| 11638 | 365 | end |