Title

ECS 120 Theory of Computation
Turing Machines
Julian Panetta
University of California, Davis

Models of Computation

  • Models deciding regular languages:
    What can be done using constant memory and a single step per input symbol?
    • Finite Automata (DFA, NFA)
    • Regular Grammars (RRG, LRG)
    • Regular Expressions
  • Models deciding context-free languages:
    What can be done using a NFA with access to an unbounded stack?
    • Context-Free Grammars (CFG)
    • Pushdown Automata (PDA)
      (Not covered; Section 2.2 of Sipser)

    Is this all we need?

  • Simple non-context-free languages:
    \[ L_1 = \setbuild{0^n 1^n 2^n}{n \in \mathbb{N}} = \{\epsilon, 012, 001122, \ldots\}, \quad \quad \fragment{L_2 = \setbuild{w w}{w \in \binary^*}} \]
    • These can be proved non-CFG-decidable using the pumping lemma for context-free languages
      (Optional Section 7.10 of lecture notes, )

Models of Computation

  • While DFAs and CFGs can solve many useful problems, they are quite limited.

  • Source of these limitations: lacking access to arbitrary amounts of memory.

  • We now take a big leap in computational power and introduce Turing machines (TM).

    • These can do anything that a real computer can!
    • We will prove there are still problems that cannot be solved by TMs!
  • TMs are a generalization of DFAs.

    0 1 1 0 0,1 DFA q3 Control Input Tape Read head q3 b6725438-3a54-4bdc-8097-c64010750f74 q1 b6725438-3a54-4bdc-8097-c64010750f74->q1 q2 Read/write head Unbounded tape!

This is now a Turing machine!

Turing Machine

data/images/tm/dfa_as_tm.svg

Distinctive features of Turing machines:

  1. They can read and write symbols on the tape.
  2. The tape has symbols outside the input alphabet (e.g., the blank symbol “⎵”).
  3. The read/write head can move right, left, or stay in place according to the control logic.
  4. The tape is unbounded to the right and input starts at the leftmost cell.
    • If the head moves to the right of the current rightmost cell, a new “⎵” cell is created.
    • Sipser says “the tape is infinite,” but a more realistic mental model is a growable array
      (e.g., Python list, C++ std::vector, Java java.util.List).
  5. They have exactly one accept state and one reject state
    and halt immediately when either is reached.

Turing Machine

data/images/tm/dfa_as_tm.svg

  • Once we gain intuition for TMs,
    we can describe the machine solving
    a given problem at a high-level while still being precise.
  • Example: design a TM to decide: \[ P = \setbuild{w \in \{0, 1\}^*}{w = \reverse{w}} \]
  • The TM will:
    1. “Zig-zag” back and forth between the left and right ends of the input, checking if the leftmost symbol equals the rightmost symbol. If not, reject immediately.
    2. “Cross off” symbols as they are checked by overwriting them with an \(\string{x}\) symbol.
    3. Continue until the entire input is crossed off, at which point the TM accepts.

Turing Machine Example (demo in simulator)

\[ P = \setbuild{w \in \{0, 1\}^*}{w = \reverse{w}} \]

  1. “Zig-zag” back and forth between the left and right ends of the input, checking if the leftmost symbol equals the rightmost symbol.
    If not, reject immediately.
  2. “Cross off” symbols as they are checked by overwriting them with an \(\string{x}\) symbol.
  3. Continue until the entire input is crossed off, at which point the TM accepts.

Turing Machine Example

\[ P = \setbuild{w \in \{0, 1\}^*}{w = \reverse{w}} \]

  1. “Zig-zag” back and forth between the left and right ends of the input, checking if the leftmost symbol equals the rightmost symbol.
    If not, reject immediately.
  2. “Cross off” symbols as they are checked by overwriting them with an \(\string{x}\) symbol.
  3. Continue until the entire input is crossed off, at which point the TM accepts.
r00 r00 s->r00 0 → x,R r11 r11 s->r11 1 → x,R r01 r01 r00->r01 1 → R r00->r00 0 → R r01->r00 0 → R r01->r01 1 → R r10 r10 r11->r10 0 → R r11->r11 1 → R r10->r11 1 → R r10->r10 0 → R qR qR ⎵, x ⎵, x lx lx r11->lx ⎵, x → L r00->lx ⎵, x → L l l lx->l 0, 1 → x,L l->l 0, 1 → L l->s x → R qA qA lx->qA x   start s->qA ⎵, x → x s s start->s

This is the default TM in the simulator.

Turing Machine Example

\[ P = \setbuild{w \in \{0, 1\}^*}{w = \reverse{w}} \]

  1. “Zig-zag” back and forth between the left and right ends of the input, checking if the leftmost symbol equals the rightmost symbol.
    If not, reject immediately.
  2. “Cross off” symbols as they are checked by overwriting them with an \(\string{x}\) symbol.
  3. Continue until the entire input is crossed off, at which point the TM accepts.
data/images/tm/palindrome_tm/diagram.svg

Example input:

1 01

Current tape:
1
0
1
data/images/tm/palindrome_tm/state_s.svg
Current tape:
1
0
1
data/images/tm/palindrome_tm/state_r11.svg
Current tape:
x
0
1
data/images/tm/palindrome_tm/state_r10.svg
Current tape:
x
0
1
data/images/tm/palindrome_tm/state_r11.svg
Current tape:
x
0
1
data/images/tm/palindrome_tm/state_lx.svg
Current tape:
x
0
1
data/images/tm/palindrome_tm/state_l.svg
Current tape:
x
0
x
data/images/tm/palindrome_tm/state_l.svg
Current tape:
x
0
x
data/images/tm/palindrome_tm/state_s.svg
Current tape:
x
0
x
data/images/tm/palindrome_tm/state_r00.svg
Current tape:
x
x
x
data/images/tm/palindrome_tm/state_lx.svg
Current tape:
x
x
x
data/images/tm/palindrome_tm/state_qA.svg

This is the default TM in Dave’s simulator!

Formal Definition of a Turing Machine

A Turing machine (TM) is a 7-tuple: \(M = (Q, \Sigma, \Gamma, \delta, s, q_a, q_r)\) where:

  1. \(Q\) is a finite set of states.
  2. \(\Sigma\) is a finite set of input symbols (the input alphabet).
  3. \(\Gamma\) is a finite set of tape symbols (the tape alphabet) with:
    \(\Sigma \subsetneq \Gamma\) and blank symbol\(\in \Gamma \setminus \Sigma\).
  4. \(s \in Q\) is the start state.
  5. \(q_a \in Q\) is the accept state.
  6. \(q_r \in Q\) is the reject state, where \(q_r \ne q_a\).
  7. \(\delta: \fragment{(Q \fragment{\setminus \{q_a, q_r\}}) \times \Gamma} \to \fragment{Q \times \fragment{\Gamma \times} \fragment{\{L, R, S\}}}\) is the transition function
    \(L\) = move left, \(R\) = move right, \(S\) = stay in place.

Formal Definition Example

\[ P = \setbuild{w \in \{0, 1\}^*}{w = \reverse{w}} \]

data/images/tm/palindrome_tm/diagram.svg

\(M = (Q, \Sigma, \Gamma, \delta, s, q_a, q_r)\) where:

  • \(Q = \{s, r_{00}, r_{11}, r_{01}, r_{10}, \string{lx}, \string{l}, q_A, q_R\}\)
  • \(\Sigma = \{0, 1\}\)
  • \(\Gamma = \{0, 1, \string{x}, ⎵\}\)
  • \(s\) is the start state, \(q_A\) is the accept state,
    and \(q_R\) is the reject state
  • \(\delta\) is defined by the arrows in the diagram…