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