author | Christian Urban <christian dot urban at kcl dot ac dot uk> |
Sun, 13 Jan 2013 23:59:29 +0000 | |
changeset 41 | 6d89ed67ba27 |
parent 0 | aa8656a8dbef |
child 50 | 816e84ca16d6 |
permissions | -rw-r--r-- |
0
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
1 |
theory turing_basic |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
2 |
imports Main |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
3 |
begin |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
4 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
5 |
section {* Basic definitions of Turing machine *} |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
6 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
7 |
(* Title: Turing machine's definition and its charater |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
8 |
Author: Xu Jian <xujian817@hotmail.com> |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
9 |
Maintainer: Xu Jian |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
10 |
*) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
11 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
12 |
text {* |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
13 |
Actions of Turing machine (Abbreviated TM in the following* ). |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
14 |
*} |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
15 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
16 |
datatype taction = |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
17 |
-- {* Write zero *} |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
18 |
W0 | |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
19 |
-- {* Write one *} |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
20 |
W1 | |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
21 |
-- {* Move left *} |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
22 |
L | |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
23 |
-- {* Move right *} |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
24 |
R | |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
25 |
-- {* Do nothing *} |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
26 |
Nop |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
27 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
28 |
text {* |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
29 |
Tape contents in every block. |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
30 |
*} |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
31 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
32 |
datatype block = |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
33 |
-- {* Blank *} |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
34 |
Bk | |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
35 |
-- {* Occupied *} |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
36 |
Oc |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
37 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
38 |
text {* |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
39 |
Tape is represented as a pair of lists $(L_{left}, L_{right})$, |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
40 |
where $L_left$, named {\em left list}, is used to represent |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
41 |
the tape to the left of RW-head and |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
42 |
$L_{right}$, named {\em right list}, is used to represent the tape |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
43 |
under and to the right of RW-head. |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
44 |
*} |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
45 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
46 |
type_synonym tape = "block list \<times> block list" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
47 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
48 |
text {* The state of turing machine.*} |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
49 |
type_synonym tstate = nat |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
50 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
51 |
text {* |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
52 |
Turing machine instruction is represented as a |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
53 |
pair @{text "(action, next_state)"}, |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
54 |
where @{text "action"} is the action to take at the current state |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
55 |
and @{text "next_state"} is the next state the machine is getting into |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
56 |
after the action. |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
57 |
*} |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
58 |
type_synonym tinst = "taction \<times> tstate" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
59 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
60 |
text {* |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
61 |
Program of Turing machine is represented as a list of Turing instructions |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
62 |
and the execution of the program starts from the head of the list. |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
63 |
*} |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
64 |
type_synonym tprog = "tinst list" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
65 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
66 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
67 |
text {* |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
68 |
Turing machine configuration, which consists of the current state |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
69 |
and the tape. |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
70 |
*} |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
71 |
type_synonym t_conf = "tstate \<times> tape" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
72 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
73 |
fun nth_of :: "'a list \<Rightarrow> nat \<Rightarrow> 'a option" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
74 |
where |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
75 |
"nth_of xs n = (if n < length xs then Some (xs!n) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
76 |
else None)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
77 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
78 |
text {* |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
79 |
The function used to fetech instruction out of Turing program. |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
80 |
*} |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
81 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
82 |
fun fetch :: "tprog \<Rightarrow> tstate \<Rightarrow> block \<Rightarrow> tinst" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
83 |
where |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
84 |
"fetch p s b = (if s = 0 then (Nop, 0) else |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
85 |
case b of |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
86 |
Bk \<Rightarrow> case nth_of p (2 * (s - 1)) of |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
87 |
Some i \<Rightarrow> i |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
88 |
| None \<Rightarrow> (Nop, 0) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
89 |
| Oc \<Rightarrow> case nth_of p (2 * (s - 1) +1) of |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
90 |
Some i \<Rightarrow> i |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
91 |
| None \<Rightarrow> (Nop, 0))" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
92 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
93 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
94 |
fun new_tape :: "taction \<Rightarrow> tape \<Rightarrow> tape" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
95 |
where |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
96 |
"new_tape action (leftn, rightn) = (case action of |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
97 |
W0 \<Rightarrow> (leftn, Bk#(tl rightn)) | |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
98 |
W1 \<Rightarrow> (leftn, Oc#(tl rightn)) | |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
99 |
L \<Rightarrow> (if leftn = [] then (tl leftn, Bk#rightn) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
100 |
else (tl leftn, (hd leftn) # rightn)) | |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
101 |
R \<Rightarrow> if rightn = [] then (Bk#leftn,tl rightn) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
102 |
else ((hd rightn)#leftn, tl rightn) | |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
103 |
Nop \<Rightarrow> (leftn, rightn) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
104 |
)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
105 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
106 |
text {* |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
107 |
The one step function used to transfer Turing machine configuration. |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
108 |
*} |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
109 |
fun tstep :: "t_conf \<Rightarrow> tprog \<Rightarrow> t_conf" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
110 |
where |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
111 |
"tstep c p = (let (s, l, r) = c in |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
112 |
let (ac, ns) = (fetch p s (case r of [] \<Rightarrow> Bk | |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
113 |
x # xs \<Rightarrow> x)) in |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
114 |
(ns, new_tape ac (l, r)))" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
115 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
116 |
text {* |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
117 |
The many-step function. |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
118 |
*} |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
119 |
fun steps :: "t_conf \<Rightarrow> tprog \<Rightarrow> nat \<Rightarrow> t_conf" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
120 |
where |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
121 |
"steps c p 0 = c" | |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
122 |
"steps c p (Suc n) = steps (tstep c p) p n" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
123 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
124 |
lemma tstep_red: "steps c p (Suc n) = tstep (steps c p n) p" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
125 |
proof(induct n arbitrary: c) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
126 |
fix c |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
127 |
show "steps c p (Suc 0) = tstep (steps c p 0) p" by(simp add: steps.simps) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
128 |
next |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
129 |
fix n c |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
130 |
assume ind: "\<And> c. steps c p (Suc n) = tstep (steps c p n) p" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
131 |
have "steps (tstep c p) p (Suc n) = tstep (steps (tstep c p) p n) p" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
132 |
by(rule ind) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
133 |
thus "steps c p (Suc (Suc n)) = tstep (steps c p (Suc n)) p" by(simp add: steps.simps) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
134 |
qed |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
135 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
136 |
declare Let_def[simp] option.split[split] |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
137 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
138 |
definition |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
139 |
"iseven n \<equiv> \<exists> x. n = 2 * x" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
140 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
141 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
142 |
text {* |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
143 |
The following @{text "t_correct"} function is used to specify the wellformedness of Turing |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
144 |
machine. |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
145 |
*} |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
146 |
fun t_correct :: "tprog \<Rightarrow> bool" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
147 |
where |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
148 |
"t_correct p = (length p \<ge> 2 \<and> iseven (length p) \<and> |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
149 |
list_all (\<lambda> (acn, s). s \<le> length p div 2) p)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
150 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
151 |
declare t_correct.simps[simp del] |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
152 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
153 |
lemma allimp: "\<lbrakk>\<forall>x. P x \<longrightarrow> Q x; \<forall>x. P x\<rbrakk> \<Longrightarrow> \<forall>x. Q x" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
154 |
by(auto elim: allE) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
155 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
156 |
lemma halt_lemma: "\<lbrakk>wf LE; \<forall> n. (\<not> P (f n) \<longrightarrow> (f (Suc n), (f n)) \<in> LE)\<rbrakk> \<Longrightarrow> \<exists> n. P (f n)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
157 |
apply(rule exCI, drule allimp, auto) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
158 |
apply(drule_tac f = f in wf_inv_image, simp add: inv_image_def) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
159 |
apply(erule wf_induct, auto) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
160 |
done |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
161 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
162 |
lemma steps_add: "steps c t (x + y) = steps (steps c t x) t y" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
163 |
by(induct x arbitrary: c, auto simp: steps.simps tstep_red) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
164 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
165 |
lemma listall_set: "list_all p t \<Longrightarrow> \<forall> a \<in> set t. p a" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
166 |
by(induct t, auto) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
167 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
168 |
lemma fetch_ex: "\<exists>b a. fetch T aa ab = (b, a)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
169 |
by(simp add: fetch.simps) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
170 |
definition exponent :: "'a \<Rightarrow> nat \<Rightarrow> 'a list" ("_\<^bsup>_\<^esup>" [0, 0]100) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
171 |
where "exponent x n = replicate n x" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
172 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
173 |
text {* |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
174 |
@{text "tinres l1 l2"} means left list @{text "l1"} is congruent with |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
175 |
@{text "l2"} with respect to the execution of Turing machine. |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
176 |
Appending Blank to the right of eigther one does not affect the |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
177 |
outcome of excution. |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
178 |
*} |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
179 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
180 |
definition tinres :: "block list \<Rightarrow> block list \<Rightarrow> bool" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
181 |
where |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
182 |
"tinres bx by = (\<exists> n. bx = by@Bk\<^bsup>n\<^esup> \<or> by = bx @ Bk\<^bsup>n\<^esup>)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
183 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
184 |
lemma exp_zero: "a\<^bsup>0\<^esup> = []" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
185 |
by(simp add: exponent_def) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
186 |
lemma exp_ind_def: "a\<^bsup>Suc x \<^esup> = a # a\<^bsup>x\<^esup>" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
187 |
by(simp add: exponent_def) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
188 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
189 |
text {* |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
190 |
The following lemma shows the meaning of @{text "tinres"} with respect to |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
191 |
one step execution. |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
192 |
*} |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
193 |
lemma tinres_step: |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
194 |
"\<lbrakk>tinres l l'; tstep (ss, l, r) t = (sa, la, ra); tstep (ss, l', r) t = (sb, lb, rb)\<rbrakk> |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
195 |
\<Longrightarrow> tinres la lb \<and> ra = rb \<and> sa = sb" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
196 |
apply(auto simp: tstep.simps fetch.simps new_tape.simps |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
197 |
split: if_splits taction.splits list.splits |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
198 |
block.splits) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
199 |
apply(case_tac [!] "t ! (2 * (ss - Suc 0))", |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
200 |
auto simp: exponent_def tinres_def split: if_splits taction.splits list.splits |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
201 |
block.splits) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
202 |
apply(case_tac [!] "t ! (2 * (ss - Suc 0) + Suc 0)", |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
203 |
auto simp: exponent_def tinres_def split: if_splits taction.splits list.splits |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
204 |
block.splits) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
205 |
done |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
206 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
207 |
declare tstep.simps[simp del] steps.simps[simp del] |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
208 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
209 |
text {* |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
210 |
The following lemma shows the meaning of @{text "tinres"} with respect to |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
211 |
many step execution. |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
212 |
*} |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
213 |
lemma tinres_steps: |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
214 |
"\<lbrakk>tinres l l'; steps (ss, l, r) t stp = (sa, la, ra); steps (ss, l', r) t stp = (sb, lb, rb)\<rbrakk> |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
215 |
\<Longrightarrow> tinres la lb \<and> ra = rb \<and> sa = sb" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
216 |
apply(induct stp arbitrary: sa la ra sb lb rb, simp add: steps.simps) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
217 |
apply(simp add: tstep_red) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
218 |
apply(case_tac "(steps (ss, l, r) t stp)") |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
219 |
apply(case_tac "(steps (ss, l', r) t stp)") |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
220 |
proof - |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
221 |
fix stp sa la ra sb lb rb a b c aa ba ca |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
222 |
assume ind: "\<And>sa la ra sb lb rb. \<lbrakk>steps (ss, l, r) t stp = (sa, la, ra); |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
223 |
steps (ss, l', r) t stp = (sb, lb, rb)\<rbrakk> \<Longrightarrow> tinres la lb \<and> ra = rb \<and> sa = sb" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
224 |
and h: " tinres l l'" "tstep (steps (ss, l, r) t stp) t = (sa, la, ra)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
225 |
"tstep (steps (ss, l', r) t stp) t = (sb, lb, rb)" "steps (ss, l, r) t stp = (a, b, c)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
226 |
"steps (ss, l', r) t stp = (aa, ba, ca)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
227 |
have "tinres b ba \<and> c = ca \<and> a = aa" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
228 |
apply(rule_tac ind, simp_all add: h) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
229 |
done |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
230 |
thus "tinres la lb \<and> ra = rb \<and> sa = sb" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
231 |
apply(rule_tac l = b and l' = ba and r = c and ss = a |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
232 |
and t = t in tinres_step) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
233 |
using h |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
234 |
apply(simp, simp, simp) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
235 |
done |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
236 |
qed |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
237 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
238 |
text {* |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
239 |
The following function @{text "tshift tp n"} is used to shift Turing programs |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
240 |
@{text "tp"} by @{text "n"} when it is going to be combined with others. |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
241 |
*} |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
242 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
243 |
fun tshift :: "tprog \<Rightarrow> nat \<Rightarrow> tprog" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
244 |
where |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
245 |
"tshift tp off = (map (\<lambda> (action, state). (action, (if state = 0 then 0 |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
246 |
else state + off))) tp)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
247 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
248 |
text {* |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
249 |
When two Turing programs are combined, the end state (state @{text "0"}) of the one |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
250 |
at the prefix position needs to be connected to the start state |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
251 |
of the one at postfix position. If @{text "tp"} is the Turing program |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
252 |
to be at the prefix, @{text "change_termi_state tp"} is the transformed Turing program. |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
253 |
*} |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
254 |
fun change_termi_state :: "tprog \<Rightarrow> tprog" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
255 |
where |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
256 |
"change_termi_state t = |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
257 |
(map (\<lambda> (acn, ns). if ns = 0 then (acn, Suc ((length t) div 2)) else (acn, ns)) t)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
258 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
259 |
text {* |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
260 |
@{text "t_add tp1 tp2"} is the combined Truing program. |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
261 |
*} |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
262 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
263 |
fun t_add :: "tprog \<Rightarrow> tprog \<Rightarrow> tprog" ("_ |+| _" [0, 0] 100) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
264 |
where |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
265 |
"t_add t1 t2 = ((change_termi_state t1) @ (tshift t2 ((length t1) div 2)))" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
266 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
267 |
text {* |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
268 |
Tests whether the current configuration is at state @{text "0"}. |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
269 |
*} |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
270 |
definition isS0 :: "t_conf \<Rightarrow> bool" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
271 |
where |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
272 |
"isS0 c = (let (s, l, r) = c in s = 0)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
273 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
274 |
declare tstep.simps[simp del] steps.simps[simp del] |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
275 |
t_add.simps[simp del] fetch.simps[simp del] |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
276 |
new_tape.simps[simp del] |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
277 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
278 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
279 |
text {* |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
280 |
Single step execution starting from state @{text "0"} will not make any progress. |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
281 |
*} |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
282 |
lemma tstep_0: "tstep (0, tp) p = (0, tp)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
283 |
apply(simp add: tstep.simps fetch.simps new_tape.simps) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
284 |
done |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
285 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
286 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
287 |
text {* |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
288 |
Many step executions starting from state @{text "0"} will not make any progress. |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
289 |
*} |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
290 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
291 |
lemma steps_0: "steps (0, tp) p stp = (0, tp)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
292 |
apply(induct stp) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
293 |
apply(simp add: steps.simps) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
294 |
apply(simp add: tstep_red tstep_0) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
295 |
done |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
296 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
297 |
lemma s_keep_step: "\<lbrakk>a \<le> length A div 2; tstep (a, b, c) A = (s, l, r); t_correct A\<rbrakk> |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
298 |
\<Longrightarrow> s \<le> length A div 2" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
299 |
apply(simp add: tstep.simps fetch.simps t_correct.simps iseven_def |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
300 |
split: if_splits block.splits list.splits) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
301 |
apply(case_tac [!] a, auto simp: list_all_length) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
302 |
apply(erule_tac x = "2 * nat" in allE, auto) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
303 |
apply(erule_tac x = "2 * nat" in allE, auto) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
304 |
apply(erule_tac x = "Suc (2 * nat)" in allE, auto) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
305 |
done |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
306 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
307 |
lemma s_keep: "\<lbrakk>steps (Suc 0, tp) A stp = (s, l, r); t_correct A\<rbrakk> \<Longrightarrow> s \<le> length A div 2" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
308 |
proof(induct stp arbitrary: s l r) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
309 |
case 0 thus "?case" by(auto simp: t_correct.simps steps.simps) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
310 |
next |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
311 |
fix stp s l r |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
312 |
assume ind: "\<And>s l r. \<lbrakk>steps (Suc 0, tp) A stp = (s, l, r); t_correct A\<rbrakk> \<Longrightarrow> s \<le> length A div 2" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
313 |
and h1: "steps (Suc 0, tp) A (Suc stp) = (s, l, r)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
314 |
and h2: "t_correct A" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
315 |
from h1 h2 show "s \<le> length A div 2" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
316 |
proof(simp add: tstep_red, cases "(steps (Suc 0, tp) A stp)", simp) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
317 |
fix a b c |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
318 |
assume h3: "tstep (a, b, c) A = (s, l, r)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
319 |
and h4: "steps (Suc 0, tp) A stp = (a, b, c)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
320 |
have "a \<le> length A div 2" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
321 |
using h2 h4 |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
322 |
by(rule_tac l = b and r = c in ind, auto) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
323 |
thus "?thesis" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
324 |
using h3 h2 |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
325 |
by(simp add: s_keep_step) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
326 |
qed |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
327 |
qed |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
328 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
329 |
lemma t_merge_fetch_pre: |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
330 |
"\<lbrakk>fetch A s b = (ac, ns); s \<le> length A div 2; t_correct A; s \<noteq> 0\<rbrakk> \<Longrightarrow> |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
331 |
fetch (A |+| B) s b = (ac, if ns = 0 then Suc (length A div 2) else ns)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
332 |
apply(subgoal_tac "2 * (s - Suc 0) < length A \<and> Suc (2 * (s - Suc 0)) < length A") |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
333 |
apply(auto simp: fetch.simps t_add.simps split: if_splits block.splits) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
334 |
apply(simp_all add: nth_append change_termi_state.simps) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
335 |
done |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
336 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
337 |
lemma [simp]: "\<lbrakk>\<not> a \<le> length A div 2; t_correct A\<rbrakk> \<Longrightarrow> fetch A a b = (Nop, 0)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
338 |
apply(auto simp: fetch.simps del: nth_of.simps split: block.splits) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
339 |
apply(case_tac [!] a, auto simp: t_correct.simps iseven_def) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
340 |
done |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
341 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
342 |
lemma [elim]: "\<lbrakk>t_correct A; \<not> isS0 (tstep (a, b, c) A)\<rbrakk> \<Longrightarrow> a \<le> length A div 2" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
343 |
apply(rule_tac classical, auto simp: tstep.simps new_tape.simps isS0_def) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
344 |
done |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
345 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
346 |
lemma [elim]: "\<lbrakk>t_correct A; \<not> isS0 (tstep (a, b, c) A)\<rbrakk> \<Longrightarrow> 0 < a" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
347 |
apply(rule_tac classical, simp add: tstep_0 isS0_def) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
348 |
done |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
349 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
350 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
351 |
lemma t_merge_pre_eq_step: "\<lbrakk>tstep (a, b, c) A = cf; t_correct A; \<not> isS0 cf\<rbrakk> |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
352 |
\<Longrightarrow> tstep (a, b, c) (A |+| B) = cf" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
353 |
apply(subgoal_tac "a \<le> length A div 2 \<and> a \<noteq> 0") |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
354 |
apply(simp add: tstep.simps) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
355 |
apply(case_tac "fetch A a (case c of [] \<Rightarrow> Bk | x # xs \<Rightarrow> x)", simp) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
356 |
apply(drule_tac B = B in t_merge_fetch_pre, simp, simp, simp, simp add: isS0_def, auto) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
357 |
done |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
358 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
359 |
lemma t_merge_pre_eq: "\<lbrakk>steps (Suc 0, tp) A stp = cf; \<not> isS0 cf; t_correct A\<rbrakk> |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
360 |
\<Longrightarrow> steps (Suc 0, tp) (A |+| B) stp = cf" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
361 |
proof(induct stp arbitrary: cf) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
362 |
case 0 thus "?case" by(simp add: steps.simps) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
363 |
next |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
364 |
fix stp cf |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
365 |
assume ind: "\<And>cf. \<lbrakk>steps (Suc 0, tp) A stp = cf; \<not> isS0 cf; t_correct A\<rbrakk> |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
366 |
\<Longrightarrow> steps (Suc 0, tp) (A |+| B) stp = cf" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
367 |
and h1: "steps (Suc 0, tp) A (Suc stp) = cf" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
368 |
and h2: "\<not> isS0 cf" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
369 |
and h3: "t_correct A" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
370 |
from h1 h2 h3 show "steps (Suc 0, tp) (A |+| B) (Suc stp) = cf" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
371 |
proof(simp add: tstep_red, cases "steps (Suc 0, tp) (A) stp", simp) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
372 |
fix a b c |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
373 |
assume h4: "tstep (a, b, c) A = cf" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
374 |
and h5: "steps (Suc 0, tp) A stp = (a, b, c)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
375 |
have "steps (Suc 0, tp) (A |+| B) stp = (a, b, c)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
376 |
proof(cases a) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
377 |
case 0 thus "?thesis" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
378 |
using h4 h2 |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
379 |
apply(simp add: tstep_0, cases cf, simp add: isS0_def) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
380 |
done |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
381 |
next |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
382 |
case (Suc n) thus "?thesis" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
383 |
using h5 h3 |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
384 |
apply(rule_tac ind, auto simp: isS0_def) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
385 |
done |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
386 |
qed |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
387 |
thus "tstep (steps (Suc 0, tp) (A |+| B) stp) (A |+| B) = cf" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
388 |
using h4 h5 h3 h2 |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
389 |
apply(simp) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
390 |
apply(rule t_merge_pre_eq_step, auto) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
391 |
done |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
392 |
qed |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
393 |
qed |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
394 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
395 |
declare nth.simps[simp del] tshift.simps[simp del] change_termi_state.simps[simp del] |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
396 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
397 |
lemma [simp]: "length (change_termi_state A) = length A" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
398 |
by(simp add: change_termi_state.simps) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
399 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
400 |
lemma first_halt_point: "steps (Suc 0, tp) A stp = (0, tp') |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
401 |
\<Longrightarrow> \<exists>stp. \<not> isS0 (steps (Suc 0, tp) A stp) \<and> steps (Suc 0, tp) A (Suc stp) = (0, tp')" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
402 |
proof(induct stp) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
403 |
case 0 thus "?case" by(simp add: steps.simps) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
404 |
next |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
405 |
case (Suc n) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
406 |
fix stp |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
407 |
assume ind: "steps (Suc 0, tp) A stp = (0, tp') \<Longrightarrow> |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
408 |
\<exists>stp. \<not> isS0 (steps (Suc 0, tp) A stp) \<and> steps (Suc 0, tp) A (Suc stp) = (0, tp')" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
409 |
and h: "steps (Suc 0, tp) A (Suc stp) = (0, tp')" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
410 |
from h show "\<exists>stp. \<not> isS0 (steps (Suc 0, tp) A stp) \<and> steps (Suc 0, tp) A (Suc stp) = (0, tp')" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
411 |
proof(simp add: tstep_red, cases "steps (Suc 0, tp) A stp", simp, case_tac a) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
412 |
fix a b c |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
413 |
assume g1: "a = (0::nat)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
414 |
and g2: "tstep (a, b, c) A = (0, tp')" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
415 |
and g3: "steps (Suc 0, tp) A stp = (a, b, c)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
416 |
have "steps (Suc 0, tp) A stp = (0, tp')" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
417 |
using g2 g1 g3 |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
418 |
by(simp add: tstep_0) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
419 |
hence "\<exists> stp. \<not> isS0 (steps (Suc 0, tp) A stp) \<and> steps (Suc 0, tp) A (Suc stp) = (0, tp')" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
420 |
by(rule ind) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
421 |
thus "\<exists>stp. \<not> isS0 (steps (Suc 0, tp) A stp) \<and> tstep (steps (Suc 0, tp) A stp) A = (0, tp')" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
422 |
apply(simp add: tstep_red) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
423 |
done |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
424 |
next |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
425 |
fix a b c nat |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
426 |
assume g1: "steps (Suc 0, tp) A stp = (a, b, c)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
427 |
and g2: "steps (Suc 0, tp) A (Suc stp) = (0, tp')" "a= Suc nat" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
428 |
thus "\<exists>stp. \<not> isS0 (steps (Suc 0, tp) A stp) \<and> tstep (steps (Suc 0, tp) A stp) A = (0, tp')" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
429 |
apply(rule_tac x = stp in exI) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
430 |
apply(simp add: isS0_def tstep_red) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
431 |
done |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
432 |
qed |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
433 |
qed |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
434 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
435 |
lemma t_merge_pre_halt_same': |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
436 |
"\<lbrakk>\<not> isS0 (steps (Suc 0, tp) A stp) ; steps (Suc 0, tp) A (Suc stp) = (0, tp'); t_correct A\<rbrakk> |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
437 |
\<Longrightarrow> steps (Suc 0, tp) (A |+| B) (Suc stp) = (Suc (length A div 2), tp')" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
438 |
proof(simp add: tstep_red, cases "steps (Suc 0, tp) A stp", simp) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
439 |
fix a b c |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
440 |
assume h1: "\<not> isS0 (a, b, c)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
441 |
and h2: "tstep (a, b, c) A = (0, tp')" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
442 |
and h3: "t_correct A" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
443 |
and h4: "steps (Suc 0, tp) A stp = (a, b, c)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
444 |
have "steps (Suc 0, tp) (A |+| B) stp = (a, b, c)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
445 |
using h1 h4 h3 |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
446 |
apply(rule_tac t_merge_pre_eq, auto) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
447 |
done |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
448 |
moreover have "tstep (a, b, c) (A |+| B) = (Suc (length A div 2), tp')" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
449 |
using h2 h3 h1 h4 |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
450 |
apply(simp add: tstep.simps) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
451 |
apply(case_tac " fetch A a (case c of [] \<Rightarrow> Bk | x # xs \<Rightarrow> x)", simp) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
452 |
apply(drule_tac B = B in t_merge_fetch_pre, auto simp: isS0_def intro: s_keep) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
453 |
done |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
454 |
ultimately show "tstep (steps (Suc 0, tp) (A |+| B) stp) (A |+| B) = (Suc (length A div 2), tp')" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
455 |
by(simp) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
456 |
qed |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
457 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
458 |
text {* |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
459 |
When Turing machine @{text "A"} and @{text "B"} are combined and the execution |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
460 |
of @{text "A"} can termination within @{text "stp"} steps, |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
461 |
the combined machine @{text "A |+| B"} will eventually get into the starting |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
462 |
state of machine @{text "B"}. |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
463 |
*} |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
464 |
lemma t_merge_pre_halt_same: " |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
465 |
\<lbrakk>steps (Suc 0, tp) A stp = (0, tp'); t_correct A; t_correct B\<rbrakk> |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
466 |
\<Longrightarrow> \<exists> stp. steps (Suc 0, tp) (A |+| B) stp = (Suc (length A div 2), tp')" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
467 |
proof - |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
468 |
assume a_wf: "t_correct A" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
469 |
and b_wf: "t_correct B" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
470 |
and a_ht: "steps (Suc 0, tp) A stp = (0, tp')" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
471 |
have halt_point: "\<exists> stp. \<not> isS0 (steps (Suc 0, tp) A stp) \<and> steps (Suc 0, tp) A (Suc stp) = (0, tp')" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
472 |
using a_ht |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
473 |
by(erule_tac first_halt_point) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
474 |
then obtain stp' where "\<not> isS0 (steps (Suc 0, tp) A stp') \<and> steps (Suc 0, tp) A (Suc stp') = (0, tp')".. |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
475 |
hence "steps (Suc 0, tp) (A |+| B) (Suc stp') = (Suc (length A div 2), tp')" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
476 |
using a_wf |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
477 |
apply(rule_tac t_merge_pre_halt_same', auto) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
478 |
done |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
479 |
thus "?thesis" .. |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
480 |
qed |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
481 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
482 |
lemma fetch_0: "fetch p 0 b = (Nop, 0)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
483 |
by(simp add: fetch.simps) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
484 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
485 |
lemma [simp]: "length (tshift B x) = length B" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
486 |
by(simp add: tshift.simps) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
487 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
488 |
lemma [simp]: "t_correct A \<Longrightarrow> 2 * (length A div 2) = length A" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
489 |
apply(simp add: t_correct.simps iseven_def, auto) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
490 |
done |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
491 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
492 |
lemma t_merge_fetch_snd: |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
493 |
"\<lbrakk>fetch B a b = (ac, ns); t_correct A; t_correct B; a > 0 \<rbrakk> |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
494 |
\<Longrightarrow> fetch (A |+| B) (a + length A div 2) b |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
495 |
= (ac, if ns = 0 then 0 else ns + length A div 2)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
496 |
apply(auto simp: fetch.simps t_add.simps split: if_splits block.splits) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
497 |
apply(case_tac [!] a, simp_all) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
498 |
apply(simp_all add: nth_append change_termi_state.simps tshift.simps) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
499 |
done |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
500 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
501 |
lemma t_merge_snd_eq_step: |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
502 |
"\<lbrakk>tstep (s, l, r) B = (s', l', r'); t_correct A; t_correct B; s > 0\<rbrakk> |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
503 |
\<Longrightarrow> tstep (s + length A div 2, l, r) (A |+| B) = |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
504 |
(if s' = 0 then 0 else s' + length A div 2, l' ,r') " |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
505 |
apply(simp add: tstep.simps) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
506 |
apply(cases "fetch B s (case r of [] \<Rightarrow> Bk | x # xs \<Rightarrow> x)") |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
507 |
apply(auto simp: t_merge_fetch_snd) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
508 |
apply(frule_tac [!] t_merge_fetch_snd, auto) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
509 |
done |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
510 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
511 |
text {* |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
512 |
Relates the executions of TM @{text "B"}, one is when @{text "B"} is executed alone, |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
513 |
the other is the execution when @{text "B"} is in the combined TM. |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
514 |
*} |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
515 |
lemma t_merge_snd_eq_steps: |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
516 |
"\<lbrakk>t_correct A; t_correct B; steps (s, l, r) B stp = (s', l', r'); s > 0\<rbrakk> |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
517 |
\<Longrightarrow> steps (s + length A div 2, l, r) (A |+| B) stp = |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
518 |
(if s' = 0 then 0 else s' + length A div 2, l', r')" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
519 |
proof(induct stp arbitrary: s' l' r') |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
520 |
case 0 thus "?case" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
521 |
by(simp add: steps.simps) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
522 |
next |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
523 |
fix stp s' l' r' |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
524 |
assume ind: "\<And>s' l' r'. \<lbrakk>t_correct A; t_correct B; steps (s, l, r) B stp = (s', l', r'); 0 < s\<rbrakk> |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
525 |
\<Longrightarrow> steps (s + length A div 2, l, r) (A |+| B) stp = |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
526 |
(if s' = 0 then 0 else s' + length A div 2, l', r')" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
527 |
and h1: "steps (s, l, r) B (Suc stp) = (s', l', r')" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
528 |
and h2: "t_correct A" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
529 |
and h3: "t_correct B" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
530 |
and h4: "0 < s" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
531 |
from h1 show "steps (s + length A div 2, l, r) (A |+| B) (Suc stp) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
532 |
= (if s' = 0 then 0 else s' + length A div 2, l', r')" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
533 |
proof(simp only: tstep_red, cases "steps (s, l, r) B stp") |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
534 |
fix a b c |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
535 |
assume h5: "steps (s, l, r) B stp = (a, b, c)" "tstep (steps (s, l, r) B stp) B = (s', l', r')" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
536 |
hence h6: "(steps (s + length A div 2, l, r) (A |+| B) stp) = |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
537 |
((if a = 0 then 0 else a + length A div 2, b, c))" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
538 |
using h2 h3 h4 |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
539 |
by(rule_tac ind, auto) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
540 |
thus "tstep (steps (s + length A div 2, l, r) (A |+| B) stp) (A |+| B) = |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
541 |
(if s' = 0 then 0 else s'+ length A div 2, l', r')" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
542 |
using h5 |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
543 |
proof(auto) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
544 |
assume "tstep (0, b, c) B = (0, l', r')" thus "tstep (0, b, c) (A |+| B) = (0, l', r')" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
545 |
by(simp add: tstep_0) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
546 |
next |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
547 |
assume "tstep (0, b, c) B = (s', l', r')" "0 < s'" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
548 |
thus "tstep (0, b, c) (A |+| B) = (s' + length A div 2, l', r')" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
549 |
by(simp add: tstep_0) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
550 |
next |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
551 |
assume "tstep (a, b, c) B = (0, l', r')" "0 < a" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
552 |
thus "tstep (a + length A div 2, b, c) (A |+| B) = (0, l', r')" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
553 |
using h2 h3 |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
554 |
by(drule_tac t_merge_snd_eq_step, auto) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
555 |
next |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
556 |
assume "tstep (a, b, c) B = (s', l', r')" "0 < a" "0 < s'" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
557 |
thus "tstep (a + length A div 2, b, c) (A |+| B) = (s' + length A div 2, l', r')" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
558 |
using h2 h3 |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
559 |
by(drule_tac t_merge_snd_eq_step, auto) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
560 |
qed |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
561 |
qed |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
562 |
qed |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
563 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
564 |
lemma t_merge_snd_halt_eq: |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
565 |
"\<lbrakk>steps (Suc 0, tp) B stp = (0, tp'); t_correct A; t_correct B\<rbrakk> |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
566 |
\<Longrightarrow> \<exists>stp. steps (Suc (length A div 2), tp) (A |+| B) stp = (0, tp')" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
567 |
apply(case_tac tp, cases tp', simp) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
568 |
apply(drule_tac s = "Suc 0" in t_merge_snd_eq_steps, auto) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
569 |
done |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
570 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
571 |
lemma t_inj: "\<lbrakk>steps (Suc 0, tp) A stpa = (0, tp1); steps (Suc 0, tp) A stpb = (0, tp2)\<rbrakk> |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
572 |
\<Longrightarrow> tp1 = tp2" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
573 |
proof - |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
574 |
assume h1: "steps (Suc 0, tp) A stpa = (0, tp1)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
575 |
and h2: "steps (Suc 0, tp) A stpb = (0, tp2)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
576 |
thus "?thesis" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
577 |
proof(cases "stpa < stpb") |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
578 |
case True thus "?thesis" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
579 |
using h1 h2 |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
580 |
apply(drule_tac less_imp_Suc_add, auto) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
581 |
apply(simp del: add_Suc_right add_Suc add: add_Suc_right[THEN sym] steps_add steps_0) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
582 |
done |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
583 |
next |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
584 |
case False thus "?thesis" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
585 |
using h1 h2 |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
586 |
apply(drule_tac leI) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
587 |
apply(case_tac "stpb = stpa", auto) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
588 |
apply(subgoal_tac "stpb < stpa") |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
589 |
apply(drule_tac less_imp_Suc_add, auto) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
590 |
apply(simp del: add_Suc_right add_Suc add: add_Suc_right[THEN sym] steps_add steps_0) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
591 |
done |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
592 |
qed |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
593 |
qed |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
594 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
595 |
type_synonym t_assert = "tape \<Rightarrow> bool" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
596 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
597 |
definition t_imply :: "t_assert \<Rightarrow> t_assert \<Rightarrow> bool" ("_ \<turnstile>-> _" [0, 0] 100) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
598 |
where |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
599 |
"t_imply a1 a2 = (\<forall> tp. a1 tp \<longrightarrow> a2 tp)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
600 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
601 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
602 |
locale turing_merge = |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
603 |
fixes A :: "tprog" and B :: "tprog" and P1 :: "t_assert" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
604 |
and P2 :: "t_assert" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
605 |
and P3 :: "t_assert" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
606 |
and P4 :: "t_assert" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
607 |
and Q1:: "t_assert" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
608 |
and Q2 :: "t_assert" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
609 |
assumes |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
610 |
A_wf : "t_correct A" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
611 |
and B_wf : "t_correct B" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
612 |
and A_halt : "P1 tp \<Longrightarrow> \<exists> stp. let (s, tp') = steps (Suc 0, tp) A stp in s = 0 \<and> Q1 tp'" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
613 |
and B_halt : "P2 tp \<Longrightarrow> \<exists> stp. let (s, tp') = steps (Suc 0, tp) B stp in s = 0 \<and> Q2 tp'" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
614 |
and A_uhalt : "P3 tp \<Longrightarrow> \<not> (\<exists> stp. isS0 (steps (Suc 0, tp) A stp))" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
615 |
and B_uhalt: "P4 tp \<Longrightarrow> \<not> (\<exists> stp. isS0 (steps (Suc 0, tp) B stp))" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
616 |
begin |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
617 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
618 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
619 |
text {* |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
620 |
The following lemma tries to derive the Hoare logic rule for sequentially combined TMs. |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
621 |
It deals with the situtation when both @{text "A"} and @{text "B"} are terminated. |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
622 |
*} |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
623 |
|
41
6d89ed67ba27
some experiments
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
0
diff
changeset
|
624 |
thm t_merge_pre_halt_same |
6d89ed67ba27
some experiments
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
0
diff
changeset
|
625 |
|
0
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
626 |
lemma t_merge_halt: |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
627 |
assumes aimpb: "Q1 \<turnstile>-> P2" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
628 |
shows "P1 \<turnstile>-> \<lambda> tp. (\<exists> stp tp'. steps (Suc 0, tp) (A |+| B) stp = (0, tp') \<and> Q2 tp')" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
629 |
proof(simp add: t_imply_def, auto) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
630 |
fix a b |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
631 |
assume h: "P1 (a, b)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
632 |
hence "\<exists> stp. let (s, tp') = steps (Suc 0, a, b) A stp in s = 0 \<and> Q1 tp'" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
633 |
using A_halt by simp |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
634 |
from this obtain stp1 where "let (s, tp') = steps (Suc 0, a, b) A stp1 in s = 0 \<and> Q1 tp'" .. |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
635 |
thus "\<exists>stp aa ba. steps (Suc 0, a, b) (A |+| B) stp = (0, aa, ba) \<and> Q2 (aa, ba)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
636 |
proof(case_tac "steps (Suc 0, a, b) A stp1", simp, erule_tac conjE) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
637 |
fix aa ba c |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
638 |
assume g1: "Q1 (ba, c)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
639 |
and g2: "steps (Suc 0, a, b) A stp1 = (0, ba, c)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
640 |
hence "P2 (ba, c)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
641 |
using aimpb apply(simp add: t_imply_def) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
642 |
done |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
643 |
hence "\<exists> stp. let (s, tp') = steps (Suc 0, ba, c) B stp in s = 0 \<and> Q2 tp'" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
644 |
using B_halt by simp |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
645 |
from this obtain stp2 where "let (s, tp') = steps (Suc 0, ba, c) B stp2 in s = 0 \<and> Q2 tp'" .. |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
646 |
thus "?thesis" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
647 |
proof(case_tac "steps (Suc 0, ba, c) B stp2", simp, erule_tac conjE) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
648 |
fix aa bb ca |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
649 |
assume g3: " Q2 (bb, ca)" "steps (Suc 0, ba, c) B stp2 = (0, bb, ca)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
650 |
have "\<exists> stp. steps (Suc 0, a, b) (A |+| B) stp = (Suc (length A div 2), ba , c)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
651 |
using g2 A_wf B_wf |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
652 |
by(rule_tac t_merge_pre_halt_same, auto) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
653 |
moreover have "\<exists> stp. steps (Suc (length A div 2), ba, c) (A |+| B) stp = (0, bb, ca)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
654 |
using g3 A_wf B_wf |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
655 |
apply(rule_tac t_merge_snd_halt_eq, auto) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
656 |
done |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
657 |
ultimately show "\<exists>stp aa ba. steps (Suc 0, a, b) (A |+| B) stp = (0, aa, ba) \<and> Q2 (aa, ba)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
658 |
apply(erule_tac exE, erule_tac exE) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
659 |
apply(rule_tac x = "stp + stpa" in exI, simp add: steps_add) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
660 |
using g3 by simp |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
661 |
qed |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
662 |
qed |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
663 |
qed |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
664 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
665 |
lemma t_merge_uhalt_tmp: |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
666 |
assumes B_uh: "\<forall>stp. \<not> isS0 (steps (Suc 0, b, c) B stp)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
667 |
and merge_ah: "steps (Suc 0, tp) (A |+| B) stpa = (Suc (length A div 2), b, c)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
668 |
shows "\<forall> stp. \<not> isS0 (steps (Suc 0, tp) (A |+| B) stp)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
669 |
using B_uh merge_ah |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
670 |
apply(rule_tac allI) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
671 |
apply(case_tac "stp > stpa") |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
672 |
apply(erule_tac x = "stp - stpa" in allE) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
673 |
apply(case_tac "(steps (Suc 0, b, c) B (stp - stpa))", simp) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
674 |
proof - |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
675 |
fix stp a ba ca |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
676 |
assume h1: "\<not> isS0 (a, ba, ca)" "stpa < stp" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
677 |
and h2: "steps (Suc 0, b, c) B (stp - stpa) = (a, ba, ca)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
678 |
have "steps (Suc 0 + length A div 2, b, c) (A |+| B) (stp - stpa) = |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
679 |
(if a = 0 then 0 else a + length A div 2, ba, ca)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
680 |
using A_wf B_wf h2 |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
681 |
by(rule_tac t_merge_snd_eq_steps, auto) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
682 |
moreover have "a > 0" using h1 by(simp add: isS0_def) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
683 |
moreover have "\<exists> stpb. stp = stpa + stpb" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
684 |
using h1 by(rule_tac x = "stp - stpa" in exI, simp) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
685 |
ultimately show "\<not> isS0 (steps (Suc 0, tp) (A |+| B) stp)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
686 |
using merge_ah |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
687 |
by(auto simp: steps_add isS0_def) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
688 |
next |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
689 |
fix stp |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
690 |
assume h: "steps (Suc 0, tp) (A |+| B) stpa = (Suc (length A div 2), b, c)" "\<not> stpa < stp" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
691 |
hence "\<exists> stpb. stpa = stp + stpb" apply(rule_tac x = "stpa - stp" in exI, auto) done |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
692 |
thus "\<not> isS0 (steps (Suc 0, tp) (A |+| B) stp)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
693 |
using h |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
694 |
apply(auto) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
695 |
apply(cases "steps (Suc 0, tp) (A |+| B) stp", simp add: steps_add isS0_def steps_0) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
696 |
done |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
697 |
qed |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
698 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
699 |
text {* |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
700 |
The following lemma deals with the situation when TM @{text "B"} can not terminate. |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
701 |
*} |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
702 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
703 |
lemma t_merge_uhalt: |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
704 |
assumes aimpb: "Q1 \<turnstile>-> P4" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
705 |
shows "P1 \<turnstile>-> \<lambda> tp. \<not> (\<exists> stp. isS0 (steps (Suc 0, tp) (A |+| B) stp))" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
706 |
proof(simp only: t_imply_def, rule_tac allI, rule_tac impI) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
707 |
fix tp |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
708 |
assume init_asst: "P1 tp" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
709 |
show "\<not> (\<exists>stp. isS0 (steps (Suc 0, tp) (A |+| B) stp))" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
710 |
proof - |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
711 |
have "\<exists> stp. let (s, tp') = steps (Suc 0, tp) A stp in s = 0 \<and> Q1 tp'" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
712 |
using A_halt[of tp] init_asst |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
713 |
by(simp) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
714 |
from this obtain stpx where "let (s, tp') = steps (Suc 0, tp) A stpx in s = 0 \<and> Q1 tp'" .. |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
715 |
thus "?thesis" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
716 |
proof(cases "steps (Suc 0, tp) A stpx", simp, erule_tac conjE) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
717 |
fix a b c |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
718 |
assume "Q1 (b, c)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
719 |
and h3: "steps (Suc 0, tp) A stpx = (0, b, c)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
720 |
hence h2: "P4 (b, c)" using aimpb |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
721 |
by(simp add: t_imply_def) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
722 |
have "\<exists> stp. steps (Suc 0, tp) (A |+| B) stp = (Suc (length A div 2), b, c)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
723 |
using h3 A_wf B_wf |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
724 |
apply(rule_tac stp = stpx in t_merge_pre_halt_same, auto) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
725 |
done |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
726 |
from this obtain stpa where h4:"steps (Suc 0, tp) (A |+| B) stpa = (Suc (length A div 2), b, c)" .. |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
727 |
have " \<not> (\<exists> stp. isS0 (steps (Suc 0, b, c) B stp))" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
728 |
using B_uhalt [of "(b, c)"] h2 apply simp |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
729 |
done |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
730 |
from this and h4 show "\<forall>stp. \<not> isS0 (steps (Suc 0, tp) (A |+| B) stp)" |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
731 |
by(rule_tac t_merge_uhalt_tmp, auto) |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
732 |
qed |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
733 |
qed |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
734 |
qed |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
735 |
end |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
736 |
|
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
737 |
end |
aa8656a8dbef
initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
738 |