Tutorial/Tutorial4.thy
author Christian Urban <urbanc@in.tum.de>
Fri, 21 Jan 2011 21:58:51 +0100
changeset 2689 ddc05a611005
parent 2687 d0fb94035969
child 2691 abb6c3ac2df2
permissions -rw-r--r--
added unbind example
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
theory Tutorial4
2689
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
     2
imports Tutorial1 Tutorial2
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
begin
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
section {* The CBV Reduction Relation (Small-Step Semantics) *}
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
text {*
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
  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
     9
  calculates a nomrmalform that corresponds to the evaluation 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
  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
    11
*}
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
inductive
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
  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
    15
where
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
  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
    17
| 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
    18
| 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
    19
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
equivariance val
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
equivariance cbv
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
nominal_inductive cbv
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
  avoids cbv1: "x"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
  unfolding fresh_star_def
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
  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
    26
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
text {*
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
  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
    29
  this relation with the additional freshness constraint
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
  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
    31
  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
    32
  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
    33
  usual rule. 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
*}
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
lemma subst_rename: 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
  assumes a: "atom y \<sharp> t"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
  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
    39
using a 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
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
    41
   (auto simp add: lam.fresh fresh_at_base)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
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
lemma better_cbv1 [intro]: 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
  assumes a: "val v" 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
  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
    47
proof -
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
  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
    49
  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
    50
    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
    51
  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
    52
  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
    53
  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
    54
qed
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
text {*
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
  The transitive closure of the cbv-reduction relation: 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
*}
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
inductive 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
  "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
    62
where
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
  cbvs1[intro]: "e \<longrightarrow>cbv* e"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
| 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
    65
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
lemma cbvs3 [intro]:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
  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
    68
  shows "e1 \<longrightarrow>cbv* e3"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
using a by (induct) (auto) 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
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
subsection {* EXERCISE 8 *}
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
text {*  
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
  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
    76
*}
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
lemma cbv_in_ctx:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
  assumes a: "t \<longrightarrow>cbv t'"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
  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
    81
using a
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
proof (induct E)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
  case Hole
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
  have "t \<longrightarrow>cbv t'" by fact
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
  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
    86
next
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
  case (CAppL E s)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
  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
    89
  moreover
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
  have "t \<longrightarrow>cbv t'" by fact
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
  ultimately 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
  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
    93
  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
    94
next
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
  case (CAppR s E)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
  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
    97
  moreover
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
  have a: "t \<longrightarrow>cbv t'" by fact
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
  ultimately 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
  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
   101
  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
   102
qed
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
section {* EXERCISE 9 *} 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
text {*
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
  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
   108
  establish the follwoing property:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
*}
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
lemma machine_implies_cbvs_ctx:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
  assumes a: "<e, Es> \<mapsto> <e', Es'>"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
  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
   114
using a 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
proof (induct)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
  case (m1 t1 t2 Es)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
  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
   119
next
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
  case (m2 v t2 Es)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
  have "val v" by fact
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
  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
   124
next
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
  case (m3 v x t Es)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
  have "val v" by fact
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
  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
   129
qed
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
text {* 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
  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
   133
  arbitrary reductions sequences of the CK machine. *}
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
lemma machines_implies_cbvs_ctx:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
  assumes a: "<e, Es> \<mapsto>* <e', Es'>"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
  shows "(Es\<down>)\<lbrakk>e\<rbrakk> \<longrightarrow>cbv* (Es'\<down>)\<lbrakk>e'\<rbrakk>"
2689
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   138
using a machine_implies_cbvs_ctx 
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   139
by (induct) (blast)+
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   141
text {* 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
  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
   143
  state and it arrives at a final state, then there exists
2689
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   144
  a corresponding cbv-reduction sequence. 
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   145
*}
2687
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'"
2689
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   150
proof - 
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   151
  have "[]\<down>\<lbrakk>e\<rbrakk> \<longrightarrow>cbv* []\<down>\<lbrakk>e'\<rbrakk>" 
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   152
     using a machines_implies_cbvs_ctx by blast
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   153
  then show "e \<longrightarrow>cbv* e'" by simp  
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   154
qed
2687
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
text {*
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   157
  We now want to relate the cbv-reduction to the evaluation
2689
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   158
  relation. For this we need two auxiliary lemmas. 
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   159
*}
2687
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 eval_val:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   162
  assumes a: "val t"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   163
  shows "t \<Down> t"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   164
using a by (induct) (auto)
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
lemma e_App_elim:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   167
  assumes a: "App t1 t2 \<Down> v"
2689
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   168
  obtains x t v' where "t1 \<Down> Lam [x].t" "t2 \<Down> v'" "t[x::=v'] \<Down> v"
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   169
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
   170
2689
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   171
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   172
subsection {* EXERCISE *}
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   173
2689
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   174
text {*
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   175
  Complete the first and second case in the 
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   176
  proof below. 
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   177
*}
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   178
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   179
lemma cbv_eval:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   180
  assumes a: "t1 \<longrightarrow>cbv t2" "t2 \<Down> t3"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   181
  shows "t1 \<Down> t3"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   182
using a
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   183
proof(induct arbitrary: t3)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   184
  case (cbv1 v x t t3)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   185
  have a1: "val v" by fact
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   186
  have a2: "t[x ::= v] \<Down> t3" by fact
2689
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   187
  have a3: "Lam [x].t \<Down> Lam [x].t" by auto
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   188
  have a4: "v \<Down> v" using a1 eval_val by auto
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   189
  show "App (Lam [x].t) v \<Down> t3" using a3 a4 a2 by auto 
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   190
next
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   191
  case (cbv2 t t' t2 t3)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   192
  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
   193
  have "App t' t2 \<Down> t3" by fact
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   194
  then obtain x t'' v' 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   195
    where a1: "t' \<Down> Lam [x].t''" 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   196
      and a2: "t2 \<Down> v'" 
2689
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   197
      and a3: "t''[x ::= v'] \<Down> t3" by (rule e_App_elim) 
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   198
  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
   199
  then show "App t t2 \<Down> t3" using a2 a3 by auto
2689
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   200
qed (auto elim!: e_App_elim)
2687
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
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   203
text {* 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   204
  Next we extend the lemma above to arbitray initial
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   205
  sequences of cbv-reductions. *}
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
lemma cbvs_eval:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   208
  assumes a: "t1 \<longrightarrow>cbv* t2" "t2 \<Down> t3"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   209
  shows "t1 \<Down> t3"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   210
using a by (induct) (auto intro: cbv_eval)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   211
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   212
text {* 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   213
  Finally, we can show that if from a term t we reach a value 
2689
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   214
  by a cbv-reduction sequence, then t evaluates to this value. 
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   215
*}
2687
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
lemma cbvs_implies_eval:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   218
  assumes a: "t \<longrightarrow>cbv* v" "val v"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   219
  shows "t \<Down> v"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   220
using a
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   221
by (induct) (auto intro: eval_val cbvs_eval)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   222
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   223
text {* 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   224
  All facts tied together give us the desired property about
2689
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   225
  machines. 
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   226
*}
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   227
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   228
theorem machines_implies_eval:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   229
  assumes a: "<t1, []> \<mapsto>* <t2, []>" 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   230
  and     b: "val t2" 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   231
  shows "t1 \<Down> t2"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   232
proof -
2689
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   233
  have "t1 \<longrightarrow>cbv* t2" using a machines_implies_cbvs by simp
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   234
  then show "t1 \<Down> t2" using b cbvs_implies_eval by simp
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   235
qed
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   236
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   237
lemma valid_elim:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   238
  assumes a: "valid ((x, T) # \<Gamma>)"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   239
  shows "atom x \<sharp> \<Gamma> \<and> valid \<Gamma>"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   240
using a by (cases) (auto)
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 valid_insert:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   243
  assumes a: "valid (\<Delta> @ [(x, T)] @ \<Gamma>)"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   244
  shows "valid (\<Delta> @ \<Gamma>)" 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   245
using a
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   246
by (induct \<Delta>)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   247
   (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
   248
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   249
lemma fresh_list: 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   250
  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
   251
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
   252
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   253
lemma context_unique:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   254
  assumes a1: "valid \<Gamma>"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   255
  and     a2: "(x, T) \<in> set \<Gamma>"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   256
  and     a3: "(x, U) \<in> set \<Gamma>"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   257
  shows "T = U" 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   258
using a1 a2 a3
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   259
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
   260
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   261
lemma type_substitution_aux:
2689
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   262
  assumes a: "\<Delta> @ [(x, T')] @ \<Gamma> \<turnstile> e : T"
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   263
  and     b: "\<Gamma> \<turnstile> e' : T'"
2689
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   264
  shows "\<Delta> @ \<Gamma> \<turnstile> e[x ::= e'] : T" 
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   265
using a b 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   266
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
   267
  case (t_Var y T x e' \<Delta>)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   268
  have a1: "valid (\<Delta> @ [(x, T')] @ \<Gamma>)" by fact
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   269
  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
   270
  have a3: "\<Gamma> \<turnstile> e' : T'" by fact
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   271
  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
   272
  { assume eq: "x = y"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   273
    from a1 a2 have "T = T'" using eq by (auto intro: context_unique)
2689
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   274
    with a3 have "\<Delta> @ \<Gamma> \<turnstile> Var y[x ::= e'] : T" using eq a4 by (auto intro: weakening)
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   275
  }
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   276
  moreover
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   277
  { assume ineq: "x \<noteq> y"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   278
    from a2 have "(y, T) \<in> set (\<Delta> @ \<Gamma>)" using ineq by simp
2689
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   279
    then have "\<Delta> @ \<Gamma> \<turnstile> Var y[x ::= e'] : T" using ineq a4 by auto
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   280
  }
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   281
  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
   282
qed (force simp add: fresh_append fresh_Cons)+
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
corollary type_substitution:
2689
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   285
  assumes a: "(x, T') # \<Gamma> \<turnstile> e : T"
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   286
  and     b: "\<Gamma> \<turnstile> e' : T'"
2689
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   287
  shows "\<Gamma> \<turnstile> e[x ::= e'] : T"
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   288
using a b type_substitution_aux[where \<Delta>="[]"]
2689
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   289
by auto
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   290
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   291
lemma t_App_elim:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   292
  assumes a: "\<Gamma> \<turnstile> App t1 t2 : T"
2689
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   293
  obtains T' where "\<Gamma> \<turnstile> t1 : T' \<rightarrow> T" "\<Gamma> \<turnstile> t2 : T'"
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   294
using a
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   295
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
   296
2689
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   297
text {* we have not yet generated strong elimination rules *}
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   298
lemma t_Lam_elim:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   299
  assumes ty: "\<Gamma> \<turnstile> Lam [x].t : T" 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   300
  and     fc: "atom x \<sharp> \<Gamma>" 
2689
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   301
  obtains T1 T2 where "T = T1 \<rightarrow> T2" "(x, T1) # \<Gamma> \<turnstile> t : T2"
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   302
using ty fc
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   303
apply(cases)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   304
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
   305
apply(auto simp add: Abs1_eq_iff)
2689
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   306
apply(rotate_tac 3)
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   307
apply(drule_tac p="(x \<leftrightarrow> xa)" in permute_boolI)
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   308
apply(perm_simp)
2689
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   309
apply(auto simp add: flip_def swap_fresh_fresh ty_fresh)
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   310
done
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   311
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   312
theorem cbv_type_preservation:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   313
  assumes a: "t \<longrightarrow>cbv t'"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   314
  and     b: "\<Gamma> \<turnstile> t : T" 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   315
  shows "\<Gamma> \<turnstile> t' : T"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   316
using a b
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   317
by (nominal_induct avoiding: \<Gamma> T rule: cbv.strong_induct)
2689
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   318
   (auto elim!: t_Lam_elim t_App_elim simp add: type_substitution ty.eq_iff)
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   319
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   320
corollary cbvs_type_preservation:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   321
  assumes a: "t \<longrightarrow>cbv* t'"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   322
  and     b: "\<Gamma> \<turnstile> t : T" 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   323
  shows "\<Gamma> \<turnstile> t' : T"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   324
using a b
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   325
by (induct) (auto intro: cbv_type_preservation)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   326
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   327
text {* 
2689
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   328
  The type-preservation property for the machine and 
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   329
  evaluation relation. 
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   330
*}
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   331
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   332
theorem machine_type_preservation:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   333
  assumes a: "<t, []> \<mapsto>* <t', []>"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   334
  and     b: "\<Gamma> \<turnstile> t : T" 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   335
  shows "\<Gamma> \<turnstile> t' : T"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   336
proof -
2689
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   337
  have "t \<longrightarrow>cbv* t'" using a machines_implies_cbvs by simp
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   338
  then show "\<Gamma> \<turnstile> t' : T" using b cbvs_type_preservation by simp
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   339
qed
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
theorem eval_type_preservation:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   342
  assumes a: "t \<Down> t'"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   343
  and     b: "\<Gamma> \<turnstile> t : T" 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   344
  shows "\<Gamma> \<turnstile> t' : T"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   345
proof -
2689
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   346
  have "<t, []> \<mapsto>* <t', []>" using a eval_implies_machines by simp
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   347
  then show "\<Gamma> \<turnstile> t' : T" using b machine_type_preservation by simp
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   348
qed
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   349
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   350
text {* The Progress Property *}
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   351
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   352
lemma canonical_tArr:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   353
  assumes a: "[] \<turnstile> t : T1 \<rightarrow> T2"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   354
  and     b: "val t"
2689
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   355
  obtains x t' where "t = Lam [x].t'"
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   356
using b a by (induct) (auto) 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   357
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   358
theorem progress:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   359
  assumes a: "[] \<turnstile> t : T"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   360
  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
   361
using a
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   362
by (induct \<Gamma>\<equiv>"[]::ty_ctx" t T)
2689
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   363
   (auto elim: canonical_tArr)
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   364
2689
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   365
text {*
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   366
  Done!
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   367
*}
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   368
2689
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   369
end
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   370