7.2 The Turing machine 103
Table 7.6 Action table for Turing machine multiplication program. The table contains
38 instructions using 15 states numbered 1, . . . , 15, plus the halt state (H), and
six symbols noted 1, X, Y, Z, W plus the underscore _, which stands for blank. The
instruction nomenclature is “input state, read symbol, output state, write symbol, move
right (>)orleft(<).” The numbers m, n to be multiplied are entered in the input tape
under the string form
M N ,whereM and N are strings of m + 1 and n + 1
successive 1s, respectively. The head is initially located to the leftmost (blank) symbol.
The output tape takes the form
M N P ,whereP is the unary representation of
mn = p (P is a string of p + 1 successive 1s).
1 1, ,1, , > 20 10, , 11, , <
2 1, 1, 2, W, > 21 10, 1, 12, Z, >
3 2, 1, 2, 1, > 22 12, 1, 12, 1, >
4 2,
,3, , > 23 12, , 13, , >
5 3, 1, 4, Y, > 24 13, 1, 13, 1, >
6 4, 1, 4, 1, > 25 13,
, 14, 1, <
7 4,
,5, , > 26 14, 1, 14, 1, <
8 5,
,6,1,< 27 14, , 14, , <
9 6,
,6, , < 28 14, Z, 10, Z, >
10 6, 1, 6, 1, < 29 14, Y, 10, Y, >
11 6, Z, 6, Z, < 30 11, 1, 11, 1, <
12 6, Y, 6, Y, < 31 11,
, 11, , <
13 6, X, 7, X, > 32 11, Z, 11, 1, <
14 6, W, 7, W, > 33 11, Y, 6, Y, <
15 7,
,8, , > 34 8, Y, 8, 1, <
16 7, 1, 9, X, > 35 8,
,8, , <
17 9, 1, 9, 1, > 36 8, X, 8, 1, <
18 9,
,9, , > 37 8, W, 15, 1, <
19 9, Y, 10, Y, > 38 15,
,H, , >
an erase/blank character). The table also shows that 38 different instructions, or TM
transitions, are necessary to complete the multiplication of the two input numbers.
To recall, such an operation can be performed with any numbers of any size, without
limitation in size, since the TM tape is theoretically infinite in length. I will come back
to this point later.
Example 7.5
This concerns the operation of division, which is also relatively simple to implement
with a TM. Given two integers m, n, the task is to find the quotient [m/n] and the
remainder r = m − n[m/n], where the brackets indicate the integer part of the ratio
m/n. A first test consists in verifying that n > 0, i.e., that the field containing n has at
least two 1s (with the convention 1
decimal
≡ 110
unary
). This test can be performed through
the above-described Comp program, which is also derived in an exercise. If n = 0, a
special character meaning “zero divide” must be output to the tape and the TM must
be put into the halt state. A second test consists in checking whether m ≥ n or m < n,
which is again performed by the Comp program. In the second case (m < n), the TM
must output [m/n] = 0 and r = 0, and then halt. In the first case (m ≥ n), the TM must