author | Christian Urban <christian dot urban at kcl dot ac dot uk> |
Tue, 21 May 2013 13:50:15 +0100 | |
changeset 258 | 32c5e8d1f6ff |
parent 256 | 04700724250f |
permissions | -rwxr-xr-x |
246
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
1 |
theory UF_Rec |
258
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
2 |
imports Recs Turing2 |
246
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
3 |
begin |
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
4 |
|
258
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
5 |
section {* Coding of Turing Machines and tapes*} |
246
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
6 |
|
258
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
7 |
text {* |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
8 |
The purpose of this section is to construct the coding function of Turing |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
9 |
Machine, which is going to be named @{text "code"}. *} |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
10 |
|
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
11 |
text {* Encoding of actions as numbers *} |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
12 |
|
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
13 |
fun action_num :: "action \<Rightarrow> nat" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
14 |
where |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
15 |
"action_num W0 = 0" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
16 |
| "action_num W1 = 1" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
17 |
| "action_num L = 2" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
18 |
| "action_num R = 3" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
19 |
| "action_num Nop = 4" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
20 |
|
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
21 |
fun cell_num :: "cell \<Rightarrow> nat" where |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
22 |
"cell_num Bk = 0" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
23 |
| "cell_num Oc = 1" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
24 |
|
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
25 |
fun code_tp :: "cell list \<Rightarrow> nat list" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
26 |
where |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
27 |
"code_tp [] = []" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
28 |
| "code_tp (c # tp) = (cell_num c) # code_tp tp" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
29 |
|
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
30 |
fun Code_tp where |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
31 |
"Code_tp tp = lenc (code_tp tp)" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
32 |
|
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
33 |
fun Code_conf where |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
34 |
"Code_conf (s, l, r) = (s, Code_tp l, Code_tp r)" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
35 |
|
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
36 |
fun code_instr :: "instr \<Rightarrow> nat" where |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
37 |
"code_instr i = penc (action_num (fst i)) (snd i)" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
38 |
|
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
39 |
fun Code_instr :: "instr \<times> instr \<Rightarrow> nat" where |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
40 |
"Code_instr i = penc (code_instr (fst i)) (code_instr (snd i))" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
41 |
|
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
42 |
fun code_tprog :: "tprog \<Rightarrow> nat list" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
43 |
where |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
44 |
"code_tprog [] = []" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
45 |
| "code_tprog (i # tm) = Code_instr i # code_tprog tm" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
46 |
|
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
47 |
lemma code_tprog_length [simp]: |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
48 |
"length (code_tprog tp) = length tp" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
49 |
by (induct tp) (simp_all) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
50 |
|
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
51 |
lemma code_tprog_nth [simp]: |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
52 |
"n < length tp \<Longrightarrow> (code_tprog tp) ! n = Code_instr (tp ! n)" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
53 |
by (induct tp arbitrary: n) (simp_all add: nth_Cons') |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
54 |
|
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
55 |
fun Code_tprog :: "tprog \<Rightarrow> nat" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
56 |
where |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
57 |
"Code_tprog tm = lenc (code_tprog tm)" |
246
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
58 |
|
250
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
59 |
section {* Universal Function in HOL *} |
246
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
60 |
|
258
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
61 |
|
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
62 |
text {* Scanning and writing the right tape *} |
246
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
63 |
|
258
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
64 |
fun Scan where |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
65 |
"Scan r = ldec r 0" |
250
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
66 |
|
258
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
67 |
fun Write where |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
68 |
"Write n r = penc n (pdec2 r)" |
246
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
69 |
|
258
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
70 |
text {* |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
71 |
The @{text Newleft} and @{text Newright} functions on page 91 of B book. |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
72 |
They calculate the new left and right tape (@{text p} and @{text r}) according |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
73 |
to an action @{text a}. |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
74 |
*} |
246
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
75 |
|
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
76 |
fun Newleft :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat" |
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
77 |
where |
258
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
78 |
"Newleft p r a = (if a = 0 \<or> a = 1 then p else |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
79 |
if a = 2 then pdec2 p else |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
80 |
if a = 3 then penc (pdec1 r) p |
246
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
81 |
else p)" |
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
82 |
|
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
83 |
fun Newright :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat" |
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
84 |
where |
258
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
85 |
"Newright p r a = (if a = 0 then Write 0 r |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
86 |
else if a = 1 then Write 1 r |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
87 |
else if a = 2 then penc (pdec1 p) r |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
88 |
else if a = 3 then pdec2 r |
246
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
89 |
else r)" |
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
90 |
|
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
91 |
text {* |
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
92 |
The @{text "Actn"} function given on page 92 of B book, which is used to |
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
93 |
fetch Turing Machine intructions. In @{text "Actn m q r"}, @{text "m"} is |
258
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
94 |
the code of the Turing Machine, @{text "q"} is the current state of |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
95 |
Turing Machine, and @{text "r"} is the scanned cell of is the right tape. |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
96 |
*} |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
97 |
|
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
98 |
fun actn :: "nat \<Rightarrow> nat \<Rightarrow> nat" where |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
99 |
"actn n 0 = pdec1 (pdec1 n)" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
100 |
| "actn n _ = pdec1 (pdec2 n)" |
250
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
101 |
|
246
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
102 |
fun Actn :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat" |
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
103 |
where |
258
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
104 |
"Actn m q r = (if q \<noteq> 0 \<and> within m q then (actn (ldec m (q - 1)) r) else 4)" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
105 |
|
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
106 |
fun newstat :: "nat \<Rightarrow> nat \<Rightarrow> nat" where |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
107 |
"newstat n 0 = pdec2 (pdec1 n)" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
108 |
| "newstat n _ = pdec2 (pdec2 n)" |
246
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
109 |
|
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
110 |
fun Newstat :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat" |
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
111 |
where |
258
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
112 |
"Newstat m q r = (if q \<noteq> 0 then (newstat (ldec m (q - 1)) r) else 0)" |
246
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
113 |
|
258
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
114 |
fun Conf :: "nat \<times> (nat \<times> nat) \<Rightarrow> nat" |
246
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
115 |
where |
258
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
116 |
"Conf (q, (l, r)) = lenc [q, l, r]" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
117 |
|
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
118 |
fun Stat where |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
119 |
(*"Stat c = (if c = 0 then 0 else ldec c 0)"*) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
120 |
"Stat c = ldec c 0" |
246
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
121 |
|
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
122 |
fun Left where |
258
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
123 |
"Left c = ldec c 1" |
246
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
124 |
|
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
125 |
fun Right where |
258
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
126 |
"Right c = ldec c 2" |
246
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
127 |
|
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
128 |
fun Newconf :: "nat \<Rightarrow> nat \<Rightarrow> nat" |
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
129 |
where |
258
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
130 |
"Newconf c m = Conf (Newstat m (Stat c) (Scan (Right c)), |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
131 |
(Newleft (Left c) (Right c) (Actn m (Stat c) (Scan (Right c))), |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
132 |
Newright (Left c) (Right c) (Actn m (Stat c) (Scan (Right c)))))" |
246
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
133 |
|
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
134 |
text {* |
258
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
135 |
@{text "Step k m r"} computes the TM configuration after @{text "k"} steps of execution |
246
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
136 |
of TM coded as @{text "m"} starting from the initial configuration where the left |
250
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
137 |
number equals @{text "0"}, right number equals @{text "r"}. *} |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
138 |
|
258
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
139 |
fun Steps :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat" |
246
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
140 |
where |
258
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
141 |
"Steps cf p 0 = cf" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
142 |
| "Steps cf p (Suc n) = Steps (Newconf cf p) p n" |
246
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
143 |
|
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
144 |
text {* |
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
145 |
@{text "Nstd c"} returns true if the configuration coded |
250
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
146 |
by @{text "c"} is not a stardard final configuration. *} |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
147 |
|
246
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
148 |
fun Nstd :: "nat \<Rightarrow> bool" |
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
149 |
where |
258
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
150 |
"Nstd c = (Stat c \<noteq> 0)" |
246
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
151 |
|
258
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
152 |
-- "tape conditions are missing" |
246
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
153 |
|
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
154 |
text{* |
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
155 |
@{text "Nostop t m r"} means that afer @{text "t"} steps of |
250
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
156 |
execution the TM coded by @{text "m"} is not at a stardard |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
157 |
final configuration. *} |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
158 |
|
246
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
159 |
fun Nostop :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> bool" |
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
160 |
where |
258
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
161 |
"Nostop m l r = Nstd (Conf (m, (l, r)))" |
246
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
162 |
|
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
163 |
text{* |
258
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
164 |
@{text "rec_halt"} is the recursive function calculating the steps a TM needs to |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
165 |
execute before to reach a stardard final configuration. This recursive function is |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
166 |
the only one using @{text "Mn"} combinator. So it is the only non-primitive recursive |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
167 |
function needs to be used in the construction of the universal function @{text "rec_uf"}. |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
168 |
*} |
246
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
169 |
|
250
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
170 |
fun Halt :: "nat \<Rightarrow> nat \<Rightarrow> nat" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
171 |
where |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
172 |
"Halt m r = (LEAST t. \<not> Nostop t m r)" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
173 |
|
258
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
174 |
(* |
250
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
175 |
fun UF :: "nat \<Rightarrow> nat \<Rightarrow> nat" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
176 |
where |
258
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
177 |
"UF c m = (Right (Conf (Halt c m) c m))" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
178 |
*) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
179 |
|
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
180 |
text {* reading the value is missing *} |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
181 |
|
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
182 |
section {* The UF can simulate Turing machines *} |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
183 |
|
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
184 |
lemma Update_left_simulate: |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
185 |
shows "Newleft (Code_tp l) (Code_tp r) (action_num a) = Code_tp (fst (update a (l, r)))" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
186 |
apply(induct a) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
187 |
apply(simp_all) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
188 |
apply(case_tac l) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
189 |
apply(simp_all) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
190 |
apply(case_tac r) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
191 |
apply(simp_all) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
192 |
done |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
193 |
|
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
194 |
lemma Update_right_simulate: |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
195 |
shows "Newright (Code_tp l) (Code_tp r) (action_num a) = Code_tp (snd (update a (l, r)))" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
196 |
apply(induct a) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
197 |
apply(simp_all) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
198 |
apply(case_tac r) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
199 |
apply(simp_all) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
200 |
apply(case_tac r) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
201 |
apply(simp_all) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
202 |
apply(case_tac l) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
203 |
apply(simp_all) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
204 |
apply(case_tac r) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
205 |
apply(simp_all) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
206 |
done |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
207 |
|
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
208 |
lemma Fetch_state_simulate: |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
209 |
"\<lbrakk>tm_wf tp\<rbrakk> \<Longrightarrow> Newstat (Code_tprog tp) st (cell_num c) = snd (fetch tp st c)" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
210 |
apply(induct tp st c rule: fetch.induct) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
211 |
apply(simp_all add: list_encode_inverse split: cell.split) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
212 |
done |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
213 |
|
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
214 |
lemma Fetch_action_simulate: |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
215 |
"\<lbrakk>tm_wf tp; st \<le> length tp\<rbrakk> \<Longrightarrow> Actn (Code_tprog tp) st (cell_num c) = action_num (fst (fetch tp st c))" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
216 |
apply(induct tp st c rule: fetch.induct) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
217 |
apply(simp_all add: list_encode_inverse split: cell.split) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
218 |
done |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
219 |
|
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
220 |
lemma Scan_simulate: |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
221 |
"Scan (Code_tp tp) = cell_num (read tp)" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
222 |
apply(case_tac tp) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
223 |
apply(simp_all) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
224 |
done |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
225 |
|
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
226 |
lemma misc: |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
227 |
"2 < (3::nat)" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
228 |
"1 < (3::nat)" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
229 |
"0 < (3::nat)" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
230 |
"length [x] = 1" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
231 |
"length [x, y] = 2" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
232 |
"length [x, y , z] = 3" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
233 |
"[x, y, z] ! 0 = x" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
234 |
"[x, y, z] ! 1 = y" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
235 |
"[x, y, z] ! 2 = z" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
236 |
apply(simp_all) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
237 |
done |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
238 |
|
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
239 |
lemma New_conf_simulate: |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
240 |
assumes "tm_wf tp" "st \<le> length tp" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
241 |
shows "Newconf (Conf (Code_conf (st, l, r))) (Code_tprog tp) = Conf (Code_conf (step (st, l, r) tp))" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
242 |
apply(subst step.simps) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
243 |
apply(simp only: Let_def) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
244 |
apply(subst Newconf.simps) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
245 |
apply(simp only: Conf.simps Code_conf.simps Right.simps Left.simps) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
246 |
apply(simp only: list_encode_inverse) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
247 |
apply(simp only: misc if_True Code_tp.simps) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
248 |
apply(simp only: prod_case_beta) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
249 |
apply(subst Fetch_state_simulate[OF assms, symmetric]) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
250 |
apply(simp only: Stat.simps) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
251 |
apply(simp only: list_encode_inverse) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
252 |
apply(simp only: misc if_True) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
253 |
apply(simp only: Scan_simulate[simplified Code_tp.simps]) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
254 |
apply(simp only: Fetch_action_simulate[OF assms]) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
255 |
apply(simp only: Update_left_simulate[simplified Code_tp.simps]) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
256 |
apply(simp only: Update_right_simulate[simplified Code_tp.simps]) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
257 |
apply(case_tac "update (fst (fetch tp st (read r))) (l, r)") |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
258 |
apply(simp only: Code_conf.simps) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
259 |
apply(simp only: Conf.simps) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
260 |
apply(simp) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
261 |
done |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
262 |
|
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
263 |
lemma Step_simulate: |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
264 |
assumes "tm_wf tp" "fst cf \<le> length tp" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
265 |
shows "Steps (Conf (Code_conf cf)) (Code_tprog tp) n = Conf (Code_conf (steps cf tp n))" |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
266 |
apply(induct n arbitrary: cf) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
267 |
apply(simp) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
268 |
apply(simp only: Steps.simps steps.simps) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
269 |
apply(case_tac cf) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
270 |
apply(simp only: ) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
271 |
apply(subst New_conf_simulate) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
272 |
apply(rule assms) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
273 |
defer |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
274 |
apply(drule_tac x="step (a, b, c) tp" in meta_spec) |
32c5e8d1f6ff
added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
256
diff
changeset
|
275 |
apply(simp) |
246
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
276 |
|
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
277 |
|
250
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
278 |
section {* Coding of Turing Machines *} |
246
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
279 |
|
248
aea02b5a58d2
repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
246
diff
changeset
|
280 |
text {* |
250
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
281 |
The purpose of this section is to construct the coding function of Turing |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
282 |
Machine, which is going to be named @{text "code"}. *} |
246
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
283 |
|
248
aea02b5a58d2
repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
246
diff
changeset
|
284 |
fun bl2nat :: "cell list \<Rightarrow> nat \<Rightarrow> nat" |
aea02b5a58d2
repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
246
diff
changeset
|
285 |
where |
aea02b5a58d2
repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
246
diff
changeset
|
286 |
"bl2nat [] n = 0" |
aea02b5a58d2
repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
246
diff
changeset
|
287 |
| "bl2nat (Bk # bl) n = bl2nat bl (Suc n)" |
aea02b5a58d2
repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
246
diff
changeset
|
288 |
| "bl2nat (Oc # bl) n = 2 ^ n + bl2nat bl (Suc n)" |
aea02b5a58d2
repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
246
diff
changeset
|
289 |
|
aea02b5a58d2
repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
246
diff
changeset
|
290 |
fun bl2wc :: "cell list \<Rightarrow> nat" |
aea02b5a58d2
repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
246
diff
changeset
|
291 |
where |
aea02b5a58d2
repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
246
diff
changeset
|
292 |
"bl2wc xs = bl2nat xs 0" |
246
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
293 |
|
250
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
294 |
lemma bl2nat_double [simp]: |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
295 |
"bl2nat xs (Suc n) = 2 * bl2nat xs n" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
296 |
apply(induct xs arbitrary: n) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
297 |
apply(auto) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
298 |
apply(case_tac a) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
299 |
apply(auto) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
300 |
done |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
301 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
302 |
lemma bl2nat_simps1 [simp]: |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
303 |
shows "bl2nat (Bk \<up> y) n = 0" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
304 |
by (induct y) (auto) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
305 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
306 |
lemma bl2nat_simps2 [simp]: |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
307 |
shows "bl2nat (Oc \<up> y) 0 = 2 ^ y - 1" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
308 |
apply(induct y) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
309 |
apply(auto) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
310 |
apply(case_tac "(2::nat)^ y") |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
311 |
apply(auto) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
312 |
done |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
313 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
314 |
fun Trpl_code :: "config \<Rightarrow> nat" |
248
aea02b5a58d2
repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
246
diff
changeset
|
315 |
where |
250
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
316 |
"Trpl_code (st, l, r) = Trpl (bl2wc l) st (bl2wc r)" |
246
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
317 |
|
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
318 |
|
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
319 |
|
248
aea02b5a58d2
repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
246
diff
changeset
|
320 |
fun block_map :: "cell \<Rightarrow> nat" |
aea02b5a58d2
repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
246
diff
changeset
|
321 |
where |
aea02b5a58d2
repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
246
diff
changeset
|
322 |
"block_map Bk = 0" |
aea02b5a58d2
repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
246
diff
changeset
|
323 |
| "block_map Oc = 1" |
246
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
324 |
|
248
aea02b5a58d2
repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
246
diff
changeset
|
325 |
fun Goedel_code' :: "nat list \<Rightarrow> nat \<Rightarrow> nat" |
aea02b5a58d2
repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
246
diff
changeset
|
326 |
where |
aea02b5a58d2
repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
246
diff
changeset
|
327 |
"Goedel_code' [] n = 1" |
aea02b5a58d2
repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
246
diff
changeset
|
328 |
| "Goedel_code' (x # xs) n = (Pi n) ^ x * Goedel_code' xs (Suc n) " |
aea02b5a58d2
repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
246
diff
changeset
|
329 |
|
aea02b5a58d2
repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
246
diff
changeset
|
330 |
fun Goedel_code :: "nat list \<Rightarrow> nat" |
aea02b5a58d2
repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
246
diff
changeset
|
331 |
where |
aea02b5a58d2
repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
246
diff
changeset
|
332 |
"Goedel_code xs = 2 ^ (length xs) * (Goedel_code' xs 1)" |
246
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
333 |
|
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
334 |
|
250
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
335 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
336 |
section {* Universal Function as Recursive Functions *} |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
337 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
338 |
definition |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
339 |
"rec_entry = CN rec_lo [Id 2 0, CN rec_pi [CN S [Id 2 1]]]" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
340 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
341 |
fun rec_listsum2 :: "nat \<Rightarrow> nat \<Rightarrow> recf" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
342 |
where |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
343 |
"rec_listsum2 vl 0 = CN Z [Id vl 0]" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
344 |
| "rec_listsum2 vl (Suc n) = CN rec_add [rec_listsum2 vl n, Id vl n]" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
345 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
346 |
fun rec_strt' :: "nat \<Rightarrow> nat \<Rightarrow> recf" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
347 |
where |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
348 |
"rec_strt' xs 0 = Z" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
349 |
| "rec_strt' xs (Suc n) = |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
350 |
(let dbound = CN rec_add [rec_listsum2 xs n, constn n] in |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
351 |
let t1 = CN rec_power [constn 2, dbound] in |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
352 |
let t2 = CN rec_power [constn 2, CN rec_add [Id xs n, dbound]] in |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
353 |
CN rec_add [rec_strt' xs n, CN rec_minus [t2, t1]])" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
354 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
355 |
fun rec_map :: "recf \<Rightarrow> nat \<Rightarrow> recf list" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
356 |
where |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
357 |
"rec_map rf vl = map (\<lambda>i. CN rf [Id vl i]) [0..<vl]" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
358 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
359 |
fun rec_strt :: "nat \<Rightarrow> recf" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
360 |
where |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
361 |
"rec_strt xs = CN (rec_strt' xs xs) (rec_map S xs)" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
362 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
363 |
definition |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
364 |
"rec_scan = CN rec_mod [Id 1 0, constn 2]" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
365 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
366 |
definition |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
367 |
"rec_newleft = |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
368 |
(let cond1 = CN rec_disj [CN rec_eq [Id 3 2, Z], CN rec_eq [Id 3 2, constn 1]] in |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
369 |
let cond2 = CN rec_eq [Id 3 2, constn 2] in |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
370 |
let cond3 = CN rec_eq [Id 3 2, constn 3] in |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
371 |
let case3 = CN rec_add [CN rec_mult [constn 2, Id 3 0], |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
372 |
CN rec_mod [Id 3 1, constn 2]] in |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
373 |
CN rec_if [cond1, Id 3 0, |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
374 |
CN rec_if [cond2, CN rec_quo [Id 3 0, constn 2], |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
375 |
CN rec_if [cond3, case3, Id 3 0]]])" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
376 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
377 |
definition |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
378 |
"rec_newright = |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
379 |
(let condn = \<lambda>n. CN rec_eq [Id 3 2, constn n] in |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
380 |
let case0 = CN rec_minus [Id 3 1, CN rec_scan [Id 3 1]] in |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
381 |
let case1 = CN rec_minus [CN rec_add [Id 3 1, constn 1], CN rec_scan [Id 3 1]] in |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
382 |
let case2 = CN rec_add [CN rec_mult [constn 2, Id 3 1], |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
383 |
CN rec_mod [Id 3 0, constn 2]] in |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
384 |
let case3 = CN rec_quo [Id 2 1, constn 2] in |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
385 |
CN rec_if [condn 0, case0, |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
386 |
CN rec_if [condn 1, case1, |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
387 |
CN rec_if [condn 2, case2, |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
388 |
CN rec_if [condn 3, case3, Id 3 1]]]])" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
389 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
390 |
definition |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
391 |
"rec_actn = (let add1 = CN rec_mult [constn 4, CN rec_pred [Id 3 1]] in |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
392 |
let add2 = CN rec_mult [constn 2, CN rec_scan [Id 3 2]] in |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
393 |
let entry = CN rec_entry [Id 3 0, CN rec_add [add1, add2]] |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
394 |
in CN rec_if [Id 3 1, entry, constn 4])" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
395 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
396 |
definition rec_newstat :: "recf" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
397 |
where |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
398 |
"rec_newstat = (let add1 = CN rec_mult [constn 4, CN rec_pred [Id 3 1]] in |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
399 |
let add2 = CN S [CN rec_mult [constn 2, CN rec_scan [Id 3 2]]] in |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
400 |
let entry = CN rec_entry [Id 3 0, CN rec_add [add1, add2]] |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
401 |
in CN rec_if [Id 3 1, entry, Z])" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
402 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
403 |
definition |
256
04700724250f
completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
250
diff
changeset
|
404 |
"rec_trpl = CN rec_penc [CN rec_penc [Id 3 0, Id 3 1], Id 3 2]" |
250
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
405 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
406 |
definition |
256
04700724250f
completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
250
diff
changeset
|
407 |
"rec_left = rec_pdec1" |
250
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
408 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
409 |
definition |
256
04700724250f
completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
250
diff
changeset
|
410 |
"rec_right = CN rec_pdec2 [rec_pdec1]" |
250
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
411 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
412 |
definition |
256
04700724250f
completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
250
diff
changeset
|
413 |
"rec_stat = CN rec_pdec2 [rec_pdec2]" |
250
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
414 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
415 |
definition |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
416 |
"rec_newconf = (let act = CN rec_actn [Id 2 0, CN rec_stat [Id 2 1], CN rec_right [Id 2 1]] in |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
417 |
let left = CN rec_left [Id 2 1] in |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
418 |
let right = CN rec_right [Id 2 1] in |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
419 |
let stat = CN rec_stat [Id 2 1] in |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
420 |
let one = CN rec_newleft [left, right, act] in |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
421 |
let two = CN rec_newstat [Id 2 0, stat, right] in |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
422 |
let three = CN rec_newright [left, right, act] |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
423 |
in CN rec_trpl [one, two, three])" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
424 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
425 |
definition |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
426 |
"rec_conf = PR (CN rec_trpl [constn 0, constn 1, Id 2 1]) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
427 |
(CN rec_newconf [Id 4 2 , Id 4 1])" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
428 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
429 |
definition |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
430 |
"rec_nstd = (let disj1 = CN rec_noteq [rec_stat, constn 0] in |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
431 |
let disj2 = CN rec_noteq [rec_left, constn 0] in |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
432 |
let rhs = CN rec_pred [CN rec_power [constn 2, CN rec_lg [CN S [rec_right], constn 2]]] in |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
433 |
let disj3 = CN rec_noteq [rec_right, rhs] in |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
434 |
let disj4 = CN rec_eq [rec_right, constn 0] in |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
435 |
CN rec_disj [CN rec_disj [CN rec_disj [disj1, disj2], disj3], disj4])" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
436 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
437 |
definition |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
438 |
"rec_nostop = CN rec_nstd [rec_conf]" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
439 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
440 |
definition |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
441 |
"rec_value = CN rec_pred [CN rec_lg [S, constn 2]]" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
442 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
443 |
definition |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
444 |
"rec_halt = MN rec_nostop" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
445 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
446 |
definition |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
447 |
"rec_uf = CN rec_value [CN rec_right [CN rec_conf [rec_halt, Id 2 0, Id 2 1]]]" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
448 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
449 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
450 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
451 |
section {* Correctness Proofs for Recursive Functions *} |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
452 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
453 |
lemma entry_lemma [simp]: |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
454 |
"rec_eval rec_entry [sr, i] = Entry sr i" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
455 |
by(simp add: rec_entry_def) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
456 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
457 |
lemma listsum2_lemma [simp]: |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
458 |
"length xs = vl \<Longrightarrow> rec_eval (rec_listsum2 vl n) xs = Listsum2 xs n" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
459 |
by (induct n) (simp_all) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
460 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
461 |
lemma strt'_lemma [simp]: |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
462 |
"length xs = vl \<Longrightarrow> rec_eval (rec_strt' vl n) xs = Strt' xs n" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
463 |
by (induct n) (simp_all add: Let_def) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
464 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
465 |
lemma map_suc: |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
466 |
"map (\<lambda>x. Suc (xs ! x)) [0..<length xs] = map Suc xs" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
467 |
proof - |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
468 |
have "Suc \<circ> (\<lambda>x. xs ! x) = (\<lambda>x. Suc (xs ! x))" by (simp add: comp_def) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
469 |
then have "map (\<lambda>x. Suc (xs ! x)) [0..<length xs] = map (Suc \<circ> (\<lambda>x. xs ! x)) [0..<length xs]" by simp |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
470 |
also have "... = map Suc (map (\<lambda>x. xs ! x) [0..<length xs])" by simp |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
471 |
also have "... = map Suc xs" by (simp add: map_nth) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
472 |
finally show "map (\<lambda>x. Suc (xs ! x)) [0..<length xs] = map Suc xs" . |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
473 |
qed |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
474 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
475 |
lemma strt_lemma [simp]: |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
476 |
"length xs = vl \<Longrightarrow> rec_eval (rec_strt vl) xs = Strt xs" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
477 |
by (simp add: comp_def map_suc[symmetric]) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
478 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
479 |
lemma scan_lemma [simp]: |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
480 |
"rec_eval rec_scan [r] = r mod 2" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
481 |
by(simp add: rec_scan_def) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
482 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
483 |
lemma newleft_lemma [simp]: |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
484 |
"rec_eval rec_newleft [p, r, a] = Newleft p r a" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
485 |
by (simp add: rec_newleft_def Let_def) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
486 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
487 |
lemma newright_lemma [simp]: |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
488 |
"rec_eval rec_newright [p, r, a] = Newright p r a" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
489 |
by (simp add: rec_newright_def Let_def) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
490 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
491 |
lemma actn_lemma [simp]: |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
492 |
"rec_eval rec_actn [m, q, r] = Actn m q r" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
493 |
by (simp add: rec_actn_def) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
494 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
495 |
lemma newstat_lemma [simp]: |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
496 |
"rec_eval rec_newstat [m, q, r] = Newstat m q r" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
497 |
by (simp add: rec_newstat_def) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
498 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
499 |
lemma trpl_lemma [simp]: |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
500 |
"rec_eval rec_trpl [p, q, r] = Trpl p q r" |
256
04700724250f
completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
250
diff
changeset
|
501 |
apply(simp) |
04700724250f
completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
250
diff
changeset
|
502 |
apply (simp add: rec_trpl_def) |
250
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
503 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
504 |
lemma left_lemma [simp]: |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
505 |
"rec_eval rec_left [c] = Left c" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
506 |
by(simp add: rec_left_def) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
507 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
508 |
lemma right_lemma [simp]: |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
509 |
"rec_eval rec_right [c] = Right c" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
510 |
by(simp add: rec_right_def) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
511 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
512 |
lemma stat_lemma [simp]: |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
513 |
"rec_eval rec_stat [c] = Stat c" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
514 |
by(simp add: rec_stat_def) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
515 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
516 |
lemma newconf_lemma [simp]: |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
517 |
"rec_eval rec_newconf [m, c] = Newconf m c" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
518 |
by (simp add: rec_newconf_def Let_def) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
519 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
520 |
lemma conf_lemma [simp]: |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
521 |
"rec_eval rec_conf [k, m, r] = Conf k m r" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
522 |
by(induct k) (simp_all add: rec_conf_def) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
523 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
524 |
lemma nstd_lemma [simp]: |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
525 |
"rec_eval rec_nstd [c] = (if Nstd c then 1 else 0)" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
526 |
by(simp add: rec_nstd_def) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
527 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
528 |
lemma nostop_lemma [simp]: |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
529 |
"rec_eval rec_nostop [t, m, r] = (if Nostop t m r then 1 else 0)" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
530 |
by (simp add: rec_nostop_def) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
531 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
532 |
lemma value_lemma [simp]: |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
533 |
"rec_eval rec_value [x] = Value x" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
534 |
by (simp add: rec_value_def) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
535 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
536 |
lemma halt_lemma [simp]: |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
537 |
"rec_eval rec_halt [m, r] = Halt m r" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
538 |
by (simp add: rec_halt_def) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
539 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
540 |
lemma uf_lemma [simp]: |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
541 |
"rec_eval rec_uf [m, r] = UF m r" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
542 |
by (simp add: rec_uf_def) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
543 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
544 |
|
248
aea02b5a58d2
repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
246
diff
changeset
|
545 |
subsection {* Relating interperter functions to the execution of TMs *} |
246
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
546 |
|
250
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
547 |
lemma rec_step: |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
548 |
assumes "(\<lambda> (s, l, r). s \<le> length tp div 2) c" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
549 |
shows "Trpl_code (step0 c tp) = Newconf (Code tp) (Trpl_code c)" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
550 |
apply(cases c) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
551 |
apply(simp only: Trpl_code.simps) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
552 |
apply(simp only: Let_def step.simps) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
553 |
apply(case_tac "fetch tp (a - 0) (read ca)") |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
554 |
apply(simp only: prod.cases) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
555 |
apply(case_tac "update aa (b, ca)") |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
556 |
apply(simp only: prod.cases) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
557 |
apply(simp only: Trpl_code.simps) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
558 |
apply(simp only: Newconf.simps) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
559 |
apply(simp only: Left.simps) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
560 |
oops |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
561 |
|
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
562 |
lemma rec_steps: |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
563 |
assumes "tm_wf0 tp" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
564 |
shows "Trpl_code (steps0 (1, Bk \<up> l, <lm>) tp stp) = Conf stp (Code tp) (bl2wc (<lm>))" |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
565 |
apply(induct stp) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
566 |
apply(simp) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
567 |
apply(simp) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
568 |
oops |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
569 |
|
246
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
570 |
|
248
aea02b5a58d2
repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
246
diff
changeset
|
571 |
lemma F_correct: |
250
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
572 |
assumes tm: "steps0 (1, Bk \<up> l, <lm>) tp stp = (0, Bk \<up> m, Oc \<up> rs @ Bk \<up> n)" |
248
aea02b5a58d2
repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
246
diff
changeset
|
573 |
and wf: "tm_wf0 tp" "0 < rs" |
aea02b5a58d2
repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
246
diff
changeset
|
574 |
shows "rec_eval rec_uf [Code tp, bl2wc (<lm>)] = (rs - Suc 0)" |
250
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
575 |
proof - |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
576 |
from least_steps[OF tm] |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
577 |
obtain stp_least where |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
578 |
before: "\<forall>stp' < stp_least. \<not> is_final (steps0 (1, Bk \<up> l, <lm>) tp stp')" and |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
579 |
after: "\<forall>stp' \<ge> stp_least. is_final (steps0 (1, Bk \<up> l, <lm>) tp stp')" by blast |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
580 |
have "Halt (Code tp) (bl2wc (<lm>)) = stp_least" sorry |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
581 |
show ?thesis |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
582 |
apply(simp only: uf_lemma) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
583 |
apply(simp only: UF.simps) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
584 |
apply(simp only: Halt.simps) |
745547bdc1c7
added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
249
diff
changeset
|
585 |
oops |
246
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
586 |
|
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
587 |
|
248
aea02b5a58d2
repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
246
diff
changeset
|
588 |
end |
246
e113420a2fce
separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
589 |