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