Docsity

Turing Machines, Summaries of Theory of Computation

Partial preview of the text

Download Turing Machines and more Summaries Theory of Computation in PDF only on Docsity!

Turing Machines Part Two

Recap from Last Time

Input and Tape Alphabets

● A Turing machine has two alphabets: – An input alphabet Σ. All input strings are written

  • in the input alphabet.A tape alphabet Γ, where Σ ⊆ Γ. The tape alphabet contains all symbols that can be written onto the tape.

● The tape alphabet Γ can contain any number of symbols, but always contains at least one blank

●^ symbol At startup, the Turing machine begins with an, denoted^ ☐. You are guaranteed^ ☐ ∉ Σ.

infnite tape of some location. The tape head is positioned at the start of the input. ☐ symbols with the input written at

A Simple Turing Machine q 0

qacc

qrej

☐ start → ☐, R 1 → 1 → ☐☐, R, R q 1

☐ → ☐, R

qacc

means^ Each “upon^ transition reading^ x^ →^ y^ , D of x ,^ thereplace^ form it with^ qrej

direction^ symbol The symbol^ y^ D and (which ☐move represents is^ theeither^ tape the L^ head or blank R^ in). symbol.

Each transition x → y (^) , D of the form means direction symbol “upon y (^) D and (^) (whichreading move is x theeither, replacetape L (^) head (^) orit R within). The symbol ☐ symbol represents. the blank

This state (^) machinespecial causes accept to the immediately accept.

This state (^) machinespecial causes accept to the immediately accept.

This state (^) machinespecial causes reject to the immediately reject.

This state (^) machinespecial causes reject to the immediately reject.

Check Check m m ≟≟ 00 Cross off 1

To End Cross off 1

Next Next 00 To End home home^ Back^ Back

home home^ Back^ Back

UnmarkUnmark

◻ → ◻, R

start 0 → 0, R 1 → 1, L 0 → 0, L

☐ → ☐, R 0 → ×, R

× → ×, R0 → 0, R1 → 1, R

◻ → ◻, L × → ×, L0 → 0, L1 → 1, L 1 → ☐, L

☐1 → 1, L → ☐, L × → ×, R

☐ → ☐, R × → 0, L

Accept!

◻ → ◻, R

Just how powerful are Turing machines? Main Question for Today:

Composite Numbers ● (^) A natural number the product of two natural numbers n ≥ 2 is composite p (^) andif it is q , ● neither of which isExample:^ n.

  • – (^) 6 = 3 · 2 is composite.42 = 7 · 6 is composite ● (^) Programming problem: write a method that^ –^ 5 is not composite. determines whether a natural number is composite.

bool if isComposite( (n ≤ 1) returnint n) {false; int while (^) ifdivisor = 2; (divisor ≠ n) {(n is a multiple of divisor) { } divisor++;^ return^ true; } return false; }

bool if isComposite( (n ≤ 1) returnint n) {false; int while (^) ifdivisor = 2; (divisor ≠ n) {(n is a multiple of divisor) { } divisor++;^ return^ true; } return false; }

Back to Languages

● Let Σ = { language 1 L } and consider the following over Σ:

● This language is not regular (think about why^ L^ = {^1 n^ |^ n^ is composite }

● this is).It's also not context-free (don't worry if you

don't see why – we didn't discuss this in CS103. ☺)

● Can we build a TM for it?

Check for ε start

1 → 1, R (^) Check for 1 1 → 1, L bool if isComposite( (n ≤ 1) returnint n) {false; int while (^) ifdivisor = 2; (divisor ≠ n) {(n is a multiple of divisor) { } divisor++;^ return^ true; } return false; }

bool if isComposite( (n ≤ 1) returnint n) {false; int while (^) ifdivisor = 2; (divisor ≠ n) {(n is a multiple of divisor) { } divisor++;^ return^ true; } return false; }

Reusing our TMs ● (^) What does our TM need to be able to do? – (^) Check if divisor = n

● (^) What TMs did we build last time?^ –^ Check if^ n^ is a multiple of^ divisor.

  • – (^) One that checks forOne that checks for 00 nm 11 nn , where n is a ● (^) Coincidence? I think not!^ multiple of^ m.

A Sketch of the TM

… bool isComposite(int n) { 0 0 1 1 1 1 1 …

if int (n ≤ 1) divisor = 2; return false; while if (divisor ≠ n) {(n is a multiple of divisor) { return true; }^ }^ divisor++; }^ return^ false;

bool if isComposite( (n ≤ 1) returnint n) {false; int while (^) ifdivisor = 2; (divisor ≠ n) {(n is a multiple of divisor) { } divisor++;^ return^ true; } return false; }

A Sketch of the TM

… bool isComposite(int n) { 0 0 1 1 1 1 1 …

if int (n ≤ 1) divisor = 2; return false; while if (divisor ≠ n) {(n is a multiple of divisor) { return true; }^ }^ divisor++; }^ return^ false;

bool if isComposite( (n ≤ 1) returnint n) {false; int while (^) ifdivisor = 2; (divisor ≠ n) {(n is a multiple of divisor) { } divisor++;^ return^ true; } return false; }

last is^ Somehow, of time the to^ formrun see^ our 0 ifm 1 n,TMthe where^ fromstring n is a multiple of m.

last is^ Somehow, of time the to^ formrun see^ our 0 ifm 1 n,TMthe where^ fromstring n is a multiple of m.

A Sketch of the TM

… bool isComposite(int 0 n) { 0 0 1 1 1 1 1 …

if int (n ≤ 1) divisor = 2; return false; while if (divisor ≠ n) {(n is a multiple of divisor) { return true; }^ }^ divisor++; }^ return^ false;

bool if isComposite( (n ≤ 1) returnint n) {false; int while (^) ifdivisor = 2; (divisor ≠ n) {(n is a multiple of divisor) { } divisor++;^ return^ true; } return false; }