CS135-lecture-20210423

Introduction to Turing machines #

Note: See text book readings for formal history of the Turing machine.

A Turing machine has a tape that is infinitely long in both directions. The machine has a tape head that can read and write to the tape.

The control unit of the Turing machine is an automata. Each transition has a pair \( x,y \) , follow the arrow if the tape head is over \( x \) , and do operation \( y \) .

image_2021-04-23-14-10-17

\( y \) can be:

  • \( R \) , move right
  • \( L \) , move left
  • \( y \) , write \( y \) , can be a blank (indicated by \( B \) ).

Turing machines are deterministic, and have no \( \lambda \) transitions. The machine halts when no transition matches, so Turing machines don’t require a transition for every alphabet character.

There are two types:

  • Recognizer, which accepts/rejects input.
  • Transducer, which takes input and produces output.

image_2021-04-23-14-16-56

By convention, the tape head always starts at the far left of the input, and ends at the far left of the output.

First example #

With a tape starting with \( n \) 1s, we want the output to be \( n \) 0s.

image_2021-04-23-14-23-23

Some simple pseudo code might be

while head is over 1
    write 0
    move R
move L
while head is over 0
    move L
move R

Make sure to check edge cases, i.e. only a single 1 being on the tape. Also check if the tape is empty initially.

This starts out as a self loop on the initial state that has the pair \( 1,0 \) .

image_2021-04-23-14-30-35

The move R can be added as another pair \( 0,R \) .

image_2021-04-23-14-31-13

Note: This would be a problem if we had any 0s in the input to begin with, we are assuming the input is good. To handle this we could have a state like

image_2021-04-23-14-32-04

Which would halt on a 0 in the initial input.

When this loop finishes, it means we are no longer over a 1. The head should be over a blank. So to transition to the next state we have the pair \( B,L \) .

image_2021-04-23-14-33-20

The next loop can be handled by \( 0,L \) . And when we reach the far right blank we can move right.

image_2021-04-23-14-33-56

The last state has no arrows, so the program will halt.

Second example #

image_2021-04-23-14-36-06 image_2021-04-23-14-38-11 image_2021-04-23-14-38-36 image_2021-04-23-14-39-53 image_2021-04-23-14-43-07 image_2021-04-23-14-44-14 image_2021-04-23-14-44-28 image_2021-04-23-14-44-53 image_2021-04-23-14-45-02 image_2021-04-23-14-45-33 image_2021-04-23-14-45-45 image_2021-04-23-14-45-53 image_2021-04-23-14-46-01 image_2021-04-23-14-46-18 image_2021-04-23-14-46-32

The pair \( B,B \) is kind of like “no operation”.

image_2021-04-23-14-50-09

Testing #

image_2021-04-23-14-51-52 image_2021-04-23-14-52-29 image_2021-04-23-14-52-31 image_2021-04-23-14-52-34 image_2021-04-23-14-52-43 image_2021-04-23-14-52-47