87 recf.id ("id\<^raw:\makebox[0mm]{\,\,\,\,>\<^isup>_\<^raw:}>\<^isub>_") and |
87 recf.id ("id\<^raw:\makebox[0mm]{\,\,\,\,>\<^isup>_\<^raw:}>\<^isub>_") and |
88 Pr ("Pr\<^isup>_") and |
88 Pr ("Pr\<^isup>_") and |
89 Cn ("Cn\<^isup>_") and |
89 Cn ("Cn\<^isup>_") and |
90 Mn ("Mn\<^isup>_") and |
90 Mn ("Mn\<^isup>_") and |
91 rec_calc_rel ("eval") and |
91 rec_calc_rel ("eval") and |
92 tm_of_rec ("translate") |
92 tm_of_rec ("translate") and |
|
93 listsum ("\<Sigma>") |
93 |
94 |
94 |
95 |
95 lemma inv_begin_print: |
96 lemma inv_begin_print: |
96 shows "s = 0 \<Longrightarrow> inv_begin n (s, tp) = inv_begin0 n tp" and |
97 shows "s = 0 \<Longrightarrow> inv_begin n (s, tp) = inv_begin0 n tp" and |
97 "s = 1 \<Longrightarrow> inv_begin n (s, tp) = inv_begin1 n tp" and |
98 "s = 1 \<Longrightarrow> inv_begin n (s, tp) = inv_begin1 n tp" and |
170 by(simp add: adjust.simps) |
171 by(simp add: adjust.simps) |
171 |
172 |
172 fun clear :: "nat \<Rightarrow> nat \<Rightarrow> abc_prog" |
173 fun clear :: "nat \<Rightarrow> nat \<Rightarrow> abc_prog" |
173 where |
174 where |
174 "clear n e = [Dec n e, Goto 0]" |
175 "clear n e = [Dec n e, Goto 0]" |
|
176 |
|
177 partial_function (tailrec) |
|
178 run |
|
179 where |
|
180 "run p cf = (if (is_final cf) then cf else run p (step0 cf p))" |
|
181 |
|
182 lemma numeral2: |
|
183 shows "11 = Suc 10" |
|
184 and "12 = Suc 11" |
|
185 and "13 = Suc 12" |
|
186 and "14 = Suc 13" |
|
187 and "15 = Suc 14" |
|
188 apply(arith)+ |
|
189 done |
|
190 |
|
191 (* |
|
192 lemma "run tcopy (1, [], <0::nat>) = (0, [Bk], [Oc, Bk, Oc])" |
|
193 apply(subst run.simps) |
|
194 apply(simp) |
|
195 apply(simp add: step.simps tcopy_def tcopy_begin_def tcopy_loop_def tcopy_end_def tm_comp.simps adjust.simps shift.simps tape_of_nat_abv fetch.simps numeral del: run.simps) |
|
196 apply(subst run.simps) |
|
197 apply(simp) |
|
198 apply(simp add: step.simps tcopy_def tcopy_begin_def tcopy_loop_def tcopy_end_def tm_comp.simps adjust.simps shift.simps tape_of_nat_abv fetch.simps numeral del: run.simps) |
|
199 apply(subst run.simps) |
|
200 apply(simp) |
|
201 apply(simp add: step.simps tcopy_def tcopy_begin_def tcopy_loop_def tcopy_end_def tm_comp.simps adjust.simps shift.simps tape_of_nat_abv fetch.simps numeral del: run.simps) |
|
202 apply(subst run.simps) |
|
203 apply(simp) |
|
204 apply(simp add: step.simps tcopy_def tcopy_begin_def tcopy_loop_def tcopy_end_def tm_comp.simps adjust.simps shift.simps tape_of_nat_abv fetch.simps numeral del: run.simps) |
|
205 apply(subst run.simps) |
|
206 apply(simp) |
|
207 apply(simp add: step.simps tcopy_def tcopy_begin_def tcopy_loop_def tcopy_end_def tm_comp.simps adjust.simps shift.simps tape_of_nat_abv fetch.simps numeral del: run.simps) |
|
208 apply(subst run.simps) |
|
209 apply(simp) |
|
210 apply(simp add: step.simps tcopy_def tcopy_begin_def tcopy_loop_def tcopy_end_def tm_comp.simps adjust.simps shift.simps tape_of_nat_abv fetch.simps numeral del: run.simps) |
|
211 apply(subst run.simps) |
|
212 apply(simp) |
|
213 apply(simp add: step.simps tcopy_def tcopy_begin_def tcopy_loop_def tcopy_end_def tm_comp.simps adjust.simps shift.simps tape_of_nat_abv fetch.simps numeral nth_of.simps del: run.simps) |
|
214 apply(simp only: numeral[symmetric]) |
|
215 apply(simp) |
|
216 apply(subst run.simps) |
|
217 apply(simp) |
|
218 apply(simp add: step.simps tcopy_def tcopy_begin_def tcopy_loop_def tcopy_end_def tm_comp.simps adjust.simps shift.simps tape_of_nat_abv fetch.simps numeral numeral2 del: run.simps) |
|
219 apply(simp only: numeral[symmetric]) |
|
220 apply(simp) |
|
221 apply(subst run.simps) |
|
222 apply(simp) |
|
223 apply(simp add: step.simps tcopy_def tcopy_begin_def tcopy_loop_def tcopy_end_def tm_comp.simps adjust.simps shift.simps tape_of_nat_abv fetch.simps numeral numeral2 del: run.simps) |
|
224 apply(simp only: numeral[symmetric]) |
|
225 apply(simp) |
|
226 apply(subst run.simps) |
|
227 apply(simp) |
|
228 apply(simp add: step.simps tcopy_def tcopy_begin_def tcopy_loop_def tcopy_end_def tm_comp.simps adjust.simps shift.simps tape_of_nat_abv fetch.simps numeral numeral2 del: run.simps) |
|
229 apply(simp only: numeral[symmetric]) |
|
230 apply(simp) |
|
231 apply(subst run.simps) |
|
232 apply(simp) |
|
233 apply(simp add: step.simps tcopy_def tcopy_begin_def tcopy_loop_def tcopy_end_def tm_comp.simps adjust.simps shift.simps tape_of_nat_abv fetch.simps numeral numeral2 del: run.simps) |
|
234 apply(simp only: numeral[symmetric]) |
|
235 apply(simp) |
|
236 apply(subst run.simps) |
|
237 apply(simp) |
|
238 apply(simp add: step.simps tcopy_def tcopy_begin_def tcopy_loop_def tcopy_end_def tm_comp.simps adjust.simps shift.simps tape_of_nat_abv fetch.simps numeral numeral2 del: run.simps) |
|
239 apply(simp only: numeral[symmetric]) |
|
240 apply(simp) |
|
241 apply(subst run.simps) |
|
242 apply(simp) |
|
243 apply(simp add: step.simps tcopy_def tcopy_begin_def tcopy_loop_def tcopy_end_def tm_comp.simps adjust.simps shift.simps tape_of_nat_abv fetch.simps numeral numeral2 del: run.simps) |
|
244 apply(simp only: numeral[symmetric]) |
|
245 apply(simp) |
|
246 apply(subst run.simps) |
|
247 apply(simp) |
|
248 apply(simp add: step.simps tcopy_def tcopy_begin_def tcopy_loop_def tcopy_end_def tm_comp.simps adjust.simps shift.simps tape_of_nat_abv fetch.simps numeral numeral2 del: run.simps) |
|
249 apply(simp only: numeral[symmetric]) |
|
250 apply(simp) |
|
251 apply(subst run.simps) |
|
252 apply(simp) |
|
253 apply(simp add: step.simps tcopy_def tcopy_begin_def tcopy_loop_def tcopy_end_def tm_comp.simps adjust.simps shift.simps tape_of_nat_abv fetch.simps numeral numeral2 del: run.simps) |
|
254 apply(simp only: numeral[symmetric]) |
|
255 apply(simp) |
|
256 apply(subst run.simps) |
|
257 apply(simp) |
|
258 done |
|
259 *) |
|
260 |
175 (*>*) |
261 (*>*) |
176 |
262 |
177 section {* Introduction *} |
263 section {* Introduction *} |
178 |
264 |
179 |
265 |
231 \noindent |
317 \noindent |
232 In this paper we take on this daunting prospect and provide a |
318 In this paper we take on this daunting prospect and provide a |
233 formalisation of Turing machines, as well as abacus machines (a kind |
319 formalisation of Turing machines, as well as abacus machines (a kind |
234 of register machines) and recursive functions. To see the difficulties |
320 of register machines) and recursive functions. To see the difficulties |
235 involved with this work, one has to understand that Turing machine |
321 involved with this work, one has to understand that Turing machine |
236 programs can be completely \emph{unstructured}, behaving similar to |
322 programs (similarly abacus programs) can be completely |
237 Basic programs containing the infamous goto \cite{Dijkstra68}. This |
323 \emph{unstructured}, behaving similar to Basic programs containing the |
238 precludes in the general case a compositional Hoare-style reasoning |
324 infamous goto \cite{Dijkstra68}. This precludes in the general case a |
239 about Turing programs. We provide such Hoare-rules for when it |
325 compositional Hoare-style reasoning about Turing programs. We provide |
240 \emph{is} possible to reason in a compositional manner (which is |
326 such Hoare-rules for when it \emph{is} possible to reason in a |
241 fortunately quite often), but also tackle the more complicated case |
327 compositional manner (which is fortunately quite often), but also |
242 when we translate abacus programs into Turing programs. This |
328 tackle the more complicated case when we translate abacus programs |
243 reasoning about concrete Turing machine programs is usually |
329 into Turing programs. This reasoning about concrete Turing machine |
244 left out in the informal literature, e.g.~\cite{Boolos87}. |
330 programs is usually left out in the informal literature, |
|
331 e.g.~\cite{Boolos87}. |
245 |
332 |
246 %To see the difficulties |
333 %To see the difficulties |
247 %involved with this work, one has to understand that interactive |
334 %involved with this work, one has to understand that interactive |
248 %theorem provers, like Isabelle/HOL, are at their best when the |
335 %theorem provers, like Isabelle/HOL, are at their best when the |
249 %data-structures at hand are ``structurally'' defined, like lists, |
336 %data-structures at hand are ``structurally'' defined, like lists, |
604 where @{term "read r"} returns the head of the list @{text r}, or if |
691 where @{term "read r"} returns the head of the list @{text r}, or if |
605 @{text r} is empty it returns @{term Bk}. It is impossible in |
692 @{text r} is empty it returns @{term Bk}. It is impossible in |
606 Isabelle/HOL to lift the @{term step}-function in order to realise a |
693 Isabelle/HOL to lift the @{term step}-function in order to realise a |
607 general evaluation function for Turing machines programs. The reason |
694 general evaluation function for Turing machines programs. The reason |
608 is that functions in HOL-based provers need to be terminating, and |
695 is that functions in HOL-based provers need to be terminating, and |
609 clearly there are programs that are not. We can however define a |
696 clearly there are programs that are not.\footnote{There is the alternative |
|
697 to use partial functions, which do not necessarily need to terminate, but |
|
698 this does not provide us with a useful induction principle \cite{Krauss10}.} We can however define a |
610 recursive evaluation function that performs exactly @{text n} steps: |
699 recursive evaluation function that performs exactly @{text n} steps: |
611 |
700 |
612 \begin{center} |
701 \begin{center} |
613 \begin{tabular}{l@ {\hspace{1mm}}c@ {\hspace{1mm}}l} |
702 \begin{tabular}{l@ {\hspace{1mm}}c@ {\hspace{1mm}}l} |
614 @{thm (lhs) steps.simps(1)} & @{text "\<equiv>"} & @{thm (rhs) steps.simps(1)}\\ |
703 @{thm (lhs) steps.simps(1)} & @{text "\<equiv>"} & @{thm (rhs) steps.simps(1)}\\ |
1218 |
1307 |
1219 \noindent |
1308 \noindent |
1220 This gives us a list of natural numbers specifying how many states |
1309 This gives us a list of natural numbers specifying how many states |
1221 are needed to translate each abacus instruction. This information |
1310 are needed to translate each abacus instruction. This information |
1222 is needed in order to calculate the state where the Turing machine program |
1311 is needed in order to calculate the state where the Turing machine program |
1223 of one abacus instruction starts. |
1312 of an abacus instruction starts. This can be defined as |
1224 |
1313 |
1225 {\it add something here about address} |
1314 \begin{center} |
1226 |
1315 @{thm address.simps[where x="n"]} |
|
1316 \end{center} |
|
1317 |
|
1318 \noindent |
|
1319 where @{text p} is an abacus program and @{term "take n"} takes the first |
|
1320 @{text n} elements from a list. |
|
1321 |
1227 The @{text Goto} |
1322 The @{text Goto} |
1228 instruction is easiest to translate requiring only one state, namely |
1323 instruction is easiest to translate requiring only one state, namely |
1229 the Turing machine program: |
1324 the Turing machine program: |
1230 |
1325 |
1231 \begin{center} |
1326 \begin{center} |