Paper/Paper.thy
changeset 97 d6f04e3e9894
parent 96 bd320b5365e2
child 98 860f05037c36
equal deleted inserted replaced
96:bd320b5365e2 97:d6f04e3e9894
    33   abc_lm_s ("set") and*)
    33   abc_lm_s ("set") and*)
    34   haltP ("stdhalt") and 
    34   haltP ("stdhalt") and 
    35   tcopy ("copy") and 
    35   tcopy ("copy") and 
    36   tape_of ("\<langle>_\<rangle>") and 
    36   tape_of ("\<langle>_\<rangle>") and 
    37   tm_comp ("_ \<oplus> _") and 
    37   tm_comp ("_ \<oplus> _") and 
    38   DUMMY  ("\<^raw:\mbox{$\_\!\_\,$}>")
    38   DUMMY  ("\<^raw:\mbox{$\_\!\_\,$}>") and
       
    39   inv_begin0 ("I\<^isub>0") and
       
    40   inv_begin1 ("I\<^isub>1") and
       
    41   inv_begin2 ("I\<^isub>2") and
       
    42   inv_begin3 ("I\<^isub>3") and
       
    43   inv_begin4 ("I\<^isub>4") and 
       
    44   inv_begin ("I\<^bsub>begin\<^esub>")
       
    45 
       
    46  
       
    47 lemma inv_begin_print:
       
    48   shows "s = 0 \<Longrightarrow> inv_begin n (s, tp) = inv_begin0 n tp" and
       
    49         "s = 1 \<Longrightarrow> inv_begin n (s, tp) = inv_begin1 n tp" and 
       
    50         "s = 2 \<Longrightarrow> inv_begin n (s, tp) = inv_begin2 n tp" and 
       
    51         "s = 3 \<Longrightarrow> inv_begin n (s, tp) = inv_begin3 n tp" and 
       
    52         "s = 4 \<Longrightarrow> inv_begin n (s, tp) = inv_begin4 n tp" and
       
    53         "s \<notin> {0,1,2,3,4} \<Longrightarrow> inv_begin n (s, l, r) = False"
       
    54 apply(case_tac [!] tp)
       
    55 by (auto)
       
    56 
       
    57 lemma inv1: 
       
    58   shows "0 < n \<Longrightarrow> inv_begin0 n \<mapsto> inv_loop1 n"
       
    59 unfolding assert_imp_def
       
    60 unfolding inv_loop1.simps inv_begin0.simps
       
    61 apply(auto)
       
    62 apply(rule_tac x="1" in exI)
       
    63 apply(auto simp add: replicate.simps)
       
    64 done
       
    65 
       
    66 lemma inv2: 
       
    67   shows "0 < n \<Longrightarrow> inv_loop0 n = inv_end1 n"
       
    68 apply(rule ext)
       
    69 apply(case_tac x)
       
    70 apply(simp add: inv_end1.simps)
       
    71 done
       
    72 
    39 
    73 
    40 declare [[show_question_marks = false]]
    74 declare [[show_question_marks = false]]
    41 
    75 
    42 (* THEOREMS *)
    76 (* THEOREMS *)
    43 notation (Rule output)
    77 notation (Rule output)
    71   "_asms" :: "prop \<Rightarrow> asms \<Rightarrow> asms" ("_ /\<^raw:{\normalsize \,>and\<^raw:\,}>/ _")
   105   "_asms" :: "prop \<Rightarrow> asms \<Rightarrow> asms" ("_ /\<^raw:{\normalsize \,>and\<^raw:\,}>/ _")
    72   "_asm" :: "prop \<Rightarrow> asms" ("_")
   106   "_asm" :: "prop \<Rightarrow> asms" ("_")
    73 
   107 
    74 lemma nats2tape:
   108 lemma nats2tape:
    75   shows "<([]::nat list)> = []"
   109   shows "<([]::nat list)> = []"
    76   and "<[n]> = Oc \<up> (n + 1)"
   110   and "<[n]> = <n>"
    77   and "ns \<noteq> [] \<Longrightarrow> <n#ns> = Oc \<up> (n + 1) @ [Bk] @ <ns>"
   111   and "ns \<noteq> [] \<Longrightarrow> <n#ns> = <(n::nat, ns)>"
    78 apply(auto simp add: tape_of_nl_abv tape_of_nat_list.simps)
   112   and "<(n, m)> = <n> @ [Bk] @ <m>"
       
   113   and "<[n, m]> = <(n, m)>"
       
   114   and "<n> = Oc \<up> (n + 1)" 
       
   115 apply(auto simp add: tape_of_nat_pair tape_of_nl_abv tape_of_nat_abv tape_of_nat_list.simps)
    79 apply(case_tac ns)
   116 apply(case_tac ns)
    80 apply(auto)
   117 apply(auto simp add: tape_of_nat_pair tape_of_nat_abv)
    81 done
   118 done 
    82 
   119 
    83 lemmas HR1 = 
   120 lemmas HR1 = 
    84   Hoare_plus_halt_simple[where ?P1.0="P" and ?P2.0="Q" and ?P3.0="R\<iota>" and ?A="p\<^isub>1" and B="p\<^isub>2"]
   121   Hoare_plus_halt_simple[where ?P1.0="P" and ?P2.0="Q" and ?P3.0="R\<iota>" and ?A="p\<^isub>1" and B="p\<^isub>2"]
    85 
   122 
    86 lemmas HR2 =
   123 lemmas HR2 =
    87   Hoare_plus_unhalt_simple[where ?P1.0="P" and ?P2.0="Q" and ?A="p\<^isub>1" and B="p\<^isub>2"]
   124   Hoare_plus_unhalt_simple[where ?P1.0="P" and ?P2.0="Q" and ?A="p\<^isub>1" and B="p\<^isub>2"]
       
   125 
       
   126 lemma inv_begin01:
       
   127   assumes "n > 1"
       
   128   shows "inv_begin0 n (l, r) = (n > 1 \<and> (l, r) = (Oc \<up> (n - 2), [Oc, Oc, Bk, Oc]))"
       
   129 using assms by auto                          
       
   130 
       
   131 lemma inv_begin02:
       
   132   assumes "n = 1"
       
   133   shows "inv_begin0 n (l, r) = (n = 1 \<and> (l, r) = ([], [Bk, Oc, Bk, Oc]))"
       
   134 using assms by auto
    88 
   135 
    89 (*>*)
   136 (*>*)
    90 
   137 
    91 section {* Introduction *}
   138 section {* Introduction *}
    92 
   139 
   177 %many proofs from the literature that use them.  We will analyse one
   224 %many proofs from the literature that use them.  We will analyse one
   178 %example---undecidability of Wang's tiling problem---in Section~\ref{Wang}. The
   225 %example---undecidability of Wang's tiling problem---in Section~\ref{Wang}. The
   179 %standard proof of this property uses the notion of universal
   226 %standard proof of this property uses the notion of universal
   180 %Turing machines.
   227 %Turing machines.
   181 
   228 
   182 We are not the first who formalised Turing machines: we are aware 
   229 We are not the first who formalised Turing machines: we are aware of
   183 of the work by Asperti and Ricciotti
   230 the work by Asperti and Ricciotti \cite{AspertiRicciotti12}. They
   184 \cite{AspertiRicciotti12}. They describe a complete formalisation of
   231 describe a complete formalisation of Turing machines in the Matita
   185 Turing machines in the Matita theorem prover, including a universal
   232 theorem prover, including a universal Turing machine. However, they do
   186 Turing machine. However, they do \emph{not} formalise the undecidability of the 
   233 \emph{not} formalise the undecidability of the halting problem since
   187 halting problem since their main focus is complexity, rather than
   234 their main focus is complexity, rather than computability theory. They
   188 computability theory. They also report that the informal proofs from which they
   235 also report that the informal proofs from which they started are not
   189 started are not ``sufficiently accurate to be directly usable as a
   236 ``sufficiently accurate to be directly usable as a guideline for
   190 guideline for formalization'' \cite[Page 2]{AspertiRicciotti12}. For
   237 formalization'' \cite[Page 2]{AspertiRicciotti12}. For our
   191 our formalisation we follow mainly the proofs from the textbook
   238 formalisation we follow mainly the proofs from the textbook
   192 \cite{Boolos87} and found that the description there is quite
   239 \cite{Boolos87} and found that the description there is quite
   193 detailed. Some details are left out however: for example, constructing
   240 detailed. Some details are left out however: for example, constructing
   194 the \emph{copy Turing machine} is left as an excerise to the reader; also 
   241 the \emph{copy Turing machine} and its correctness proof are left as
   195 \cite{Boolos87} only shows how the universal Turing machine is constructed for Turing
   242 an excerise to the reader; also \cite{Boolos87} only shows how the
   196 machines computing unary functions. We had to figure out a way to
   243 universal Turing machine is constructed for Turing machines computing
   197 generalise this result to $n$-ary functions. Similarly, when compiling
   244 unary functions. We had to figure out a way to generalise this result
   198 recursive functions to abacus machines, the textbook again only shows
   245 to $n$-ary functions. Similarly, when compiling recursive functions to
   199 how it can be done for 2- and 3-ary functions, but in the
   246 abacus machines, the textbook again only shows how it can be done for
   200 formalisation we need arbitrary functions. But the general ideas for
   247 2- and 3-ary functions, but in the formalisation we need arbitrary
   201 how to do this are clear enough in \cite{Boolos87}. 
   248 functions. But the general ideas for how to do this are clear enough
       
   249 in \cite{Boolos87}.
   202 %However, one
   250 %However, one
   203 %aspect that is completely left out from the informal description in
   251 %aspect that is completely left out from the informal description in
   204 %\cite{Boolos87}, and similar ones we are aware of, is arguments why certain Turing
   252 %\cite{Boolos87}, and similar ones we are aware of, is arguments why certain Turing
   205 %machines are correct. We will introduce Hoare-style proof rules
   253 %machines are correct. We will introduce Hoare-style proof rules
   206 %which help us with such correctness arguments of Turing machines.
   254 %which help us with such correctness arguments of Turing machines.
   441 
   489 
   442   \noindent
   490   \noindent
   443   In this definition the function @{term nth_of} returns the @{text n}th element
   491   In this definition the function @{term nth_of} returns the @{text n}th element
   444   from a list, provided it exists (@{term Some}-case), or if it does not, it
   492   from a list, provided it exists (@{term Some}-case), or if it does not, it
   445   returns the default action @{term Nop} and the default state @{text 0} 
   493   returns the default action @{term Nop} and the default state @{text 0} 
   446   (@{term None}-case). We often need to restrict Turing machine programs 
   494   (@{term None}-case). We often have to restrict Turing machine programs 
   447   to be well-formed: a program @{term p} is \emph{well-formed} if it 
   495   to be well-formed: a program @{term p} is \emph{well-formed} if it 
   448   satisfies the following three properties:
   496   satisfies the following three properties:
   449 
   497 
   450   \begin{center}
   498   \begin{center}
   451   @{thm tm_wf.simps[where p="p" and off="0::nat", simplified, THEN eq_reflection]}
   499   @{thm tm_wf.simps[where p="p" and off="0::nat", simplified, THEN eq_reflection]}
   636   \draw[fill]     ( 0.85,0.1) rectangle (1.15,0.4);
   684   \draw[fill]     ( 0.85,0.1) rectangle (1.15,0.4);
   637   \end{scope}
   685   \end{scope}
   638   \end{tikzpicture}\\[-8mm]\mbox{} 
   686   \end{tikzpicture}\\[-8mm]\mbox{} 
   639   \end{center}
   687   \end{center}
   640   \caption{The three components of the \emph{copy Turing machine} (above). If started 
   688   \caption{The three components of the \emph{copy Turing machine} (above). If started 
   641   (below) with the tape @{term "([], <[2::nat]>)"} the first machine appends @{term "[Bk, Oc]"} at 
   689   (below) with the tape @{term "([], <(2::nat)>)"} the first machine appends @{term "[Bk, Oc]"} at 
   642   the end of the right tape; the second then ``moves'' all @{term Oc}s except the 
   690   the end of the right tape; the second then ``moves'' all @{term Oc}s except the 
   643   first from the beginning of the tape to the end; the third ``refills'' the original 
   691   first from the beginning of the tape to the end; the third ``refills'' the original 
   644   block of @{term "Oc"}s. The resulting tape is @{term "([Bk], <[2::nat, 2::nat]>)"}.}
   692   block of @{term "Oc"}s. The resulting tape is @{term "([Bk], <(2::nat, 2::nat)>)"}.}
   645   \label{copy}
   693   \label{copy}
   646   \end{figure}
   694   \end{figure}
   647 
   695 
   648 
   696 
   649   We often need to restrict tapes to be in \emph{standard form}, which means 
   697   We often need to restrict tapes to be in \emph{standard form}, which means 
   650   the left list of the tape is either empty or only contains @{text "Bk"}s, and 
   698   the left list of the tape is either empty or only contains @{text "Bk"}s, and 
   651   the right list contains some ``clusters'' of @{text "Oc"}s separted by single 
   699   the right list contains some ``clusters'' of @{text "Oc"}s separted by single 
   652   blanks. To make this formal we define the following function
   700   blanks. To make this formal we define the following overloaded function
   653   
   701   
   654   \begin{center}
   702   \begin{center}
   655   \begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1mm}}l@ {}}
   703   \begin{tabular}[t]{@ {}l@ {\hspace{1mm}}c@ {\hspace{1mm}}l@ {}}
       
   704   @{thm (lhs) nats2tape(6)} & @{text "\<equiv>"} & @{thm (rhs) nats2tape(6)}\\
       
   705   @{thm (lhs) nats2tape(4)} & @{text "\<equiv>"} & @{thm (rhs) nats2tape(4)}\\
       
   706   \end{tabular}\hspace{6mm}
       
   707   \begin{tabular}[t]{@ {}l@ {\hspace{1mm}}c@ {\hspace{1mm}}l@ {}}
   656   @{thm (lhs) nats2tape(1)} & @{text "\<equiv>"} & @{thm (rhs) nats2tape(1)}\\
   708   @{thm (lhs) nats2tape(1)} & @{text "\<equiv>"} & @{thm (rhs) nats2tape(1)}\\
   657   @{thm (lhs) nats2tape(2)} & @{text "\<equiv>"} & @{thm (rhs) nats2tape(2)}\\
   709   @{thm (lhs) nats2tape(2)} & @{text "\<equiv>"} & @{thm (rhs) nats2tape(2)}\\
   658   @{thm (lhs) nats2tape(3)} & @{text "\<equiv>"} & @{thm (rhs) nats2tape(3)}
   710   @{thm (lhs) nats2tape(3)} & @{text "\<equiv>"} & @{thm (rhs) nats2tape(3)}
   659   \end{tabular}
   711   \end{tabular}
   660   \end{center}
   712   \end{center}
   664   and @{text "n\<^isub>i"}. Note that the head in a standard tape ``points'' to the 
   716   and @{text "n\<^isub>i"}. Note that the head in a standard tape ``points'' to the 
   665   leftmost @{term "Oc"} on the tape. Note also that the natural number @{text 0} 
   717   leftmost @{term "Oc"} on the tape. Note also that the natural number @{text 0} 
   666   is represented by a single filled cell on a standard tape, @{text 1} by two filled cells and so on.
   718   is represented by a single filled cell on a standard tape, @{text 1} by two filled cells and so on.
   667 
   719 
   668   Before we can prove the undecidability of the halting problem for our
   720   Before we can prove the undecidability of the halting problem for our
   669   Turing machines, we need to analyse two concrete Turing machine
   721   Turing machines, we have to analyse two concrete Turing machine
   670   programs and establish that they are correct---that means they are
   722   programs and establish that they are correct---that means they are
   671   ``doing what they are supposed to be doing''.  Such correctness proofs are usually left
   723   ``doing what they are supposed to be doing''.  Such correctness proofs are usually left
   672   out in the informal literature, for example \cite{Boolos87}.  One program 
   724   out in the informal literature, for example \cite{Boolos87}.  The first program 
   673   we need to prove correct is the @{term dither} program shown in \eqref{dither} 
   725   we need to prove correct is the @{term dither} program shown in \eqref{dither} 
   674   and the other program is @{term "tcopy"} defined as
   726   and the other program is @{term "tcopy"} defined as
   675 
   727 
   676   \begin{equation}
   728   \begin{equation}
   677   \mbox{\begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1mm}}l@ {}}
   729   \mbox{\begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1mm}}l@ {}}
   678   @{thm (lhs) tcopy_def} & @{text "\<equiv>"} & @{thm (rhs) tcopy_def}
   730   @{thm (lhs) tcopy_def} & @{text "\<equiv>"} & @{thm (rhs) tcopy_def}
   679   \end{tabular}}\label{tcopy}
   731   \end{tabular}}\label{tcopy}
   680   \end{equation}
   732   \end{equation}
   681 
   733 
   682   \noindent
   734   \noindent
   683   whose three components are given in Figure~\ref{copy}. To the prove
   735   whose three components are given in Figure~\ref{copy}. We introduce
   684   the correctness of Turing machine programs, we introduce the
   736   the notion of total correctness defined in terms of
   685   notion of total correctness defined in terms of
   737   \emph{Hoare-triples}, written @{term "{P} p {Q}"} (this notion is
   686   \emph{Hoare-triples}, written @{term "{P} p {Q}"}. They are very similar
   738   very similar to \emph{realisability} in \cite{AspertiRicciotti12}).
   687   to the notion of \emph{realisability} in \cite{AspertiRicciotti12}.  
   739   The Hoare-triples implement the idea that a program @{term p}
   688   They implement the 
   740   started in state @{term "1::nat"} with a tape satisfying @{term P}
   689   idea that a program @{term p} started in state @{term "1::nat"} with
   741   will after some @{text n} steps halt (have transitioned into the
   690   a tape satisfying @{term P} will after some @{text n} steps halt (have
   742   halting state) with a tape satisfying @{term Q}. We also have
   691   transitioned into the halting state) with a tape satisfying @{term
   743   \emph{Hoare-pairs} of the form @{term "{P} p \<up>"} implementing the
   692   Q}. We also have \emph{Hoare-pairs} of the form @{term "{P} p \<up>"}
   744   case that a program @{term p} started with a tape satisfying @{term
   693   implementing the case that a program @{term p} started with a tape
   745   P} will loop (never transition into the halting state). Both notion
   694   satisfying @{term P} will loop (never transition into the halting
   746   are formally defined as
   695   state). Both notion are formally defined as
       
   696 
   747 
   697   \begin{center}
   748   \begin{center}
   698   \begin{tabular}{@ {}c@ {\hspace{4mm}}c@ {}}
   749   \begin{tabular}{@ {}c@ {\hspace{4mm}}c@ {}}
   699   \begin{tabular}[t]{@ {}l@ {}}
   750   \begin{tabular}[t]{@ {}l@ {}}
   700   \colorbox{mygrey}{@{thm (lhs) Hoare_halt_def}} @{text "\<equiv>"}\\[1mm]
   751   \colorbox{mygrey}{@{thm (lhs) Hoare_halt_def}} @{text "\<equiv>"}\\[1mm]
   794   \noindent
   845   \noindent
   795   The first is by a simple calculation. The second is by induction on the
   846   The first is by a simple calculation. The second is by induction on the
   796   number of steps we can perform starting from the input tape.
   847   number of steps we can perform starting from the input tape.
   797 
   848 
   798   The program @{term tcopy} defined in \eqref{tcopy} has 15 states;
   849   The program @{term tcopy} defined in \eqref{tcopy} has 15 states;
   799   its purpose is to produce the standard tape @{term "(DUMMY, <[n,
   850   its purpose is to produce the standard tape @{term "(DUMMY, <(n,
   800   n::nat]>)"} when started with @{term "(DUMMY, <[n::nat]>)"}, that is
   851   n::nat)>)"} when started with @{term "(DUMMY, <(n::nat)>)"}, that is
   801   making a copy of a value on the tape.  Reasoning about this program
   852   making a copy of a value on the tape.  Reasoning about this program
   802   is substantially harder than about @{term dither}. To ease the
   853   is substantially harder than about @{term dither}. To ease the
   803   burden, we prove the following two Hoare-rules for sequentially
   854   burden, we derive the following two Hoare-rules for sequentially
   804   composed programs.
   855   composed programs.
   805 
   856 
   806   \begin{center}
   857   \begin{center}
   807   \begin{tabular}{@ {\hspace{-10mm}}c@ {\hspace{14mm}}c@ {}}
   858   \begin{tabular}{@ {\hspace{-10mm}}c@ {\hspace{14mm}}c@ {}}
   808   $\inferrule*[Right=@{thm (prem 3) HR1}]
   859   $\inferrule*[Right=@{thm (prem 3) HR1}]
   823   terminates generating a tape for which the second program loops.
   874   terminates generating a tape for which the second program loops.
   824   The side-condition about @{thm (prem 3) HR2} is needed in both rules
   875   The side-condition about @{thm (prem 3) HR2} is needed in both rules
   825   in order to ensure that the redirection of the halting and initial
   876   in order to ensure that the redirection of the halting and initial
   826   state in @{term "p\<^isub>1"} and @{term "p\<^isub>2"} match up correctly.
   877   state in @{term "p\<^isub>1"} and @{term "p\<^isub>2"} match up correctly.
   827 
   878 
   828 
       
   829   The Hoare-rules above allow us to prove the correctness of @{term tcopy}
   879   The Hoare-rules above allow us to prove the correctness of @{term tcopy}
   830   by considering the correctness of @{term "tcopy_begin"}, @{term "tcopy_loop"} 
   880   by considering the correctness of the components @{term "tcopy_begin"}, @{term "tcopy_loop"} 
   831   and @{term "tcopy_end"} in isolation. We will show the details for 
   881   and @{term "tcopy_end"} in isolation. We will show the details for 
   832   the program @{term "tcopy_begin"}. We found the following invariants for each
   882   the program @{term "tcopy_begin"}. Given the invariants @{term "inv_begin0"},\ldots, @{term "inv_begin4"} 
   833   state:
   883   shown in Figure~\ref{invbegin},
   834 
   884   we define the following invariant for @{term "tcopy_begin"}.
   835   \begin{center}
   885 
   836   @{thm inv_begin0.simps}\\
   886   \begin{figure}
   837   @{thm inv_begin1.simps}\\
   887   \begin{center}
   838   @{thm inv_begin2.simps}\\
   888   \begin{tabular}{@ {}lcl@ {\hspace{-2cm}}l@ {}}
   839   @{thm inv_begin3.simps}\\
   889   @{thm (lhs) inv_begin0.simps} & @{text "\<equiv>"} & @{thm (rhs) inv_begin01} @{text "\<or>"}& (halting state)\\
   840   @{thm inv_begin4.simps}
   890                                 &             & @{thm (rhs) inv_begin02} \\
   841   \end{center}
   891   @{thm (lhs) inv_begin1.simps} & @{text "\<equiv>"} & @{thm (rhs) inv_begin1.simps} & (starting state)\\
   842 
   892   @{thm (lhs) inv_begin2.simps} & @{text "\<equiv>"} & @{thm (rhs) inv_begin2.simps}\\
       
   893   @{thm (lhs) inv_begin3.simps} & @{text "\<equiv>"} & @{thm (rhs) inv_begin3.simps}\\
       
   894   @{thm (lhs) inv_begin4.simps} & @{text "\<equiv>"} & @{thm (rhs) inv_begin4.simps}
       
   895   \end{tabular}
       
   896   \end{center}
       
   897   \caption{The invariants for each state of @{term tcopy_begin}. They depend on
       
   898   the number @{term n} of @{term Oc}s with which this Turing machine is started.}\label{invbegin}
       
   899   \end{figure}
       
   900 
       
   901   \begin{center}
       
   902   \begin{tabular}{rcl}
       
   903   @{thm (lhs) inv_begin.simps} & @{text "\<equiv>"} & 
       
   904   @{text "if"} @{thm (prem 1) inv_begin_print(1)} @{text then} @{thm (rhs) inv_begin_print(1)}\\
       
   905   & & @{text else} @{text "if"} @{thm (prem 1) inv_begin_print(2)} @{text then} @{thm (rhs) inv_begin_print(2)} \\
       
   906  & & @{text else} @{text "if"} @{thm (prem 1) inv_begin_print(3)} @{text then} @{thm (rhs) inv_begin_print(3)}\\
       
   907   & & @{text else} @{text "if"} @{thm (prem 1) inv_begin_print(4)} @{text then} @{thm (rhs) inv_begin_print(4)}\\
       
   908    & & @{text else} @{text "if"} @{thm (prem 1) inv_begin_print(5)} @{text then} @{thm (rhs) inv_begin_print(5)}\\
       
   909   & & @{text else} @{thm (rhs) inv_begin_print(6)}
       
   910   \end{tabular}
       
   911   \end{center}
       
   912 
       
   913   \noindent
       
   914   This definition depends on @{term n}, which represents the number
       
   915   of @{term Oc}s on the tape. It is not hard (26 lines of automated proof script)
       
   916   to show that for @{term "n > (0::nat)"} this invariant is preserved under @{term step} and @{term steps}.
       
   917   
   843 
   918 
   844   measure for the copying TM, which we however omit.
   919   measure for the copying TM, which we however omit.
       
   920 
       
   921   
       
   922   \begin{center}
       
   923   @{thm begin_correct}\\
       
   924   @{thm loop_correct}\\
       
   925   @{thm end_correct}
       
   926   \end{center}
       
   927 
       
   928 
   845 
   929 
   846   \begin{center}
   930   \begin{center}
   847   @{thm haltP_def[where lm="ns"]}
   931   @{thm haltP_def[where lm="ns"]}
   848   \end{center}
   932   \end{center}
   849 
   933