94 in Isabelle/HOL and other HOL theorem provers, since they are based on classical logic |
94 in Isabelle/HOL and other HOL theorem provers, since they are based on classical logic |
95 where the law of excluded middle ensures that \mbox{@{term "P \<or> \<not>P"}} |
95 where the law of excluded middle ensures that \mbox{@{term "P \<or> \<not>P"}} |
96 is always provable no matter whether @{text P} is constructed by |
96 is always provable no matter whether @{text P} is constructed by |
97 computable means. We hit this limitation previously when we mechanised the correctness |
97 computable means. We hit this limitation previously when we mechanised the correctness |
98 proofs of two algorithms \cite{UrbanCheneyBerghofer11,WuZhangUrban12}, |
98 proofs of two algorithms \cite{UrbanCheneyBerghofer11,WuZhangUrban12}, |
99 but were unable to formalise arguments about computability. |
99 but were unable to formalise arguments about decidability. |
100 |
100 |
101 %The same problem would arise if we had formulated |
101 %The same problem would arise if we had formulated |
102 %the algorithms as recursive functions, because internally in |
102 %the algorithms as recursive functions, because internally in |
103 %Isabelle/HOL, like in all HOL-based theorem provers, functions are |
103 %Isabelle/HOL, like in all HOL-based theorem provers, functions are |
104 %represented as inductively defined predicates too. |
104 %represented as inductively defined predicates too. |
216 {\bf Contributions:} We formalised in Isabelle/HOL Turing machines following the |
216 {\bf Contributions:} We formalised in Isabelle/HOL Turing machines following the |
217 description of Boolos et al \cite{Boolos87} where tapes only have blank or |
217 description of Boolos et al \cite{Boolos87} where tapes only have blank or |
218 occupied cells. We mechanise the undecidability of the halting problem and |
218 occupied cells. We mechanise the undecidability of the halting problem and |
219 prove the correctness of concrete Turing machines that are needed |
219 prove the correctness of concrete Turing machines that are needed |
220 in this proof; such correctness proofs are left out in the informal literature. |
220 in this proof; such correctness proofs are left out in the informal literature. |
221 We construct the universal Turing machine from \cite{Boolos87} by |
221 For reasoning about Turing machine programs we derive Hoare-rules. |
|
222 We also construct the universal Turing machine from \cite{Boolos87} by |
222 relating recursive functions to abacus machines and abacus machines to |
223 relating recursive functions to abacus machines and abacus machines to |
223 Turing machines. Since we have set up in Isabelle/HOL a very general computability |
224 Turing machines. Since we have set up in Isabelle/HOL a very general computability |
224 model and undecidability result, we are able to formalise other |
225 model and undecidability result, we are able to formalise other |
225 results: we describe a proof of the computational equivalence |
226 results: we describe a proof of the computational equivalence |
226 of single-sided Turing machines, which is not given in \cite{Boolos87}, |
227 of single-sided Turing machines, which is not given in \cite{Boolos87}, |
423 The first says that @{text p} must have at least an instruction for the starting |
424 The first says that @{text p} must have at least an instruction for the starting |
424 state; the second that @{text p} has a @{term Bk} and @{term Oc} instruction for every |
425 state; the second that @{text p} has a @{term Bk} and @{term Oc} instruction for every |
425 state, and the third that every next-state is one of the states mentioned in |
426 state, and the third that every next-state is one of the states mentioned in |
426 the program or being the @{text 0}-state. |
427 the program or being the @{text 0}-state. |
427 |
428 |
428 A \emph{configuration} @{term c} of a Turing machine is a state together with |
429 We need to be able to sequentially compose Turing machine programs. Given our |
429 a tape. This is written as @{text "(s, (l, r))"}. If we have a |
430 concrete representation, this is relatively straightforward, if |
430 configuration and a program, we can calculate |
431 slightly fiddly. We use the following two auxiliary functions: |
431 what the next configuration is by fetching the appropriate action and next state |
432 |
432 from the program, and by updating the state and tape accordingly. |
433 \begin{center} |
433 This single step of execution is defined as the function @{term step} |
434 \begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1mm}}l@ {}} |
|
435 @{thm (lhs) shift.simps} @{text "\<equiv>"} @{thm (rhs) shift.simps}\\ |
|
436 @{thm (lhs) adjust.simps} @{text "\<equiv>"} @{thm (rhs) adjust.simps}\\ |
|
437 \end{tabular} |
|
438 \end{center} |
|
439 |
|
440 \noindent |
|
441 The first adds @{text n} to all states, exept the @{text 0}-state, |
|
442 thus moving all ``regular'' states to the segment starting at @{text |
|
443 n}; the second adds @{term "Suc(length p div 2)"} to the @{text |
|
444 0}-state, thus redirecting all references to the ``halting state'' |
|
445 to the first state after the program @{text p}. With these two |
|
446 functions in place, we can define the \emph{sequential composition} |
|
447 of two Turing machine programs @{text "p\<^isub>1"} and @{text "p\<^isub>2"} |
|
448 |
|
449 \begin{center} |
|
450 @{thm tm_comp.simps[where ?p1.0="p\<^isub>1" and ?p2.0="p\<^isub>2", THEN eq_reflection]} |
|
451 \end{center} |
|
452 |
|
453 \noindent |
|
454 %This means @{text "p\<^isub>1"} is executed first. Whenever it originally |
|
455 %transitioned to the @{text 0}-state, it will in the composed program transition to the starting |
|
456 %state of @{text "p\<^isub>2"} instead. All the states of @{text "p\<^isub>2"} |
|
457 %have been shifted in order to make sure that the states of the composed |
|
458 %program @{text "p\<^isub>1 \<oplus> p\<^isub>2"} still only ``occupy'' |
|
459 %an initial segment of the natural numbers. |
|
460 |
|
461 A \emph{configuration} @{term c} of a Turing machine is a state |
|
462 together with a tape. This is written as @{text "(s, (l, r))"}. We |
|
463 say a configuration is \emph{final} if @{term "s = (0::nat)"} and we |
|
464 say a predicate @{text P} \emph{holds for} a configuration if @{text |
|
465 "P (l, r)"} holds. If we have a configuration and a program, we can |
|
466 calculate what the next configuration is by fetching the appropriate |
|
467 action and next state from the program, and by updating the state |
|
468 and tape accordingly. This single step of execution is defined as |
|
469 the function @{term step} |
434 |
470 |
435 \begin{center} |
471 \begin{center} |
436 \begin{tabular}{l@ {\hspace{1mm}}c@ {\hspace{1mm}}l} |
472 \begin{tabular}{l@ {\hspace{1mm}}c@ {\hspace{1mm}}l} |
437 @{text "step (s, (l, r)) p"} & @{text "\<equiv>"} & @{text "let (a, s') = fetch p s (read r)"}\\ |
473 @{text "step (s, (l, r)) p"} & @{text "\<equiv>"} & @{text "let (a, s') = fetch p s (read r)"}\\ |
438 & & @{text "in (s', update (l, r) a)"} |
474 & & @{text "in (s', update (l, r) a)"} |
461 then @{text n} steps before it halts, then in our setting the @{term steps}-evaluation |
497 then @{text n} steps before it halts, then in our setting the @{term steps}-evaluation |
462 does not actually halt, but rather transitions to the @{text 0}-state and |
498 does not actually halt, but rather transitions to the @{text 0}-state and |
463 remains there performing @{text Nop}-actions until @{text n} is reached. |
499 remains there performing @{text Nop}-actions until @{text n} is reached. |
464 |
500 |
465 Before we can prove the undecidability of the halting problem for Turing machines, |
501 Before we can prove the undecidability of the halting problem for Turing machines, |
466 we have to define how to compose two Turing machine programs. Given our setup, this is |
502 we need to analyse two concrete Turing machine programs and establish that |
467 relatively straightforward, if slightly fiddly. We use the following two |
503 they ``doing what they are supposed to be doing''. To do so we will derive |
468 auxiliary functions: |
504 some Hoare-style reasoning rules for Turing machine programs. A \emph{Hoare-triple} |
469 |
505 for a terminating Turing machine program is defined as |
470 \begin{center} |
506 |
471 \begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1mm}}l@ {}} |
507 \begin{center} |
472 @{thm (lhs) shift.simps} @{text "\<equiv>"} @{thm (rhs) shift.simps}\\ |
508 @{thm Hoare_halt_def} |
473 @{thm (lhs) adjust.simps} @{text "\<equiv>"} @{thm (rhs) adjust.simps}\\ |
509 \end{center} |
474 \end{tabular} |
510 |
475 \end{center} |
511 \begin{center} |
476 |
512 @{thm Hoare_unhalt_def} |
477 \noindent |
513 \end{center} |
478 The first adds @{text n} to all states, exept the @{text 0}-state, |
|
479 thus moving all ``regular'' states to the segment starting at @{text |
|
480 n}; the second adds @{term "Suc(length p div 2)"} to the @{text |
|
481 0}-state, thus redirecting all references to the ``halting state'' |
|
482 to the first state after the program @{text p}. With these two |
|
483 functions in place, we can define the \emph{sequential composition} |
|
484 of two Turing machine programs @{text "p\<^isub>1"} and @{text "p\<^isub>2"} |
|
485 |
|
486 \begin{center} |
|
487 @{thm tm_comp.simps[where ?p1.0="p\<^isub>1" and ?p2.0="p\<^isub>2", THEN eq_reflection]} |
|
488 \end{center} |
|
489 |
|
490 \noindent |
|
491 %This means @{text "p\<^isub>1"} is executed first. Whenever it originally |
|
492 %transitioned to the @{text 0}-state, it will in the composed program transition to the starting |
|
493 %state of @{text "p\<^isub>2"} instead. All the states of @{text "p\<^isub>2"} |
|
494 %have been shifted in order to make sure that the states of the composed |
|
495 %program @{text "p\<^isub>1 \<oplus> p\<^isub>2"} still only ``occupy'' |
|
496 %an initial segment of the natural numbers. |
|
497 |
514 |
498 In the following we will consider the following Turing machine program |
515 In the following we will consider the following Turing machine program |
499 that makes a copies a value on the tape. |
516 that makes a copies a value on the tape. |
500 |
517 |
501 \begin{figure} |
518 \begin{figure} |