Tutorial/Tutorial4.thy
author Christian Urban <urbanc@in.tum.de>
Thu, 20 Jan 2011 23:19:30 +0100
changeset 2687 d0fb94035969
child 2689 ddc05a611005
permissions -rw-r--r--
first split of tutorrial theory
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
theory Tutorial4
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
imports Tutorial1
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
begin
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
section {* The CBV Reduction Relation (Small-Step Semantics) *}
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
text {*
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
  In order to help establishing the property that the CK Machine
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
  calculates a nomrmalform that corresponds to the evaluation 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
  relation, we introduce the call-by-value small-step semantics.
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
*}
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
inductive
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
  cbv :: "lam \<Rightarrow> lam \<Rightarrow> bool" ("_ \<longrightarrow>cbv _" [60, 60] 60) 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
where
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
  cbv1: "\<lbrakk>val v; atom x \<sharp> v\<rbrakk> \<Longrightarrow> App (Lam [x].t) v \<longrightarrow>cbv t[x ::= v]"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
| cbv2[intro]: "t \<longrightarrow>cbv t' \<Longrightarrow> App t t2 \<longrightarrow>cbv App t' t2"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
| cbv3[intro]: "t \<longrightarrow>cbv t' \<Longrightarrow> App t2 t \<longrightarrow>cbv App t2 t'"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
equivariance val
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
equivariance cbv
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
nominal_inductive cbv
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
  avoids cbv1: "x"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
  unfolding fresh_star_def
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
  by (simp_all add: lam.fresh Abs_fresh_iff fresh_Pair fresh_fact)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
text {*
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
  In order to satisfy the vc-condition we have to formulate
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
  this relation with the additional freshness constraint
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
  atom x \<sharp> v. Although this makes the definition vc-ompatible, it
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
  makes the definition less useful. We can with a little bit of 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
  pain show that the more restricted rule is equivalent to the
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
  usual rule. 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
*}
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
lemma subst_rename: 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
  assumes a: "atom y \<sharp> t"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
  shows "t[x ::= s] = ((y \<leftrightarrow> x) \<bullet> t)[y ::= s]"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
using a 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
by (nominal_induct t avoiding: x y s rule: lam.strong_induct)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
   (auto simp add: lam.fresh fresh_at_base)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
lemma better_cbv1 [intro]: 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
  assumes a: "val v" 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
  shows "App (Lam [x].t) v \<longrightarrow>cbv t[x::=v]"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
proof -
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
  obtain y::"name" where fs: "atom y \<sharp> (x, t, v)" by (rule obtain_fresh)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
  have "App (Lam [x].t) v = App (Lam [y].((y \<leftrightarrow> x) \<bullet> t)) v" using fs
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
    by (auto simp add: lam.eq_iff Abs1_eq_iff' flip_def fresh_Pair fresh_at_base)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
  also have "\<dots> \<longrightarrow>cbv ((y \<leftrightarrow> x) \<bullet> t)[y ::= v]" using fs a cbv1 by auto
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
  also have "\<dots> = t[x ::= v]" using fs subst_rename[symmetric] by simp
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
  finally show "App (Lam [x].t) v \<longrightarrow>cbv t[x ::= v]" by simp
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
qed
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
text {*
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
  The transitive closure of the cbv-reduction relation: 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
*}
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
inductive 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
  "cbvs" :: "lam \<Rightarrow> lam \<Rightarrow> bool" (" _ \<longrightarrow>cbv* _" [60, 60] 60)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
where
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
  cbvs1[intro]: "e \<longrightarrow>cbv* e"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
| cbvs2[intro]: "\<lbrakk>e1\<longrightarrow>cbv e2; e2 \<longrightarrow>cbv* e3\<rbrakk> \<Longrightarrow> e1 \<longrightarrow>cbv* e3"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
lemma cbvs3 [intro]:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
  assumes a: "e1 \<longrightarrow>cbv* e2" "e2 \<longrightarrow>cbv* e3"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
  shows "e1 \<longrightarrow>cbv* e3"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
using a by (induct) (auto) 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
subsection {* EXERCISE 8 *}
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
text {*  
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
  If more simple exercises are needed, then complete the following proof. 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
*}
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
lemma cbv_in_ctx:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
  assumes a: "t \<longrightarrow>cbv t'"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
  shows "E\<lbrakk>t\<rbrakk> \<longrightarrow>cbv E\<lbrakk>t'\<rbrakk>"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
using a
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
proof (induct E)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
  case Hole
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
  have "t \<longrightarrow>cbv t'" by fact
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
  then show "\<box>\<lbrakk>t\<rbrakk> \<longrightarrow>cbv \<box>\<lbrakk>t'\<rbrakk>" by simp
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
next
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
  case (CAppL E s)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
  have ih: "t \<longrightarrow>cbv t' \<Longrightarrow> E\<lbrakk>t\<rbrakk> \<longrightarrow>cbv E\<lbrakk>t'\<rbrakk>" by fact
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
  moreover
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
  have "t \<longrightarrow>cbv t'" by fact
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
  ultimately 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
  have "E\<lbrakk>t\<rbrakk> \<longrightarrow>cbv E\<lbrakk>t'\<rbrakk>" by simp
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
  then show "(CAppL E s)\<lbrakk>t\<rbrakk> \<longrightarrow>cbv (CAppL E s)\<lbrakk>t'\<rbrakk>" by auto
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
next
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
  case (CAppR s E)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
  have ih: "t \<longrightarrow>cbv t' \<Longrightarrow> E\<lbrakk>t\<rbrakk> \<longrightarrow>cbv E\<lbrakk>t'\<rbrakk>" by fact
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
  moreover
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
  have a: "t \<longrightarrow>cbv t'" by fact
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
  ultimately 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
  have "E\<lbrakk>t\<rbrakk> \<longrightarrow>cbv E\<lbrakk>t'\<rbrakk>" by simp
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
  then show "(CAppR s E)\<lbrakk>t\<rbrakk> \<longrightarrow>cbv (CAppR s E)\<lbrakk>t'\<rbrakk>" by auto
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
qed
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
section {* EXERCISE 9 *} 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
text {*
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
  The point of the cbv-reduction was that we can easily relatively 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
  establish the follwoing property:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
*}
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
lemma machine_implies_cbvs_ctx:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
  assumes a: "<e, Es> \<mapsto> <e', Es'>"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
  shows "(Es\<down>)\<lbrakk>e\<rbrakk> \<longrightarrow>cbv* (Es'\<down>)\<lbrakk>e'\<rbrakk>"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
using a 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
proof (induct)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
  case (m1 t1 t2 Es)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
  show "Es\<down>\<lbrakk>App t1 t2\<rbrakk> \<longrightarrow>cbv* ((CAppL \<box> t2) # Es)\<down>\<lbrakk>t1\<rbrakk>" sorry
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
next
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
  case (m2 v t2 Es)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
  have "val v" by fact
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
  show "((CAppL \<box> t2) # Es)\<down>\<lbrakk>v\<rbrakk> \<longrightarrow>cbv* (CAppR v \<box> # Es)\<down>\<lbrakk>t2\<rbrakk>" sorry
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
next
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
  case (m3 v x t Es)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
  have "val v" by fact
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
  show "(((CAppR (Lam [x].t) \<box>) # Es)\<down>)\<lbrakk>v\<rbrakk> \<longrightarrow>cbv* (Es\<down>)\<lbrakk>(t[x ::= v])\<rbrakk>" sorry
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
qed
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
text {* 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
  It is not difficult to extend the lemma above to
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
  arbitrary reductions sequences of the CK machine. *}
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
lemma machines_implies_cbvs_ctx:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
  assumes a: "<e, Es> \<mapsto>* <e', Es'>"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138
  shows "(Es\<down>)\<lbrakk>e\<rbrakk> \<longrightarrow>cbv* (Es'\<down>)\<lbrakk>e'\<rbrakk>"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   139
using a 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
by (induct) (auto dest: machine_implies_cbvs_ctx)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   141
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
text {* 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   143
  So whenever we let the CL machine start in an initial
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   144
  state and it arrives at a final state, then there exists
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   145
  a corresponding cbv-reduction sequence. *}
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   146
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   147
corollary machines_implies_cbvs:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
  assumes a: "<e, []> \<mapsto>* <e', []>"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   149
  shows "e \<longrightarrow>cbv* e'"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   150
using a by (auto dest: machines_implies_cbvs_ctx)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   151
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   152
text {*
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   153
  We now want to relate the cbv-reduction to the evaluation
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   154
  relation. For this we need two auxiliary lemmas. *}
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   155
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   156
lemma eval_val:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   157
  assumes a: "val t"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   158
  shows "t \<Down> t"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   159
using a by (induct) (auto)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   160
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   161
lemma e_App_elim:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   162
  assumes a: "App t1 t2 \<Down> v"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   163
  shows "\<exists>x t v'. t1 \<Down> Lam [x].t \<and> t2 \<Down> v' \<and> t[x::=v'] \<Down> v"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   164
using a by (cases) (auto simp add: lam.eq_iff lam.distinct) 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   165
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   166
text {******************************************************************
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   167
  
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   168
  10.) Exercise
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   169
  -------------
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   170
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   171
  Complete the first case in the proof below. 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   172
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   173
*}
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   174
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   175
lemma cbv_eval:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   176
  assumes a: "t1 \<longrightarrow>cbv t2" "t2 \<Down> t3"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   177
  shows "t1 \<Down> t3"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   178
using a
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   179
proof(induct arbitrary: t3)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   180
  case (cbv1 v x t t3)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   181
  have a1: "val v" by fact
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   182
  have a2: "t[x ::= v] \<Down> t3" by fact
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   183
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   184
  show "App (Lam [x].t) v \<Down> t3" sorry
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   185
next
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   186
  case (cbv2 t t' t2 t3)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   187
  have ih: "\<And>t3. t' \<Down> t3 \<Longrightarrow> t \<Down> t3" by fact
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   188
  have "App t' t2 \<Down> t3" by fact
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   189
  then obtain x t'' v' 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   190
    where a1: "t' \<Down> Lam [x].t''" 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   191
      and a2: "t2 \<Down> v'" 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   192
      and a3: "t''[x ::= v'] \<Down> t3" using e_App_elim by blast
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   193
  have "t \<Down>  Lam [x].t''" using ih a1 by auto 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   194
  then show "App t t2 \<Down> t3" using a2 a3 by auto
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   195
qed (auto dest!: e_App_elim)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   196
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   197
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   198
text {* 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   199
  Next we extend the lemma above to arbitray initial
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   200
  sequences of cbv-reductions. *}
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   201
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   202
lemma cbvs_eval:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   203
  assumes a: "t1 \<longrightarrow>cbv* t2" "t2 \<Down> t3"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   204
  shows "t1 \<Down> t3"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   205
using a by (induct) (auto intro: cbv_eval)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   206
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   207
text {* 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   208
  Finally, we can show that if from a term t we reach a value 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   209
  by a cbv-reduction sequence, then t evaluates to this value. *}
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   210
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   211
lemma cbvs_implies_eval:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   212
  assumes a: "t \<longrightarrow>cbv* v" "val v"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   213
  shows "t \<Down> v"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   214
using a
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   215
by (induct) (auto intro: eval_val cbvs_eval)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   216
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   217
text {* 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   218
  All facts tied together give us the desired property about
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   219
  K machines. *}
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   220
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   221
theorem machines_implies_eval:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   222
  assumes a: "<t1, []> \<mapsto>* <t2, []>" 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   223
  and     b: "val t2" 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   224
  shows "t1 \<Down> t2"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   225
proof -
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   226
  have "t1 \<longrightarrow>cbv* t2" using a by (simp add: machines_implies_cbvs)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   227
  then show "t1 \<Down> t2" using b by (simp add: cbvs_implies_eval)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   228
qed
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   229
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   230
lemma valid_elim:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   231
  assumes a: "valid ((x, T) # \<Gamma>)"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   232
  shows "atom x \<sharp> \<Gamma> \<and> valid \<Gamma>"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   233
using a by (cases) (auto)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   234
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   235
lemma valid_insert:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   236
  assumes a: "valid (\<Delta> @ [(x, T)] @ \<Gamma>)"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   237
  shows "valid (\<Delta> @ \<Gamma>)" 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   238
using a
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   239
by (induct \<Delta>)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   240
   (auto simp add: fresh_append fresh_Cons dest!: valid_elim)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   241
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   242
lemma fresh_list: 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   243
  shows "atom y \<sharp> xs = (\<forall>x \<in> set xs. atom y \<sharp> x)"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   244
by (induct xs) (simp_all add: fresh_Nil fresh_Cons)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   245
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   246
lemma context_unique:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   247
  assumes a1: "valid \<Gamma>"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   248
  and     a2: "(x, T) \<in> set \<Gamma>"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   249
  and     a3: "(x, U) \<in> set \<Gamma>"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   250
  shows "T = U" 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   251
using a1 a2 a3
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   252
by (induct) (auto simp add: fresh_list fresh_Pair fresh_at_base)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   253
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   254
lemma type_substitution_aux:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   255
  assumes a: "(\<Delta> @ [(x, T')] @ \<Gamma>) \<turnstile> e : T"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   256
  and     b: "\<Gamma> \<turnstile> e' : T'"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   257
  shows "(\<Delta> @ \<Gamma>) \<turnstile> e[x ::= e'] : T" 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   258
using a b 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   259
proof (nominal_induct \<Gamma>'\<equiv>"\<Delta> @ [(x, T')] @ \<Gamma>" e T avoiding: x e' \<Delta> rule: typing.strong_induct)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   260
  case (t_Var y T x e' \<Delta>)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   261
  have a1: "valid (\<Delta> @ [(x, T')] @ \<Gamma>)" by fact
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   262
  have a2: "(y,T) \<in> set (\<Delta> @ [(x, T')] @ \<Gamma>)" by fact 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   263
  have a3: "\<Gamma> \<turnstile> e' : T'" by fact
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   264
  from a1 have a4: "valid (\<Delta> @ \<Gamma>)" by (rule valid_insert)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   265
  { assume eq: "x = y"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   266
    from a1 a2 have "T = T'" using eq by (auto intro: context_unique)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   267
    with a3 have "\<Delta> @ \<Gamma> \<turnstile> Var y[x::=e'] : T" using eq a4 by (auto intro: weakening)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   268
  }
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   269
  moreover
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   270
  { assume ineq: "x \<noteq> y"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   271
    from a2 have "(y, T) \<in> set (\<Delta> @ \<Gamma>)" using ineq by simp
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   272
    then have "\<Delta> @ \<Gamma> \<turnstile> Var y[x::=e'] : T" using ineq a4 by auto
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   273
  }
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   274
  ultimately show "\<Delta> @ \<Gamma> \<turnstile> Var y[x::=e'] : T" by blast
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   275
qed (force simp add: fresh_append fresh_Cons)+
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   276
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   277
corollary type_substitution:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   278
  assumes a: "(x,T') # \<Gamma> \<turnstile> e : T"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   279
  and     b: "\<Gamma> \<turnstile> e' : T'"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   280
  shows "\<Gamma> \<turnstile> e[x::=e'] : T"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   281
using a b type_substitution_aux[where \<Delta>="[]"]
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   282
by (auto)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   283
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   284
lemma t_App_elim:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   285
  assumes a: "\<Gamma> \<turnstile> App t1 t2 : T"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   286
  shows "\<exists>T'. \<Gamma> \<turnstile> t1 : T' \<rightarrow> T \<and> \<Gamma> \<turnstile> t2 : T'"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   287
using a
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   288
by (cases) (auto simp add: lam.eq_iff lam.distinct)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   289
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   290
lemma t_Lam_elim:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   291
  assumes ty: "\<Gamma> \<turnstile> Lam [x].t : T" 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   292
  and     fc: "atom x \<sharp> \<Gamma>" 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   293
  shows "\<exists>T1 T2. T = T1 \<rightarrow> T2 \<and> (x, T1) # \<Gamma> \<turnstile> t : T2"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   294
using ty fc
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   295
apply(cases)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   296
apply(auto simp add: lam.eq_iff lam.distinct ty.eq_iff)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   297
apply(auto simp add: Abs1_eq_iff)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   298
apply(rule_tac p="(x \<leftrightarrow> xa)" in permute_boolE)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   299
apply(perm_simp)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   300
apply(simp add: flip_def swap_fresh_fresh ty_fresh)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   301
done
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   302
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   303
theorem cbv_type_preservation:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   304
  assumes a: "t \<longrightarrow>cbv t'"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   305
  and     b: "\<Gamma> \<turnstile> t : T" 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   306
  shows "\<Gamma> \<turnstile> t' : T"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   307
using a b
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   308
by (nominal_induct avoiding: \<Gamma> T rule: cbv.strong_induct)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   309
   (auto dest!: t_Lam_elim t_App_elim simp add: type_substitution ty.eq_iff)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   310
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   311
corollary cbvs_type_preservation:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   312
  assumes a: "t \<longrightarrow>cbv* t'"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   313
  and     b: "\<Gamma> \<turnstile> t : T" 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   314
  shows "\<Gamma> \<turnstile> t' : T"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   315
using a b
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   316
by (induct) (auto intro: cbv_type_preservation)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   317
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   318
text {* 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   319
  The Type-Preservation Property for the Machine and Evaluation Relation. *}
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   320
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   321
theorem machine_type_preservation:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   322
  assumes a: "<t, []> \<mapsto>* <t', []>"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   323
  and     b: "\<Gamma> \<turnstile> t : T" 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   324
  shows "\<Gamma> \<turnstile> t' : T"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   325
proof -
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   326
  from a have "t \<longrightarrow>cbv* t'" by (simp add: machines_implies_cbvs)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   327
  then show "\<Gamma> \<turnstile> t' : T" using b by (simp add: cbvs_type_preservation)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   328
qed
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   329
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   330
theorem eval_type_preservation:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   331
  assumes a: "t \<Down> t'"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   332
  and     b: "\<Gamma> \<turnstile> t : T" 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   333
  shows "\<Gamma> \<turnstile> t' : T"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   334
proof -
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   335
  from a have "<t, []> \<mapsto>* <t', []>" by (simp add: eval_implies_machines)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   336
  then show "\<Gamma> \<turnstile> t' : T" using b by (simp add: machine_type_preservation)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   337
qed
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   338
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   339
text {* The Progress Property *}
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   340
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   341
lemma canonical_tArr:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   342
  assumes a: "[] \<turnstile> t : T1 \<rightarrow> T2"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   343
  and     b: "val t"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   344
  shows "\<exists>x t'. t = Lam [x].t'"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   345
using b a by (induct) (auto) 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   346
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   347
theorem progress:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   348
  assumes a: "[] \<turnstile> t : T"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   349
  shows "(\<exists>t'. t \<longrightarrow>cbv t') \<or> (val t)"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   350
using a
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   351
by (induct \<Gamma>\<equiv>"[]::ty_ctx" t T)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   352
   (auto intro: cbv.intros dest!: canonical_tArr)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   353
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   354