326 left out in the informal literature. For reasoning about Turing |
326 left out in the informal literature. For reasoning about Turing |
327 machine programs we derive Hoare-rules. We also construct the |
327 machine programs we derive Hoare-rules. We also construct the |
328 universal Turing machine from \cite{Boolos87} by translating recursive |
328 universal Turing machine from \cite{Boolos87} by translating recursive |
329 functions to abacus machines and abacus machines to Turing |
329 functions to abacus machines and abacus machines to Turing |
330 machines. When formalising the universal Turing machine, |
330 machines. When formalising the universal Turing machine, |
331 we stumbled upon an inconsistence use of the definition of |
331 we stumbled upon an inconsistent use of the definition of |
332 what function a Turing machine calculates. Since we have set up in |
332 what function a Turing machine calculates. |
333 Isabelle/HOL a very general computability model and undecidability |
333 %Since we have set up in |
334 result, we are able to formalise other results: we describe a proof of |
334 %Isabelle/HOL a very general computability model and undecidability |
335 the computational equivalence of single-sided Turing machines, which |
335 %result, we are able to formalise other results: we describe a proof of |
336 is not given in \cite{Boolos87}, but needed for example for |
336 %the computational equivalence of single-sided Turing machines, which |
337 formalising the undecidability proof of Wang's tiling problem |
337 %is not given in \cite{Boolos87}, but needed for example for |
338 \cite{Robinson71}. %We are not aware of any other %formalisation of a |
338 %formalising the undecidability proof of Wang's tiling problem |
339 substantial undecidability problem. |
339 %\cite{Robinson71}. %We are not aware of any other %formalisation of a |
|
340 %substantial undecidability problem. |
340 *} |
341 *} |
341 |
342 |
342 section {* Turing Machines *} |
343 section {* Turing Machines *} |
343 |
344 |
344 text {* \noindent |
345 text {* \noindent |
1308 where @{text n} indicates the function expects @{term n} arguments |
1309 where @{text n} indicates the function expects @{term n} arguments |
1309 (@{text z} and @{term s} expect one argument), and @{text rs} stands |
1310 (@{text z} and @{term s} expect one argument), and @{text rs} stands |
1310 for a list of recursive functions. Since we know in each case |
1311 for a list of recursive functions. Since we know in each case |
1311 the arity, say @{term l}, we can define an inductive evaluation relation that |
1312 the arity, say @{term l}, we can define an inductive evaluation relation that |
1312 relates a recursive function @{text r} and a list @{term ns} of natural numbers of length @{text l}, |
1313 relates a recursive function @{text r} and a list @{term ns} of natural numbers of length @{text l}, |
1313 to what the result of the recursive function is, say @{text n}---we omit the straightforward |
1314 to what the result of the recursive function is, say @{text n}. We omit the |
1314 definition of @{term "rec_calc_rel r ns n"}. Because of space reasons, we also omit the |
1315 definition of @{term "rec_calc_rel r ns n"}. Because of space reasons, we also omit the |
1315 definition of translating |
1316 definition of translating |
1316 recursive functions into abacus programs. We can prove the following |
1317 recursive functions into abacus programs. We can prove, however, the following |
1317 theorem about the translation: If |
1318 theorem about the translation: If |
1318 @{thm (prem 1) recursive_compile_to_tm_correct3[where recf="r" and args="ns" and r="n"]} |
1319 @{thm (prem 1) recursive_compile_to_tm_correct3[where recf="r" and args="ns" and r="n"]} |
1319 holds for the recursive function @{text r}, then the following Hoare-triple holds |
1320 holds for the recursive function @{text r}, then the following Hoare-triple holds |
1320 |
1321 |
1321 \begin{center} |
1322 \begin{center} |
1322 @{thm (concl) recursive_compile_to_tm_correct3[where recf="r" and args="ns" and r="n"]} |
1323 @{thm (concl) recursive_compile_to_tm_correct3[where recf="r" and args="ns" and r="n"]} |
1323 \end{center} |
1324 \end{center} |
1324 |
1325 |
1325 \noindent |
1326 \noindent |
1326 for the Turing machine. This |
1327 for the translated Turing machine @{term "translate r"}. This |
1327 means that if the recursive function @{text r} with arguments @{text ns} evaluates |
1328 means that if the recursive function @{text r} with arguments @{text ns} evaluates |
1328 to @{text n}, then the corresponding Turing machine @{term "tm_of_rec r"} if started |
1329 to @{text n}, then the translated Turing machine if started |
1329 with the standard tape @{term "([Bk, Bk], <ns::nat list>)"} will terminate |
1330 with the standard tape @{term "([Bk, Bk], <ns::nat list>)"} will terminate |
1330 with the standard tape @{term "(Bk \<up> k, <n::nat> @ Bk \<up> l)"} for some @{text k} and @{text l}. |
1331 with the standard tape @{term "(Bk \<up> k, <n::nat> @ Bk \<up> l)"} for some @{text k} and @{text l}. |
1331 |
1332 |
1332 Having recursive functions under our belt, we can construct an universal |
1333 Having recursive functions under our belt, we can construct an universal |
1333 function and consider the translated (universal) Turing machine @{term UTM}. |
1334 function and consider its translated (universal) Turing machine, written @{term UTM}. |
1334 Suppose |
1335 Suppose |
1335 a Turing program is well-formed and @{term p} when started with the standard |
1336 a Turing program @{term p} is well-formed and when started with the standard |
1336 tape containing the arguments @{term arg}, produces a standard tape |
1337 tape containing the arguments @{term args}, will produce a standard tape |
1337 with ``output'' @{term n}. This assumption can be written as the |
1338 with ``output'' @{term n}. This assumption can be written as the |
1338 Hoare-triple |
1339 Hoare-triple |
1339 |
1340 |
1340 \begin{center} |
1341 \begin{center} |
1341 @{thm (prem 3) UTM_halt_lemma2} |
1342 @{thm (prem 3) UTM_halt_lemma2} |
1342 \end{center} |
1343 \end{center} |
1343 |
1344 |
1344 \noindent |
1345 \noindent |
1345 where we assume the @{term args} are non-empty, then the universal Turing |
1346 where we assume the @{term args} stand for a non-empty list. Then the universal Turing |
1346 machine @{term UTM} started with the code of @{term p} and the arguments |
1347 machine @{term UTM} started with the code of @{term p} and the arguments |
1347 @{term args} calculates the same result: |
1348 @{term args} calculates the same result, namely |
1348 |
1349 |
1349 \begin{center} |
1350 \begin{center} |
1350 @{thm (concl) UTM_halt_lemma2} |
1351 @{thm (concl) UTM_halt_lemma2} |
1351 \end{center} |
1352 \end{center} |
1352 |
1353 |
1365 |
1366 |
1366 \begin{center} |
1367 \begin{center} |
1367 @{thm (concl) UTM_unhalt_lemma2} |
1368 @{thm (concl) UTM_unhalt_lemma2} |
1368 \end{center} |
1369 \end{center} |
1369 |
1370 |
1370 Analysing the universal Turing machine constructed in \cite{Boolos87} more carefully |
1371 %Analysing the universal Turing machine constructed in \cite{Boolos87} more carefully |
1371 we can strengthen this result slightly by observing that @{text m} is at most |
1372 %we can strengthen this result slightly by observing that @{text m} is at most |
1372 2 in the output tape. This observation allows one to construct a universal Turing machine that works |
1373 %2 in the output tape. This observation allows one to construct a universal Turing machine that works |
1373 entirely on the left-tape by composing it with a machine that drags the tape |
1374 %entirely on the left-tape by composing it with a machine that drags the tape |
1374 two cells to the right. A corollary is that one-sided Turing machines (where the |
1375 %two cells to the right. A corollary is that one-sided Turing machines (where the |
1375 tape only extends to the right) are computationally as powerful as our two-sided |
1376 %tape only extends to the right) are computationally as powerful as our two-sided |
1376 Turing machines. So our undecidability proof for the halting problem extends |
1377 %Turing machines. So our undecidability proof for the halting problem extends |
1377 also to one-sided Turing machines, which is needed for example in order to |
1378 %also to one-sided Turing machines, which is needed for example in order to |
1378 formalise the undecidability of Wang's tiling problem \cite{Robinson71}. |
1379 %formalise the undecidability of Wang's tiling problem \cite{Robinson71}. |
1379 |
1380 |
1380 While formalising the chapter about universal Turing machines in \cite{Boolos87}, |
1381 While formalising the chapter in \cite{Boolos87} about universal Turing machines, an |
1381 we noticed that they use their definition about what function Turing machines |
1382 unexpected outcome is that we identified an inconsistency in |
1382 calculate. They write in Chapter 3 \cite[Page 32]{Boolos87}: |
1383 their use of a definition. It is unexpected since it is a classic textbook which has |
|
1384 undergone several editions. The main idea is that every Turing machine started with |
|
1385 a standard tape computes a |
|
1386 partial arithmetic function. The inconsitency is when they define |
|
1387 when this function should \emph{not} return a result. They write in Chapter |
|
1388 3 \cite[Page 32]{Boolos87}: |
1383 |
1389 |
1384 \begin{quote}\it |
1390 \begin{quote}\it |
1385 ``If the function that is to be computed assigns no value to the arguments that |
1391 ``If the function that is to be computed assigns no value to the arguments that |
1386 are represented initially on the tape, then the machine either will never halt, |
1392 are represented initially on the tape, then the machine either will never halt, |
1387 or will halt in some nonstandard configuration\ldots'' |
1393 or will halt in some nonstandard configuration\ldots'' |
1388 \end{quote} |
1394 \end{quote} |
1389 |
1395 |
1390 \noindent |
1396 \noindent |
1391 Interestingly, they do not implement this definition when considering |
1397 Interestingly, they do not implement this definition when constructing |
1392 their universal Turing machine. |
1398 their universal Turing machine. On page 93, a recursive function |
1393 |
1399 @{term stdh} is defined as: |
1394 This means that if you encode the plus function but only give one argument, |
1400 |
1395 then the TM will either loop {\bf or} stop with a non-standard tape |
1401 \begin{equation}\label{stdh_def} |
1396 |
1402 @{text "stdh(m, x, t) \<equiv> stat(conf(m, x, t)) + nstd(conf(m, x, t))"} |
1397 But in the definition of the universal function the TMs will never stop |
1403 \end{equation} |
1398 with non-standard tapes. |
|
1399 |
|
1400 SO the following TM calculates something according to def from chap 8, |
|
1401 but not with chap 3. For example: |
|
1402 |
1404 |
|
1405 \noindent |
|
1406 where @{text "stat(conf(m, x, t))"} computes the current state of the |
|
1407 simulated Turing machine, and the @{text "nstd(conf(m, x, t))"} returns @{text 1} |
|
1408 if the tape content is non-standard. If either one evaluates to |
|
1409 nonzero, then @{text "stdh(m, x, t)"} will be nonzero, because of the $+$ |
|
1410 operation. One the same page, a function @{text "halt(m, x)"} is defined |
|
1411 in terms of @{text stdh} for computing the steps the Turing machine needs to |
|
1412 execute before it halts. According to this definition, the simulated |
|
1413 Turing machine will continue to run after entering the @{text 0}-state |
|
1414 with a non-standard tape. The consequence of this inconsistency is |
|
1415 that there exists Turing machines that compute non-values |
|
1416 according to Chapter 3, but returns a proper result according to |
|
1417 the definition in Chapter 8. One such Turing machine is: |
|
1418 |
|
1419 %This means that if you encode the plus function but only give one argument, |
|
1420 %then the TM will either loop {\bf or} stop with a non-standard tape |
|
1421 |
|
1422 %But in the definition of the universal function the TMs will never stop |
|
1423 %with non-standard tapes. |
|
1424 |
|
1425 %SO the following TM calculates something according to def from chap 8, |
|
1426 %but not with chap 3. For example: |
|
1427 |
1403 \begin{center} |
1428 \begin{center} |
1404 @{term "[(L, (0::nat)), (L, 2), (R, 2), (R, 0)]"} |
1429 @{term "[(L, (0::nat)), (L, 2), (R, 2), (R, 0)]"} |
1405 \end{center} |
1430 \end{center} |
1406 |
1431 |
|
1432 \noindent |
1407 If started with @{term "([], [Oc])"} it halts with the |
1433 If started with @{term "([], [Oc])"} it halts with the |
1408 non-standard tape @{term "([Oc], [])"} according to the definition in Chap 3; |
1434 non-standard tape @{term "([Oc], [])"} according to the definition in Chapter 3---so no |
1409 but with @{term "([], [Oc])"} according to def Chap 8 |
1435 result is calculated; but with the standard tape @{term "([], [Oc])"} according to def Chapter 8. |
1410 *} |
1436 *} |
1411 |
1437 |
1412 (* |
1438 (* |
1413 section {* XYZ *} |
1439 section {* XYZ *} |
1414 |
1440 |