This is a comprehensive manual for the 4th version of my Turing Machine Simulator. This application was created by Justus "slyphix" Henneberg in 2022 for the purpose of assisting in computer science education.
The syntax for programming has changed since the last version, but you can still run programs from previous versions as-is. However, to benefit from the most recent features, you will have to migrate to the new syntax eventually.
The new syntax features meta instructions, which start with an @
symbol and cannot be indented.
Meta instructions can only appear at the beginning of the program.
To opt in to the new syntax, write @ADVANCED
as the first line of your code.
The following meta instructions are available:
@TAPES X
sets the number of tapes to X
.
@BLANK X
defines X
as the blank symbol.
@INIT X
sets the initial state of the machine to X
.
@HALT X
adds X
to the set of halt states.
@ACCEPT X
adds X
to the set of accepting states.
@COMMA X
replaces the ,
separator with X
.
@ARROW X
replaces the ->
separator with X
.
Every program using the new syntax has to define an initial state as well as a blank symbol using the corresponding meta instructions. All other meta instructions are optional.
Accepting states are purely cosmetic: The user interface will show whether the current state is accepting or not. This feature is designed to be used for decision problems.
Comments can be added at any point by using the #
character at the beginning of a line.
The remainder of the program consists of transition rules. The form of a transition rule depends on the number of tapes. Here are two examples of transition rules for a three-tape Turing Machine:
q0, a,b,c -> q1, x,y,z, >,<,_
q0, a,b,c -> q1, x,y,z, >
A transition rule consists of a condition and an action, separated by an arrow symbol.
The condition lists a state name followed by a symbol to match for each tape.
The action consists of a state name to transition into, a symbol to write to each tape, followed by the direction each tape head is supposed to move in.
Directions can be specified as >
/R
(right), <
/L
(left) or _
(no direction).
A shorthand notation can be used if the direction is identical for all tapes.
The first exemplary transition rule matches if the Turing Machine is currently in state q0
and the three tape heads read the symbols a
, b
, and c
, respectively.
In this case, the Turing Machine transitions into state q1
, writes x
, y
, and z
to the three tapes,
then moves the first tape head right and the second head left.
The third head is not moved.
The second example is identical to the first one, but this time, all three tape heads move right.
Two more things are rather noteworthy: Firstly, regular instructions ignore tabs and spaces. Writing a space character to the tape is only possible through the user-defined blank symbol. Secondly, while the Turing Machine theoretically supports more than one character per tape cell, only the first character will be shown in the user interface.
When you are ready to run your program, press the install button in the bottom right corner. The user interface will report if the simulator accepted the program, or if it encountered any errors during installation. After a successful installation, you should see the specified number of tapes appear on the left side.
Before starting the simulation, you can specify the initial contents of each tape in the corresponding text fields. Click one of the init buttons to set up all tapes and to reset the Turing Machine to its initial state.
Click the play/pause button to start the simulation, causing the Turing Machine to perform a transition periodically. Click the play/pause button again to pause the simulation. You can change the speed while the simulation is running by using the buttons at the top. Click the step button or press the space bar to perform a single transition.
Click the skip button to simulate the machine in the background. This results in a faster simulation. To prevent endless loops, skipping will time out after a couple of seconds. You can continue the simulation by pressing skip again. You can abort skipping manually by clicking play/pause.
During simulation, the simulator will show statistics in the user interface.
The simulation will halt automatically once either a halt state has been reached, or if there is no transition rule applicable to the current configuration. Use one of the init buttons to reset the Turing Machine.
The features listed here are not part of the core simulator, but rather extras to enhance the user experience.
Some modern browsers allow websites to be installed like applications, so that they can be used even if there is no internet connection. This is more convenient than downloading the page, especially for mobile users. The simulator can be installed as an application, provided that your browser is compatible with Progressive Web Apps.
Your browser supports Progressive Web Apps! Click this paragraph to install the simulator as a PWA.
Each tape is usually centered around the tape head, since all modifications to the tape will happen there. However, you can instead choose to keep the view focused to a fixed cell to prevent the tape from moving all the time. This can be done by navigating left or right with the buttons on either side of the tape, or by entering a position directly in the corresponding text field. There are also buttons to quickly navigate to the leftmost and rightmost non-blank symbols on the tape. To re-center the tape around the tape head, press the head button.
To export the contents of a tape into a textual format, use the buttons on the bottom right on each tape.
Exporting raw will copy the tape contents as the user sees it, using only the first character of each cell.
You can also export into machine-readable formats: Exporting as CSV will include all empty cells between populated cells, while JSON will only include populated cells.
The exported tape will be added to the program as a comment.
To link directly to a specific program, the web version of the simulator can embed the program into the URL. This URL can then be saved or shared, and the embedded program will appear automatically once the URL is entered into a browser. Click the share button in the bottom right to embed the currently entered program. The program does not have to be syntactically correct in order to be embedded into the URL.
The PWA version does not have a real URL, and therefore, the code is copied to the clipboard instead.
If you manually change code=
to install=
in the URL, the program will install and initialize automatically once the page is loaded.
You can also include suggestions for initial tape contents in your program, which will be copied to the respective input fields during installation.
To do so, add a comment of the form #T1+42!abc
to the program,
which contains the tape to be written to (T1
), the signed offset (+42
),
terminated by a single exclamation mark (!
), and the text itself (abc
).
The simulator includes a list of example programs. To load a program, click the examples button on the bottom right. Each of the features mentioned above is included in at least one example.
If your mobile device does not provision enough screen space to view the simulator, use the buttons in the bottom right corner to scale or hide parts of the user interface.