author | Christian Urban <urbanc@in.tum.de> |
Fri, 21 Jan 2011 22:23:44 +0100 | |
changeset 2691 | abb6c3ac2df2 |
parent 2689 | ddc05a611005 |
child 2693 | 2abc8cb46a5c |
child 2705 | 67451725fb41 |
permissions | -rw-r--r-- |
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 |
|
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
8 |
text {* |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
9 |
In order to help establishing the property that the CK Machine |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
10 |
calculates a nomrmalform that corresponds to the evaluation |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
11 |
relation, we introduce the call-by-value small-step semantics. |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
12 |
*} |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
13 |
|
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
14 |
inductive |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
15 |
cbv :: "lam \<Rightarrow> lam \<Rightarrow> bool" ("_ \<longrightarrow>cbv _" [60, 60] 60) |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
16 |
where |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
17 |
cbv1: "\<lbrakk>val v; atom x \<sharp> v\<rbrakk> \<Longrightarrow> App (Lam [x].t) v \<longrightarrow>cbv t[x ::= v]" |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
18 |
| cbv2[intro]: "t \<longrightarrow>cbv t' \<Longrightarrow> App t t2 \<longrightarrow>cbv App t' t2" |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
19 |
| cbv3[intro]: "t \<longrightarrow>cbv t' \<Longrightarrow> App t2 t \<longrightarrow>cbv App t2 t'" |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
20 |
|
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
21 |
equivariance val |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
22 |
equivariance cbv |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
23 |
nominal_inductive cbv |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
24 |
avoids cbv1: "x" |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
25 |
unfolding fresh_star_def |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
26 |
by (simp_all add: lam.fresh Abs_fresh_iff fresh_Pair fresh_fact) |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
27 |
|
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
28 |
text {* |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
29 |
In order to satisfy the vc-condition we have to formulate |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
30 |
this relation with the additional freshness constraint |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
31 |
atom x \<sharp> v. Although this makes the definition vc-ompatible, it |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
32 |
makes the definition less useful. We can with a little bit of |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
33 |
pain show that the more restricted rule is equivalent to the |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
34 |
usual rule. |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
35 |
*} |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
36 |
|
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
37 |
lemma subst_rename: |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
38 |
assumes a: "atom y \<sharp> t" |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
39 |
shows "t[x ::= s] = ((y \<leftrightarrow> x) \<bullet> t)[y ::= s]" |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
40 |
using a |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
41 |
by (nominal_induct t avoiding: x y s rule: lam.strong_induct) |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
42 |
(auto simp add: lam.fresh fresh_at_base) |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
43 |
|
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
44 |
|
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
45 |
lemma better_cbv1 [intro]: |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
46 |
assumes a: "val v" |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
47 |
shows "App (Lam [x].t) v \<longrightarrow>cbv t[x::=v]" |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
48 |
proof - |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
49 |
obtain y::"name" where fs: "atom y \<sharp> (x, t, v)" by (rule obtain_fresh) |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
50 |
have "App (Lam [x].t) v = App (Lam [y].((y \<leftrightarrow> x) \<bullet> t)) v" using fs |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
51 |
by (auto simp add: lam.eq_iff Abs1_eq_iff' flip_def fresh_Pair fresh_at_base) |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
52 |
also have "\<dots> \<longrightarrow>cbv ((y \<leftrightarrow> x) \<bullet> t)[y ::= v]" using fs a cbv1 by auto |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
53 |
also have "\<dots> = t[x ::= v]" using fs subst_rename[symmetric] by simp |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
54 |
finally show "App (Lam [x].t) v \<longrightarrow>cbv t[x ::= v]" by simp |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
55 |
qed |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
56 |
|
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
57 |
text {* |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
58 |
The transitive closure of the cbv-reduction relation: |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
59 |
*} |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
60 |
|
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
61 |
inductive |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
62 |
"cbvs" :: "lam \<Rightarrow> lam \<Rightarrow> bool" (" _ \<longrightarrow>cbv* _" [60, 60] 60) |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
63 |
where |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
64 |
cbvs1[intro]: "e \<longrightarrow>cbv* e" |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
65 |
| cbvs2[intro]: "\<lbrakk>e1\<longrightarrow>cbv e2; e2 \<longrightarrow>cbv* e3\<rbrakk> \<Longrightarrow> e1 \<longrightarrow>cbv* e3" |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
66 |
|
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
67 |
lemma cbvs3 [intro]: |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
68 |
assumes a: "e1 \<longrightarrow>cbv* e2" "e2 \<longrightarrow>cbv* e3" |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
69 |
shows "e1 \<longrightarrow>cbv* e3" |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
70 |
using a by (induct) (auto) |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
71 |
|
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
72 |
|
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
73 |
subsection {* EXERCISE 8 *} |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
74 |
|
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
75 |
text {* |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
76 |
If more simple exercises are needed, then complete the following proof. |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
77 |
*} |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
78 |
|
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
79 |
lemma cbv_in_ctx: |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
80 |
assumes a: "t \<longrightarrow>cbv t'" |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
81 |
shows "E\<lbrakk>t\<rbrakk> \<longrightarrow>cbv E\<lbrakk>t'\<rbrakk>" |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
82 |
using a |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
83 |
proof (induct E) |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
84 |
case Hole |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
85 |
have "t \<longrightarrow>cbv t'" by fact |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
86 |
then show "\<box>\<lbrakk>t\<rbrakk> \<longrightarrow>cbv \<box>\<lbrakk>t'\<rbrakk>" by simp |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
87 |
next |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
88 |
case (CAppL E s) |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
89 |
have ih: "t \<longrightarrow>cbv t' \<Longrightarrow> E\<lbrakk>t\<rbrakk> \<longrightarrow>cbv E\<lbrakk>t'\<rbrakk>" by fact |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
90 |
moreover |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
91 |
have "t \<longrightarrow>cbv t'" by fact |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
92 |
ultimately |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
93 |
have "E\<lbrakk>t\<rbrakk> \<longrightarrow>cbv E\<lbrakk>t'\<rbrakk>" by simp |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
94 |
then show "(CAppL E s)\<lbrakk>t\<rbrakk> \<longrightarrow>cbv (CAppL E s)\<lbrakk>t'\<rbrakk>" by auto |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
95 |
next |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
96 |
case (CAppR s E) |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
97 |
have ih: "t \<longrightarrow>cbv t' \<Longrightarrow> E\<lbrakk>t\<rbrakk> \<longrightarrow>cbv E\<lbrakk>t'\<rbrakk>" by fact |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
98 |
moreover |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
99 |
have a: "t \<longrightarrow>cbv t'" by fact |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
100 |
ultimately |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
101 |
have "E\<lbrakk>t\<rbrakk> \<longrightarrow>cbv E\<lbrakk>t'\<rbrakk>" by simp |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
102 |
then show "(CAppR s E)\<lbrakk>t\<rbrakk> \<longrightarrow>cbv (CAppR s E)\<lbrakk>t'\<rbrakk>" by auto |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
103 |
qed |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
104 |
|
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
105 |
section {* EXERCISE 9 *} |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
106 |
|
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
107 |
text {* |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
108 |
The point of the cbv-reduction was that we can easily relatively |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
109 |
establish the follwoing property: |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
110 |
*} |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
111 |
|
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
112 |
lemma machine_implies_cbvs_ctx: |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
113 |
assumes a: "<e, Es> \<mapsto> <e', Es'>" |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
114 |
shows "(Es\<down>)\<lbrakk>e\<rbrakk> \<longrightarrow>cbv* (Es'\<down>)\<lbrakk>e'\<rbrakk>" |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
115 |
using a |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
116 |
proof (induct) |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
117 |
case (m1 t1 t2 Es) |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
118 |
|
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
119 |
show "Es\<down>\<lbrakk>App t1 t2\<rbrakk> \<longrightarrow>cbv* ((CAppL \<box> t2) # Es)\<down>\<lbrakk>t1\<rbrakk>" sorry |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
120 |
next |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
121 |
case (m2 v t2 Es) |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
122 |
have "val v" by fact |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
123 |
|
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
124 |
show "((CAppL \<box> t2) # Es)\<down>\<lbrakk>v\<rbrakk> \<longrightarrow>cbv* (CAppR v \<box> # Es)\<down>\<lbrakk>t2\<rbrakk>" sorry |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
125 |
next |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
126 |
case (m3 v x t Es) |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
127 |
have "val v" by fact |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
128 |
|
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
129 |
show "(((CAppR (Lam [x].t) \<box>) # Es)\<down>)\<lbrakk>v\<rbrakk> \<longrightarrow>cbv* (Es\<down>)\<lbrakk>(t[x ::= v])\<rbrakk>" sorry |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
130 |
qed |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
131 |
|
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
132 |
text {* |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
133 |
It is not difficult to extend the lemma above to |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
134 |
arbitrary reductions sequences of the CK machine. *} |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
135 |
|
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
136 |
lemma machines_implies_cbvs_ctx: |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
137 |
assumes a: "<e, Es> \<mapsto>* <e', Es'>" |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
138 |
shows "(Es\<down>)\<lbrakk>e\<rbrakk> \<longrightarrow>cbv* (Es'\<down>)\<lbrakk>e'\<rbrakk>" |
2689 | 139 |
using a machine_implies_cbvs_ctx |
140 |
by (induct) (blast)+ |
|
2687
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
141 |
|
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
142 |
text {* |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
143 |
So whenever we let the CL machine start in an initial |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
144 |
state and it arrives at a final state, then there exists |
2689 | 145 |
a corresponding cbv-reduction sequence. |
146 |
*} |
|
2687
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 |
corollary machines_implies_cbvs: |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
149 |
assumes a: "<e, []> \<mapsto>* <e', []>" |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
150 |
shows "e \<longrightarrow>cbv* e'" |
2689 | 151 |
proof - |
152 |
have "[]\<down>\<lbrakk>e\<rbrakk> \<longrightarrow>cbv* []\<down>\<lbrakk>e'\<rbrakk>" |
|
153 |
using a machines_implies_cbvs_ctx by blast |
|
154 |
then show "e \<longrightarrow>cbv* e'" by simp |
|
155 |
qed |
|
2687
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
156 |
|
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
157 |
text {* |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
158 |
We now want to relate the cbv-reduction to the evaluation |
2689 | 159 |
relation. For this we need two auxiliary lemmas. |
160 |
*} |
|
2687
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
161 |
|
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
162 |
lemma eval_val: |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
163 |
assumes a: "val t" |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
164 |
shows "t \<Down> t" |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
165 |
using a by (induct) (auto) |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
166 |
|
2691
abb6c3ac2df2
separated type preservation and progress into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
2689
diff
changeset
|
167 |
|
2687
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
168 |
lemma e_App_elim: |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
169 |
assumes a: "App t1 t2 \<Down> v" |
2689 | 170 |
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
|
171 |
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
|
172 |
|
2689 | 173 |
|
174 |
subsection {* EXERCISE *} |
|
2687
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
175 |
|
2689 | 176 |
text {* |
177 |
Complete the first and second case in the |
|
178 |
proof below. |
|
2687
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
179 |
*} |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
180 |
|
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
181 |
lemma cbv_eval: |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
182 |
assumes a: "t1 \<longrightarrow>cbv t2" "t2 \<Down> t3" |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
183 |
shows "t1 \<Down> t3" |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
184 |
using a |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
185 |
proof(induct arbitrary: t3) |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
186 |
case (cbv1 v x t t3) |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
187 |
have a1: "val v" by fact |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
188 |
have a2: "t[x ::= v] \<Down> t3" by fact |
2689 | 189 |
have a3: "Lam [x].t \<Down> Lam [x].t" by auto |
190 |
have a4: "v \<Down> v" using a1 eval_val by auto |
|
191 |
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
|
192 |
next |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
193 |
case (cbv2 t t' t2 t3) |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
194 |
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
|
195 |
have "App t' t2 \<Down> t3" by fact |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
196 |
then obtain x t'' v' |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
197 |
where a1: "t' \<Down> Lam [x].t''" |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
198 |
and a2: "t2 \<Down> v'" |
2689 | 199 |
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
|
200 |
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
|
201 |
then show "App t t2 \<Down> t3" using a2 a3 by auto |
2689 | 202 |
qed (auto elim!: e_App_elim) |
2687
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
203 |
|
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
204 |
|
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
205 |
text {* |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
206 |
Next we extend the lemma above to arbitray initial |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
207 |
sequences of cbv-reductions. *} |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
208 |
|
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
209 |
lemma cbvs_eval: |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
210 |
assumes a: "t1 \<longrightarrow>cbv* t2" "t2 \<Down> t3" |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
211 |
shows "t1 \<Down> t3" |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
212 |
using a by (induct) (auto intro: cbv_eval) |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
213 |
|
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
214 |
text {* |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
215 |
Finally, we can show that if from a term t we reach a value |
2689 | 216 |
by a cbv-reduction sequence, then t evaluates to this value. |
217 |
*} |
|
2687
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
218 |
|
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
219 |
lemma cbvs_implies_eval: |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
220 |
assumes a: "t \<longrightarrow>cbv* v" "val v" |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
221 |
shows "t \<Down> v" |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
222 |
using a |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
223 |
by (induct) (auto intro: eval_val cbvs_eval) |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
224 |
|
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
225 |
text {* |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
226 |
All facts tied together give us the desired property about |
2689 | 227 |
machines. |
228 |
*} |
|
2687
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
229 |
|
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
230 |
theorem machines_implies_eval: |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
231 |
assumes a: "<t1, []> \<mapsto>* <t2, []>" |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
232 |
and b: "val t2" |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
233 |
shows "t1 \<Down> t2" |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
234 |
proof - |
2689 | 235 |
have "t1 \<longrightarrow>cbv* t2" using a machines_implies_cbvs by simp |
236 |
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
|
237 |
qed |
d0fb94035969
first split of tutorrial theory
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
238 |
|
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 |
|
2689 | 242 |
end |
243 |