author | Christian Urban <christian dot urban at kcl dot ac dot uk> |
Fri, 18 Jan 2013 11:40:01 +0000 | |
changeset 48 | 559e5c6e5113 |
parent 47 | 251e192339b7 |
child 60 | c8ff97d9f8da |
permissions | -rw-r--r-- |
47
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
1 |
header {* |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
2 |
{\em abacus} a kind of register machine |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
3 |
*} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
4 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
5 |
theory abacus |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
6 |
imports Main turing_basic |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
7 |
begin |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
8 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
9 |
text {* |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
10 |
{\em Abacus} instructions: |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
11 |
*} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
12 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
13 |
datatype abc_inst = |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
14 |
-- {* @{text "Inc n"} increments the memory cell (or register) with address @{text "n"} by one. |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
15 |
*} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
16 |
Inc nat |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
17 |
-- {* |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
18 |
@{text "Dec n label"} decrements the memory cell with address @{text "n"} by one. |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
19 |
If cell @{text "n"} is already zero, no decrements happens and the executio jumps to |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
20 |
the instruction labeled by @{text "label"}. |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
21 |
*} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
22 |
| Dec nat nat |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
23 |
-- {* |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
24 |
@{text "Goto label"} unconditionally jumps to the instruction labeled by @{text "label"}. |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
25 |
*} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
26 |
| Goto nat |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
27 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
28 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
29 |
text {* |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
30 |
Abacus programs are defined as lists of Abacus instructions. |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
31 |
*} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
32 |
type_synonym abc_prog = "abc_inst list" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
33 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
34 |
section {* |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
35 |
Sample Abacus programs |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
36 |
*} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
37 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
38 |
text {* |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
39 |
Abacus for addition and clearance. |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
40 |
*} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
41 |
fun plus_clear :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> abc_prog" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
42 |
where |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
43 |
"plus_clear m n e = [Dec m e, Inc n, Goto 0]" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
44 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
45 |
text {* |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
46 |
Abacus for clearing memory untis. |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
47 |
*} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
48 |
fun clear :: "nat \<Rightarrow> nat \<Rightarrow> abc_prog" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
49 |
where |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
50 |
"clear n e = [Dec n e, Goto 0]" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
51 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
52 |
fun plus:: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> abc_prog" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
53 |
where |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
54 |
"plus m n p e = [Dec m 4, Inc n, Inc p, |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
55 |
Goto 0, Dec p e, Inc m, Goto 4]" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
56 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
57 |
fun mult :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> abc_prog" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
58 |
where |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
59 |
"mult m1 m2 n p e = [Dec m1 e]@ plus m1 m2 p 1" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
60 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
61 |
fun expo :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> abc_prog" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
62 |
where |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
63 |
"expo n m1 m2 p e = [Inc n, Dec m1 e] @ mult m2 n n p 2" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
64 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
65 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
66 |
text {* |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
67 |
The state of Abacus machine. |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
68 |
*} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
69 |
type_synonym abc_state = nat |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
70 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
71 |
(* text {* |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
72 |
The memory of Abacus machine is defined as a function from address to contents. |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
73 |
*} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
74 |
type_synonym abc_mem = "nat \<Rightarrow> nat" *) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
75 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
76 |
text {* |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
77 |
The memory of Abacus machine is defined as a list of contents, with |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
78 |
every units addressed by index into the list. |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
79 |
*} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
80 |
type_synonym abc_lm = "nat list" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
81 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
82 |
text {* |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
83 |
Fetching contents out of memory. Units not represented by list elements are considered |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
84 |
as having content @{text "0"}. |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
85 |
*} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
86 |
fun abc_lm_v :: "abc_lm \<Rightarrow> nat \<Rightarrow> nat" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
87 |
where |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
88 |
"abc_lm_v lm n = (if (n < length lm) then (lm!n) else 0)" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
89 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
90 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
91 |
text {* |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
92 |
Set the content of memory unit @{text "n"} to value @{text "v"}. |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
93 |
@{text "am"} is the Abacus memory before setting. |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
94 |
If address @{text "n"} is outside to scope of @{text "am"}, @{text "am"} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
95 |
is extended so that @{text "n"} becomes in scope. |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
96 |
*} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
97 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
98 |
fun abc_lm_s :: "abc_lm \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> abc_lm" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
99 |
where |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
100 |
"abc_lm_s am n v = (if (n < length am) then (am[n:=v]) else |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
101 |
am@ (replicate (n - length am) 0) @ [v])" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
102 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
103 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
104 |
text {* |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
105 |
The configuration of Abaucs machines consists of its current state and its |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
106 |
current memory: |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
107 |
*} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
108 |
type_synonym abc_conf = "abc_state \<times> abc_lm" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
109 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
110 |
text {* |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
111 |
Fetch instruction out of Abacus program: |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
112 |
*} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
113 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
114 |
fun abc_fetch :: "nat \<Rightarrow> abc_prog \<Rightarrow> abc_inst option" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
115 |
where |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
116 |
"abc_fetch s p = (if (s < length p) then Some (p ! s) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
117 |
else None)" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
118 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
119 |
text {* |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
120 |
Single step execution of Abacus machine. If no instruction is feteched, |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
121 |
configuration does not change. |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
122 |
*} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
123 |
fun abc_step_l :: "abc_conf \<Rightarrow> abc_inst option \<Rightarrow> abc_conf" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
124 |
where |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
125 |
"abc_step_l (s, lm) a = (case a of |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
126 |
None \<Rightarrow> (s, lm) | |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
127 |
Some (Inc n) \<Rightarrow> (let nv = abc_lm_v lm n in |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
128 |
(s + 1, abc_lm_s lm n (nv + 1))) | |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
129 |
Some (Dec n e) \<Rightarrow> (let nv = abc_lm_v lm n in |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
130 |
if (nv = 0) then (e, abc_lm_s lm n 0) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
131 |
else (s + 1, abc_lm_s lm n (nv - 1))) | |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
132 |
Some (Goto n) \<Rightarrow> (n, lm) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
133 |
)" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
134 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
135 |
text {* |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
136 |
Multi-step execution of Abacus machine. |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
137 |
*} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
138 |
fun abc_steps_l :: "abc_conf \<Rightarrow> abc_prog \<Rightarrow> nat \<Rightarrow> abc_conf" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
139 |
where |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
140 |
"abc_steps_l (s, lm) p 0 = (s, lm)" | |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
141 |
"abc_steps_l (s, lm) p (Suc n) = |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
142 |
abc_steps_l (abc_step_l (s, lm) (abc_fetch s p)) p n" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
143 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
144 |
section {* |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
145 |
Compiling Abacus machines into Truing machines |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
146 |
*} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
147 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
148 |
subsection {* |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
149 |
Compiling functions |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
150 |
*} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
151 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
152 |
text {* |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
153 |
@{text "findnth n"} returns the TM which locates the represention of |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
154 |
memory cell @{text "n"} on the tape and changes representation of zero |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
155 |
on the way. |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
156 |
*} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
157 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
158 |
fun findnth :: "nat \<Rightarrow> instr list" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
159 |
where |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
160 |
"findnth 0 = []" | |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
161 |
"findnth (Suc n) = (findnth n @ [(W1, 2 * n + 1), |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
162 |
(R, 2 * n + 2), (R, 2 * n + 3), (R, 2 * n + 2)])" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
163 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
164 |
text {* |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
165 |
@{text "tinc_b"} returns the TM which increments the representation |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
166 |
of the memory cell under rw-head by one and move the representation |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
167 |
of cells afterwards to the right accordingly. |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
168 |
*} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
169 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
170 |
definition tinc_b :: "instr list" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
171 |
where |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
172 |
"tinc_b \<equiv> [(W1, 1), (R, 2), (W1, 3), (R, 2), (W1, 3), (R, 4), |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
173 |
(L, 7), (W0, 5), (R, 6), (W0, 5), (W1, 3), (R, 6), |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
174 |
(L, 8), (L, 7), (R, 9), (L, 7), (R, 10), (W0, 9)]" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
175 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
176 |
text {* |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
177 |
@{text "tinc ss n"} returns the TM which simulates the execution of |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
178 |
Abacus instruction @{text "Inc n"}, assuming that TM is located at |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
179 |
location @{text "ss"} in the final TM complied from the whole |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
180 |
Abacus program. |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
181 |
*} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
182 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
183 |
fun tinc :: "nat \<Rightarrow> nat \<Rightarrow> instr list" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
184 |
where |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
185 |
"tinc ss n = shift (findnth n @ shift tinc_b (2 * n)) (ss - 1)" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
186 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
187 |
text {* |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
188 |
@{text "tinc_b"} returns the TM which decrements the representation |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
189 |
of the memory cell under rw-head by one and move the representation |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
190 |
of cells afterwards to the left accordingly. |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
191 |
*} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
192 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
193 |
definition tdec_b :: "instr list" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
194 |
where |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
195 |
"tdec_b \<equiv> [(W1, 1), (R, 2), (L, 14), (R, 3), (L, 4), (R, 3), |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
196 |
(R, 5), (W0, 4), (R, 6), (W0, 5), (L, 7), (L, 8), |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
197 |
(L, 11), (W0, 7), (W1, 8), (R, 9), (L, 10), (R, 9), |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
198 |
(R, 5), (W0, 10), (L, 12), (L, 11), (R, 13), (L, 11), |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
199 |
(R, 17), (W0, 13), (L, 15), (L, 14), (R, 16), (L, 14), |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
200 |
(R, 0), (W0, 16)]" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
201 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
202 |
text {* |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
203 |
@{text "sete tp e"} attaches the termination edges (edges leading to state @{text "0"}) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
204 |
of TM @{text "tp"} to the intruction labelled by @{text "e"}. |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
205 |
*} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
206 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
207 |
fun sete :: "instr list \<Rightarrow> nat \<Rightarrow> instr list" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
208 |
where |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
209 |
"sete tp e = map (\<lambda> (action, state). (action, if state = 0 then e else state)) tp" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
210 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
211 |
text {* |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
212 |
@{text "tdec ss n label"} returns the TM which simulates the execution of |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
213 |
Abacus instruction @{text "Dec n label"}, assuming that TM is located at |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
214 |
location @{text "ss"} in the final TM complied from the whole |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
215 |
Abacus program. |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
216 |
*} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
217 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
218 |
fun tdec :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> instr list" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
219 |
where |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
220 |
"tdec ss n e = sete (shift (findnth n @ shift tdec_b (2 * n)) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
221 |
(ss - 1)) e" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
222 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
223 |
text {* |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
224 |
@{text "tgoto f(label)"} returns the TM simulating the execution of Abacus instruction |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
225 |
@{text "Goto label"}, where @{text "f(label)"} is the corresponding location of |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
226 |
@{text "label"} in the final TM compiled from the overall Abacus program. |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
227 |
*} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
228 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
229 |
fun tgoto :: "nat \<Rightarrow> instr list" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
230 |
where |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
231 |
"tgoto n = [(Nop, n), (Nop, n)]" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
232 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
233 |
text {* |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
234 |
The layout of the final TM compiled from an Abacus program is represented |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
235 |
as a list of natural numbers, where the list element at index @{text "n"} represents the |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
236 |
starting state of the TM simulating the execution of @{text "n"}-th instruction |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
237 |
in the Abacus program. |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
238 |
*} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
239 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
240 |
type_synonym layout = "nat list" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
241 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
242 |
text {* |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
243 |
@{text "length_of i"} is the length of the |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
244 |
TM simulating the Abacus instruction @{text "i"}. |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
245 |
*} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
246 |
fun length_of :: "abc_inst \<Rightarrow> nat" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
247 |
where |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
248 |
"length_of i = (case i of |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
249 |
Inc n \<Rightarrow> 2 * n + 9 | |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
250 |
Dec n e \<Rightarrow> 2 * n + 16 | |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
251 |
Goto n \<Rightarrow> 1)" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
252 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
253 |
text {* |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
254 |
@{text "layout_of ap"} returns the layout of Abacus program @{text "ap"}. |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
255 |
*} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
256 |
fun layout_of :: "abc_prog \<Rightarrow> layout" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
257 |
where "layout_of ap = map length_of ap" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
258 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
259 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
260 |
text {* |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
261 |
@{text "start_of layout n"} looks out the starting state of @{text "n"}-th |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
262 |
TM in the finall TM. |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
263 |
*} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
264 |
thm listsum_def |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
265 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
266 |
fun start_of :: "nat list \<Rightarrow> nat \<Rightarrow> nat" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
267 |
where |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
268 |
"start_of ly x = (Suc (listsum (take x ly))) " |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
269 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
270 |
text {* |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
271 |
@{text "ci lo ss i"} complies Abacus instruction @{text "i"} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
272 |
assuming the TM of @{text "i"} starts from state @{text "ss"} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
273 |
within the overal layout @{text "lo"}. |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
274 |
*} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
275 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
276 |
fun ci :: "layout \<Rightarrow> nat \<Rightarrow> abc_inst \<Rightarrow> instr list" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
277 |
where |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
278 |
"ci ly ss (Inc n) = tinc ss n" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
279 |
| "ci ly ss (Dec n e) = tdec ss n (start_of ly e)" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
280 |
| "ci ly ss (Goto n) = tgoto (start_of ly n)" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
281 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
282 |
text {* |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
283 |
@{text "tpairs_of ap"} transfroms Abacus program @{text "ap"} pairing |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
284 |
every instruction with its starting state. |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
285 |
*} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
286 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
287 |
fun tpairs_of :: "abc_prog \<Rightarrow> (nat \<times> abc_inst) list" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
288 |
where "tpairs_of ap = (zip (map (start_of (layout_of ap)) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
289 |
[0..<(length ap)]) ap)" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
290 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
291 |
text {* |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
292 |
@{text "tms_of ap"} returns the list of TMs, where every one of them simulates |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
293 |
the corresponding Abacus intruction in @{text "ap"}. |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
294 |
*} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
295 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
296 |
fun tms_of :: "abc_prog \<Rightarrow> (instr list) list" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
297 |
where "tms_of ap = map (\<lambda> (n, tm). ci (layout_of ap) n tm) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
298 |
(tpairs_of ap)" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
299 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
300 |
text {* |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
301 |
@{text "tm_of ap"} returns the final TM machine compiled from Abacus program @{text "ap"}. |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
302 |
*} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
303 |
fun tm_of :: "abc_prog \<Rightarrow> instr list" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
304 |
where "tm_of ap = concat (tms_of ap)" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
305 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
306 |
text {* |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
307 |
The following two functions specify the well-formedness of complied TM. |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
308 |
*} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
309 |
(* |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
310 |
fun t_ncorrect :: "tprog \<Rightarrow> bool" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
311 |
where |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
312 |
"t_ncorrect tp = (length tp mod 2 = 0)" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
313 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
314 |
fun abc2t_correct :: "abc_prog \<Rightarrow> bool" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
315 |
where |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
316 |
"abc2t_correct ap = list_all (\<lambda> (n, tm). |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
317 |
t_ncorrect (ci (layout_of ap) n tm)) (tpairs_of ap)" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
318 |
*) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
319 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
320 |
lemma length_findnth: |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
321 |
"length (findnth n) = 4 * n" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
322 |
apply(induct n, auto) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
323 |
done |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
324 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
325 |
lemma ci_length : "length (ci ns n ai) div 2 = length_of ai" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
326 |
apply(auto simp: ci.simps tinc_b_def tdec_b_def length_findnth |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
327 |
split: abc_inst.splits) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
328 |
done |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
329 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
330 |
subsection {* |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
331 |
Representation of Abacus memory by TM tape |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
332 |
*} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
333 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
334 |
text {* |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
335 |
@{text "crsp acf tcf"} meams the abacus configuration @{text "acf"} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
336 |
is corretly represented by the TM configuration @{text "tcf"}. |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
337 |
*} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
338 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
339 |
fun crsp :: "layout \<Rightarrow> abc_conf \<Rightarrow> config \<Rightarrow> cell list \<Rightarrow> bool" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
340 |
where |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
341 |
"crsp ly (as, lm) (s, l, r) inres = |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
342 |
(s = start_of ly as \<and> (\<exists> x. r = <lm> @ Bk\<up>x) \<and> |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
343 |
l = Bk # Bk # inres)" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
344 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
345 |
declare crsp.simps[simp del] |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
346 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
347 |
subsection {* |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
348 |
A more general definition of TM execution. |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
349 |
*} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
350 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
351 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
352 |
text {* |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
353 |
The type of invarints expressing correspondence between |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
354 |
Abacus configuration and TM configuration. |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
355 |
*} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
356 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
357 |
type_synonym inc_inv_t = "abc_conf \<Rightarrow> config \<Rightarrow> cell list \<Rightarrow> bool" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
358 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
359 |
declare tms_of.simps[simp del] tm_of.simps[simp del] |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
360 |
layout_of.simps[simp del] abc_fetch.simps [simp del] |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
361 |
tpairs_of.simps[simp del] start_of.simps[simp del] |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
362 |
ci.simps [simp del] length_of.simps[simp del] |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
363 |
layout_of.simps[simp del] |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
364 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
365 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
366 |
(* |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
367 |
subsection {* The compilation of @{text "Inc n"} *} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
368 |
*) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
369 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
370 |
text {* |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
371 |
The lemmas in this section lead to the correctness of |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
372 |
the compilation of @{text "Inc n"} instruction. |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
373 |
*} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
374 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
375 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
376 |
declare abc_step_l.simps[simp del] abc_steps_l.simps[simp del] |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
377 |
lemma [simp]: "start_of ly as > 0" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
378 |
apply(simp add: start_of.simps) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
379 |
done |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
380 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
381 |
lemma abc_step_red: |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
382 |
"abc_steps_l ac aprog stp = (as, am) \<Longrightarrow> |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
383 |
abc_steps_l ac aprog (Suc stp) = abc_step_l (as, am) (abc_fetch as aprog) " |
48
559e5c6e5113
updated to ITP and updated directories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
47
diff
changeset
|
384 |
oops |
47
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
385 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
386 |
lemma tm_shift_fetch: |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
387 |
"\<lbrakk>fetch A s b = (ac, ns); ns \<noteq> 0 \<rbrakk> |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
388 |
\<Longrightarrow> fetch (shift A off) s b = (ac, ns + off)" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
389 |
apply(case_tac b) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
390 |
apply(case_tac [!] s, auto simp: fetch.simps shift.simps) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
391 |
done |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
392 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
393 |
lemma tm_shift_eq_step: |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
394 |
assumes exec: "step (s, l, r) (A, 0) = (s', l', r')" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
395 |
and notfinal: "s' \<noteq> 0" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
396 |
shows "step (s + off, l, r) (shift A off, off) = (s' + off, l', r')" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
397 |
using assms |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
398 |
apply(simp add: step.simps) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
399 |
apply(case_tac "fetch A s (read r)", auto) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
400 |
apply(drule_tac [!] off = off in tm_shift_fetch, simp_all) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
401 |
done |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
402 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
403 |
lemma tm_shift_eq_steps: |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
404 |
assumes layout: "ly = layout_of ap" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
405 |
and compile: "tp = tm_of ap" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
406 |
and exec: "steps (s, l, r) (A, 0) stp = (s', l', r')" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
407 |
and notfinal: "s' \<noteq> 0" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
408 |
shows "steps (s + off, l, r) (shift A off, off) stp = (s' + off, l', r')" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
409 |
using exec notfinal |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
410 |
proof(induct stp arbitrary: s' l' r', simp add: steps.simps) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
411 |
fix stp s' l' r' |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
412 |
assume ind: "\<And>s' l' r'. \<lbrakk>steps (s, l, r) (A, 0) stp = (s', l', r'); s' \<noteq> 0\<rbrakk> |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
413 |
\<Longrightarrow> steps (s + off, l, r) (shift A off, off) stp = (s' + off, l', r')" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
414 |
and h: " steps (s, l, r) (A, 0) (Suc stp) = (s', l', r')" "s' \<noteq> 0" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
415 |
obtain s1 l1 r1 where g: "steps (s, l, r) (A, 0) stp = (s1, l1, r1)" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
416 |
apply(case_tac "steps (s, l, r) (A, 0) stp") by blast |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
417 |
moreover then have "s1 \<noteq> 0" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
418 |
using h |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
419 |
apply(simp add: step_red, case_tac "0 < s1", simp, simp) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
420 |
done |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
421 |
ultimately have "steps (s + off, l, r) (shift A off, off) stp = |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
422 |
(s1 + off, l1, r1)" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
423 |
apply(rule_tac ind, simp_all) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
424 |
done |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
425 |
thus "steps (s + off, l, r) (shift A off, off) (Suc stp) = (s' + off, l', r')" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
426 |
using h g assms |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
427 |
apply(simp add: step_red) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
428 |
apply(rule_tac tm_shift_eq_step, auto) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
429 |
done |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
430 |
qed |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
431 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
432 |
lemma startof_not0[simp]: "0 < start_of ly as" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
433 |
apply(simp add: start_of.simps) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
434 |
done |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
435 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
436 |
lemma startof_ge1[simp]: "Suc 0 \<le> start_of ly as" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
437 |
apply(simp add: start_of.simps) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
438 |
done |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
439 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
440 |
lemma step_eq_fetch: |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
441 |
assumes layout: "ly = layout_of ap" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
442 |
and compile: "tp = tm_of ap" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
443 |
and abc_fetch: "abc_fetch as ap = Some ins" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
444 |
and fetch: "fetch (ci ly (start_of ly as) ins) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
445 |
(Suc s - start_of ly as) b = (ac, ns)" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
446 |
and notfinal: "ns \<noteq> 0" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
447 |
shows "fetch tp s b = (ac, ns)" |
48
559e5c6e5113
updated to ITP and updated directories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
47
diff
changeset
|
448 |
oops |
47
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
449 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
450 |
lemma step_eq_in: |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
451 |
assumes layout: "ly = layout_of ap" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
452 |
and compile: "tp = tm_of ap" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
453 |
and fetch: "abc_fetch as ap = Some ins" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
454 |
and exec: "step (s, l, r) (ci ly (start_of ly as) ins, start_of ly as - 1) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
455 |
= (s', l', r')" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
456 |
and notfinal: "s' \<noteq> 0" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
457 |
shows "step (s, l, r) (tp, 0) = (s', l', r')" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
458 |
using assms |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
459 |
apply(simp add: step.simps) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
460 |
apply(case_tac "fetch (ci (layout_of ap) (start_of (layout_of ap) as) ins) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
461 |
(Suc s - start_of (layout_of ap) as) (read r)", simp) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
462 |
using layout |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
463 |
apply(drule_tac s = s and b = "read r" and ac = a in step_eq_fetch, auto) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
464 |
done |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
465 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
466 |
lemma steps_eq_in: |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
467 |
assumes layout: "ly = layout_of ap" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
468 |
and compile: "tp = tm_of ap" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
469 |
and crsp: "crsp ly (as, lm) (s, l, r) ires" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
470 |
and fetch: "abc_fetch as ap = Some ins" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
471 |
and exec: "steps (s, l, r) (ci ly (start_of ly as) ins, start_of ly as - 1) stp |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
472 |
= (s', l', r')" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
473 |
and notfinal: "s' \<noteq> 0" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
474 |
shows "steps (s, l, r) (tp, 0) stp = (s', l', r')" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
475 |
using exec notfinal |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
476 |
proof(induct stp arbitrary: s' l' r', simp add: steps.simps) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
477 |
fix stp s' l' r' |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
478 |
assume ind: |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
479 |
"\<And>s' l' r'. \<lbrakk>steps (s, l, r) (ci ly (start_of ly as) ins, start_of ly as - 1) stp = (s', l', r'); s' \<noteq> 0\<rbrakk> |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
480 |
\<Longrightarrow> steps (s, l, r) (tp, 0) stp = (s', l', r')" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
481 |
and h: "steps (s, l, r) (ci ly (start_of ly as) ins, start_of ly as - 1) (Suc stp) = (s', l', r')" "s' \<noteq> 0" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
482 |
obtain s1 l1 r1 where g: "steps (s, l, r) (ci ly (start_of ly as) ins, start_of ly as - 1) stp = |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
483 |
(s1, l1, r1)" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
484 |
apply(case_tac "steps (s, l, r) (ci ly (start_of ly as) ins, start_of ly as - 1) stp") by blast |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
485 |
moreover hence "s1 \<noteq> 0" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
486 |
using h |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
487 |
apply(simp add: step_red) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
488 |
apply(case_tac "0 < s1", simp_all) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
489 |
done |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
490 |
ultimately have "steps (s, l, r) (tp, 0) stp = (s1, l1, r1)" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
491 |
apply(rule_tac ind, auto) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
492 |
done |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
493 |
thus "steps (s, l, r) (tp, 0) (Suc stp) = (s', l', r')" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
494 |
using h g assms |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
495 |
apply(simp add: step_red) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
496 |
apply(rule_tac step_eq_in, auto) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
497 |
done |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
498 |
qed |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
499 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
500 |
lemma tm_append_fetch_first: |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
501 |
"\<lbrakk>fetch A s b = (ac, ns); ns \<noteq> 0\<rbrakk> \<Longrightarrow> |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
502 |
fetch (A @ B) s b = (ac, ns)" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
503 |
apply(case_tac b) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
504 |
apply(case_tac [!] s, auto simp: fetch.simps nth_append split: if_splits) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
505 |
done |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
506 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
507 |
lemma tm_append_first_step_eq: |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
508 |
assumes "step (s, l, r) (A, 0) = (s', l', r')" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
509 |
and "s' \<noteq> 0" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
510 |
shows "step (s, l, r) (A @ B, 0) = (s', l', r')" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
511 |
using assms |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
512 |
apply(simp add: step.simps) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
513 |
apply(case_tac "fetch A s (read r)") |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
514 |
apply(frule_tac B = B and b = "read r" in tm_append_fetch_first, auto) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
515 |
done |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
516 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
517 |
lemma tm_append_first_steps_eq: |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
518 |
assumes "steps (s, l, r) (A, 0) stp = (s', l', r')" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
519 |
and "s' \<noteq> 0" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
520 |
shows "steps (s, l, r) (A @ B, 0) stp = (s', l', r')" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
521 |
using assms |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
522 |
sorry |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
523 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
524 |
lemma tm_append_second_steps_eq: |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
525 |
assumes |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
526 |
exec: "steps (s, l, r) (B, 0) stp = (s', l', r')" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
527 |
and notfinal: "s' \<noteq> 0" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
528 |
and off: "off = length A div 2" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
529 |
and even: "length A mod 2 = 0" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
530 |
shows "steps (s + off, l, r) (A @ shift B off, 0) stp = (s' + off, l', r')" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
531 |
using assms |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
532 |
sorry |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
533 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
534 |
lemma tm_append_steps: |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
535 |
assumes |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
536 |
aexec: "steps (s, l, r) (A, 0) stpa = (Suc (length A div 2), la, ra)" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
537 |
and bexec: "steps (Suc 0, la, ra) (B, 0) stpb = (sb, lb, rb)" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
538 |
and notfinal: "sb \<noteq> 0" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
539 |
and off: "off = length A div 2" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
540 |
and even: "length A mod 2 = 0" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
541 |
shows "steps (s, l, r) (A @ shift B off, 0) (stpa + stpb) = (sb + off, lb, rb)" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
542 |
proof - |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
543 |
have "steps (s, l, r) (A@shift B off, 0) stpa = (Suc (length A div 2), la, ra)" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
544 |
apply(rule_tac tm_append_first_steps_eq) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
545 |
apply(auto simp: assms) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
546 |
done |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
547 |
moreover have "steps (1 + off, la, ra) (A @ shift B off, 0) stpb = (sb + off, lb, rb)" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
548 |
apply(rule_tac tm_append_second_steps_eq) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
549 |
apply(auto simp: assms bexec) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
550 |
done |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
551 |
ultimately show "steps (s, l, r) (A @ shift B off, 0) (stpa + stpb) = (sb + off, lb, rb)" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
552 |
apply(simp add: steps_add off) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
553 |
done |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
554 |
qed |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
555 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
556 |
subsection {* Crsp of Inc*} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
557 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
558 |
lemma crsp_step_inc: |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
559 |
assumes layout: "ly = layout_of ap" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
560 |
and crsp: "crsp ly (as, lm) (s, l, r) ires" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
561 |
and fetch: "abc_fetch as ap = Some (Inc n)" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
562 |
shows "\<exists>stp. crsp ly (abc_step_l (as, lm) (Some (Inc n))) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
563 |
(steps (s, l, r) (ci ly (start_of ly as) (Inc n), start_of ly as - Suc 0) stp) ires" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
564 |
sorry |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
565 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
566 |
subsection{* Crsp of Dec n e*} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
567 |
lemma crsp_step_dec: |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
568 |
assumes layout: "ly = layout_of ap" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
569 |
and crsp: "crsp ly (as, lm) (s, l, r) ires" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
570 |
shows "\<exists>stp. crsp ly (abc_step_l (as, lm) (Some (Dec n e))) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
571 |
(steps (s, l, r) (ci ly (start_of ly as) (Dec n e), start_of ly as - Suc 0) stp) ires" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
572 |
sorry |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
573 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
574 |
subsection{*Crsp of Goto*} |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
575 |
lemma crsp_step_goto: |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
576 |
assumes layout: "ly = layout_of ap" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
577 |
and crsp: "crsp ly (as, lm) (s, l, r) ires" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
578 |
shows "\<exists>stp. crsp ly (abc_step_l (as, lm) (Some (Goto n))) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
579 |
(steps (s, l, r) (ci ly (start_of ly as) (Goto n), |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
580 |
start_of ly as - Suc 0) stp) ires" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
581 |
sorry |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
582 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
583 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
584 |
lemma crsp_step_in: |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
585 |
assumes layout: "ly = layout_of ap" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
586 |
and compile: "tp = tm_of ap" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
587 |
and crsp: "crsp ly (as, lm) (s, l, r) ires" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
588 |
and fetch: "abc_fetch as ap = Some ins" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
589 |
shows "\<exists> stp. crsp ly (abc_step_l (as, lm) (Some ins)) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
590 |
(steps (s, l, r) (ci ly (start_of ly as) ins, start_of ly as - 1) stp) ires" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
591 |
using assms |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
592 |
apply(case_tac ins, simp_all) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
593 |
apply(rule crsp_step_inc, simp_all) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
594 |
apply(rule crsp_step_dec, simp_all) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
595 |
apply(rule_tac crsp_step_goto, simp_all) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
596 |
done |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
597 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
598 |
lemma crsp_step: |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
599 |
assumes layout: "ly = layout_of ap" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
600 |
and compile: "tp = tm_of ap" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
601 |
and crsp: "crsp ly (as, lm) (s, l, r) ires" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
602 |
and fetch: "abc_fetch as ap = Some ins" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
603 |
shows "\<exists> stp. crsp ly (abc_step_l (as, lm) (Some ins)) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
604 |
(steps (s, l, r) (tp, 0) stp) ires" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
605 |
proof - |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
606 |
have "\<exists> stp. crsp ly (abc_step_l (as, lm) (Some ins)) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
607 |
(steps (s, l, r) (ci ly (start_of ly as) ins, start_of ly as - 1) stp) ires" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
608 |
using assms |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
609 |
apply(erule_tac crsp_step_in, simp_all) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
610 |
done |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
611 |
from this obtain stp where d: "crsp ly (abc_step_l (as, lm) (Some ins)) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
612 |
(steps (s, l, r) (ci ly (start_of ly as) ins, start_of ly as - 1) stp) ires" .. |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
613 |
obtain s' l' r' where e: |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
614 |
"(steps (s, l, r) (ci ly (start_of ly as) ins, start_of ly as - 1) stp) = (s', l', r')" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
615 |
apply(case_tac "(steps (s, l, r) (ci ly (start_of ly as) ins, start_of ly as - 1) stp)") |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
616 |
by blast |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
617 |
then have "steps (s, l, r) (tp, 0) stp = (s', l', r')" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
618 |
using assms d |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
619 |
apply(rule_tac steps_eq_in) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
620 |
apply(simp_all) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
621 |
apply(case_tac "(abc_step_l (as, lm) (Some ins))", simp add: crsp.simps) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
622 |
done |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
623 |
thus " \<exists>stp. crsp ly (abc_step_l (as, lm) (Some ins)) (steps (s, l, r) (tp, 0) stp) ires" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
624 |
using d e |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
625 |
apply(rule_tac x = stp in exI, simp) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
626 |
done |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
627 |
qed |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
628 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
629 |
lemma crsp_steps: |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
630 |
assumes layout: "ly = layout_of ap" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
631 |
and compile: "tp = tm_of ap" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
632 |
and crsp: "crsp ly (as, lm) (s, l, r) ires" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
633 |
shows "\<exists> stp. crsp ly (abc_steps_l (as, lm) ap n) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
634 |
(steps (s, l, r) (tp, 0) stp) ires" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
635 |
using crsp |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
636 |
apply(induct n) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
637 |
apply(rule_tac x = 0 in exI) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
638 |
apply(simp add: steps.simps abc_steps_l.simps, simp) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
639 |
apply(case_tac "(abc_steps_l (as, lm) ap n)", auto) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
640 |
apply(frule_tac abc_step_red, simp) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
641 |
apply(case_tac "abc_fetch a ap", simp add: abc_step_l.simps, auto) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
642 |
apply(case_tac "steps (s, l, r) (tp, 0) stp", simp) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
643 |
using assms |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
644 |
apply(drule_tac s = ab and l = ba and r = c in crsp_step, auto) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
645 |
apply(rule_tac x = "stp + stpa" in exI, simp add: steps_add) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
646 |
done |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
647 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
648 |
lemma tp_correct': |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
649 |
assumes layout: "ly = layout_of ap" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
650 |
and compile: "tp = tm_of ap" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
651 |
and crsp: "crsp ly (0, lm) (Suc 0, l, r) ires" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
652 |
and abc_halt: "abc_steps_l (0, lm) ap stp = (length ap, am)" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
653 |
shows "\<exists> stp k. steps (Suc 0, l, r) (tp, 0) stp = (start_of ly (length ap), Bk # Bk # ires, <am> @ Bk\<up>k)" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
654 |
using assms |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
655 |
apply(drule_tac n = stp in crsp_steps, auto) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
656 |
apply(rule_tac x = stpa in exI) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
657 |
apply(case_tac "steps (Suc 0, l, r) (tm_of ap, 0) stpa", simp add: crsp.simps) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
658 |
done |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
659 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
660 |
(***normalize the tp compiled from ap, and we can use Hoare_plus when composed with mopup machine*) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
661 |
definition tp_norm :: "abc_prog \<Rightarrow> instr list" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
662 |
where |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
663 |
"tp_norm ap = tm_of ap @ [(Nop, 0), (Nop, 0)]" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
664 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
665 |
lemma tp_correct: |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
666 |
assumes layout: "ly = layout_of ap" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
667 |
and crsp: "crsp ly (0, lm) (Suc 0, l, r) ires" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
668 |
and abc_halt: "abc_steps_l (0, lm) ap stp = (length ap, am)" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
669 |
shows "\<exists> stp k. steps (Suc 0, l, r) (tp_norm ap, 0) stp = (0, Bk # Bk # ires, <am> @ Bk\<up>k)" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
670 |
sorry |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
671 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
672 |
(****mop_up***) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
673 |
fun mopup_a :: "nat \<Rightarrow> instr list" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
674 |
where |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
675 |
"mopup_a 0 = []" | |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
676 |
"mopup_a (Suc n) = mopup_a n @ |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
677 |
[(R, 2*n + 3), (W0, 2*n + 2), (R, 2*n + 1), (W1, 2*n + 2)]" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
678 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
679 |
definition mopup_b :: "instr list" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
680 |
where |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
681 |
"mopup_b \<equiv> [(R, 2), (R, 1), (L, 5), (W0, 3), (R, 4), (W0, 3), |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
682 |
(R, 2), (W0, 3), (L, 5), (L, 6), (R, 0), (L, 6)]" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
683 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
684 |
fun mopup :: "nat \<Rightarrow> instr list" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
685 |
where |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
686 |
"mopup n = mopup_a n @ shift mopup_b (2*n)" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
687 |
(****) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
688 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
689 |
(*we can use Hoare_plus here*) |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
690 |
lemma compile_correct_halt: |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
691 |
assumes layout: "ly = layout_of ap" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
692 |
and crsp: "crsp ly (0, lm) (Suc 0, l, r) ires" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
693 |
and abc_halt: "abc_steps_l (0, lm) ap stp = (length ap, am)" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
694 |
and rs_loc: "n < length am" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
695 |
and rs: "rs = abc_lm_v am n" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
696 |
shows "\<exists> stp i j. steps (Suc 0, l, r) (tp_norm ap |+| mopup n, 0) stp = (0, Bk\<up>i @ Bk # Bk # ires, Oc\<up>Suc rs @ Bk\<up>j)" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
697 |
sorry |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
698 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
699 |
lemma compile_correct_unhalt: |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
700 |
assumes layout: "ly = layout_of ap" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
701 |
and crsp: "crsp ly (0, lm) (Suc 0, l, r) ires" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
702 |
and abc_unhalt: "\<forall> stp. (\<lambda> (as, am). as < length ap) (abc_steps_l (0, lm) ap stp)" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
703 |
shows "\<forall> stp.\<not> is_final (steps (Suc 0, l, r) (tp_norm ap |+| mopup n, 0) stp)" |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
704 |
sorry |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
705 |
|
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
706 |
end |
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
707 |