Tutorial/Tutorial4.thy
author Christian Urban <urbanc@in.tum.de>
Sat, 22 Jan 2011 16:37:00 -0600
changeset 2700 e0391947b7da
parent 2693 2abc8cb46a5c
child 2701 7b2691911fbc
permissions -rw-r--r--
merged
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2691
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents: 2689
diff changeset
     1
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
theory Tutorial4
2691
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents: 2689
diff changeset
     3
imports Tutorial1 Tutorial2 Tutorial3
2687
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
2693
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
     8
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
     9
inductive
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    10
  cbv :: "lam \<Rightarrow> lam \<Rightarrow> bool" ("_ \<longrightarrow>cbv _" [60, 60] 60) 
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    11
where
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    12
  cbv1: "\<lbrakk>val v; atom x \<sharp> v\<rbrakk> \<Longrightarrow> App (Lam [x].t) v \<longrightarrow>cbv t[x ::= v]"
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    13
| cbv2: "t \<longrightarrow>cbv t' \<Longrightarrow> App t t2 \<longrightarrow>cbv App t' t2"
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    14
| cbv3: "t \<longrightarrow>cbv t' \<Longrightarrow> App t2 t \<longrightarrow>cbv App t2 t'"
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    15
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    16
inductive 
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    17
  "cbv_star" :: "lam \<Rightarrow> lam \<Rightarrow> bool" (" _ \<longrightarrow>cbv* _" [60, 60] 60)
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    18
where
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    19
  cbvs1: "e \<longrightarrow>cbv* e"
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    20
| cbvs2: "\<lbrakk>e1\<longrightarrow>cbv e2; e2 \<longrightarrow>cbv* e3\<rbrakk> \<Longrightarrow> e1 \<longrightarrow>cbv* e3"
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    21
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    22
declare cbv.intros[intro] cbv_star.intros[intro]
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    23
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    24
subsection {* EXERCISE 3 *}
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    25
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    26
text {*
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    27
  Show that cbv* is transitive, by filling the gaps in the 
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    28
  proof below.
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    29
*}
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    30
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    31
lemma 
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    32
  assumes a: "e1 \<longrightarrow>cbv* e2" "e2 \<longrightarrow>cbv* e3"
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    33
  shows "e1 \<longrightarrow>cbv* e3"
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    34
using a 
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    35
proof (induct) 
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    36
  case (cbvs1 e1)
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    37
  have asm: "e1 \<longrightarrow>cbv* e3" by fact
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    38
  show "e1 \<longrightarrow>cbv* e3" sorry
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    39
next
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    40
  case (cbvs2 e1 e2 e3')
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    41
  have "e1 \<longrightarrow>cbv e2" by fact
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    42
  have "e2 \<longrightarrow>cbv* e3'" by fact
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    43
  have "e3' \<longrightarrow>cbv* e3 \<Longrightarrow> e2 \<longrightarrow>cbv* e3" by fact
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    44
  have "e3' \<longrightarrow>cbv* e3" by fact
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    45
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    46
  show "e1 \<longrightarrow>cbv* e3" sorry
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    47
qed 
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    48
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    49
lemma cbvs3 [intro]:
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    50
  assumes a: "e1 \<longrightarrow>cbv* e2" "e2 \<longrightarrow>cbv* e3"
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    51
  shows "e1 \<longrightarrow>cbv* e3"
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    52
using a by (induct) (auto) 
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    53
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    54
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    55
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    56
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    57
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
text {*
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
  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
    60
  calculates a nomrmalform that corresponds to the evaluation 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
  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
    62
*}
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
equivariance val
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
equivariance cbv
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
nominal_inductive cbv
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
  avoids cbv1: "x"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
  unfolding fresh_star_def
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
  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
    71
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
text {*
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
  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
    74
  this relation with the additional freshness constraint
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
  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
    76
  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
    77
  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
    78
  usual rule. 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
*}
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
lemma subst_rename: 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
  assumes a: "atom y \<sharp> t"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
  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
    84
using a 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
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
    86
   (auto simp add: lam.fresh fresh_at_base)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
lemma better_cbv1 [intro]: 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
  assumes a: "val v" 
2693
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
    91
  shows "App (Lam [x].t) v \<longrightarrow>cbv t[x ::= v]"
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
proof -
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
  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
    94
  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
    95
    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
    96
  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
    97
  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
    98
  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
    99
qed
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
text {*
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
  The transitive closure of the cbv-reduction relation: 
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
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
2693
2abc8cb46a5c better version of Tutorial 1
Christian Urban <urbanc@in.tum.de>
parents: 2691
diff changeset
   106
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
subsection {* EXERCISE 8 *}
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
text {*  
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
  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
   113
*}
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
lemma cbv_in_ctx:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
  assumes a: "t \<longrightarrow>cbv t'"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
  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
   118
using a
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
proof (induct E)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
  case Hole
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
  have "t \<longrightarrow>cbv t'" by fact
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
  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
   123
next
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
  case (CAppL E s)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
  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
   126
  moreover
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
  have "t \<longrightarrow>cbv t'" by fact
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
  ultimately 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
  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
   130
  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
   131
next
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
  case (CAppR s E)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
  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
   134
  moreover
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
  have a: "t \<longrightarrow>cbv t'" by fact
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
  ultimately 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
  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
   138
  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
   139
qed
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
section {* EXERCISE 9 *} 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   143
text {*
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   144
  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
   145
  establish the follwoing property:
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
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
lemma machine_implies_cbvs_ctx:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   149
  assumes a: "<e, Es> \<mapsto> <e', Es'>"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   150
  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
   151
using a 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   152
proof (induct)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   153
  case (m1 t1 t2 Es)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   154
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   155
  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
   156
next
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   157
  case (m2 v t2 Es)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   158
  have "val v" by fact
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   159
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   160
  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
   161
next
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   162
  case (m3 v x t Es)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   163
  have "val v" by fact
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   164
 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   165
  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
   166
qed
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
text {* 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   169
  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
   170
  arbitrary reductions sequences of the CK machine. *}
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   171
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   172
lemma machines_implies_cbvs_ctx:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   173
  assumes a: "<e, Es> \<mapsto>* <e', Es'>"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   174
  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
   175
using a machine_implies_cbvs_ctx 
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   176
by (induct) (blast)+
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
text {* 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   179
  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
   180
  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
   181
  a corresponding cbv-reduction sequence. 
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   182
*}
2687
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
corollary machines_implies_cbvs:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   185
  assumes a: "<e, []> \<mapsto>* <e', []>"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   186
  shows "e \<longrightarrow>cbv* e'"
2689
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   187
proof - 
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   188
  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
   189
     using a machines_implies_cbvs_ctx by blast
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   190
  then show "e \<longrightarrow>cbv* e'" by simp  
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   191
qed
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   192
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   193
text {*
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   194
  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
   195
  relation. For this we need two auxiliary lemmas. 
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   196
*}
2687
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
lemma eval_val:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   199
  assumes a: "val t"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   200
  shows "t \<Down> t"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   201
using a by (induct) (auto)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   202
2691
abb6c3ac2df2 separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents: 2689
diff changeset
   203
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   204
lemma e_App_elim:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   205
  assumes a: "App t1 t2 \<Down> v"
2689
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   206
  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
   207
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
   208
2689
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   209
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   210
subsection {* EXERCISE *}
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   211
2689
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   212
text {*
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   213
  Complete the first and second case in the 
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   214
  proof below. 
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   215
*}
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 cbv_eval:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   218
  assumes a: "t1 \<longrightarrow>cbv t2" "t2 \<Down> t3"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   219
  shows "t1 \<Down> t3"
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
proof(induct arbitrary: t3)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   222
  case (cbv1 v x t t3)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   223
  have a1: "val v" by fact
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   224
  have a2: "t[x ::= v] \<Down> t3" by fact
2689
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   225
  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
   226
  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
   227
  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
   228
next
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   229
  case (cbv2 t t' t2 t3)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   230
  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
   231
  have "App t' t2 \<Down> t3" by fact
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   232
  then obtain x t'' v' 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   233
    where a1: "t' \<Down> Lam [x].t''" 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   234
      and a2: "t2 \<Down> v'" 
2689
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   235
      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
   236
  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
   237
  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
   238
qed (auto elim!: e_App_elim)
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   239
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   240
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   241
text {* 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   242
  Next we extend the lemma above to arbitray initial
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   243
  sequences of cbv-reductions. *}
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   244
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   245
lemma cbvs_eval:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   246
  assumes a: "t1 \<longrightarrow>cbv* t2" "t2 \<Down> t3"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   247
  shows "t1 \<Down> t3"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   248
using a by (induct) (auto intro: cbv_eval)
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   249
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   250
text {* 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   251
  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
   252
  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
   253
*}
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   254
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   255
lemma cbvs_implies_eval:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   256
  assumes a: "t \<longrightarrow>cbv* v" "val v"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   257
  shows "t \<Down> v"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   258
using a
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   259
by (induct) (auto intro: eval_val cbvs_eval)
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
text {* 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   262
  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
   263
  machines. 
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   264
*}
2687
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   265
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   266
theorem machines_implies_eval:
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   267
  assumes a: "<t1, []> \<mapsto>* <t2, []>" 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   268
  and     b: "val t2" 
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   269
  shows "t1 \<Down> t2"
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   270
proof -
2689
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   271
  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
   272
  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
   273
qed
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   274
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
d0fb94035969 first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   277
2689
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   278
end
ddc05a611005 added unbind example
Christian Urban <urbanc@in.tum.de>
parents: 2687
diff changeset
   279