Search⌘ K
AI Features

Turing Machines as Functions

Explore how Turing machines compute functions by manipulating unary and binary numbers on the tape. Understand implementations for modulo calculations, addition, rounding, and division by two. This lesson clarifies Turing machine design, state transitions, and function outputs using various examples.

Turing machines can also act as functions by leaving output on the tape. The following TM\text{TM} computes n  mod  2n \;\text{mod}\; 2. We encode numbers in unary notation, so 1=1,2=11,3=1111 = 1, 2 = 11, 3 = 111, etc. The idea is to use two states for evenness vs. oddness and then leave either a 00 or 11 on the tape.

TM that computes n mod 2
TM that computes n mod 2

States q2q_2 and q3q_3 change all 11's to blanks. The q4q_4 state is the halt state. When a number is even, a blank will eventually appear while in state q0q_0, so we erase all the 11’s and leave a 00 on the tape. From q1q_1, we end up leaving a 11. There is no need for an accepting state since the machine produces output.

Adding two numbers

It is easy to add ...