<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>A Java visual Simulator of Turing Machines?</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Alessandro Burigana</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Francesco De Martino</string-name>
          <email>demartino.francescog@spes.uniud.it</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Agostino Dovier</string-name>
          <email>agostino.dovier@uniud.it</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Dipartimento di Scienze Matematiche, Informatiche e Fisiche Universita di Udine</institution>
          ,
          <addr-line>33100 Udine</addr-line>
          ,
          <country country="IT">Italy</country>
        </aff>
      </contrib-group>
      <abstract>
        <p>We present a graphical simulator of 1-Tape, k-Tapes, deterministic and non deterministic Turing machines. The simulator is written in Java and as such it runs on most platforms. During and after the computation it returns interesting features such as the amount of space visited/used and the number of steps. When simulating non-deterministic Turing machines it allows to browse the \tree" of non deterministic computations. It is developed purely for didactic purposes: it can be used in courses of Foundations of Computer Science, in courses of Computational Complexity, as well as in didactic projects with high schools.</p>
      </abstract>
      <kwd-group>
        <kwd>Turing Machines Teaching Computer Science Computability Complexity</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>Introduction</title>
      <p>When computer science students meet computation models, and in particular
Turing machines, they nd useful (and even funny) testing their rst programs
using a simulator. Although encoding a simulator can be proposed as a useful
exercise using a high level programming language, the availability of a graphical
working simulator is in general very appreciated.</p>
      <p>Several existing simulators are available, some of them running on Android
and iOS. However, the availability of multi-platform simulators is rather limited,
and, as far as the authors know, there is only one simulator for multi tape
deterministic Turing machines, and no simulators at all for non-deterministic Turing
machines. With this communication we would like to present a graphical
simulator of 1-Tape, k-Tapes, deterministic and non deterministic Turing machines
that, being written in Java, runs on most operating systems, and in particular
it is tested on Windows, Linux, and macOS. The simulator (.jar) is available
for free download and use from http://clp.dimi.uniud.it/sw/.</p>
      <p>
        We rely on the syntax based on 5-tuples (q; s; q0; s0; L=R) as originally
presented by Alan Turing in his seminal paper On Computable Numbers, with an
Application to the Entscheidungsproblem [
        <xref ref-type="bibr" rid="ref13">13</xref>
        ]. The syntax is slightly extended
for multi tape Turing machines as suggested in, e.g., [
        <xref ref-type="bibr" rid="ref4 ref8">8, 4</xref>
        ], while [
        <xref ref-type="bibr" rid="ref10">10</xref>
        ] and [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ] used
? Copyright c 2020 for this paper by its authors. Use permitted under Creative
Commons License Attribution 4.0 International (CC BY 4.0).
a simpli ed syntax (in a single step the machine either write a new symbol or
move, but not the two things together).
      </p>
      <p>
        As anticipated above, Turing Machine simulators are available. A complete
analysis is out of the scope of this paper. We just survey some of them focusing
on those based on a 5-tuple syntax. Some of them are obsolete, such as [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ],
running on MS-DOS and based on a character-based interface. Uber Turing
Machine [
        <xref ref-type="bibr" rid="ref12">12</xref>
        ] runs only on Windows systems and it is not free SW. Tursi [
        <xref ref-type="bibr" rid="ref11">11</xref>
        ]
and Alan [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ] are instead multi-platform simulators. A particular remark is due
to Turing Machine Simulator [
        <xref ref-type="bibr" rid="ref14">14</xref>
        ] that, being a free app running on Android
systems, including smartphones, it can be of interest of students. All the listed
proposals simulate single-tape deterministic Turing machines only. There are
then other multi-platform simulators based on other representations such as
Tuatara [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ] that allows also to experiment with formal languages, and JFlap [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ]
that allows to simulate multi-tape Turing machines.
      </p>
      <p>
        The tool we present (split in two components, A-machine and NA-machine,
N standing for Non deterministic) is devised as a support for students of
Computer Science or Mathematics, but it can be used for didactic projects with high
schools (e.g., PLS project). However, the authors hope that it can be of
interest of passionate scienti c readers of introductory books such as The Universal
Computer [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ] or The millennium problems [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ]. NA-machine can, in fact, help the
reader in investigating the fascinating NP world.
2
      </p>
    </sec>
    <sec id="sec-2">
      <title>Turing Machines</title>
      <p>A Turing Machine is a 4-tuple hQ; ; P; q0i where Q is a nite set of (mental)
states, q0 2 Q is the initial state, is the alphabet of the machine, that should
contain at least two symbols: one symbol for the \empty" cell (blank) \ " and
another symbol (tally). P is a set of 5-tuples of the form (q; s; q0; s0; m) where
q; q0 2 Q, s; s0 2 and m 2 fL; Rg where L stands for left and R for right such
that for each pair (q; s) there is at most one tuple beginning with q; s in P to
guarantee determinism.</p>
      <p>An instantaneous description (ID) is a 4-tuple hq; `; s; ri where q is the current
state, `sr denotes the \interesting" portion of the tape: ` the string at the left
of the head, s the symbol currently read, and r the string at the right of the
head. P allows us to determine the deterministic relation successor (`) among
IDs, and hence, the notion of computation. A machine halts if (and only if) the
current ID is hq; `; s; ri and no tuples starting with q; s is in the program P .</p>
      <p>
        Some common variations are allowed in Turing Machines. For instance, the
possibility of staying in the same position (that can be simulated by the
execution of two consecutive instructions L and R) We refer to this feature as
S (for \Stay"). In [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ] P is assumed to de ne a function : Q ! (Q [
fyes; no; haltg) fL; S; Rg. Basically, when the machine halts it reaches a
pseudo-state that acts as nal state. This is of course allowed by the standard
de nition by using three states to be selectively reached at the stop time, and by
adding no 5-tuples in P starting with them. Ending with yes, no, or halt can be
exploited as output signal. Those terminating always with yes and no are used
for decision purposes.
      </p>
      <p>
        It is well-known that a Turing machine with tape limited on one side (e.g.,
on the left) is su cient to prove the equivalence between the set of Turing
computable function and the set of (partial) recursive function (see, e.g., [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ]),
the Theorem that led to the Church-Turing thesis. Sometimes this can be made
explicit by requiring that the tape begins with a symbol B which imposes some
constraints: it cannot be cancelled and the head simply move R (and possibly
change state) when reading it.
      </p>
      <p>
        Following [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ], k-tapes Turing machines are allowed. In this case the use of
B is explicitly required in all tapes. Other restrictions are added. The rst tape
contains the input. Machines terminating with halt compute functions: in this
case the result can be retrieved in the tape k. The program P is therefore
described by a function : Q ( )k ! (Q[fyes; no; haltg) ( fL; S; Rg)k. I/O
k-tapes Turing machines have the same structure; some further requirements are
added on the behaviour relative to tape 1 and k. These machines are used for
studying classes in space and for analyzing the functions used for reductions
between problems.
      </p>
      <p>Last, non determinism must be kept into account (leading to the famous
open problem P vs NP). Non deterministic Turing machines are simply one-tape
machines1 with the unique (but crucial) di erence that P is no longer a function:
more than one tuple starting with a pair q; s are allowed. This leads to a de nition
of ` which is no longer deterministic. Starting from an initial ID0 = hq0; "; B; xi,2
the machine can run a set of non-deterministic computations. This set can be
visualized as paths in a tree rooted by ID0 and we refer to it as the tree of non
deterministic computations (brie y, ND tree).
3</p>
    </sec>
    <sec id="sec-3">
      <title>The deterministic Turing Machine simulator</title>
      <p>
        The rst tool we present in this paper is the A-Machine; its name is inspired
from [
        <xref ref-type="bibr" rid="ref13">13</xref>
        ] where Alan Turing said
      </p>
      <p>If at each stage the motion of a machine [...] is completely determined
by the con guration, we shall call the machine an \automatic machine"
(or a-machine).</p>
      <p>The simulator is written in Java, using the graphical library JavaFX. It is
multiplatform and tested under Linux, Windows, and macOS systems.</p>
      <p>The alphabet contains two symbols by default: # and blank ( ). # is used
as an ASCII version of B (it is not a technical problem, but we experimentally
realized that its absence in the keyboards decreases the usability) and starts
every tape. New symbols can be added by selecting the option in the upper right
square (see Fig. 1). Each state has its unique name and an optional description.
1 Multi tape non-deterministic Turing machines are easy to be de ned.
2 " denotes, as usual, the empty string.
States can be added by selecting the option in the lower right square. A new
machine is endowed with the initial state q0 and the \pseudo" states yes, no, and
halt (see Section 2).</p>
      <p>Program instructions are added by clicking \+" below the left table. There
is a text eld where a description of the instruction can be added. Instructions
can be later easily modi ed or cancelled. Some facilities to sort instructions,
symbols, and states are available. Programs can be saved and retrieved.</p>
      <p>The machine has one tape as default. New tapes can be can be added or
erased. All tapes start with #. The input in the tape can be written/erased by
clicking on the pencil in the right low corner.</p>
      <p>Execution can be launched/interrupted by pressing on the common
animation buttons. In Fig. 2 we report one example of execution. From the menu
Computation (see Fig. 1), the user can select the Computation log and get all
details (step by step) of the computation, the number of computation steps (info
related to the time complexity), and the numbers of total cells and of new cells
used (info related to space complexity).</p>
      <p>The simulator have also other features that can be read in the manual
available at the download site. We just give a quick overview here. I/O Turing
machines can be generated and used by the tool. The programmer can choose if
generate a new \standard" Turing machine or a I/O one. In the latter case the
machine starts with 3 tapes. Veri cation of the constraints of I/O Turing
machines are checked during programming. The interpreter is capable of using other
machines as sub-routines (Turing referred to them as skeleton tables ). They can
be selected by specifying the path of the corresponding le. With this trick it is
possible to de ne (mutually) recursive machines. The interpreter is capable of
de ning and running more machines at the same time.</p>
    </sec>
    <sec id="sec-4">
      <title>The non deterministic Turing Machine simulator</title>
      <p>Although there is no proof of the fact that the main deterministic and non
deterministic time computational classes are di erent (or equal) every computer
scientist has experienced the exponential blow up that emerges in the
simulation of a non deterministic Turing Machine with a deterministic one, when
building and/or visiting the tree of non-deterministic computations. This
intrinsic di culty often leads students to avoiding the activity of programming non
deterministic Turing Machine even for simple examples. The simulator we are
presenting here could represent a support in the early stages of the study of
non deterministic classes by automatically executing the code in a breadth rst
fashion and allowing the user to zoom on the interesting part of the ND tree.
Handling of graphics is in this case demanded to the graphical Java environment
Swing.</p>
      <p>We refer as NA-machine (non deterministic A-machine) to this version of the
simulator. The overall appearance of the program and user interface is the same
as of A-machine for adding symbols, states, instructions. The constraint that for
each pair q; s there is at most one instruction beginning with q; s is of course
relaxed to allow non-determinism.</p>
      <p>Three windows reporting computation data can be analyzed. Statistics keeps
track of some general info on the ND tree and of the number of \yes" node that
has been reached; ND Tree shows the main structure of the ND tree: the picture
of the tree can be enlarged and, clicking on a node, the corresponding ID is
shown; Instantaneous description reports the list of the all IDs associated with
the nodes of the ND tree. See Fig. 3 for an example.
We have presented a Java simulator for one tape, multi tape, deterministic and
non deterministic Turing machines. The language of the interpreter (Italian vs
English) can be selected modifying a settings le. The authors are ready to
modify the simulators and/or add di erent features according to user requests.</p>
      <p>Research partially supported by the University of Udine PRID ENCASE project.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <given-names>N. J.</given-names>
            <surname>Cutland</surname>
          </string-name>
          .
          <article-title>An Introduction to Recursive Function Theory</article-title>
          . CUP,
          <year>1980</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <given-names>M.</given-names>
            <surname>Davis</surname>
          </string-name>
          .
          <article-title>The Universal Computer: The Road from Leibniz to Turing</article-title>
          . CRC,
          <year>2011</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <given-names>Keith</given-names>
            <surname>Devlin</surname>
          </string-name>
          .
          <article-title>The Millennium Problems</article-title>
          . Granta Books,
          <year>2002</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <given-names>A.</given-names>
            <surname>Dovier</surname>
          </string-name>
          and
          <string-name>
            <given-names>R.</given-names>
            <surname>Giacobazzi</surname>
          </string-name>
          .
          <article-title>Fondamenti dell'Informatica: Linguaggi Formali</article-title>
          , Computabilita, Complessita.
          <source>Bollati Boringhieri</source>
          ,
          <year>2020</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <given-names>J.</given-names>
            <surname>Foulds</surname>
          </string-name>
          .
          <source>Tuatara Turing Machine Simulator</source>
          , University of Waikato. https://sourceforge.net/projects/tuataratmsim/
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6.
          <string-name>
            <surname>J. Kennedy.</surname>
          </string-name>
          <article-title>Turing machine simulator</article-title>
          .
          <source>Santa Monica College</source>
          ,
          <year>1996</year>
          . http://archives.math.utk.edu/software/msdos/miscellaneous/jkturing/
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          7.
          <string-name>
            <given-names>D.</given-names>
            <surname>Neuber</surname>
          </string-name>
          ,
          <string-name>
            <given-names>O.</given-names>
            <surname>Pahl</surname>
          </string-name>
          , and
          <string-name>
            <given-names>D.</given-names>
            <surname>Seichter</surname>
          </string-name>
          . Alan. University of Applied Sciences Rosenheim. http://alan.sourceforge.net/
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          8.
          <string-name>
            <given-names>C. H.</given-names>
            <surname>Papadimitriou</surname>
          </string-name>
          . Computational Complexity. Addison-Wesley,
          <year>1994</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          9.
          <string-name>
            <given-names>S. H.</given-names>
            <surname>Rodger</surname>
          </string-name>
          . JFLAP. Duke University. https://www2.cs.duke.edu/csed/j ap/
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          10.
          <string-name>
            <given-names>H. J.</given-names>
            <surname>Rogers</surname>
          </string-name>
          .
          <article-title>Theory of Recursive Functions and E ective Computability</article-title>
          . The MIT Press,
          <year>1988</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          11.
          <string-name>
            <surname>C.</surname>
          </string-name>
          <article-title>Schatzle</article-title>
          . Tursi. Univ of Freiburg. https://schaetzc.github.io/tursi/index.html
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          12. SuperUtils. Uber Turing Machine. https://uber-turing
          <source>-machine.soft32.com/</source>
        </mixed-citation>
      </ref>
      <ref id="ref13">
        <mixed-citation>
          13.
          <string-name>
            <surname>A. M. Turing</surname>
          </string-name>
          .
          <article-title>On computable numbers with an application to the entscheidungsproblem</article-title>
          .
          <source>Proc. of the London Math. Society</source>
          ,
          <volume>42</volume>
          (
          <issue>2</issue>
          ):
          <volume>230</volume>
          {
          <fpage>265</fpage>
          ,
          <year>1936</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref14">
        <mixed-citation>
          14.
          <string-name>
            <surname>I. Yudov.</surname>
          </string-name>
          <article-title>Turing Machine Simulator</article-title>
          . https://play.google.com/store/apps/details?id=ru.ilyayudov.TM.
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>