src/HOL/Lambda/StrongNorm.thy
author haftmann
Fri, 01 Jun 2007 10:44:26 +0200
changeset 23181 f52b555f8141
parent 22271 51a80e238b29
child 23464 bc2563c37b1a
permissions -rw-r--r--
localized
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14064
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
     1
(*  Title:      HOL/Lambda/StrongNorm.thy
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
     2
    ID:         $Id$
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
     3
    Author:     Stefan Berghofer
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
     4
    Copyright   2000 TU Muenchen
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
     5
*)
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
     6
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
     7
header {* Strong normalization for simply-typed lambda calculus *}
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
     8
16417
9bc16273c2d4 migrated theory headers to new format
haftmann
parents: 14064
diff changeset
     9
theory StrongNorm imports Type InductTermi begin
14064
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    10
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    11
text {*
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    12
Formalization by Stefan Berghofer. Partly based on a paper proof by
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    13
Felix Joachimski and Ralph Matthes \cite{Matthes-Joachimski-AML}.
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    14
*}
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    15
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    16
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    17
subsection {* Properties of @{text IT} *}
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    18
22271
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
    19
lemma lift_IT [intro!]: "IT t \<Longrightarrow> IT (lift t i)"
20503
503ac4c5ef91 induct method: renamed 'fixing' to 'arbitrary';
wenzelm
parents: 18257
diff changeset
    20
  apply (induct arbitrary: i set: IT)
14064
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    21
    apply (simp (no_asm))
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    22
    apply (rule conjI)
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    23
     apply
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    24
      (rule impI,
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    25
       rule IT.Var,
22271
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
    26
       erule listsp.induct,
14064
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    27
       simp (no_asm),
22271
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
    28
       rule listsp.Nil,
14064
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    29
       simp (no_asm),
22271
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
    30
       rule listsp.Cons,
14064
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    31
       blast,
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    32
       assumption)+
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    33
     apply auto
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    34
   done
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    35
22271
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
    36
lemma lifts_IT: "listsp IT ts \<Longrightarrow> listsp IT (map (\<lambda>t. lift t 0) ts)"
14064
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    37
  by (induct ts) auto
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    38
22271
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
    39
lemma subst_Var_IT: "IT r \<Longrightarrow> IT (r[Var i/j])"
20503
503ac4c5ef91 induct method: renamed 'fixing' to 'arbitrary';
wenzelm
parents: 18257
diff changeset
    40
  apply (induct arbitrary: i j set: IT)
14064
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    41
    txt {* Case @{term Var}: *}
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    42
    apply (simp (no_asm) add: subst_Var)
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    43
    apply
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    44
    ((rule conjI impI)+,
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    45
      rule IT.Var,
22271
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
    46
      erule listsp.induct,
14064
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    47
      simp (no_asm),
22271
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
    48
      rule listsp.Nil,
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
    49
      simp (no_asm),
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
    50
      rule listsp.Cons,
14064
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    51
      fast,
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    52
      assumption)+
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    53
   txt {* Case @{term Lambda}: *}
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    54
   apply atomize
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    55
   apply simp
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    56
   apply (rule IT.Lambda)
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    57
   apply fast
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    58
  txt {* Case @{term Beta}: *}
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    59
  apply atomize
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    60
  apply (simp (no_asm_use) add: subst_subst [symmetric])
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    61
  apply (rule IT.Beta)
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    62
   apply auto
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    63
  done
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    64
22271
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
    65
lemma Var_IT: "IT (Var n)"
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
    66
  apply (subgoal_tac "IT (Var n \<degree>\<degree> [])")
14064
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    67
   apply simp
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    68
  apply (rule IT.Var)
22271
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
    69
  apply (rule listsp.Nil)
14064
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    70
  done
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    71
22271
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
    72
lemma app_Var_IT: "IT t \<Longrightarrow> IT (t \<degree> Var i)"
14064
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    73
  apply (induct set: IT)
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    74
    apply (subst app_last)
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    75
    apply (rule IT.Var)
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    76
    apply simp
22271
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
    77
    apply (rule listsp.Cons)
14064
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    78
     apply (rule Var_IT)
22271
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
    79
    apply (rule listsp.Nil)
14064
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    80
   apply (rule IT.Beta [where ?ss = "[]", unfolded foldl_Nil [THEN eq_reflection]])
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    81
    apply (erule subst_Var_IT)
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    82
   apply (rule Var_IT)
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    83
  apply (subst app_last)
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    84
  apply (rule IT.Beta)
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    85
   apply (subst app_last [symmetric])
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    86
   apply assumption
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    87
  apply assumption
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    88
  done
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    89
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    90
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    91
subsection {* Well-typed substitution preserves termination *}
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    92
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    93
lemma subst_type_IT:
22271
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
    94
  "\<And>t e T u i. IT t \<Longrightarrow> e\<langle>i:U\<rangle> \<turnstile> t : T \<Longrightarrow>
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
    95
    IT u \<Longrightarrow> e \<turnstile> u : U \<Longrightarrow> IT (t[u/i])"
14064
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    96
  (is "PROP ?P U" is "\<And>t e T u i. _ \<Longrightarrow> PROP ?Q t e T u i U")
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    97
proof (induct U)
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    98
  fix T t
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
    99
  assume MI1: "\<And>T1 T2. T = T1 \<Rightarrow> T2 \<Longrightarrow> PROP ?P T1"
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   100
  assume MI2: "\<And>T1 T2. T = T1 \<Rightarrow> T2 \<Longrightarrow> PROP ?P T2"
22271
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   101
  assume "IT t"
14064
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   102
  thus "\<And>e T' u i. PROP ?Q t e T' u i T"
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   103
  proof induct
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   104
    fix e T' u i
22271
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   105
    assume uIT: "IT u"
14064
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   106
    assume uT: "e \<turnstile> u : T"
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   107
    {
22271
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   108
      case (Var rs n e_ T'_ u_ i_)
14064
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   109
      assume nT: "e\<langle>i:T\<rangle> \<turnstile> Var n \<degree>\<degree> rs : T'"
22271
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   110
      let ?ty = "\<lambda>t. \<exists>T'. e\<langle>i:T\<rangle> \<turnstile> t : T'"
14064
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   111
      let ?R = "\<lambda>t. \<forall>e T' u i.
22271
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   112
        e\<langle>i:T\<rangle> \<turnstile> t : T' \<longrightarrow> IT u \<longrightarrow> e \<turnstile> u : T \<longrightarrow> IT (t[u/i])"
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   113
      show "IT ((Var n \<degree>\<degree> rs)[u/i])"
14064
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   114
      proof (cases "n = i")
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   115
        case True
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   116
        show ?thesis
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   117
        proof (cases rs)
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   118
          case Nil
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   119
          with uIT True show ?thesis by simp
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   120
        next
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   121
          case (Cons a as)
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   122
          with nT have "e\<langle>i:T\<rangle> \<turnstile> Var n \<degree> a \<degree>\<degree> as : T'" by simp
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   123
          then obtain Ts
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   124
              where headT: "e\<langle>i:T\<rangle> \<turnstile> Var n \<degree> a : Ts \<Rrightarrow> T'"
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   125
              and argsT: "e\<langle>i:T\<rangle> \<tturnstile> as : Ts"
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   126
            by (rule list_app_typeE)
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   127
          from headT obtain T''
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   128
              where varT: "e\<langle>i:T\<rangle> \<turnstile> Var n : T'' \<Rightarrow> Ts \<Rrightarrow> T'"
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   129
              and argT: "e\<langle>i:T\<rangle> \<turnstile> a : T''"
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   130
            by cases simp_all
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   131
          from varT True have T: "T = T'' \<Rightarrow> Ts \<Rrightarrow> T'"
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   132
            by cases auto
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   133
          with uT have uT': "e \<turnstile> u : T'' \<Rightarrow> Ts \<Rrightarrow> T'" by simp
22271
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   134
          from T have "IT ((Var 0 \<degree>\<degree> map (\<lambda>t. lift t 0)
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   135
            (map (\<lambda>t. t[u/i]) as))[(u \<degree> a[u/i])/0])"
14064
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   136
          proof (rule MI2)
22271
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   137
            from T have "IT ((lift u 0 \<degree> Var 0)[a[u/i]/0])"
14064
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   138
            proof (rule MI1)
22271
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   139
              have "IT (lift u 0)" by (rule lift_IT)
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   140
              thus "IT (lift u 0 \<degree> Var 0)" by (rule app_Var_IT)
14064
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   141
              show "e\<langle>0:T''\<rangle> \<turnstile> lift u 0 \<degree> Var 0 : Ts \<Rrightarrow> T'"
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   142
              proof (rule typing.App)
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   143
                show "e\<langle>0:T''\<rangle> \<turnstile> lift u 0 : T'' \<Rightarrow> Ts \<Rrightarrow> T'"
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   144
                  by (rule lift_type) (rule uT')
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   145
                show "e\<langle>0:T''\<rangle> \<turnstile> Var 0 : T''"
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   146
                  by (rule typing.Var) simp
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   147
              qed
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   148
              from Var have "?R a" by cases (simp_all add: Cons)
22271
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   149
              with argT uIT uT show "IT (a[u/i])" by simp
14064
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   150
              from argT uT show "e \<turnstile> a[u/i] : T''"
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   151
                by (rule subst_lemma) simp
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   152
            qed
22271
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   153
            thus "IT (u \<degree> a[u/i])" by simp
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   154
            from Var have "listsp ?R as"
14064
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   155
              by cases (simp_all add: Cons)
22271
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   156
            moreover from argsT have "listsp ?ty as"
14064
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   157
              by (rule lists_typings)
22271
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   158
            ultimately have "listsp (\<lambda>t. ?R t \<and> ?ty t) as"
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   159
              by simp
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   160
            hence "listsp IT (map (\<lambda>t. lift t 0) (map (\<lambda>t. t[u/i]) as))"
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   161
              (is "listsp IT (?ls as)")
14064
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   162
            proof induct
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   163
              case Nil
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   164
              show ?case by fastsimp
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   165
            next
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   166
              case (Cons b bs)
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   167
              hence I: "?R b" by simp
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   168
              from Cons obtain U where "e\<langle>i:T\<rangle> \<turnstile> b : U" by fast
22271
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   169
              with uT uIT I have "IT (b[u/i])" by simp
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   170
              hence "IT (lift (b[u/i]) 0)" by (rule lift_IT)
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   171
              hence "listsp IT (lift (b[u/i]) 0 # ?ls bs)"
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   172
                by (rule listsp.Cons) (rule Cons)
14064
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   173
              thus ?case by simp
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   174
            qed
22271
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   175
            thus "IT (Var 0 \<degree>\<degree> ?ls as)" by (rule IT.Var)
14064
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   176
            have "e\<langle>0:Ts \<Rrightarrow> T'\<rangle> \<turnstile> Var 0 : Ts \<Rrightarrow> T'"
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   177
              by (rule typing.Var) simp
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   178
            moreover from uT argsT have "e \<tturnstile> map (\<lambda>t. t[u/i]) as : Ts"
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   179
              by (rule substs_lemma)
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   180
            hence "e\<langle>0:Ts \<Rrightarrow> T'\<rangle> \<tturnstile> ?ls as : Ts"
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   181
              by (rule lift_types)
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   182
            ultimately show "e\<langle>0:Ts \<Rrightarrow> T'\<rangle> \<turnstile> Var 0 \<degree>\<degree> ?ls as : T'"
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   183
              by (rule list_app_typeI)
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   184
            from argT uT have "e \<turnstile> a[u/i] : T''"
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   185
              by (rule subst_lemma) (rule refl)
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   186
            with uT' show "e \<turnstile> u \<degree> a[u/i] : Ts \<Rrightarrow> T'"
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   187
              by (rule typing.App)
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   188
          qed
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   189
          with Cons True show ?thesis
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20503
diff changeset
   190
            by (simp add: map_compose [symmetric] comp_def)
14064
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   191
        qed
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   192
      next
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   193
        case False
22271
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   194
        from Var have "listsp ?R rs" by simp
14064
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   195
        moreover from nT obtain Ts where "e\<langle>i:T\<rangle> \<tturnstile> rs : Ts"
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   196
          by (rule list_app_typeE)
22271
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   197
        hence "listsp ?ty rs" by (rule lists_typings)
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   198
        ultimately have "listsp (\<lambda>t. ?R t \<and> ?ty t) rs"
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   199
          by simp
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   200
        hence "listsp IT (map (\<lambda>x. x[u/i]) rs)"
14064
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   201
        proof induct
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   202
          case Nil
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   203
          show ?case by fastsimp
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   204
        next
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   205
          case (Cons a as)
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   206
          hence I: "?R a" by simp
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   207
          from Cons obtain U where "e\<langle>i:T\<rangle> \<turnstile> a : U" by fast
22271
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   208
          with uT uIT I have "IT (a[u/i])" by simp
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   209
          hence "listsp IT (a[u/i] # map (\<lambda>t. t[u/i]) as)"
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   210
            by (rule listsp.Cons) (rule Cons)
14064
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   211
          thus ?case by simp
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   212
        qed
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   213
        with False show ?thesis by (auto simp add: subst_Var)
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   214
      qed
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   215
    next
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   216
      case (Lambda r e_ T'_ u_ i_)
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   217
      assume "e\<langle>i:T\<rangle> \<turnstile> Abs r : T'"
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   218
        and "\<And>e T' u i. PROP ?Q r e T' u i T"
22271
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   219
      with uIT uT show "IT (Abs r[u/i])"
14064
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   220
        by fastsimp
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   221
    next
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   222
      case (Beta r a as e_ T'_ u_ i_)
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   223
      assume T: "e\<langle>i:T\<rangle> \<turnstile> Abs r \<degree> a \<degree>\<degree> as : T'"
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   224
      assume SI1: "\<And>e T' u i. PROP ?Q (r[a/0] \<degree>\<degree> as) e T' u i T"
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   225
      assume SI2: "\<And>e T' u i. PROP ?Q a e T' u i T"
22271
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   226
      have "IT (Abs (r[lift u 0/Suc i]) \<degree> a[u/i] \<degree>\<degree> map (\<lambda>t. t[u/i]) as)"
14064
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   227
      proof (rule IT.Beta)
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   228
        have "Abs r \<degree> a \<degree>\<degree> as \<rightarrow>\<^sub>\<beta> r[a/0] \<degree>\<degree> as"
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   229
          by (rule apps_preserves_beta) (rule beta.beta)
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   230
        with T have "e\<langle>i:T\<rangle> \<turnstile> r[a/0] \<degree>\<degree> as : T'"
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   231
          by (rule subject_reduction)
22271
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   232
        hence "IT ((r[a/0] \<degree>\<degree> as)[u/i])"
14064
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   233
          by (rule SI1)
22271
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   234
        thus "IT (r[lift u 0/Suc i][a[u/i]/0] \<degree>\<degree> map (\<lambda>t. t[u/i]) as)"
14064
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   235
          by (simp del: subst_map add: subst_subst subst_map [symmetric])
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   236
        from T obtain U where "e\<langle>i:T\<rangle> \<turnstile> Abs r \<degree> a : U"
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   237
          by (rule list_app_typeE) fast
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   238
        then obtain T'' where "e\<langle>i:T\<rangle> \<turnstile> a : T''" by cases simp_all
22271
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   239
        thus "IT (a[u/i])" by (rule SI2)
14064
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   240
      qed
22271
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   241
      thus "IT ((Abs r \<degree> a \<degree>\<degree> as)[u/i])" by simp
14064
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   242
    }
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   243
  qed
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   244
qed
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   245
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   246
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   247
subsection {* Well-typed terms are strongly normalizing *}
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   248
18257
2124b24454dd tuned induct proofs;
wenzelm
parents: 16417
diff changeset
   249
lemma type_implies_IT:
2124b24454dd tuned induct proofs;
wenzelm
parents: 16417
diff changeset
   250
  assumes "e \<turnstile> t : T"
22271
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   251
  shows "IT t"
18257
2124b24454dd tuned induct proofs;
wenzelm
parents: 16417
diff changeset
   252
  using prems
2124b24454dd tuned induct proofs;
wenzelm
parents: 16417
diff changeset
   253
proof induct
2124b24454dd tuned induct proofs;
wenzelm
parents: 16417
diff changeset
   254
  case Var
2124b24454dd tuned induct proofs;
wenzelm
parents: 16417
diff changeset
   255
  show ?case by (rule Var_IT)
2124b24454dd tuned induct proofs;
wenzelm
parents: 16417
diff changeset
   256
next
2124b24454dd tuned induct proofs;
wenzelm
parents: 16417
diff changeset
   257
  case Abs
2124b24454dd tuned induct proofs;
wenzelm
parents: 16417
diff changeset
   258
  show ?case by (rule IT.Lambda)
2124b24454dd tuned induct proofs;
wenzelm
parents: 16417
diff changeset
   259
next
22271
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   260
  case (App e s T U t)
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   261
  have "IT ((Var 0 \<degree> lift t 0)[s/0])"
18257
2124b24454dd tuned induct proofs;
wenzelm
parents: 16417
diff changeset
   262
  proof (rule subst_type_IT)
22271
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   263
    have "IT (lift t 0)" by (rule lift_IT)
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   264
    hence "listsp IT [lift t 0]" by (rule listsp.Cons) (rule listsp.Nil)
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   265
    hence "IT (Var 0 \<degree>\<degree> [lift t 0])" by (rule IT.Var)
18257
2124b24454dd tuned induct proofs;
wenzelm
parents: 16417
diff changeset
   266
    also have "Var 0 \<degree>\<degree> [lift t 0] = Var 0 \<degree> lift t 0" by simp
22271
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   267
    finally show "IT \<dots>" .
18257
2124b24454dd tuned induct proofs;
wenzelm
parents: 16417
diff changeset
   268
    have "e\<langle>0:T \<Rightarrow> U\<rangle> \<turnstile> Var 0 : T \<Rightarrow> U"
2124b24454dd tuned induct proofs;
wenzelm
parents: 16417
diff changeset
   269
      by (rule typing.Var) simp
2124b24454dd tuned induct proofs;
wenzelm
parents: 16417
diff changeset
   270
    moreover have "e\<langle>0:T \<Rightarrow> U\<rangle> \<turnstile> lift t 0 : T"
2124b24454dd tuned induct proofs;
wenzelm
parents: 16417
diff changeset
   271
      by (rule lift_type)
2124b24454dd tuned induct proofs;
wenzelm
parents: 16417
diff changeset
   272
    ultimately show "e\<langle>0:T \<Rightarrow> U\<rangle> \<turnstile> Var 0 \<degree> lift t 0 : U"
2124b24454dd tuned induct proofs;
wenzelm
parents: 16417
diff changeset
   273
      by (rule typing.App)
14064
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   274
  qed
18257
2124b24454dd tuned induct proofs;
wenzelm
parents: 16417
diff changeset
   275
  thus ?case by simp
14064
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   276
qed
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   277
22271
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   278
theorem type_implies_termi: "e \<turnstile> t : T \<Longrightarrow> termi beta t"
14064
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   279
proof -
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   280
  assume "e \<turnstile> t : T"
22271
51a80e238b29 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
   281
  hence "IT t" by (rule type_implies_IT)
14064
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   282
  thus ?thesis by (rule IT_implies_termi)
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   283
qed
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   284
35d36f43ba06 Moved strong normalization proof to StrongNorm.thy
berghofe
parents:
diff changeset
   285
end