CS 637: Mathematics-II

Lecture 5: What is a Turing Machine?

From Logic to Computation

Recap What We've Learned So Far (Lectures 2-3):
  • Propositional Logic: Formulas, truth tables, CNF/DNF normal forms
  • Inference Rules: Modus Ponens, Modus Tollens, Hypothetical Syllogism
  • The SAT Problem: Given a CNF formula, is there a satisfying assignment?
  • Proof Techniques: Mathematical induction, formal step-by-step proofs

The Natural Next Question

Key QuestionCan We Automate Proofs?
In Lecture 3, we learned to construct formal proofs using inference rules like Modus Ponens:

\( p \to q, \quad p \quad \therefore \quad q \)

Each step is mechanicalβ€”we apply a fixed rule to derive new truths. This raises a profound question:

"Can we build a machine that automatically discovers proofs for any mathematical statement?"
HistoricalHilbert's Entscheidungsproblem (1928)
David Hilbert posed the Decision Problem: Is there an algorithm that, given any logical formula in first-order logic, can determine whether it is valid (true in all interpretations)?

Think of it this way: Given a formula like \( \forall x (P(x) \to Q(x)) \), can a machine tell us if it's always true?

This is exactly what Turing Machines were invented to answer!

From SAT to Computation

ConnectionSAT as a Computational Problem
Recall the SAT problem from Lecture 2: Given a CNF formula like:

\( (p \lor \neg q) \land (\neg p \lor r) \land (q \lor \neg r) \)

Is there an assignment of truth values that makes it true?

Observation: We can verify a solution mechanically (just substitute and evaluate), but finding a solution seems harder. How hard? Turing Machines help us precisely answer this!

πŸ”— The Bridge: Proofs β†’ Algorithms β†’ Computation

Lecture 2-3: We learned that proofs are sequences of logical steps.
Key Insight: Each inference rule (Modus Ponens, etc.) is like an instruction.
Natural Question: What if we had infinitely many instructions? What can be computed?
Lecture 4: Turing Machines give us a precise definition of "algorithm" and "computable."

Why Turing Machines in a Mathematics Course?

MotivationThe Limits of Mathematical Reasoning
  • Decidability: Which mathematical questions can be answered by algorithms?
  • Computability: Which functions can be computed mechanically?
  • Complexity: Even if solvable, how much time/space does a solution require?

Turing's answer to the Entscheidungsproblem was negativeβ€”not all logical truths can be decided algorithmically! This fundamental result shapes modern computer science and mathematics.
Preview What's Coming:

In this lecture, we'll define Turing Machines formally and see how they capture the intuitive notion of "mechanical computation." Later, we'll use TMs to prove that certain problems (like the Halting Problem) are undecidableβ€”no algorithm exists to solve them!

Introduction to Mechanical Computation

ConceptThe Idea of an Algorithm
Before the advent of physical computers, mathematicians sought to formalize the notion of "effective calculability." What does it mean for a problem to be solvable by a step-by-step procedure?

Connection to Proofs: Just as we chain inference rules (Modus Ponens β†’ Simplification β†’ Modus Tollens) to build proofs, an algorithm chains elementary operations to solve problems.

Alan Turing and the 1936 Paper

History "On Computable Numbers, with an Application to the Entscheidungsproblem"

In 1936, Alan Turing introduced the "Automatic Machine" (now called the Turing Machine). His goal was to answer Hilbert's Entscheidungsproblem (the Decision Problem) that we discussed in the previous tab.

  • Physical Intuition: Turing modeled his machine on a human "computer" (a person performing calculations) with a pencil, paper, and a set of instructionsβ€”much like following inference rules!
  • Simplicity: By reducing computation to the simplest possible steps (reading/writing a symbol, moving a head), he provided a rigorous foundation for what "mechanical" means.
ContextWhy Turing's Model?
While other models existed (like Alonzo Church's Lambda Calculus), Turing's model was praised for its intuitive "mechanical" nature. Just as we understand inference rules as concrete steps, each TM transition is a concrete, unambiguous action.
Key ResultTuring's Answer to the Entscheidungsproblem
Turing proved that no algorithm exists that can decide the truth of all logical statements. The Entscheidungsproblem is undecidable.

This negative result is actually liberatingβ€”it tells us exactly where the boundaries of mechanical reasoning lie.

The Universality of Turing Machines

ThesisChurch-Turing Thesis
The informal notion of "algorithm" or "effective procedure" is exactly captured by the formal definition of a Turing Machine.

Note: This is a thesis, not a mathematical theorem, because it connects an informal concept to a formal one. To date, no model of computation has been found that is more powerful than a Turing Machine.
Def 1Universal Turing Machine (UTM)
A single Turing Machine \( U \) that can simulate *any* other Turing Machine \( M \) on an input \( w \), provided it is given a description of \( M \). This is the theoretical blueprint for the general-purpose computer.

πŸš€ Why Universal?

Before UTMs, machines were built for specific tasks. Turing's insight was that data and instructions are the same thing. If you can encode a machine's behavior as symbols on a tape, then another machine can read those symbols and act accordingly.

Formal Definition of a DTM

Def 27-tuple Definition
A Deterministic Turing Machine (DTM) is a 7-tuple \( M = (Q, \Sigma, \Gamma, \delta, q_0, B, F) \):
  • \( Q \): A finite set of states.
  • \( \Sigma \): A finite set of input symbols (subset of \( \Gamma \setminus \{B\} \)).
  • \( \Gamma \): A finite set of tape symbols.
  • \( \delta \): The transition function: \( Q \times \Gamma \to Q \times \Gamma \times \{L, R\} \).
  • \( q_0 \): The initial state (\( q_0 \in Q \)).
  • \( B \): The blank symbol (\( B \in \Gamma \), but \( B \notin \Sigma \)).
  • \( F \): The set of final or accepting states (\( F \subseteq Q \)).

Understanding the Transition Function

Ex$\delta(q, a) = (p, b, D)$
If the machine is in state \( q \) and the head reads symbol \( a \):
  1. Change state to \( p \).
  2. Write symbol \( b \) on the current cell (replacing \( a \)).
  3. Move the head in direction \( D \) (\( L \) for Left, \( R \) for Right).

The Tape and Head Mechanism

πŸ“ The Infinite Tape

The tape is divided into cells, each capable of holding one symbol from \( \Gamma \). It is infinite in both directions (or semi-infinite in some models). Initially, the tape contains the input string followed by infinite "Blank" ($B$) symbols.

Def 3Read/Write Head
The head points to a single cell on the tape. At each step:
  • It **reads** the symbol at the current cell.
  • It **writes** a new symbol (can be the same).
  • It **moves** one cell to the left or right.
0
1
1
0
B
0
1
q1
Mechanism The Deterministic Attribute:

For any given state and symbol, there is at most one transition possible. This means the path of computation is a single line, never branching.

Interactive TM Simulation

FormalTM for $L = \{0^n 1^n \mid n \geq 0\}$
7-Tuple Definition: $M = (Q, \Sigma, \Gamma, \delta, q_0, B, F)$
  • $Q$ = $\{q_0, q_1, q_2, q_3, q_{\text{accept}}, q_{\text{reject}}\}$ β€” Set of states
  • $\Sigma$ = $\{0, 1\}$ β€” Input alphabet
  • $\Gamma$ = $\{0, 1, X, Y, B\}$ β€” Tape alphabet ($X$, $Y$ are markers, $B$ is blank)
  • $\delta$ = Transition function (defined below)
  • $q_0$ = Initial state
  • $B$ = Blank symbol
  • $F$ = $\{q_{\text{accept}}\}$ β€” Accepting states
Algorithm High-Level Strategy:

The TM repeatedly "crosses off" matching pairs of $0$s and $1$s:

  1. Find leftmost unmarked $0$ β†’ Mark it with $X$
  2. Scan right past all $0$s and $Y$s to find the leftmost unmarked $1$
  3. Mark the $1$ with $Y$
  4. Scan left back to the $X$ just placed, then move right to find next unmarked $0$
  5. Repeat until all $0$s are marked as $X$s
  6. Verify that only $Y$s remain (no leftover $1$s) β†’ Accept

State Descriptions

$q_0$ β€” Start/Scan for 0

Look for leftmost unmarked $0$. If found, mark it $X$ and go to $q_1$. If we see $Y$, skip right to check for completion.

$q_1$ β€” Scan Right for 1

Move right, skipping $0$s and $Y$s. When we find a $1$, mark it $Y$ and switch to $q_2$.

$q_2$ β€” Return Left

Move left, skipping $0$s and $Y$s. When we hit $X$, move right and return to $q_0$.

$q_3$ β€” Verify Completion

All $0$s are marked. Scan right to ensure only $Y$s and blanks remain. If so, accept.

Complete Transition Function $\delta$

TableAll Transition Rules

Format: $\delta(\text{state}, \text{read}) = (\text{new state}, \text{write}, \text{move})$

Current State Read Symbol Write Symbol Move Next State Explanation
$q_0$ $0$ $X$ R $q_1$ Mark leftmost 0, start searching for matching 1
$q_0$ $Y$ $Y$ R $q_3$ No more 0s; verify all 1s are marked
$q_0$ $B$ $B$ R $q_{\text{accept}}$ Empty input $\varepsilon$ is valid ($0^0 1^0$)
$q_1$ $0$ $0$ R $q_1$ Skip over remaining 0s
$q_1$ $Y$ $Y$ R $q_1$ Skip over previously marked 1s
$q_1$ $X$ $X$ R $q_1$ Skip over marked 0s
$q_1$ $1$ $Y$ L $q_2$ Found matching 1; mark it Y, go back
$q_1$ $B$ $B$ L $q_{\text{reject}}$ Ran out of 1s before matching all 0s
$q_2$ $0$ $0$ L $q_2$ Move left past 0s
$q_2$ $Y$ $Y$ L $q_2$ Move left past marked 1s
$q_2$ $X$ $X$ R $q_0$ Reached last marked 0; restart from next cell
$q_3$ $Y$ $Y$ R $q_3$ Skip past marked 1s
$q_3$ $B$ $B$ R $q_{\text{accept}}$ All 1s matched; accept!
$q_3$ $0$ $0$ R $q_{\text{reject}}$ Leftover 0s (shouldn't happen in valid path)
$q_3$ $1$ $1$ R $q_{\text{reject}}$ Leftover 1s; more 1s than 0s

Example Computation Trace

TraceInput: "0011"

Configuration format: tape content with underline showing head position, state in parentheses

  1. $(q_0)$ 0011B β†’ Write X, move R β†’ $X$011B
  2. $(q_1)$ X011B β†’ Skip 0, move R β†’ X011B
  3. $(q_1)$ X011B β†’ Write Y, move L β†’ X0Y1B
  4. $(q_2)$ X0Y1B β†’ Skip 0, move L β†’ X0Y1B
  5. $(q_2)$ X0Y1B β†’ Found X, move R β†’ X0Y1B
  6. $(q_0)$ X0Y1B β†’ Write X, move R β†’ XXY1B
  7. $(q_1)$ XXY1B β†’ Skip Y, move R β†’ XXY1B
  8. $(q_1)$ XXY1B β†’ Write Y, move L β†’ XXYYB
  9. $(q_2)$ XXYYB β†’ Skip Y, move L β†’ XXYYB
  10. $(q_2)$ XXYYB β†’ Found X, move R β†’ XXYYB
  11. $(q_0)$ XXYYB β†’ No more 0s, enter $q_3$ β†’ XXYYB
  12. $(q_3)$ XXYYB β†’ Skip Y, move R β†’ XXYYB
  13. $(q_3)$ XXYYB β†’ Blank reached β†’ ACCEPT!

Try It Yourself

🎯 Test the TM

Enter a string of 0s and 1s below. Valid strings in $L$ include: "", "01", "0011", "000111", etc.

Try an invalid string like "0111" or "0010" to see rejection!

HEAD
Ready to start...
πŸ