...

/

Turing Machines as Functions

Turing Machines as Functions

Learn about the various applications of Turing machines.

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.

Press + to interact
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 ...

Access this course and 1400+ top-rated courses and projects.