How to create a turing machine that serves as function calculator for x^y

andandandand picture andandandand · Jun 23, 2009 · Viewed 7.5k times · Source

I'm studying for a test on Turing machines, and I'm stuck with a problem in which I have to create a Turing Machine that serves as a function calculator for:

f(x,y) = x ^ y 

I understand my tape input would come separated like this:

1's of base 0 1's of exponent 

With my tape output being like

1's of base 0 1's of exponent 0 1's of the computed result

How would I go about placing X's and Y's on the tape(s)? (It can be a multi-tape machine) What would the state diagram look like?

Note: I'm using unary with 1 used to represent 0 and 0 used not as value but as a delimiter.

So:

   0 = delimiter
   1 =    0
   11 =   1
   111 =  2
   1111=  3
   11111= 4 
   etc.

Answer

1800 INFORMATION picture 1800 INFORMATION · Jun 23, 2009

I'm guessing a bit here, it's been a little while since I played with Turing machine simulators. First of all, I would want to divide the task up into several conceptual steps:

  1. increment a number on the tape by the value of another number on the tape
  2. multiply a number on the tape by the value of another number on the tape - this can be done by performing step 1 repeatedly
  3. square a number on the tape - x ^ 2 is worked out by putting x on the tape then multiplying it by itself
  4. (the final step) raise a number on the tape to the power of the value of another number on the tape - this can be done by performing step 2 repeatedly

To perform a task repeatedly N times, put N onto the tape, perform the task once, then subtract 1 from the end of the number N. Repeat until the number N is gone from the tape.

Hopefully this is sufficient to get you started anyway. The state machine can be constructed more or less mechanically in this fashion.