Turing Machine for Subtraction in Automata Theory



Read this chapter to learn how a Turing Machine can be used to perform subtraction of two integers. Although Turing Machines for subtraction can be little bit complex, but they can efficiently solve the subtraction.

Here, we will break down the process into easy-to-understand steps and provide examples to illustrate how subtraction is done using a Turing Machine, for a better understanding.

Basic Structure of a Turing Machine for Subtraction

To perform subtraction using a Turing Machine, we represent the numbers on the tape using a series of symbols, typically zeros (0), with a separator between the numbers. For example, if we want to subtract two numbers, x and y, we can represent them on the tape as −

$$\mathrm{0^{x}\: 10^{y}}$$

Here, 0x represents the first number x, 1 is the separator, and 0y represents the second number y.

The subtraction operation, f(x, y) = x - y, will be performed by the Turing Machine in a series of steps, modifying the tape according to the rules defined in the transition function.

Step-by-Step Subtraction Process

The Turing Machine performs subtraction by following these steps −

  • Initial Setup − The machine starts at the leftmost end of the tape and moves right, replacing the first 0 of x with a blank B. This indicates that the first number is being processed.
  • Traverse the First Number − The machine continues to traverse the tape, moving right through the rest of the zeros in the first number until it reaches the separator 1.
  • Processing the Separator − When the machine encounters the 1, it changes state and moves to process the second number y.
  • Subtraction Process − The machine starts subtracting by replacing the leftmost 0 of y with 1. This action represents subtracting one unit from x.
  • Return to the Start − The machine then moves left, back to the beginning of the first number, to repeat the process until either all of y is subtracted from x, or it detects that y is greater than x.
  • Final Steps − If y is subtracted completely and x > y, the remaining zeros represent the result x - y. If y is greater than x, the machine will clear the tape, resulting in 0, indicating that the result is zero.

The transition diagram for this process is shown below −

Step-by-Step Subtraction Process

Example 1: Subtracting Two Numbers

Lets work through an example to subtract 5 3 using the Turing Machine. Here is how we would represent this operation on the tape −

Copy code

000001000

This setup represents the numbers 5 and 3 to be subtracted.

The steps are as follows −

  • Initial State (q0) − The machine starts in state q0, reading the first 0. It changes the first 0 of x to B, indicating that the number is being processed, and moves to the right, transitioning to state q1.
  • Traverse First Number − The machine continues to move right through the remaining zeros of x, staying in state q1 until it encounters 1.
  • Processing Separator (q2) − Upon encountering the separator 1, the machine moves right into state q2 and starts processing the second number y.
  • Subtracting (q3) − The machine replaces the leftmost 0 of y with 1, indicating that one unit has been subtracted from x, and moves left to start the process over.
  • Repeat Process − The machine repeats the process until all 0s in y have been processed, leaving the tape as 00, which represents 2, the result of 5 - 3.
  • Final State − The machine halts in state q6 when the subtraction is complete, and the final tape configuration is 00, representing the result 2.

Example 2

Construct a Turing machine (TM) for subtraction of two unary integers.

Solution

Subtraction of two unary integers

$$\mathrm{3 \:-\: 2 \:=\: 1}$$

In Turing Machine 3 represents: 111 and 2 represents: 11

Let "M" be a symbol used to separate two integers

B 1 1 1 M 1 1 B

Here B = blank

M = Symbol used two separate two integers

Construct Turing machine for subtraction1

Algorithm

Follow the step wise algorithm given below to construct a TM for subtraction −

Step 1 − Let's take two unary integers as an input. We start from the initial state q0.

Step 2 − If we find the 1 in the string then go to the same state without changing the value of 1, and go to the right of the string.

Step 3 − If we find the m symbol then ignore this symbol without changing the symbol and go to the right of the string.

Step 4 − If we find the 1 after the pass the M symbol then change the value of 1 into the X and go to the left of the string.

Step 5 − Then pass the symbol of M and go to the left and if we find the 1 then change the value of 1 to X and go to the right.

Step 6 − So, this type after the symbol(M) we change all values of 1's into X and the same total number of 1's change into the X before the symbol M.

Step 7 − Apply these steps and get the Turing machine subtraction of two unary integers.

While working with subtraction, the Turing machine considers any of the three cases based on input given by the user.

If "a" and "b" are two integers, we have two consider whether −

$$\mathrm{a \: \gt \: b}$$

$$\mathrm{a \: \lt \: b}$$

$$\mathrm{a \: = \: b}$$

By consider all the three conditions, the final Turing machine is as follows −

Construct Turing machine for subtraction2

Explanation of the Diagram

Step 1 − Consider an input string as 110111

i.e. a = 11 and b = 111, according to given input a

Step 2 − Scan string from left to right.

Step 3 − Mark '1' as 'X' and then move to the right.

Step 4 − Reaching to the right of '0' and marking '1' as 'X' and moving left.

Step 5 − Reaching 'X' on left of '0' and moving one step right.

Step 6 − Again mark '1' as 'X' and then move to the right.

Step 7 − Reaching to the right of '0' and passing 'X', mark '1' as 'X' and move left.

Step 8 − Reach 'X' in the left of '0'and move one step right.

Step 9 − If there is a "0" after 'X' that means all '1's are finished before '0'.

Step 10 − Pass '0', 'X' and there is '1' remaining. That is, the second number is greater than the first one.

Step 11 − And then the final state is "a < b"

Turing Machine for the Function f(x) = x - 2

In this section, we will discuss how a Turing Machine can be used to compute the function f(x) = x - 2. This function involves subtracting 2 from a given number x. The process is straightforward but highlights the flexibility of Turing Machines in performing simple arithmetic operations.

Representation of the Input

To represent the integer x on the Turing Machines tape, we use a sequence of zeros (0). The input for the function f(x) = x 2 is written as −

$$\mathrm{0^{x} B}$$

Here, 0x represents the integer xxx, and B is the blank space following the number.

Step-by-Step Process to Compute f(x) = x 2

The Turing Machine computes result using the following these steps −

  • Traverse the Input Number − The machine starts at the leftmost end of the tape and moves right, traversing the sequence of zeros (0x) that represent the number x.
  • Subtract the First Zero − When the machine reaches the end of the sequence of zeros, just before the blank B, it changes the state and replaces the last 0 with B, effectively subtracting one zero from x.
  • Subtract the Second Zero − The machine moves left to find the next 0 and replaces this 0 with another B, thereby subtracting the second zero.
  • Handle Small Values of xxx − If x is less than or equal to 2, the machine will encounter a situation where it cannot subtract two zeros. In such cases, the machine will clear the tape, leaving only a blank to indicate that the result is zero.
  • Halt − The machine halts after subtracting two zeros. The final state of the tape represents x 2.

Shown below is the transition diagram that illustrates these steps −

Step-by-Step Process to Compute

Conclusion

In this chapter, we explained in detail how you can perform the subtraction operation using a Turing Machine. We presented the basic concept along with the state transition diagrams for a better understanding.

Advertisements