author | Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at> |
Fri, 21 Dec 2018 15:30:24 +0100 | |
changeset 291 | 93db7414931d |
parent 288 | a9003e6d0463 |
child 292 | 293e9c6f22e1 |
permissions | -rwxr-xr-x |
168
d7570dbf9f06
small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
163
diff
changeset
|
1 |
(* Title: thys/Turing.thy |
d7570dbf9f06
small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
163
diff
changeset
|
2 |
Author: Jian Xu, Xingyuan Zhang, and Christian Urban |
43
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
3 |
*) |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
4 |
|
288
a9003e6d0463
Up to date for Isabelle 2018. Gave names to simp rules in UF and UTM
Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
parents:
250
diff
changeset
|
5 |
chapter {* Turing Machines *} |
168
d7570dbf9f06
small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
163
diff
changeset
|
6 |
|
163
67063c5365e1
changed theory names to uppercase
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
97
diff
changeset
|
7 |
theory Turing |
43
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
8 |
imports Main |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
9 |
begin |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
10 |
|
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
11 |
section {* Basic definitions of Turing machine *} |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
12 |
|
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
13 |
datatype action = W0 | W1 | L | R | Nop |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
14 |
|
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
15 |
datatype cell = Bk | Oc |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
16 |
|
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
17 |
type_synonym tape = "cell list \<times> cell list" |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
18 |
|
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
19 |
type_synonym state = nat |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
20 |
|
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
21 |
type_synonym instr = "action \<times> state" |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
22 |
|
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
23 |
type_synonym tprog = "instr list \<times> nat" |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
24 |
|
54
e7d845acb0a7
changed slightly HOARE-def
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
53
diff
changeset
|
25 |
type_synonym tprog0 = "instr list" |
e7d845acb0a7
changed slightly HOARE-def
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
53
diff
changeset
|
26 |
|
43
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
27 |
type_synonym config = "state \<times> tape" |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
28 |
|
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
29 |
fun nth_of where |
168
d7570dbf9f06
small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
163
diff
changeset
|
30 |
"nth_of xs i = (if i \<ge> length xs then None else Some (xs ! i))" |
43
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
31 |
|
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
32 |
lemma nth_of_map [simp]: |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
33 |
shows "nth_of (map f p) n = (case (nth_of p n) of None \<Rightarrow> None | Some x \<Rightarrow> Some (f x))" |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
34 |
apply(induct p arbitrary: n) |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
35 |
apply(auto) |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
36 |
apply(case_tac n) |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
37 |
apply(auto) |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
38 |
done |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
39 |
|
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
40 |
fun |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
41 |
fetch :: "instr list \<Rightarrow> state \<Rightarrow> cell \<Rightarrow> instr" |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
42 |
where |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
43 |
"fetch p 0 b = (Nop, 0)" |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
44 |
| "fetch p (Suc s) Bk = |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
45 |
(case nth_of p (2 * s) of |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
46 |
Some i \<Rightarrow> i |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
47 |
| None \<Rightarrow> (Nop, 0))" |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
48 |
|"fetch p (Suc s) Oc = |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
49 |
(case nth_of p ((2 * s) + 1) of |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
50 |
Some i \<Rightarrow> i |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
51 |
| None \<Rightarrow> (Nop, 0))" |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
52 |
|
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
53 |
lemma fetch_Nil [simp]: |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
54 |
shows "fetch [] s b = (Nop, 0)" |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
55 |
apply(case_tac s) |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
56 |
apply(auto) |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
57 |
apply(case_tac b) |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
58 |
apply(auto) |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
59 |
done |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
60 |
|
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
61 |
fun |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
62 |
update :: "action \<Rightarrow> tape \<Rightarrow> tape" |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
63 |
where |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
64 |
"update W0 (l, r) = (l, Bk # (tl r))" |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
65 |
| "update W1 (l, r) = (l, Oc # (tl r))" |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
66 |
| "update L (l, r) = (if l = [] then ([], Bk # r) else (tl l, (hd l) # r))" |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
67 |
| "update R (l, r) = (if r = [] then (Bk # l, []) else ((hd r) # l, tl r))" |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
68 |
| "update Nop (l, r) = (l, r)" |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
69 |
|
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
70 |
abbreviation |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
71 |
"read r == if (r = []) then Bk else hd r" |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
72 |
|
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
73 |
fun step :: "config \<Rightarrow> tprog \<Rightarrow> config" |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
74 |
where |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
75 |
"step (s, l, r) (p, off) = |
50
816e84ca16d6
updated turing_basic by Jian
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
47
diff
changeset
|
76 |
(let (a, s') = fetch p (s - off) (read r) in (s', update a (l, r)))" |
43
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
77 |
|
168
d7570dbf9f06
small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
163
diff
changeset
|
78 |
abbreviation |
d7570dbf9f06
small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
163
diff
changeset
|
79 |
"step0 c p \<equiv> step c (p, 0)" |
d7570dbf9f06
small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
163
diff
changeset
|
80 |
|
43
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
81 |
fun steps :: "config \<Rightarrow> tprog \<Rightarrow> nat \<Rightarrow> config" |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
82 |
where |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
83 |
"steps c p 0 = c" | |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
84 |
"steps c p (Suc n) = steps (step c p) p n" |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
85 |
|
54
e7d845acb0a7
changed slightly HOARE-def
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
53
diff
changeset
|
86 |
abbreviation |
e7d845acb0a7
changed slightly HOARE-def
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
53
diff
changeset
|
87 |
"steps0 c p n \<equiv> steps c (p, 0) n" |
e7d845acb0a7
changed slightly HOARE-def
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
53
diff
changeset
|
88 |
|
43
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
89 |
lemma step_red [simp]: |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
90 |
shows "steps c p (Suc n) = step (steps c p n) p" |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
91 |
by (induct n arbitrary: c) (auto) |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
92 |
|
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
93 |
lemma steps_add [simp]: |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
94 |
shows "steps c p (m + n) = steps (steps c p m) p n" |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
95 |
by (induct m arbitrary: c) (auto) |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
96 |
|
56
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
97 |
lemma step_0 [simp]: |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
98 |
shows "step (0, (l, r)) p = (0, (l, r))" |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
99 |
by (case_tac p, simp) |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
100 |
|
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
101 |
lemma steps_0 [simp]: |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
102 |
shows "steps (0, (l, r)) p n = (0, (l, r))" |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
103 |
by (induct n) (simp_all) |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
104 |
|
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
105 |
fun |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
106 |
is_final :: "config \<Rightarrow> bool" |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
107 |
where |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
108 |
"is_final (s, l, r) = (s = 0)" |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
109 |
|
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
110 |
lemma is_final_eq: |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
111 |
shows "is_final (s, tp) = (s = 0)" |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
112 |
by (case_tac tp) (auto) |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
113 |
|
250
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
190
diff
changeset
|
114 |
lemma is_finalI [intro]: |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
190
diff
changeset
|
115 |
shows "is_final (0, tp)" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
190
diff
changeset
|
116 |
by (simp add: is_final_eq) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
190
diff
changeset
|
117 |
|
61
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
118 |
lemma after_is_final: |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
119 |
assumes "is_final c" |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
120 |
shows "is_final (steps c p n)" |
56
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
121 |
using assms |
61
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
122 |
apply(induct n) |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
123 |
apply(case_tac [!] c) |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
124 |
apply(auto) |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
125 |
done |
56
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
126 |
|
250
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
190
diff
changeset
|
127 |
lemma is_final: |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
190
diff
changeset
|
128 |
assumes a: "is_final (steps c p n1)" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
190
diff
changeset
|
129 |
and b: "n1 \<le> n2" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
190
diff
changeset
|
130 |
shows "is_final (steps c p n2)" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
190
diff
changeset
|
131 |
proof - |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
190
diff
changeset
|
132 |
obtain n3 where eq: "n2 = n1 + n3" using b by (metis le_iff_add) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
190
diff
changeset
|
133 |
from a show "is_final (steps c p n2)" unfolding eq |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
190
diff
changeset
|
134 |
by (simp add: after_is_final) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
190
diff
changeset
|
135 |
qed |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
190
diff
changeset
|
136 |
|
61
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
137 |
lemma not_is_final: |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
138 |
assumes a: "\<not> is_final (steps c p n1)" |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
139 |
and b: "n2 \<le> n1" |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
140 |
shows "\<not> is_final (steps c p n2)" |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
141 |
proof (rule notI) |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
142 |
obtain n3 where eq: "n1 = n2 + n3" using b by (metis le_iff_add) |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
143 |
assume "is_final (steps c p n2)" |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
144 |
then have "is_final (steps c p n1)" unfolding eq |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
145 |
by (simp add: after_is_final) |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
146 |
with a show "False" by simp |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
147 |
qed |
56
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
148 |
|
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
149 |
(* if the machine is in the halting state, there must have |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
150 |
been a state just before the halting state *) |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
151 |
lemma before_final: |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
152 |
assumes "steps0 (1, tp) A n = (0, tp')" |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
153 |
shows "\<exists> n'. \<not> is_final (steps0 (1, tp) A n') \<and> steps0 (1, tp) A (Suc n') = (0, tp')" |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
154 |
using assms |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
155 |
proof(induct n arbitrary: tp') |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
156 |
case (0 tp') |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
157 |
have asm: "steps0 (1, tp) A 0 = (0, tp')" by fact |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
158 |
then show "\<exists>n'. \<not> is_final (steps0 (1, tp) A n') \<and> steps0 (1, tp) A (Suc n') = (0, tp')" |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
159 |
by simp |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
160 |
next |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
161 |
case (Suc n tp') |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
162 |
have ih: "\<And>tp'. steps0 (1, tp) A n = (0, tp') \<Longrightarrow> |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
163 |
\<exists>n'. \<not> is_final (steps0 (1, tp) A n') \<and> steps0 (1, tp) A (Suc n') = (0, tp')" by fact |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
164 |
have asm: "steps0 (1, tp) A (Suc n) = (0, tp')" by fact |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
165 |
obtain s l r where cases: "steps0 (1, tp) A n = (s, l, r)" |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
166 |
by (auto intro: is_final.cases) |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
167 |
then show "\<exists>n'. \<not> is_final (steps0 (1, tp) A n') \<and> steps0 (1, tp) A (Suc n') = (0, tp')" |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
168 |
proof (cases "s = 0") |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
169 |
case True (* in halting state *) |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
170 |
then have "steps0 (1, tp) A n = (0, tp')" |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
171 |
using asm cases by (simp del: steps.simps) |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
172 |
then show ?thesis using ih by simp |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
173 |
next |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
174 |
case False (* not in halting state *) |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
175 |
then have "\<not> is_final (steps0 (1, tp) A n) \<and> steps0 (1, tp) A (Suc n) = (0, tp')" |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
176 |
using asm cases by simp |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
177 |
then show ?thesis by auto |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
178 |
qed |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
179 |
qed |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
180 |
|
250
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
190
diff
changeset
|
181 |
lemma least_steps: |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
190
diff
changeset
|
182 |
assumes "steps0 (1, tp) A n = (0, tp')" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
190
diff
changeset
|
183 |
shows "\<exists> n'. (\<forall>n'' < n'. \<not> is_final (steps0 (1, tp) A n'')) \<and> |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
190
diff
changeset
|
184 |
(\<forall>n'' \<ge> n'. is_final (steps0 (1, tp) A n''))" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
190
diff
changeset
|
185 |
proof - |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
190
diff
changeset
|
186 |
from before_final[OF assms] |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
190
diff
changeset
|
187 |
obtain n' where |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
190
diff
changeset
|
188 |
before: "\<not> is_final (steps0 (1, tp) A n')" and |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
190
diff
changeset
|
189 |
final: "steps0 (1, tp) A (Suc n') = (0, tp')" by auto |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
190
diff
changeset
|
190 |
from before |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
190
diff
changeset
|
191 |
have "\<forall>n'' < Suc n'. \<not> is_final (steps0 (1, tp) A n'')" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
190
diff
changeset
|
192 |
using not_is_final by auto |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
190
diff
changeset
|
193 |
moreover |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
190
diff
changeset
|
194 |
from final |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
190
diff
changeset
|
195 |
have "\<forall>n'' \<ge> Suc n'. is_final (steps0 (1, tp) A n'')" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
190
diff
changeset
|
196 |
using is_final[of _ _ "Suc n'"] by (auto simp add: is_final_eq) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
190
diff
changeset
|
197 |
ultimately |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
190
diff
changeset
|
198 |
show "\<exists> n'. (\<forall>n'' < n'. \<not> is_final (steps0 (1, tp) A n'')) \<and> (\<forall>n'' \<ge> n'. is_final (steps0 (1, tp) A n''))" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
190
diff
changeset
|
199 |
by blast |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
190
diff
changeset
|
200 |
qed |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
190
diff
changeset
|
201 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
190
diff
changeset
|
202 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
190
diff
changeset
|
203 |
|
56
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
204 |
(* well-formedness of Turing machine programs *) |
71
8c7f10b3da7b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
63
diff
changeset
|
205 |
abbreviation "is_even n \<equiv> (n::nat) mod 2 = 0" |
8c7f10b3da7b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
63
diff
changeset
|
206 |
|
43
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
207 |
fun |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
208 |
tm_wf :: "tprog \<Rightarrow> bool" |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
209 |
where |
71
8c7f10b3da7b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
63
diff
changeset
|
210 |
"tm_wf (p, off) = (length p \<ge> 2 \<and> is_even (length p) \<and> |
54
e7d845acb0a7
changed slightly HOARE-def
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
53
diff
changeset
|
211 |
(\<forall>(a, s) \<in> set p. s \<le> length p div 2 + off \<and> s \<ge> off))" |
43
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
212 |
|
63
35fe8fe12e65
small updates
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
61
diff
changeset
|
213 |
abbreviation |
35fe8fe12e65
small updates
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
61
diff
changeset
|
214 |
"tm_wf0 p \<equiv> tm_wf (p, 0)" |
35fe8fe12e65
small updates
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
61
diff
changeset
|
215 |
|
43
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
216 |
abbreviation exponent :: "'a \<Rightarrow> nat \<Rightarrow> 'a list" ("_ \<up> _" [100, 99] 100) |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
217 |
where "x \<up> n == replicate n x" |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
218 |
|
288
a9003e6d0463
Up to date for Isabelle 2018. Gave names to simp rules in UF and UTM
Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
parents:
250
diff
changeset
|
219 |
class tape = |
a9003e6d0463
Up to date for Isabelle 2018. Gave names to simp rules in UF and UTM
Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
parents:
250
diff
changeset
|
220 |
fixes tape_of :: "'a \<Rightarrow> cell list" ("<_>" 100) |
84
4c8325c64dab
updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
71
diff
changeset
|
221 |
|
47
251e192339b7
added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
43
diff
changeset
|
222 |
|
288
a9003e6d0463
Up to date for Isabelle 2018. Gave names to simp rules in UF and UTM
Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
parents:
250
diff
changeset
|
223 |
instantiation nat::tape begin |
a9003e6d0463
Up to date for Isabelle 2018. Gave names to simp rules in UF and UTM
Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
parents:
250
diff
changeset
|
224 |
definition tape_of_nat where "tape_of_nat (n::nat) \<equiv> Oc \<up> (Suc n)" |
a9003e6d0463
Up to date for Isabelle 2018. Gave names to simp rules in UF and UTM
Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
parents:
250
diff
changeset
|
225 |
instance by standard |
a9003e6d0463
Up to date for Isabelle 2018. Gave names to simp rules in UF and UTM
Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
parents:
250
diff
changeset
|
226 |
end |
a9003e6d0463
Up to date for Isabelle 2018. Gave names to simp rules in UF and UTM
Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
parents:
250
diff
changeset
|
227 |
|
a9003e6d0463
Up to date for Isabelle 2018. Gave names to simp rules in UF and UTM
Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
parents:
250
diff
changeset
|
228 |
type_synonym nat_list = "nat list" |
a9003e6d0463
Up to date for Isabelle 2018. Gave names to simp rules in UF and UTM
Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
parents:
250
diff
changeset
|
229 |
|
a9003e6d0463
Up to date for Isabelle 2018. Gave names to simp rules in UF and UTM
Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
parents:
250
diff
changeset
|
230 |
instantiation list::(tape) tape begin |
a9003e6d0463
Up to date for Isabelle 2018. Gave names to simp rules in UF and UTM
Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
parents:
250
diff
changeset
|
231 |
fun tape_of_nat_list :: "('a::tape) list \<Rightarrow> cell list" |
a9003e6d0463
Up to date for Isabelle 2018. Gave names to simp rules in UF and UTM
Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
parents:
250
diff
changeset
|
232 |
where |
a9003e6d0463
Up to date for Isabelle 2018. Gave names to simp rules in UF and UTM
Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
parents:
250
diff
changeset
|
233 |
"tape_of_nat_list [] = []" | |
a9003e6d0463
Up to date for Isabelle 2018. Gave names to simp rules in UF and UTM
Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
parents:
250
diff
changeset
|
234 |
"tape_of_nat_list [n] = <n>" | |
a9003e6d0463
Up to date for Isabelle 2018. Gave names to simp rules in UF and UTM
Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
parents:
250
diff
changeset
|
235 |
"tape_of_nat_list (n#ns) = <n> @ Bk # (tape_of_nat_list ns)" |
a9003e6d0463
Up to date for Isabelle 2018. Gave names to simp rules in UF and UTM
Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
parents:
250
diff
changeset
|
236 |
definition tape_of_list where "tape_of_list \<equiv> tape_of_nat_list" |
a9003e6d0463
Up to date for Isabelle 2018. Gave names to simp rules in UF and UTM
Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
parents:
250
diff
changeset
|
237 |
instance by standard |
a9003e6d0463
Up to date for Isabelle 2018. Gave names to simp rules in UF and UTM
Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
parents:
250
diff
changeset
|
238 |
end |
a9003e6d0463
Up to date for Isabelle 2018. Gave names to simp rules in UF and UTM
Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
parents:
250
diff
changeset
|
239 |
|
a9003e6d0463
Up to date for Isabelle 2018. Gave names to simp rules in UF and UTM
Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
parents:
250
diff
changeset
|
240 |
instantiation prod:: (tape, tape) tape begin |
a9003e6d0463
Up to date for Isabelle 2018. Gave names to simp rules in UF and UTM
Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
parents:
250
diff
changeset
|
241 |
fun tape_of_nat_prod :: "('a::tape) \<times> ('b::tape) \<Rightarrow> cell list" |
a9003e6d0463
Up to date for Isabelle 2018. Gave names to simp rules in UF and UTM
Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
parents:
250
diff
changeset
|
242 |
where "tape_of_nat_prod (n, m) = <n> @ [Bk] @ <m>" |
a9003e6d0463
Up to date for Isabelle 2018. Gave names to simp rules in UF and UTM
Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
parents:
250
diff
changeset
|
243 |
definition tape_of_prod where "tape_of_prod \<equiv> tape_of_nat_prod" |
a9003e6d0463
Up to date for Isabelle 2018. Gave names to simp rules in UF and UTM
Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
parents:
250
diff
changeset
|
244 |
instance by standard |
a9003e6d0463
Up to date for Isabelle 2018. Gave names to simp rules in UF and UTM
Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
parents:
250
diff
changeset
|
245 |
end |
43
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
246 |
|
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
247 |
fun |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
248 |
shift :: "instr list \<Rightarrow> nat \<Rightarrow> instr list" |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
249 |
where |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
250 |
"shift p n = (map (\<lambda> (a, s). (a, (if s = 0 then 0 else s + n))) p)" |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
251 |
|
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
252 |
fun |
190
f1ecb4a68a54
renamed sete definition to adjust and old special case of adjust to adjust0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
253 |
adjust :: "instr list \<Rightarrow> nat \<Rightarrow> instr list" |
43
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
254 |
where |
190
f1ecb4a68a54
renamed sete definition to adjust and old special case of adjust to adjust0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
255 |
"adjust p e = map (\<lambda> (a, s). (a, if s = 0 then e else s)) p" |
f1ecb4a68a54
renamed sete definition to adjust and old special case of adjust to adjust0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
256 |
|
f1ecb4a68a54
renamed sete definition to adjust and old special case of adjust to adjust0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
257 |
abbreviation |
f1ecb4a68a54
renamed sete definition to adjust and old special case of adjust to adjust0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
258 |
"adjust0 p \<equiv> adjust p (Suc (length p div 2))" |
43
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
259 |
|
54
e7d845acb0a7
changed slightly HOARE-def
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
53
diff
changeset
|
260 |
lemma length_shift [simp]: |
56
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
261 |
shows "length (shift p n) = length p" |
54
e7d845acb0a7
changed slightly HOARE-def
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
53
diff
changeset
|
262 |
by simp |
e7d845acb0a7
changed slightly HOARE-def
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
53
diff
changeset
|
263 |
|
56
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
264 |
lemma length_adjust [simp]: |
190
f1ecb4a68a54
renamed sete definition to adjust and old special case of adjust to adjust0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
265 |
shows "length (adjust p n) = length p" |
43
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
266 |
by (induct p) (auto) |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
267 |
|
56
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
268 |
|
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
269 |
(* composition of two Turing machines *) |
43
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
270 |
fun |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
271 |
tm_comp :: "instr list \<Rightarrow> instr list \<Rightarrow> instr list" ("_ |+| _" [0, 0] 100) |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
272 |
where |
190
f1ecb4a68a54
renamed sete definition to adjust and old special case of adjust to adjust0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
273 |
"tm_comp p1 p2 = ((adjust0 p1) @ (shift p2 (length p1 div 2)))" |
43
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
274 |
|
56
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
275 |
lemma tm_comp_length: |
54
e7d845acb0a7
changed slightly HOARE-def
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
53
diff
changeset
|
276 |
shows "length (A |+| B) = length A + length B" |
e7d845acb0a7
changed slightly HOARE-def
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
53
diff
changeset
|
277 |
by auto |
e7d845acb0a7
changed slightly HOARE-def
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
53
diff
changeset
|
278 |
|
93
f2bda6ba4952
updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
84
diff
changeset
|
279 |
lemma tm_comp_wf[intro]: |
f2bda6ba4952
updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
84
diff
changeset
|
280 |
"\<lbrakk>tm_wf (A, 0); tm_wf (B, 0)\<rbrakk> \<Longrightarrow> tm_wf (A |+| B, 0)" |
288
a9003e6d0463
Up to date for Isabelle 2018. Gave names to simp rules in UF and UTM
Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
parents:
250
diff
changeset
|
281 |
by (fastforce) |
93
f2bda6ba4952
updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
84
diff
changeset
|
282 |
|
61
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
283 |
lemma tm_comp_step: |
58
fbd346f5af86
more proofs polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
57
diff
changeset
|
284 |
assumes unfinal: "\<not> is_final (step0 c A)" |
fbd346f5af86
more proofs polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
57
diff
changeset
|
285 |
shows "step0 c (A |+| B) = step0 c A" |
fbd346f5af86
more proofs polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
57
diff
changeset
|
286 |
proof - |
fbd346f5af86
more proofs polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
57
diff
changeset
|
287 |
obtain s l r where eq: "c = (s, l, r)" by (metis is_final.cases) |
fbd346f5af86
more proofs polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
57
diff
changeset
|
288 |
have "\<not> is_final (step0 (s, l, r) A)" using unfinal eq by simp |
fbd346f5af86
more proofs polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
57
diff
changeset
|
289 |
then have "case (fetch A s (read r)) of (a, s) \<Rightarrow> s \<noteq> 0" |
fbd346f5af86
more proofs polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
57
diff
changeset
|
290 |
by (auto simp add: is_final_eq) |
fbd346f5af86
more proofs polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
57
diff
changeset
|
291 |
then have "fetch (A |+| B) s (read r) = fetch A s (read r)" |
fbd346f5af86
more proofs polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
57
diff
changeset
|
292 |
apply(case_tac [!] "read r") |
fbd346f5af86
more proofs polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
57
diff
changeset
|
293 |
apply(case_tac [!] s) |
fbd346f5af86
more proofs polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
57
diff
changeset
|
294 |
apply(auto simp: tm_comp_length nth_append) |
fbd346f5af86
more proofs polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
57
diff
changeset
|
295 |
done |
fbd346f5af86
more proofs polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
57
diff
changeset
|
296 |
then show "step0 c (A |+| B) = step0 c A" by (simp add: eq) |
fbd346f5af86
more proofs polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
57
diff
changeset
|
297 |
qed |
43
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
298 |
|
61
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
299 |
lemma tm_comp_steps: |
59
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
300 |
assumes "\<not> is_final (steps0 c A n)" |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
301 |
shows "steps0 c (A |+| B) n = steps0 c A n" |
58
fbd346f5af86
more proofs polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
57
diff
changeset
|
302 |
using assms |
fbd346f5af86
more proofs polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
57
diff
changeset
|
303 |
proof(induct n) |
fbd346f5af86
more proofs polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
57
diff
changeset
|
304 |
case 0 |
59
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
305 |
then show "steps0 c (A |+| B) 0 = steps0 c A 0" by auto |
58
fbd346f5af86
more proofs polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
57
diff
changeset
|
306 |
next |
fbd346f5af86
more proofs polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
57
diff
changeset
|
307 |
case (Suc n) |
59
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
308 |
have ih: "\<not> is_final (steps0 c A n) \<Longrightarrow> steps0 c (A |+| B) n = steps0 c A n" by fact |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
309 |
have fin: "\<not> is_final (steps0 c A (Suc n))" by fact |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
310 |
then have fin1: "\<not> is_final (step0 (steps0 c A n) A)" |
58
fbd346f5af86
more proofs polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
57
diff
changeset
|
311 |
by (auto simp only: step_red) |
59
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
312 |
then have fin2: "\<not> is_final (steps0 c A n)" |
58
fbd346f5af86
more proofs polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
57
diff
changeset
|
313 |
by (metis is_final_eq step_0 surj_pair) |
fbd346f5af86
more proofs polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
57
diff
changeset
|
314 |
|
59
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
315 |
have "steps0 c (A |+| B) (Suc n) = step0 (steps0 c (A |+| B) n) (A |+| B)" |
58
fbd346f5af86
more proofs polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
57
diff
changeset
|
316 |
by (simp only: step_red) |
59
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
317 |
also have "... = step0 (steps0 c A n) (A |+| B)" by (simp only: ih[OF fin2]) |
61
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
318 |
also have "... = step0 (steps0 c A n) A" by (simp only: tm_comp_step[OF fin1]) |
59
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
319 |
finally show "steps0 c (A |+| B) (Suc n) = steps0 c A (Suc n)" |
58
fbd346f5af86
more proofs polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
57
diff
changeset
|
320 |
by (simp only: step_red) |
43
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
321 |
qed |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
322 |
|
59
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
323 |
lemma tm_comp_fetch_in_A: |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
324 |
assumes h1: "fetch A s x = (a, 0)" |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
325 |
and h2: "s \<le> length A div 2" |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
326 |
and h3: "s \<noteq> 0" |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
327 |
shows "fetch (A |+| B) s x = (a, Suc (length A div 2))" |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
328 |
using h1 h2 h3 |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
329 |
apply(case_tac s) |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
330 |
apply(case_tac [!] x) |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
331 |
apply(auto simp: tm_comp_length nth_append) |
43
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
332 |
done |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
333 |
|
59
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
334 |
lemma tm_comp_exec_after_first: |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
335 |
assumes h1: "\<not> is_final c" |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
336 |
and h2: "step0 c A = (0, tp)" |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
337 |
and h3: "fst c \<le> length A div 2" |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
338 |
shows "step0 c (A |+| B) = (Suc (length A div 2), tp)" |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
339 |
using h1 h2 h3 |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
340 |
apply(case_tac c) |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
341 |
apply(auto simp del: tm_comp.simps) |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
342 |
apply(case_tac "fetch A a Bk") |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
343 |
apply(simp del: tm_comp.simps) |
288
a9003e6d0463
Up to date for Isabelle 2018. Gave names to simp rules in UF and UTM
Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
parents:
250
diff
changeset
|
344 |
apply(subst tm_comp_fetch_in_A;force) |
a9003e6d0463
Up to date for Isabelle 2018. Gave names to simp rules in UF and UTM
Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
parents:
250
diff
changeset
|
345 |
apply(case_tac "fetch A a (hd ca)") |
59
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
346 |
apply(simp del: tm_comp.simps) |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
347 |
apply(subst tm_comp_fetch_in_A) |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
348 |
apply(auto)[4] |
43
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
349 |
done |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
350 |
|
59
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
351 |
lemma step_in_range: |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
352 |
assumes h1: "\<not> is_final (step0 c A)" |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
353 |
and h2: "tm_wf (A, 0)" |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
354 |
shows "fst (step0 c A) \<le> length A div 2" |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
355 |
using h1 h2 |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
356 |
apply(case_tac c) |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
357 |
apply(case_tac a) |
288
a9003e6d0463
Up to date for Isabelle 2018. Gave names to simp rules in UF and UTM
Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
parents:
250
diff
changeset
|
358 |
apply(auto simp add: Let_def case_prod_beta') |
a9003e6d0463
Up to date for Isabelle 2018. Gave names to simp rules in UF and UTM
Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
parents:
250
diff
changeset
|
359 |
apply(case_tac "hd ca") |
a9003e6d0463
Up to date for Isabelle 2018. Gave names to simp rules in UF and UTM
Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
parents:
250
diff
changeset
|
360 |
apply(auto simp add: case_prod_beta') |
43
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
361 |
done |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
362 |
|
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
363 |
lemma steps_in_range: |
59
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
364 |
assumes h1: "\<not> is_final (steps0 (1, tp) A stp)" |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
365 |
and h2: "tm_wf (A, 0)" |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
366 |
shows "fst (steps0 (1, tp) A stp) \<le> length A div 2" |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
367 |
using h1 |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
368 |
proof(induct stp) |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
369 |
case 0 |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
370 |
then show "fst (steps0 (1, tp) A 0) \<le> length A div 2" using h2 |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
371 |
by (auto simp add: steps.simps tm_wf.simps) |
43
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
372 |
next |
59
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
373 |
case (Suc stp) |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
374 |
have ih: "\<not> is_final (steps0 (1, tp) A stp) \<Longrightarrow> fst (steps0 (1, tp) A stp) \<le> length A div 2" by fact |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
375 |
have h: "\<not> is_final (steps0 (1, tp) A (Suc stp))" by fact |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
376 |
from ih h h2 show "fst (steps0 (1, tp) A (Suc stp)) \<le> length A div 2" |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
377 |
by (metis step_in_range step_red) |
43
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
378 |
qed |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
379 |
|
168
d7570dbf9f06
small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
163
diff
changeset
|
380 |
(* if A goes into the final state, then A |+| B will go into the first state of B *) |
d7570dbf9f06
small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
163
diff
changeset
|
381 |
lemma tm_comp_next: |
59
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
382 |
assumes a_ht: "steps0 (1, tp) A n = (0, tp')" |
43
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
383 |
and a_wf: "tm_wf (A, 0)" |
59
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
384 |
obtains n' where "steps0 (1, tp) (A |+| B) n' = (Suc (length A div 2), tp')" |
43
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
385 |
proof - |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
386 |
assume a: "\<And>n. steps (1, tp) (A |+| B, 0) n = (Suc (length A div 2), tp') \<Longrightarrow> thesis" |
59
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
387 |
obtain stp' where fin: "\<not> is_final (steps0 (1, tp) A stp')" and h: "steps0 (1, tp) A (Suc stp') = (0, tp')" |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
388 |
using before_final[OF a_ht] by blast |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
389 |
from fin have h1:"steps0 (1, tp) (A |+| B) stp' = steps0 (1, tp) A stp'" |
61
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
390 |
by (rule tm_comp_steps) |
59
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
391 |
from h have h2: "step0 (steps0 (1, tp) A stp') A = (0, tp')" |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
392 |
by (simp only: step_red) |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
393 |
|
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
394 |
have "steps0 (1, tp) (A |+| B) (Suc stp') = step0 (steps0 (1, tp) (A |+| B) stp') (A |+| B)" |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
395 |
by (simp only: step_red) |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
396 |
also have "... = step0 (steps0 (1, tp) A stp') (A |+| B)" using h1 by simp |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
397 |
also have "... = (Suc (length A div 2), tp')" |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
398 |
by (rule tm_comp_exec_after_first[OF fin h2 steps_in_range[OF fin a_wf]]) |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
399 |
finally show thesis using a by blast |
43
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
400 |
qed |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
401 |
|
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
402 |
lemma tm_comp_fetch_second_zero: |
59
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
403 |
assumes h1: "fetch B s x = (a, 0)" |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
404 |
and hs: "tm_wf (A, 0)" "s \<noteq> 0" |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
405 |
shows "fetch (A |+| B) (s + (length A div 2)) x = (a, 0)" |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
406 |
using h1 hs |
43
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
407 |
apply(case_tac x) |
59
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
408 |
apply(case_tac [!] s) |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
409 |
apply(auto simp: tm_comp_length nth_append) |
43
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
410 |
done |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
411 |
|
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
412 |
lemma tm_comp_fetch_second_inst: |
59
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
413 |
assumes h1: "fetch B sa x = (a, s)" |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
414 |
and hs: "tm_wf (A, 0)" "sa \<noteq> 0" "s \<noteq> 0" |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
415 |
shows "fetch (A |+| B) (sa + length A div 2) x = (a, s + length A div 2)" |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
416 |
using h1 hs |
43
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
417 |
apply(case_tac x) |
59
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
418 |
apply(case_tac [!] sa) |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
419 |
apply(auto simp: tm_comp_length nth_append) |
43
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
420 |
done |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
421 |
|
59
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
422 |
|
168
d7570dbf9f06
small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
163
diff
changeset
|
423 |
lemma tm_comp_second: |
43
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
424 |
assumes a_wf: "tm_wf (A, 0)" |
59
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
425 |
and steps: "steps0 (1, l, r) B stp = (s', l', r')" |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
426 |
shows "steps0 (Suc (length A div 2), l, r) (A |+| B) stp |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
427 |
= (if s' = 0 then 0 else s' + length A div 2, l', r')" |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
428 |
using steps |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
429 |
proof(induct stp arbitrary: s' l' r') |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
430 |
case 0 |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
431 |
then show ?case by (simp add: steps.simps) |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
432 |
next |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
433 |
case (Suc stp s' l' r') |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
434 |
obtain s'' l'' r'' where a: "steps0 (1, l, r) B stp = (s'', l'', r'')" |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
435 |
by (metis is_final.cases) |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
436 |
then have ih1: "s'' = 0 \<Longrightarrow> steps0 (Suc (length A div 2), l, r) (A |+| B) stp = (0, l'', r'')" |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
437 |
and ih2: "s'' \<noteq> 0 \<Longrightarrow> steps0 (Suc (length A div 2), l, r) (A |+| B) stp = (s'' + length A div 2, l'', r'')" |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
438 |
using Suc by (auto) |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
439 |
have h: "steps0 (1, l, r) B (Suc stp) = (s', l', r')" by fact |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
440 |
|
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
441 |
{ assume "s'' = 0" |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
442 |
then have ?case using a h ih1 by (simp del: steps.simps) |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
443 |
} moreover |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
444 |
{ assume as: "s'' \<noteq> 0" "s' = 0" |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
445 |
from as a h |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
446 |
have "step0 (s'', l'', r'') B = (0, l', r')" by (simp del: steps.simps) |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
447 |
with as have ?case |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
448 |
apply(simp add: ih2[OF as(1)] step.simps del: tm_comp.simps steps.simps) |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
449 |
apply(case_tac "fetch B s'' (read r'')") |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
450 |
apply(auto simp add: tm_comp_fetch_second_zero[OF _ a_wf] simp del: tm_comp.simps) |
43
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
451 |
done |
59
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
452 |
} moreover |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
453 |
{ assume as: "s'' \<noteq> 0" "s' \<noteq> 0" |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
454 |
from as a h |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
455 |
have "step0 (s'', l'', r'') B = (s', l', r')" by (simp del: steps.simps) |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
456 |
with as have ?case |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
457 |
apply(simp add: ih2[OF as(1)] step.simps del: tm_comp.simps steps.simps) |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
458 |
apply(case_tac "fetch B s'' (read r'')") |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
459 |
apply(auto simp add: tm_comp_fetch_second_inst[OF _ a_wf as] simp del: tm_comp.simps) |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
460 |
done |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
461 |
} |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
462 |
ultimately show ?case by blast |
43
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
463 |
qed |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
464 |
|
168
d7570dbf9f06
small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
163
diff
changeset
|
465 |
|
d7570dbf9f06
small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
163
diff
changeset
|
466 |
lemma tm_comp_final: |
59
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
467 |
assumes "tm_wf (A, 0)" |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
468 |
and "steps0 (1, l, r) B stp = (0, l', r')" |
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
58
diff
changeset
|
469 |
shows "steps0 (Suc (length A div 2), l, r) (A |+| B) stp = (0, l', r')" |
168
d7570dbf9f06
small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
163
diff
changeset
|
470 |
using tm_comp_second[OF assms] by (simp) |
43
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
471 |
|
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
472 |
end |
a8785fa80278
updated literature
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
41
diff
changeset
|
473 |