- 2073 Shrawan
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.
- Phase 1 (state q0): move each head to the right end of its own number (a head that already sees a blank stays).
- 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).
- 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 T1 | Moves | Next state |
|---|---|---|---|---|
| q0 | (0/1, 0/1) | same | R, R | q0 |
| q0 | (0/1, ⊔) | same | R, S | q0 |
| q0 | (⊔, 0/1) | same | S, R | q0 |
| q0 | (⊔, ⊔) | same | L, L | c0 |
| c0 | (0,0) | 0 | L, L | c0 |
| c0 | (0,1) or (1,0) | 1 | L, L | c0 |
| c0 | (1,1) | 0 | L, L | c1 |
| c1 | (0,0) | 1 | L, L | c0 |
| c1 | (0,1) or (1,0) | 0 | L, L | c1 |
| c1 | (1,1) | 1 | L, L | c1 |
| c0 | (⊔,⊔) | – | S, S | qa |
| c1 | (⊔,⊔) | 1 | S, S | qa |
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)
Related questions
- TM for aⁿcbⁿ (single tape, deterministic) · Theory of Computation, chapter 4
- TM that doubles a binary number · Theory of Computation, chapter 4
- Multitape TM as copying machine · Theory of Computation, chapter 4
- Define multitape Turing machine · Theory of Computation, chapter 4
- What is a Turing machine; its operation · Theory of Computation, chapter 4
- How a universal Turing machine works · Theory of Computation, chapter 5
- 3-bit multiplier with binary parallel adder · Digital Logic, chapter 5
- Short note: binary parallel adder · Digital Logic, chapter 5
- Two 4-bit parallel adder · Digital Logic, chapter 5
- 4-bit multiplier with parallel adder · Digital Logic, chapter 5