How to use the Turing Machine simulator


Getting Python


If you have already used Python, you may skip this section.

The simulator is written in Python. There is a version of the simulator written for Python 2, one one for Python 3.  You do not need to know any Python to use the simulator, but you do need to have Python installed. If you have a Mac, you probably already have Python.  You should check this by going to the Terminal utility and typing

python

at the prompt.  You should see that the command is recognized, and that you're running version 2.something or version 3.something.  Alternatively, you can install the latest version from python.org, using the link in the next paragraph.

On Windows, go to the website https://www.python.org/downloads/ and download the latest version, which is probably 3.7. You will then need to edit the Environment variable Path to include the directory containing python.exe. (I believe you  can skip this step if you use IDLE--see below.)

Preparing Input for the Simulator


You specify the Turing machine by creating an ordinary text file and giving it the extension .tm.  The best way to see how this works is to compare the specification file reverse.tm with the description of the same TM in the lecture notes.  You should note the following:

Running the Simulator

Using the Command Line

Download tm.py or tmpy2.py , depending on whether you are running Python 3 or Python 2. Also download  the specification reverse.tm.  On a Mac, open the Terminal utility, and navigate to the folder where you have stored these files.  On Windows, open the Command Prompt accessory and navigate to the folder where you have stored these files. Type (Python 3)

python3
import tm

or (Python 2)

python
import tmpy2

Then, if you want to run the specification reverse.tm on the input 1011, type

tm.runtm('reverse','1011')

You can run any specification on any input in exactly the same way.

Using IDLE

Alternatively, you can use Python's built-in interactive development environment IDLE.  You aunch IDLE from the command line in a Mac by typing

idle

In Windows, launch it by selecting it from the Python folder under `All Programs'.  Once in IDLE, you can open tm.py or tmpy2.py directly from the File menu.  Select Run Module from the Run menu and the Python Shell window will appear.  Type

runtm('reverse','1011')

at the prompt. Observe that you don't need to type tm in front of runtm.

Options

The  simulator  allows runtm to be executed with two optional arguments.  If you type

runtm('reverse','1011',verbose=False)

then the simulator will only print the final halted configuration. If you type

runtm('reverse','1011',bidirectional=False)

the specification will be interpreted as for a machine with a one-way infinite tape (see Assignment 2).  The two options can be combined.