Turing Machine for Multiplication in Automata Theory



In this chapter, we will explain how to design a Turing machine that can perform multiplication of two numbers. The numbers will be unary numbers as we are using in other examples as well. We start with the basics and then get a detailed example with steps for a better understanding of the concept.

Basics of Turing Machine Multiplication

We know the Turing Machines are used to solve problems that can be solved through polynomial time algorithms. In other words, it can simulate the logic of any computer algorithm. In our case, we will use it to multiply two numbers which is also a straightforward operation.

Representing Numbers

In a Turing machine, we use the unary number system. This means −

  • The number 2 is represented as "11"
  • The number 3 is represented as "111"

Multiplication Logic

The key idea is to use repeated addition. For example −

  • 2 × 3 = 3 + 3
  • We add 3 to itself 2 times

Detailed Example: Multiplying 2 × 3

Let us walk through the process of designing a Turing machine to multiply 2 and 3.

Initial Tape Setup

Our Turing machine tape will look like this at the start −

$$\mathrm{110111}$$

The first "11" represents 2. The "111" after the separator represents 3. Between these two, the "0" is there for a separator. And the remaining tape is blank. We leave blank space for the result.

Step-by-Step Process

The steps are as follows –

  • Cancel the First '1' − We start by canceling the first '1' from the first number (2). This helps us keep track of how many times we need to add.
  • Copy the Second Number − We copy the pattern "111" (representing 3) to the result area. We use a special marker (let's call it 'Y') to remember where we copied from.
  • Repeat and Add − We go back to the first number. If there is still a '1', we repeat the process. This means we will add 3 again to our result.
  • Cleanup − After all, '1's from the first number are used, we clean up. We remove the original numbers and separators. We are left with just the result on the tape.

Detailed Turing Machine States

Here is the detailed State Diagram –

Detailed Turing Machine States

Detailed Turing Machine Transition Table

Here is the detailed Transition Table –

Current State Input Symbol Next State Output Move
q0 1 q1 X Right
q0 X q9 X Right
q0 X q12 X Left
q1 1 q1 1 Right
q1 X q2 X Right
q12 X q12 1 Left
q12 B q11 B Right
q9 1 q9 1 Left
q9 X q0 X Right
q2 1 q4 Y Right
q3 Y q3 1 Left
q8 B q3 B Left
q7 Y q8 Y Right
q4 1 q4 1 Right
q4 B q5 B Right
q5 1 q5 1 Right
q5 B q6 1 Left
q6 1 q6 1 Left
q7 1 q7 1 Left
q6 B q7 B Left
q3 X q9 X Left
q2 B q3 B Left
q8 1 q4 Y Right

Explanations

  • q0 (Start and Main Loop) − Begins by scanning for the first unprocessed symbol in the input. If it encounters a '1', it knows it's in the first factor and transitions to q1. If it encounters an 'X', it moves right (staying in q0) to continue the search. If it encounters a 'B' (blank), it means the first factor is fully processed, and it transitions to q12.
  • q1 (Process '1' in First Factor) − Skips over any '1's in the first factor, moving right until it finds the separating 'X'.
  • q2 (Found Separator) − Marks that the current digit of the first factor is processed. Transitions to q3 without changing the tape.
  • q3 (Reset Second Factor) − Converts any 'Y's (marking processed '1's in the second factor) back to '1's. Prepares for the next iteration by moving left until it encounters an 'X' (marking processed '1's in the first factor).
  • q4 (Process '1' in Second Factor) − Found a '1' in the second factor. Replaces the '1' with a 'Y' to mark it as processed. Moves right to add a '1' to the result at the end of the tape.
  • q5 (Add to Result) − Skips over any existing '1's in the result, moving right. When it encounters a 'B' (blank), it writes a '1' to represent adding one to the product. Then, it transitions to q6 to move back left.
  • q6, q7 (Return to Second Factor) − These states guide the machine leftward, skipping over '1's representing the product and the second factor until reaching the beginning of the second factor again.
  • q8 (Found Processed '1' in Second Factor) − Encounters a 'Y', indicating a '1' in the second factor was used. Transitions to q4 to process this '1' again (for the next digit of the first factor).
  • q9 (Return to Next Digit in First Factor) − Skips over any '1's in the first factor, moving right, to find the next unprocessed '1'. Transitions back to q0 to continue the main loop.
  • q12 (First Factor Consumed) − Converts all the 'X's back to '1's to reset the first factor for potential future multiplications. Transitions to q11, signalling that the multiplication is complete.
  • q11 (Halt) − Represents the halting state. The tape now contains the product of the input numbers.

Conclusion

Multiplication is a complex process with around 12 to 13 different states. In this chapter, we demonstrated step-by-step how you can use a Turing machine to multiple two numbers. We also presented the state diagram and the transition table for an easy understanding.

Advertisements