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