One can do a surprising amount of Computer Science in Turtle Art.
This is an example of a universal computer designed by Alan Turing in order to investigate problems in computability. As far as we know (Church-Turing Thesis), any function that can be computed by an effective algorithm can be computed by a Turing Machine. A multitude of other systems has been proposed, and all are equivalent to the Turing Machine and to each other. However, there are questions that we would like to ask that neither a Turing Machine nor any of those other systems can answer.
Before we get to those undecidable questions, however, how is a Turing Machine constructed, and what is our Turing Machine going to do?
This Turing Machine is the simplest kind of adding machine. It starts, as in the first illustration, with two blocks of cells with a separator in between. The number of cells in each block is our input, which the user can change by editing the Setup action. The output will be a single block containing as many cells as the sum of the two input numbers. It will do this by replacing the separator with the color of the number blocks, and erasing one number cell at the end of the second block, giving a configuration as in the second illustration for its result. This model Turing Machine also logs each of its actions in a table, described below.
A Turing Machine is not designed for efficiency, like commercial microprocessors. It is designed to be easy to reason about, and so is about as simple as Turing and a few other mathematicians could make it.
The essential elements of a Turing machine are
The machine can be in any of a finite number of states, represented here by color values. One of the states is interpreted as Halt: the Machine stops executing the program. The rows of the program table correspond to combinations of the current state with the symbol read from the current cell on the tape. For a three-state machine with two symbols, such as our adding machine, the order of the program table is
State | Symbol | Line |
---|---|---|
1 | 1 | 1 |
1 | 2 | 2 |
2 | 1 | 3 |
2 | 2 | 4 |
3 | 1 | 5 |
3 | 2 | 6 |
This table starts counting at 1. In programming it is often more convenient to start counting at 0. You will see examples of this practice if you examine the code for this Turing Machine.
In operation, the starting point is a given tape with a finite sequence of symbols prewritten on it, a given program, and the Turing Machine head over the leftmost symbol on the tape in state 1. At each step, the head reads the symbol in the current cell, then follows the instruction in the row corresponding to that symbol and the current state. There are three parts to the instruction:
The actual program table in numerical symbols is
Write | Move | State | Interpretation |
---|---|---|---|
0 | 1 | 2 | If cell = 0 Write 0. Go right. State 2 End of first number |
1 | 1 | 1 | If cell = 1 Write 1. Go right. State 1. Continue to end of number |
0 | 0 | 3 | If 0 Write 0. Go left. State 3 End of second number |
1 | 1 | 2 | If 1 Write 1. Go right. State 2 |
0 | 1 | 4 | If 0 Write 0. Go right. State 4. Halt |
0 | 1 | 4 | If 1 Write 0. Go right. State 4. Halt |
Where
In addition to the essential workings of the Turing Machine, this program logs each step in the process on the screen, showing the numerical values of the step, symbol, move, state, and cell on each pass. Students are encouraged to run the program in step mode (Turtle or Bug), watching the process unfold.
The process proceeds in stages.
Line 5 is never executed, but has to be there to complete the table.
In summary, move past the first number block, rewrite 0 to 1 (removing the separator), move past the second number block, back up one step and rewrite 1 to 0 to balance the extra 1 written earlier.
For complete details about the workings of this Turing Machine, see Turtle Art Code for Turing Machine and Logo Code for Turtle Art Turing Machine.
Among others things, Turing
2012 is Alan Turing Year - a centenary celebration of his life and work. www.turingcentenary.eu