Paper/Paper.thy
changeset 73 a673539f2f75
parent 72 49f8e5cf82c5
child 75 97eaf7514988
equal deleted inserted replaced
72:49f8e5cf82c5 73:a673539f2f75
    21   W0 ("W\<^bsub>\<^raw:\hspace{-2pt}>Bk\<^esub>") and
    21   W0 ("W\<^bsub>\<^raw:\hspace{-2pt}>Bk\<^esub>") and
    22   W1 ("W\<^bsub>\<^raw:\hspace{-2pt}>Oc\<^esub>") and
    22   W1 ("W\<^bsub>\<^raw:\hspace{-2pt}>Oc\<^esub>") and
    23   update2 ("update") and
    23   update2 ("update") and
    24   tm_wf0 ("wf") and
    24   tm_wf0 ("wf") and
    25   is_even ("iseven") and
    25   is_even ("iseven") and
       
    26   tcopy_init ("copy\<^bsub>begin\<^esub>") and
       
    27   tcopy_loop ("copy\<^bsub>loop\<^esub>") and
       
    28   tcopy_end ("copy\<^bsub>end\<^esub>") and
    26 (*  abc_lm_v ("lookup") and
    29 (*  abc_lm_v ("lookup") and
    27   abc_lm_s ("set") and*)
    30   abc_lm_s ("set") and*)
    28   haltP ("stdhalt") and 
    31   haltP ("stdhalt") and 
    29   tcopy ("copy") and 
    32   tcopy ("copy") and 
    30   tape_of_nat_list ("\<ulcorner>_\<urcorner>") and 
    33   tape_of_nat_list ("\<ulcorner>_\<urcorner>") and 
   164 \cite{AspertiRicciotti12}. They describe a complete formalisation of
   167 \cite{AspertiRicciotti12}. They describe a complete formalisation of
   165 Turing machines in the Matita theorem prover, including a universal
   168 Turing machines in the Matita theorem prover, including a universal
   166 Turing machine. They report that the informal proofs from which they
   169 Turing machine. They report that the informal proofs from which they
   167 started are \emph{not} ``sufficiently accurate to be directly usable as a
   170 started are \emph{not} ``sufficiently accurate to be directly usable as a
   168 guideline for formalization'' \cite[Page 2]{AspertiRicciotti12}. For
   171 guideline for formalization'' \cite[Page 2]{AspertiRicciotti12}. For
   169 our formalisation we followed mainly the proofs from the textbook
   172 our formalisation we follow mainly the proofs from the textbook
   170 \cite{Boolos87} and found that the description there is quite
   173 \cite{Boolos87} and found that the description there is quite
   171 detailed. Some details are left out however: for example, it is only
   174 detailed. Some details are left out however: for example, it is only
   172 shown how the universal Turing machine is constructed for Turing
   175 shown how the universal Turing machine is constructed for Turing
   173 machines computing unary functions. We had to figure out a way to
   176 machines computing unary functions. We had to figure out a way to
   174 generalise this result to $n$-ary functions. Similarly, when compiling
   177 generalise this result to $n$-ary functions. Similarly, when compiling
   350   %machines: we would need to combine two finite sets of states,
   353   %machines: we would need to combine two finite sets of states,
   351   %possibly renaming states apart whenever both machines share
   354   %possibly renaming states apart whenever both machines share
   352   %states.\footnote{The usual disjoint union operation in Isabelle/HOL
   355   %states.\footnote{The usual disjoint union operation in Isabelle/HOL
   353   %cannot be used as it does not preserve types.} This renaming can be
   356   %cannot be used as it does not preserve types.} This renaming can be
   354   %quite cumbersome to reason about. 
   357   %quite cumbersome to reason about. 
   355   We followed the choice made in \cite{AspertiRicciotti12} 
   358   We follow the choice made in \cite{AspertiRicciotti12} 
   356   representing a state by a natural number and the states in a Turing
   359   representing a state by a natural number and the states in a Turing
   357   machine programme by the initial segment of natural numbers starting from @{text 0}.
   360   machine program by the initial segment of natural numbers starting from @{text 0}.
   358   In doing so we can compose two Turing machine programs by
   361   In doing so we can compose two Turing machine programs by
   359   shifting the states of one by an appropriate amount to a higher
   362   shifting the states of one by an appropriate amount to a higher
   360   segment and adjusting some ``next states'' in the other. 
   363   segment and adjusting some ``next states'' in the other. 
   361 
   364 
   362   An \emph{instruction} of a Turing machine is a pair consisting of 
   365   An \emph{instruction} of a Turing machine is a pair consisting of 
   365   program, which consists of four instructions
   368   program, which consists of four instructions
   366 
   369 
   367   \begin{equation}
   370   \begin{equation}
   368   \begin{tikzpicture}
   371   \begin{tikzpicture}
   369   \node [anchor=base] at (0,0) {@{thm dither_def}};
   372   \node [anchor=base] at (0,0) {@{thm dither_def}};
   370   \node [anchor=west] at (-1.5,-0.42) {$\underbrace{\hspace{21mm}}_{\text{1st state}}$};
   373   \node [anchor=west] at (-1.5,-0.64) 
       
   374   {$\underbrace{\hspace{21mm}}_{\text{\begin{tabular}{@ {}l@ {}}1st state\\[-2mm] 
       
   375   = starting state\end{tabular}}}$};
       
   376   
   371   \node [anchor=west] at ( 1.1,-0.42) {$\underbrace{\hspace{17mm}}_{\text{2nd state}}$};
   377   \node [anchor=west] at ( 1.1,-0.42) {$\underbrace{\hspace{17mm}}_{\text{2nd state}}$};
   372   \node [anchor=west] at (-1.5,0.65) {$\overbrace{\hspace{10mm}}^{\text{@{term Bk}-case}}$};
   378   \node [anchor=west] at (-1.5,0.65) {$\overbrace{\hspace{10mm}}^{\text{@{term Bk}-case}}$};
   373   \node [anchor=west] at (-0.1,0.65) {$\overbrace{\hspace{6mm}}^{\text{@{term Oc}-case}}$};
   379   \node [anchor=west] at (-0.1,0.65) {$\overbrace{\hspace{6mm}}^{\text{@{term Oc}-case}}$};
   374   \end{tikzpicture}
   380   \end{tikzpicture}
   375   \label{dither}
   381   \label{dither}
   458   %program @{text "p\<^isub>1 \<oplus> p\<^isub>2"} still only ``occupy'' 
   464   %program @{text "p\<^isub>1 \<oplus> p\<^isub>2"} still only ``occupy'' 
   459   %an initial segment of the natural numbers.
   465   %an initial segment of the natural numbers.
   460 
   466 
   461   A \emph{configuration} @{term c} of a Turing machine is a state
   467   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
   468   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
   469   say a configuration \emph{is final} if @{term "s = (0::nat)"} and we
   464   say a predicate @{text P} \emph{holds for} a configuration if @{text
   470   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
   471   "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
   472   calculate what the next configuration is by fetching the appropriate
   467   action and next state from the program, and by updating the state
   473   action and next state from the program, and by updating the state
   468   and tape accordingly.  This single step of execution is defined as
   474   and tape accordingly.  This single step of execution is defined as
   489   @{thm (lhs) steps.simps(1)} & @{text "\<equiv>"} & @{thm (rhs) steps.simps(1)}\\
   495   @{thm (lhs) steps.simps(1)} & @{text "\<equiv>"} & @{thm (rhs) steps.simps(1)}\\
   490   @{thm (lhs) steps.simps(2)} & @{text "\<equiv>"} & @{thm (rhs) steps.simps(2)}\\
   496   @{thm (lhs) steps.simps(2)} & @{text "\<equiv>"} & @{thm (rhs) steps.simps(2)}\\
   491   \end{tabular}
   497   \end{tabular}
   492   \end{center}
   498   \end{center}
   493 
   499 
   494   \noindent
   500   \noindent Recall our definition of @{term fetch} (shown in
   495   Recall our definition of @{term fetch} (shown in \ref{fetch}) with the default value for
   501   \eqref{fetch}) with the default value for the @{text 0}-state. In
   496   the @{text 0}-state. In case a Turing program takes in \cite{Boolos87} less 
   502   case a Turing program takes according to the usual textbook
   497   then @{text n} steps before it halts, then in our setting the @{term steps}-evaluation
   503   definition \cite{Boolos87} less than @{text n} steps before it
   498   does not actually halt, but rather transitions to the @{text 0}-state and 
   504   halts, then in our setting the @{term steps}-evaluation does not
   499   remains there performing @{text Nop}-actions until @{text n} is reached. 
   505   actually halt, but rather transitions to the @{text 0}-state (the
   500 
   506   final state) and remains there performing @{text Nop}-actions until
   501   Before we can prove the undecidability of the halting problem for Turing machines, 
   507   @{text n} is reached.
   502   we need to analyse two concrete Turing machine programs and establish that
   508   
   503   they ``doing what they are supposed to be doing''. To do so we will derive
   509   \begin{figure}[t]
   504   some Hoare-style reasoning rules for Turing machine programs. A \emph{Hoare-triple}
   510   \begin{center}
   505   for a terminating Turing machine program is defined as
   511   \begin{tabular}{@ {}p{3.6cm}@ {\hspace{4mm}}p{3.6cm}@ {\hspace{4mm}}p{3.6cm}@ {}}
       
   512   @{thm (lhs) tcopy_init_def} @{text "\<equiv>"} &
       
   513   @{thm (lhs) tcopy_loop_def} @{text "\<equiv>"} &
       
   514   @{thm (lhs) tcopy_end_def} @{text "\<equiv>"}\\
       
   515   @{thm (rhs) tcopy_init_def} &
       
   516   @{thm (rhs) tcopy_loop_def} &
       
   517   @{thm (rhs) tcopy_end_def}
       
   518   \end{tabular}
       
   519   \end{center}
       
   520   \caption{Copy machine}\label{copy}
       
   521   \end{figure}
       
   522 
       
   523   Before we can prove the undecidability of the halting problem for
       
   524   Turing machines, we need to analyse two concrete Turing machine
       
   525   programs and establish that they are correct, that is they are
       
   526   ``doing what they are supposed to be doing''.  This is usually left
       
   527   out in the informal computability literature, for example
       
   528   \cite{Boolos87}.  One program we prove correct is the @{term dither}
       
   529   program shown in \eqref{dither} and the other program @{term
       
   530   "tcopy"} is defined as
       
   531 
       
   532   \begin{center}
       
   533   \begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1mm}}l@ {}}
       
   534   @{thm (lhs) tcopy_def} & @{text "\<equiv>"} & @{thm (rhs) tcopy_def}
       
   535   \end{tabular}
       
   536   \end{center}
       
   537 
       
   538   \noindent
       
   539   whose three components are given in Figure~\ref{copy}.
       
   540   To prove the correctness, we derive some Hoare-style reasoning rules for 
       
   541   Turing machine programs. A \emph{Hoare-triple} for a terminating Turing 
       
   542   machine program is defined as
   506 
   543 
   507   \begin{center}
   544   \begin{center}
   508   @{thm Hoare_halt_def}
   545   @{thm Hoare_halt_def}
   509   \end{center}
   546   \end{center}
   510 
   547 
   513   \end{center}
   550   \end{center}
   514 
   551 
   515   In the following we will consider the following Turing machine program
   552   In the following we will consider the following Turing machine program
   516   that makes a copies a value on the tape.
   553   that makes a copies a value on the tape.
   517 
   554 
   518   \begin{figure}
   555  
   519   \begin{center}
   556 
   520   \begin{tabular}{@ {}p{3.6cm}@ {\hspace{4mm}}p{3.6cm}@ {\hspace{4mm}}p{3.6cm}@ {}}
   557 
   521   @{thm tcopy_init_def} &
   558   
   522   @{thm tcopy_loop_def} &
       
   523   @{thm tcopy_end_def}
       
   524   \end{tabular}
       
   525   \end{center}
       
   526   \end{figure}
       
   527 
       
   528 
       
   529   \begin{center}
       
   530   \begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1mm}}p{6.9cm}@ {}}
       
   531   @{thm (lhs) tcopy_def} & @{text "\<equiv>"} & @{thm (rhs) tcopy_def}
       
   532   \end{tabular}
       
   533   \end{center}
       
   534 
   559 
   535 
   560 
   536   assertion holds for all tapes
   561   assertion holds for all tapes
   537 
   562 
   538   Hoare rule for composition
   563   Hoare rule for composition
   592   \begin{center}
   617   \begin{center}
   593   %@ {thm clear.simps[where n="R\<iota>" and e="o\<iota>", THEN eq_reflection]}
   618   %@ {thm clear.simps[where n="R\<iota>" and e="o\<iota>", THEN eq_reflection]}
   594   \end{center}
   619   \end{center}
   595 
   620 
   596   \noindent
   621   \noindent
   597   The second opcode @{term "Goto 0"} in this programm means we 
   622   The second opcode @{term "Goto 0"} in this program means we 
   598   jump back to the first opcode, namely @{text "Dec R o"}.
   623   jump back to the first opcode, namely @{text "Dec R o"}.
   599   The \emph{memory} $m$ of an abacus machine holding the values
   624   The \emph{memory} $m$ of an abacus machine holding the values
   600   of the registers is represented as a list of natural numbers.
   625   of the registers is represented as a list of natural numbers.
   601   We have a lookup function for this memory, written @{term "abc_lm_v m R\<iota>"},
   626   We have a lookup function for this memory, written @{term "abc_lm_v m R\<iota>"},
   602   which looks up the content of register $R$; if $R$
   627   which looks up the content of register $R$; if $R$