Skip to main content

Two-tape TM as binary adder

Short answer

The TM positions both tape heads at the least significant bits, then adds digit by digit with a carry state. It writes the sum bit on tape 1, updates carry, and moves left, halting when both tapes are blank, writing a final carry if 1.

Design a two tape Turing machine that acts as a binary adder.

Setup. Tape 1 holds binary number A and tape 2 holds binary number B (most significant digit on the left, blanks elsewhere), each head starting on the leftmost digit. The sum is written on tape 1 (overwriting A); tape 2 is unchanged. S means the head stays.

Idea. Add from the least significant digit, as in school arithmetic, carrying through the state. A blank counts as 0.

  1. Phase 1 (state q0): move each head to the right end of its own number (a head that already sees a blank stays).
  2. Phase 2 (states c0, c1 = carry 0 or 1): read (x, y), compute s = x + y + carry; write s mod 2 on tape 1; the new carry is s div 2; move both heads left (head 2 stays when on a blank).
  3. When both heads read blank: if the carry is 1, write 1 on tape 1; halt.

M has states {q0, c0, c1, qa} and tape alphabet {0, 1, ⊔}. Rules (digit x on tape 1, y on tape 2):

State(x, y)Write on T1MovesNext state
q0(0/1, 0/1)sameR, Rq0
q0(0/1, ⊔)sameR, Sq0
q0(⊔, 0/1)sameS, Rq0
q0(⊔, ⊔)sameL, Lc0
c0(0,0)0L, Lc0
c0(0,1) or (1,0)1L, Lc0
c0(1,1)0L, Lc1
c1(0,0)1L, Lc0
c1(0,1) or (1,0)0L, Lc1
c1(1,1)1L, Lc1
c0(⊔,⊔)–S, Sqa
c1(⊔,⊔)1S, Sqa

In the c0/c1 digit rows a blank is treated as 0 (for example (⊔,1) behaves as (0,1)), and head 2 stays instead of moving left once it reads a blank.

 ──► (q0) ──(both ⊔) L,L──► (c0) ◄──► (c1)
     ↺ moves heads            │          │
       to the right ends      └─(⊔,⊔)─► ((qa))

Example: 101 + 11 (5 + 3 = 8)

digit  x y  carry  write  new carry
 1     1 1    0      0       1
 2     0 1    1      0       1
 3     1 ⊔    1      0       1
 end   ⊔ ⊔    1      1  (write carry)

Tape 1 becomes 1000 = 8. First q0 runs both heads to the right ends; each row above is then one move of the adder states. The machine runs in about 2·max(|A|, |B|) steps.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Theory of Computation chapter 4 questions →