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