Turing Machine implementation based The Emperor's New Mind


This implements the Turing machine and three of the example programs from Roger Penrose's, "The Emperor's New Mind".


So we have the Turing 1 computer. Penrose programmed it. I've programmed it. You can be the third person in the world to do so. I just finished the feature to add a program.
This is my first...
0 0 0 0 R
0 1 1 0 R
1 0 0 1 S
1 1 2 0 R
2 0 3 1 R
2 1 1 0 R
3 0 0 1 S
3 1 0 1 S
It takes a single number input and finishes showing 1 if the number is odd or 11 if the number is even.

I call it choban for the Japanese odd-even dice gambling game Zatoichi used to play on early Saturday morning TV. It differs slightly from Penrose's in that it has multiple stop states, three of the eight states are actually stop states. One of those probably shouldn't happen, the 3 1 meaning the tape reads a 1. That 1 shouldn't be there for single number input. But I included it for completeness to have state 3 get two entries for 0 or 1 tape read conditions. It also differs from Penrose in that it doesn't return a computational result but a numeric constant indicating the odd/even number attribute.

The program fields should follow the order indicated in the description for the source listing component below. The only non-numeric is the direction field with R(ight)/L(eft)/S(top). This reasonably true to what Penrose shows for program listings as well.

I had also planned on including a max/min type function example that isn't done yet, unless someone beats me to it? Make your own attempt if you want. Pasting in the source doesn't work for me, which is apparently a somewhat newer Java security feature restricting access to the system clipboard. Drag and drop did work on my Mac to get the source in from a text file.


The three programs that run on the Turing machine are...
UN + 1 will add 1 to a number you enter.
UN X 2 will double a number you enter.
EUC implements Euclid's algorithm and finds the highest common factor of two numbers.


Numbers are represented on the tape as a string of ones. For example...

1 = 010
2 = 0110
3 = 01110
4 = 011110
The tape is only marked with 1's and 0's. A blue bar at the top of a slot indicates the program's current position on the tape


The fields in the scrolling program listing are - going left to right...
1) The machine's/program's current state. There are two entries for each state, red if the input tape reads 0 at the current location and a green entry if the tape is marked with a 1.
2) The number following that is the state to go to next.
3) After that will be a pencil symbol if the state action marks the tape with 1, or it will show an eraser if the current tape slot is zapped with a zero.
4) The final column is direction, a left arrow is shown if the program moves left on the tape, or a right arrow, or a stop sign symbol if the program stops in this state. The program only moves one tape slot at a time. The bounds checking for going off the tape is still not the best, so as I said in the original version of the applet, keep your numbers reasonable. If you don't you'll probably just crash the applet.

The current state is indicated as selected with a light blue background.