Tutorial/Tutorial5.thy
author Christian Urban <urbanc@in.tum.de>
Thu, 19 Apr 2018 13:58:22 +0100
branchNominal2-Isabelle2016-1
changeset 3246 66114fa3d2ee
parent 3238 b2e1a7b83e05
permissions -rw-r--r--
updated to Isabelle 2016-1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2701
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
     1
2691
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
theory Tutorial5
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
imports Tutorial4
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
begin
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
2701
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
     6
section {* Type-Preservation and Progress Lemma*}
2691
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
2701
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
     8
text {*
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
     9
  The point of this tutorial is to prove the
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    10
  type-preservation and progress lemma. Since
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    11
  we now know that \<Down>, \<longrightarrow>cbv* and the machine
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    12
  correspond to each other, we only need to
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    13
  prove this property for one of them. We chose
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    14
  \<longrightarrow>cbv.
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    15
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    16
  First we need to establish two elimination
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    17
  properties and two auxiliary lemmas about contexts.
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    18
*}
2691
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
lemma valid_elim:
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
  assumes a: "valid ((x, T) # \<Gamma>)"
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
  shows "atom x \<sharp> \<Gamma> \<and> valid \<Gamma>"
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
using a by (cases) (auto)
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
lemma valid_insert:
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
  assumes a: "valid (\<Delta> @ [(x, T)] @ \<Gamma>)"
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
  shows "valid (\<Delta> @ \<Gamma>)" 
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
using a
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
by (induct \<Delta>)
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
   (auto simp add: fresh_append fresh_Cons dest!: valid_elim)
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
lemma fresh_list: 
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
  shows "atom y \<sharp> xs = (\<forall>x \<in> set xs. atom y \<sharp> x)"
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
by (induct xs) (simp_all add: fresh_Nil fresh_Cons)
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
lemma context_unique:
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
  assumes a1: "valid \<Gamma>"
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
  and     a2: "(x, T) \<in> set \<Gamma>"
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
  and     a3: "(x, U) \<in> set \<Gamma>"
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
  shows "T = U" 
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
using a1 a2 a3
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
by (induct) (auto simp add: fresh_list fresh_Pair fresh_at_base)
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
2701
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    45
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    46
section {* EXERCISE 16 *}
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    47
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    48
text {*
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    49
  Next we want to show the type substitution lemma. Unfortunately,
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    50
  we have to prove a slightly more general version of it, where
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    51
  the variable being substituted occurs somewhere inside the 
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    52
  context.
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    53
*}
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    54
2691
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
lemma type_substitution_aux:
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
  assumes a: "\<Delta> @ [(x, T')] @ \<Gamma> \<turnstile> e : T"
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
  and     b: "\<Gamma> \<turnstile> e' : T'"
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
  shows "\<Delta> @ \<Gamma> \<turnstile> e[x ::= e'] : T" 
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
using a b 
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
proof (nominal_induct \<Gamma>'\<equiv>"\<Delta> @ [(x, T')] @ \<Gamma>" e T avoiding: x e' \<Delta> rule: typing.strong_induct)
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
  case (t_Var y T x e' \<Delta>)
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
  have a1: "valid (\<Delta> @ [(x, T')] @ \<Gamma>)" by fact
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
  have a2: "(y,T) \<in> set (\<Delta> @ [(x, T')] @ \<Gamma>)" by fact 
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
  have a3: "\<Gamma> \<turnstile> e' : T'" by fact
2701
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    65
  
2691
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
  from a1 have a4: "valid (\<Delta> @ \<Gamma>)" by (rule valid_insert)
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
  { assume eq: "x = y"
2701
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    68
    
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    69
    have "\<Delta> @ \<Gamma> \<turnstile> Var y[x ::= e'] : T" sorry
2691
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
  }
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
  moreover
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
  { assume ineq: "x \<noteq> y"
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
    from a2 have "(y, T) \<in> set (\<Delta> @ \<Gamma>)" using ineq by simp
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
    then have "\<Delta> @ \<Gamma> \<turnstile> Var y[x ::= e'] : T" using ineq a4 by auto
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
  }
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
  ultimately show "\<Delta> @ \<Gamma> \<turnstile> Var y[x::=e'] : T" by blast
2701
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    77
next
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    78
  case (t_Lam y T1 t T2 x e' \<Delta>)
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    79
  have a1: "atom y \<sharp> e'" by fact
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    80
  have a2: "atom y \<sharp> \<Delta> @ [(x, T')] @ \<Gamma>" by fact
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    81
  have a3: "\<Gamma> \<turnstile> e' : T'" by fact 
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    82
  have ih: "\<Gamma> \<turnstile> e' : T' \<Longrightarrow> ((y, T1) # \<Delta>) @ \<Gamma> \<turnstile> t [x ::= e'] : T2" 
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    83
    using t_Lam(6)[of "(y, T1) # \<Delta>"] by auto 
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    84
  
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    85
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    86
  show "\<Delta> @ \<Gamma> \<turnstile> (Lam [y]. t)[x ::= e'] : T1 \<rightarrow> T2" sorry
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    87
next
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    88
  case (t_App t1 T1 T2 t2 x e' \<Delta>)
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    89
  have ih1: "\<Gamma> \<turnstile> e' : T' \<Longrightarrow> \<Delta> @ \<Gamma> \<turnstile> t1 [x ::= e'] : T1 \<rightarrow> T2" using t_App(2) by auto 
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    90
  have ih2: "\<Gamma> \<turnstile> e' : T' \<Longrightarrow> \<Delta> @ \<Gamma> \<turnstile> t2 [x ::= e'] : T1" using t_App(4) by auto 
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    91
  have a: "\<Gamma> \<turnstile> e' : T'" by fact
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    92
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    93
  show "\<Delta> @ \<Gamma> \<turnstile> App t1 t2 [x ::= e'] : T2" sorry
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    94
qed 
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    95
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    96
text {*
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    97
  From this we can derive the usual version of the substitution
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    98
  lemma.
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
    99
*}
2691
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
corollary type_substitution:
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
  assumes a: "(x, T') # \<Gamma> \<turnstile> e : T"
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
  and     b: "\<Gamma> \<turnstile> e' : T'"
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
  shows "\<Gamma> \<turnstile> e[x ::= e'] : T"
2701
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
   105
using a b type_substitution_aux[of "[]"]
2691
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
by auto
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
2701
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
   108
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
   109
section {* Type Preservation *}
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
   110
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
   111
text {*
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
   112
  Finally we are in a position to establish the type preservation
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
   113
  property. We just need the following two inversion rules for
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
   114
  particualr typing instances.
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
   115
*}
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
   116
2691
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
lemma t_App_elim:
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
  assumes a: "\<Gamma> \<turnstile> App t1 t2 : T"
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
  obtains T' where "\<Gamma> \<turnstile> t1 : T' \<rightarrow> T" "\<Gamma> \<turnstile> t2 : T'"
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
using a
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
by (cases) (auto simp add: lam.eq_iff lam.distinct)
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
text {* we have not yet generated strong elimination rules *}
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
lemma t_Lam_elim:
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
  assumes ty: "\<Gamma> \<turnstile> Lam [x].t : T" 
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
  and     fc: "atom x \<sharp> \<Gamma>" 
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
  obtains T1 T2 where "T = T1 \<rightarrow> T2" "(x, T1) # \<Gamma> \<turnstile> t : T2"
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
using ty fc
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
apply(cases)
3192
14c7d7e29c44 added a simproc for alpha-equivalence to the simplifier
Christian Urban <urbanc@in.tum.de>
parents: 3132
diff changeset
   130
using [[simproc del: alpha_lst]]
2691
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
apply(auto simp add: Abs1_eq_iff)
3238
b2e1a7b83e05 updated for 2014 release
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3192
diff changeset
   132
apply(rotate_tac 4)
2691
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
apply(drule_tac p="(x \<leftrightarrow> xa)" in permute_boolI)
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
apply(perm_simp)
3192
14c7d7e29c44 added a simproc for alpha-equivalence to the simplifier
Christian Urban <urbanc@in.tum.de>
parents: 3132
diff changeset
   135
apply(auto simp add: flip_fresh_fresh ty_fresh)
2691
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
done
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
2701
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
   138
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
   139
section {* EXERCISE 17 *}
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
   140
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
   141
text {*
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
   142
  Fill in the gaps in the t_Lam case. You will need
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
   143
  the type substitution lemma proved above. 
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
   144
*}
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
   145
2691
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   146
theorem cbv_type_preservation:
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   147
  assumes a: "t \<longrightarrow>cbv t'"
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
  and     b: "\<Gamma> \<turnstile> t : T" 
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   149
  shows "\<Gamma> \<turnstile> t' : T"
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   150
using a b
2701
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
   151
proof (nominal_induct avoiding: \<Gamma> T rule: cbv.strong_induct)
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
   152
  case (cbv1 v x t \<Gamma> T) 
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
   153
  have fc: "atom x \<sharp> \<Gamma>" by fact
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
   154
  have "\<Gamma> \<turnstile> App (Lam [x]. t) v : T" by fact
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
   155
  then obtain T' where 
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
   156
      *: "\<Gamma> \<turnstile> Lam [x]. t : T' \<rightarrow> T" and 
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
   157
     **: "\<Gamma> \<turnstile> v : T'" by (rule t_App_elim)
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
   158
  have "(x, T') # \<Gamma> \<turnstile> t : T" using * fc by (rule t_Lam_elim) (simp add: ty.eq_iff)
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
   159
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
   160
  show "\<Gamma> \<turnstile> t [x ::= v] : T " sorry
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
   161
qed (auto elim!: t_App_elim)
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
   162
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
   163
text {*
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
   164
  We can easily extend this to sequences of cbv* reductions.
7b2691911fbc cleaning up
Christian Urban <urbanc@in.tum.de>
parents: 2698
diff changeset
   165
*}
2691
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   166
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   167
corollary cbvs_type_preservation:
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   168
  assumes a: "t \<longrightarrow>cbv* t'"
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   169
  and     b: "\<Gamma> \<turnstile> t : T" 
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   170
  shows "\<Gamma> \<turnstile> t' : T"
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   171
using a b
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   172
by (induct) (auto intro: cbv_type_preservation)
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   173
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   174
text {* 
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   175
  The type-preservation property for the machine and 
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   176
  evaluation relation. 
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   177
*}
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   178
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   179
theorem machine_type_preservation:
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   180
  assumes a: "<t, []> \<mapsto>* <t', []>"
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   181
  and     b: "\<Gamma> \<turnstile> t : T" 
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   182
  shows "\<Gamma> \<turnstile> t' : T"
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   183
proof -
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   184
  have "t \<longrightarrow>cbv* t'" using a machines_implies_cbvs by simp
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   185
  then show "\<Gamma> \<turnstile> t' : T" using b cbvs_type_preservation by simp
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   186
qed
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   187
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   188
theorem eval_type_preservation:
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   189
  assumes a: "t \<Down> t'"
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   190
  and     b: "\<Gamma> \<turnstile> t : T" 
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   191
  shows "\<Gamma> \<turnstile> t' : T"
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   192
proof -
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   193
  have "<t, []> \<mapsto>* <t', []>" using a eval_implies_machines by simp
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   194
  then show "\<Gamma> \<turnstile> t' : T" using b machine_type_preservation by simp
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   195
qed
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   196
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   197
text {* The Progress Property *}
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   198
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   199
lemma canonical_tArr:
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   200
  assumes a: "[] \<turnstile> t : T1 \<rightarrow> T2"
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   201
  and     b: "val t"
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   202
  obtains x t' where "t = Lam [x].t'"
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   203
using b a by (induct) (auto) 
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   204
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   205
theorem progress:
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   206
  assumes a: "[] \<turnstile> t : T"
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   207
  shows "(\<exists>t'. t \<longrightarrow>cbv t') \<or> (val t)"
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   208
using a
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   209
by (induct \<Gamma>\<equiv>"[]::ty_ctx" t T)
2698
96f3ac5d11ad Missing val.simps
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2691
diff changeset
   210
   (auto elim: canonical_tArr simp add: val.simps)
2691
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   211
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   212
text {*
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   213
  Done! Congratulations!
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   214
*}
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   215
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   216
end
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   217