249
The Universal Turing Machine

The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

The Universal Turing Machine

Page 2: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Where We Are

● The Church-Turing thesis tells us that all effective models of computation are no more powerful than a Turing machine.

● We have a family of programming languages (WBn) that are equivalent to Turing machines.

● Let's start exploring what we can do with this new model of computation.

Page 3: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Important Ideas for Today

● The material from today will lay the groundwork for the next few weeks.

● Key concepts:● Encodings.● Universal machines.● High-level specifications● Nondeterministic Turing machines.● Decidable and recognizable languages.

Page 4: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Encodings

Page 5: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

An Interesting Observation

● WB programs give us a way to check whether a string is contained within some language.

● WB programs themselves are strings.● This means that we can run WB programs,

taking other WB programs as input!● Major questions:

● Is this specific to WB programs?● What can we do with this knowledge?

Page 6: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

There is a subtle flaw in this reasoning:

“Because WB programs are strings, WB programs can be run on the source code of

other WB programs.”

What is it?

Page 7: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

The Alphabet Problem

● WB programs are described using multiple characters: letters, digits, colons, newlines, etc., plus potentially all tape symbols being used.

● Not all WB programs are written for languages over this alphabet; in fact, most do not.

● We cannot directly write the source of a WB program onto the input tape of another WB program.

● Can we fix this?

Page 8: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

A Better Encoding

● We will restrict ourselves to talking about languages over alphabets containing at least two symbols in them.

● Let's assume, without loss of generality, that we're dealing with the alphabet = { � 0, 1 }.

● It's always possible to encode a string with a large alphabet using a string with just the binary alphabet.● Think about how real computers work.

Page 9: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Encoding WB Programs

● Determine how many different characters are needed to represent the program.● This includes letters for keywords, etc. along with tape

symbols.

● Build a fixed-length binary encoding for each symbol in some canonical order.● Perhaps write out keyword symbols first, then the blank

symbol, then the rest of the input symbols, etc.

● Replace each character in the program with the binary encoding.

Page 10: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Notation for Encodings

● If P is a WB program, we will denote its binary encoding as ⟨P⟩.

● Don't worry too much about the details about how exactly you would compute ⟨P ; the ⟩important part is that there's at least one way to do it.

Page 11: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Encoding Other Automata

● Using similar techniques, we can encode all the other automata we've seen so far as binary strings.

● For example, if M is a Turing machine, ⟨M ⟩refers to a binary encoding of it.

● More generally, if we have any object O we want to encode as a binary string, we can write it out as ⟨O .⟩

Page 12: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Encoding Multiple Objects

● Suppose that we want to provide an encoding of multiple objects.● Several WB programs.● A WB program and a string.● A graph and a path in the graph.● A rock and a hard place.

● There are many ways that we can do this.

Page 13: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

One Encoding Scheme

0 10 01

0 0 1 1 0 00 0 1 1 0

Page 14: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Encoding Multiple Objects

● Given several different objects O1, O

2, …, O

n, we

can represent the encoding of those n objects as O⟨

1, O

2, …, O

n⟩.

● Example:● If P is a WB program and w is a string, then ⟨P, w ⟩

is an encoding of that program and that string.● If G is a context-free grammar and P is a PDA, then ⟨G, P is an encoding of that grammar and that ⟩PDA.

Page 15: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Universal Machines

Page 16: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Universal Machines and Programs

● Theorem: There is a Turing machine UTM called

the universal Turing machine that, when run on ⟨M, w , where ⟩ M is a Turing machine and w is a string, simulates M running on w.

● Theorem: There is a WB program UWB called

the universal WB program that, when run on ⟨P, w , where ⟩ P is a WB program and w is a string, simulates P running on w.

Page 17: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Why This Matters

● As a historically significant achievement.● The universal Turing machine might be the very first “complicated”

algorithm ever designed for a computer.● Motivation for the “stored-program” model of computers.

● As a justification for the Church-Turing thesis.● All sufficiently powerful models of computation can simulate one

another.

● As a stepping stone to building elaborate models of computation.● More on that later today.

● As a stepping stone to finding unsolvable problems.● More on that on Friday.

Page 18: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Sketch of the Universal WB Program

● It is a bit easier to understand the universal WB program than the universal TM.

● We will write the universal WB program in WB6 (finite variables, multiple tracks, multiple tapes, multiple stacks) for simplicity, and can then “compile” it down into normal WB.

Page 19: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Sketch of the Universal WB Program

● To run a WB program, at each point in time we need to track three pieces of information:● The contents of the tape.● The location of the read head.● The index of the current instruction.

● Our program will enter a loop and repeatedly do the following:● Find the next instruction to execute.● Simulate that execution on the simulated tape.

Page 20: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

0 : M o v ...

...

e l e f t . 1 : G

0 1 x 0 0 A 0 <

o>

...

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr

Sketch of the Universal WB Program

>

Letter

Page 21: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

0 : M o v ...

...

e l e f t . 1 : G

0 1 x 0 0 A 0 <

o>

...

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr

Sketch of the Universal WB Program

>

Letter

Page 22: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

0 : M o v ...

...

e l e f t . 1 : G

0 1 x 0 0 A 0 <

o>

...

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr

Sketch of the Universal WB Program

>

Letter

Page 23: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

0 : M o v ...

...

e l e f t . 1 : G

0 1 x 0 0 A 0 <

o>

...

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr

Sketch of the Universal WB Program

>

Letter

Page 24: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

0 : M o v ...

...

e l e f t . 1 : G

0 1 x 0 0 A 0 <

o>

...

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr

Sketch of the Universal WB Program

>

Letter

Page 25: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

0 : M o v ...

...

e l e f t . 1 : G

0 1 x 0 0 A 0 <

o>

...

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr

Sketch of the Universal WB Program

>

Letter

Page 26: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

0 : M o v ...

...

e l e f t . 1 : G

0 1 x 0 0 A 0 <

o>

...

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr

Sketch of the Universal WB Program

>

Letter

Page 27: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

0 : M o v ...

...

e l e f t . 1 : G

0 1 x 0 0 A 0 <

o>

...

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr

Sketch of the Universal WB Program

>

Letter

Page 28: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

0 : M o v ...

...

e l e f t . 1 : G

0 1 x 0 0 A 0 <

o>

...

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr

Sketch of the Universal WB Program

>

Letter

Page 29: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

0 : M o v ...

...

e l e f t . 1 : G

0 1 x 0 0 A 0 <

o>

...

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr

Sketch of the Universal WB Program

>

Letter

Page 30: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

0 : M o v ...

...

e l e f t . 1 : G

0 1 x 0 0 A 0 <

o>

...

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr

Sketch of the Universal WB Program

>

Letter

Page 31: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

0 : M o v ...

...

e l e f t . 1 : G

0 1 x 0 0 A 0 <

o>

...

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr

Sketch of the Universal WB Program

>

Letter

Page 32: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

0 : M o v ...

...

e l e f t . 1 : G

0 1 x 0 0 A 0 <

o>

...

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr

Sketch of the Universal WB Program

>

Letter

Page 33: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

0 : M o v ...

...

e l e f t . 1 : G

0 1 x 0 0 A 0 <

o>

...

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr ML

Sketch of the Universal WB Program

>

Letter

Page 34: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

0 : M o v ...

...

e l e f t . 1 : G

0 1 x 0 0 A 0 <

o>

...

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr ML

Sketch of the Universal WB Program

>

Letter

Page 35: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

0 : M o v ...

...

e l e f t . 1 : G

0 1 x 0 0 A 0 <

o>

...

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr

Sketch of the Universal WB Program

>

Letter

Page 36: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

...

...

1 : G

0 1 x 0 0 A 0 <

o

...

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr

Sketch of the Universal WB Program

>

... t o 1 3 7 . 2 : A c c e

Letter

Page 37: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

...

...

1 : G

0 1 x 0 0 A 0 <

o

...

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr

Sketch of the Universal WB Program

>

... t o 1 3 7 . 2 : A c c e

Letter

Page 38: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

...

...

1 : G

0 1 x 0 0 A 0 <

o

...

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr

Sketch of the Universal WB Program

>

... t o 1 3 7 . 2 : A c c e

Letter

Page 39: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

...

...

1 : G

0 1 x 0 0 A 0 <

o

...

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr

Sketch of the Universal WB Program

>

... t o 1 3 7 . 2 : A c c e

Letter

Page 40: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

...

...

1 : G

0 1 x 0 0 A 0 <

o

...

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr

Sketch of the Universal WB Program

>

... t o 1 3 7 . 2 : A c c e

Letter

Page 41: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

...

...

1 : G

0 1 x 0 0 A 0 <

o

...

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr

Sketch of the Universal WB Program

>

... t o 1 3 7 . 2 : A c c e

Letter

Page 42: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

...

...

1 : G

0 1 x 0 0 A 0 <

o

...

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr

Sketch of the Universal WB Program

>

... t o 1 3 7 . 2 : A c c e

Letter

Page 43: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

...

...

1 : G

0 1 x 0 0 A 0 <

o

...

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr

Sketch of the Universal WB Program

>

... t o 1 3 7 . 2 : A c c e

Letter

Page 44: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

...

...

1 : G

0 1 x 0 0 A 0 <

o

...

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr

Sketch of the Universal WB Program

>

... t o 1 3 7 . 2 : A c c e

Letter

Page 45: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

...

...

1 : G

0 1 x 0 0 A 0 <

o

...

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr GoTo

Sketch of the Universal WB Program

>

... t o 1 3 7 . 2 : A c c e

Letter

Page 46: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

...

...

1 : G

0 1 x 0 0 A 0 <

o

...

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr GoTo

Sketch of the Universal WB Program

>

... t o 1 3 7 . 2 : A c c e

Letter

Page 47: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

...

...

1 : G

0 1 x 0 0 A 0 <

o

...>

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr GoTo

Sketch of the Universal WB Program

>

... t o 1 3 7 . 2 : A c c e

Letter

Page 48: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

...

...

1 : G

0 1 x 0 0 A 0 <

o

...>

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr GoTo

Sketch of the Universal WB Program

>

... t o 1 3 7 . 2 : A c c e

Letter

Page 49: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

...

...

1 : G

0 1 x 0 0 A 0 <

o

...>

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr GoTo

Sketch of the Universal WB Program

>

... t o 1 3 7 . 2 : A c c e

Letter 1

Page 50: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

...

...

1 : G

0 1 x 0 0 A 0 <

o

...> 1

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr GoTo

Sketch of the Universal WB Program

>

... t o 1 3 7 . 2 : A c c e

Letter 1

Page 51: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

...

...

1 : G

0 1 x 0 0 A 0 <

o

...> 1

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr GoTo

Sketch of the Universal WB Program

>

... t o 1 3 7 . 2 : A c c e

Letter 1

Page 52: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

...

...

1 : G

0 1 x 0 0 A 0 <

o

...> 1

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr GoTo

Sketch of the Universal WB Program

>

... t o 1 3 7 . 2 : A c c e

Letter 3

Page 53: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

...

...

1 : G

0 1 x 0 0 A 0 <

o

...> 1

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr GoTo

Sketch of the Universal WB Program

>

... t o 1 3 7 . 2 : A c c e

Letter 3

Page 54: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

...

...

1 : G

0 1 x 0 0 A 0 <

o

...> 1 3

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr GoTo

Sketch of the Universal WB Program

>

... t o 1 3 7 . 2 : A c c e

Letter 3

Page 55: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

...

...

1 : G

0 1 x 0 0 A 0 <

o

...> 1 3

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr GoTo

Sketch of the Universal WB Program

>

... t o 1 3 7 . 2 : A c c e

Letter 3

Page 56: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

...

...

1 : G

0 1 x 0 0 A 0 <

o

...> 1 3

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr GoTo

Sketch of the Universal WB Program

>

... t o 1 3 7 . 2 : A c c e

Letter 7

Page 57: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

...

...

1 : G

0 1 x 0 0 A 0 <

o

...> 1 3

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr GoTo

Sketch of the Universal WB Program

>

... t o 1 3 7 . 2 : A c c e

Letter 7

Page 58: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

...

...

1 : G

0 1 x 0 0 A 0 <

o

...> 1 3 7

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr GoTo

Sketch of the Universal WB Program

>

... t o 1 3 7 . 2 : A c c e

Letter 7

Page 59: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

...

...

1 : G

0 1 x 0 0 A 0 <

o

...> 1 3 7

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr GoTo

Sketch of the Universal WB Program

>

... t o 1 3 7 . 2 : A c c e

Letter 7

Page 60: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

...

...

1 : G

0 1 x 0 0 A 0 <

o

...> 1 3 7

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr GoTo

Sketch of the Universal WB Program

>

... t o 1 3 7 . 2 : A c c e

Letter 7

Page 61: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

...

...0 1 x 0 0 A 0 <

...> 1 3 7

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr GoTo

Sketch of the Universal WB Program

>

Letter 7

0 : M o v e l e f t . 1 : G o>

Page 62: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

...

...0 1 x 0 0 A 0 <

...> 1 3 7

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr GoTo

Sketch of the Universal WB Program

>

Letter 7

0 : M o v e l e f t . 1 : G o>

Page 63: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

...

...0 1 x 0 0 A 0 <

...> 1 3 7

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr GoTo

Sketch of the Universal WB Program

>

Letter 7

0 : M o v e l e f t . 1 : G o>

Page 64: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

...

...0 1 x 0 0 A 0 <

...> 1 3 7

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr GoTo

Sketch of the Universal WB Program

>

Letter 7

0 : M o v e l e f t . 1 : G o>

Page 65: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

...

...0 1 x 0 0 A 0 <

...> 1 3 7

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr GoTo

Sketch of the Universal WB Program

>

Letter 7

0 : M o v e l e f t . 1 : G o>

Page 66: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

...

...0 1 x 0 0 A 0 <

...> 1 3 7

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr GoTo

Sketch of the Universal WB Program

>

Letter 7

0 : M o v e l e f t . 1 : G o>

Page 67: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

...

...0 1 x 0 0 A 0 <

...> 1 3 7

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr GoTo

Sketch of the Universal WB Program

>

Letter 7

0 : M o v e l e f t . 1 : G o>

Page 68: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

...

...0 1 x 0 0 A 0 <

...> 1 3 7

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr GoTo

Sketch of the Universal WB Program

>

Letter 7

0 : M o v e l e f t . 1 : G o>

Page 69: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

...

...0 1 x 0 0 A 0 <

...> 1 3 7

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr GoTo

Sketch of the Universal WB Program

>

Letter 7

0 : M o v e l e f t . 1 : G o>

Page 70: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

...

...0 1 x 0 0 A 0 <

...> 1 3 7

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr GoTo

Sketch of the Universal WB Program

>

Letter 7

0 : M o v e l e f t . 1 : G o>

Page 71: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

The Language of UTM

● From a formal language perspective, what is the language of a universal machine?

● The universal Turing machine accepts all strings of the form ⟨M, w , where ⟩ M is a Turing machine that accepts string w.

● This language is called ATM

:

ATM

= { ⟨M, w | ⟩ M is a TM that accepts w. }

● The universal WB program has language AWB

:

AWB

= { ⟨P, w | ⟩ P is a WB program that accepts w. }

● Both ATM

and AWB

are recursively enumerable.

Page 72: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

The Language of UTM

● From a formal language perspective, what is the language of a universal machine?

● The universal Turing machine accepts all strings of the form ⟨M, w , where ⟩ M is a Turing machine that accepts string w.

● This language is called ATM

:

ATM

= { ⟨M, w | ⟩ M is a TM and w (∈ ℒ M) }

● The universal WB program has language AWB

:

AWB

= { ⟨P, w | ⟩ P is a WB program and w (∈ ℒ P) }

● Both ATM

and AWB

are recursively enumerable.

Page 73: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Instrumenting UTM

● Each universal machine has the following structure:● Find the next instruction to execute.● Determine how to execute that instruction.● Simulate the execution of that instruction.● Repeat.

● In-between each of those steps, we can add extra logic to modify the behavior of the simulated machine.

Page 74: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Tricks with Universal Machines

● Suppose that we have a TM (or WB program) and a string and want to see if that TM accepts the string within n steps.

● Can this be done with a Turing machine or WB program?

● As a language problem:

AFAST

= { ⟨M, w, n⟩

| M is a TM that accepts w in

at most n steps. }

● Is AFAST

recursively enumerable?

Page 75: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Sketch of a Program for AFAST

● We could write a program for AFAST

using the following logic:

● “On input x:● Check that x has the form ⟨M, w, n for a TM ⟩ M, string w,

and natural number n. If not, reject the input string.● Copy n to a separate tape.● Using the universal Turing machine, run M on w. Before

executing any step of M, decrement n.● If n reaches 0, reject.● Otherwise, if M accepts w, accept the input string x.● Otherwise, if M rejects w, reject the input string x.”

Page 76: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Tricks with Universal Machines

● Suppose we have a WB program P and want to see if it accepts string w without ever executing the same instruction twice.

● Can we design a TM or WB program to determine this?● As a language problem:

AONCE

= { ⟨P, w | ⟩ P is a WB program that accepts w without executing the same instruction twice. }

● Is AONCE

recursively enumerable?

Page 77: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Sketch of a Program for AONCE

● We could write a program for AONCE

using the following logic:

● “On input x:● Check that x has the form ⟨P, w for a ⟩ WB program P

and string w. If not, reject the input string.● Use the universal WB program to run P on w.● After executing each instruction, replace that

instruction with Reject.

● If P accepts w, accept the input string x.● If P rejects w, reject the input string x.”

Page 78: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

High-Level Machine Specifications

● The machines we have described in the past few examples all the form● “On input x:

– Description of what to do on x.”

● These descriptions are called high-level descriptions.● Because of the Church-Turing thesis, if we can know

that every step could be done by a computer, then we know a TM/WB program exists for the description.

● Unless explicitly asked to write a WB program or Turing machine, feel free to use high-level descriptions in your proofs.

Page 79: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Sketch of a Program for AFAST

● “On input x:● Check that x has the form ⟨M, w, n for a TM ⟩ M,

string w, and natural number n. If not, reject the input string.

● Copy n to a separate tape.● Using the universal Turing machine, run M on w.

Before executing any step of M, decrement n.● If n reaches 0, reject.● Otherwise, if M accepts w, accept the input string x.● Otherwise, if M rejects w, reject the input string x.”

Page 80: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Sketch of a Program for AFAST

● “On input x:● Check that x has the form ⟨M, w, n for a TM ⟩ M,

string w, and natural number n. If not, reject the input string.

Copy n to a separate tape.

Using the universal Turing machine, run M on w. Before executing any step of M, decrement n.

If n reaches 0, reject.

Otherwise, if M accepts w, accept the input string x.

Otherwise, if M rejects w, reject the input string x.”

Page 81: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Sketch of a Program for AONCE

● “On input x:● Check that x has the form ⟨P, w for a ⟩ WB program P and string w. If not, reject the input string.

● Use the universal WB program to run P on w.● After executing each instruction, replace that

instruction with Reject.

● If P accepts w, accept the input string x.● If P rejects w, reject the input string x.”

Page 82: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Sketch of a Program for AONCE

● “On input x:● Check that x has the form ⟨P, w for a ⟩ WB program P and string w. If not, reject the input string.

Use the universal WB program to run P on w.

After executing each instruction, replace that instruction with Reject.

If P accepts w, accept the input string x.

If P rejects w, reject the input string x.”

Page 83: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

A Nice Shorthand

● Most interesting programs require their input to be structured in some fashion.

● As a new notation, we will allow ourselves to write high-level descriptions like this:

“On input O⟨1, O

2, …, O

n:⟩

Do something with O1, …, O

n.”

to mean

“On input x:

Check that x has the form O⟨1, O

2, …, O

n. If not, reject.⟩

Do something with O1, …, O

n.”

Page 84: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Turing Machines

Page 85: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Turing Machines

● A nondeterministic Turing machine (abbreviated NTM) is a Turing machine in which there may be multiple transitions defined for a particular state/input combination.

● If any possible set of choices causes the machine to accept, it accepts.

● Otherwise, if there is at least one choice that loops forever, the NTM loops forever.

● Otherwise, all choices cause the machine to reject, and the NTM rejects.

Page 86: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

● A natural number greater than 0 is composite if it is not prime.

● Let Σ = { 1 } and consider the language

COMPOSITE = { 1n | n is composite }

● We can build a multitape, nondeterministic TM for COMPOSITE as follows:

● M = “On input 1n:

● Nondeterministically write out q 1s on a second tape (2 ≤ q < n)

● Nondeterministically write out r 1s on a third tape (2 ≤ r < n)

● Deterministically check if qr = n.

● If so, accept.

● Otherwise, reject”

Page 87: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

● A natural number greater than 0 is composite if it is not prime.

● Let Σ = { 1 } and consider the language

COMPOSITE = { 1n | n is composite }

● We can build a multitape, nondeterministic TM for COMPOSITE as follows:

● M = “On input 1n:

● Nondeterministically write out q 1s on a second tape (2 ≤ q < n)

● Nondeterministically write out r 1s on a third tape (2 ≤ r < n)

● Deterministically check if qr = n.

● If so, accept.

● Otherwise, reject”

Page 88: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Guess q and r(Nondeterministic)

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Page 89: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Guess q and r(Nondeterministic)

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1

1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Page 90: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Guess q and r(Nondeterministic)

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Page 91: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)Guess q and r

(Nondeterministic)

Page 92: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)Guess q and r

(Nondeterministic)

Page 93: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)Guess q and r

(Nondeterministic)

Page 94: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)Guess q and r

(Nondeterministic)

Page 95: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)Guess q and r

(Nondeterministic)

Page 96: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)Guess q and r

(Nondeterministic)

Page 97: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)Guess q and r

(Nondeterministic)

Page 98: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)Guess q and r

(Nondeterministic)

Page 99: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Compute qr(Deterministic)

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)

Page 100: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)

Page 101: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)

Compute qr(Deterministic)

Compute qr(Deterministic)

Page 102: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)

Compute qr(Deterministic)

Page 103: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)

Compute qr(Deterministic)

Page 104: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)

Compute qr(Deterministic)

Page 105: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)

Compute qr(Deterministic)

Page 106: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)

Compute qr(Deterministic)

Page 107: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)

Compute qr(Deterministic)

Page 108: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)

Compute qr(Deterministic)

Page 109: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)

Compute qr(Deterministic)

Page 110: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)

Compute qr(Deterministic)

Page 111: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

1 1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)

Compute qr(Deterministic)

Page 112: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

1 1 1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)

Compute qr(Deterministic)

Page 113: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

1 1 1 1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)

Compute qr(Deterministic)

Page 114: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

1 1 1 1 1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)

Compute qr(Deterministic)

Page 115: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

1 1 1 1 1 1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)

Compute qr(Deterministic)

Page 116: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

1 1 1 1 1 1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)

Compute qr(Deterministic)

Page 117: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

1 1 1 1 1 1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)

Compute qr(Deterministic)

Page 118: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

1 1 1 1 1 1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)

Compute qr(Deterministic)

Page 119: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

1 1 1 1 1 1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)

Compute qr(Deterministic)

Page 120: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

1 1 1 1 1 1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)

Compute qr(Deterministic)

Page 121: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

1 1 1 1 1 1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)

Compute qr(Deterministic)

Page 122: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Check if n = qr(Deterministic)

Compute qr(Deterministic)

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

1 1 1 1 1 1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

…Guess q and r

(Nondeterministic)

Page 123: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

1 1 1 1 1 1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)

Check if n = qr(Deterministic)

Page 124: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

1 1 1 1 1 1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)

Check if n = qr(Deterministic)

Page 125: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

1 1 1 1 1 1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)

Check if n = qr(Deterministic)

Page 126: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

1 1 1 1 1 1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)

Check if n = qr(Deterministic)

Page 127: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

1 1 1 1 1 1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)

Check if n = qr(Deterministic)

Page 128: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

1 1 1 1 1 1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)

Check if n = qr(Deterministic)

Page 129: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

1 1 1 1 1 1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)

Check if n = qr(Deterministic)

Page 130: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

1 1 1 1 1 1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)

Check if n = qr(Deterministic)

Page 131: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

1 1 1 1 1 1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)

Check if n = qr(Deterministic)

Page 132: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

1 1 1 1 1 1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)

Check if n = qr(Deterministic)

Page 133: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

1 1 1 1 1 1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)

Check if n = qr(Deterministic)

Page 134: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

1 1 1 1 1 1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)

Check if n = qr(Deterministic)

Page 135: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

1 1 1 1 1 1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)

Check if n = qr(Deterministic)

Page 136: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

1 1 1 1 1 1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)

Check if n = qr(Deterministic)

Page 137: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

1 1 1 1 1 1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)

Check if n = qr(Deterministic)

Page 138: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

1 1 1 1 1 1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)

Check if n = qr(Deterministic)

Page 139: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

1 1 1 1 1 1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)

Check if n = qr(Deterministic)

Page 140: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

1 1 1 1 1 1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)

Check if n = qr(Deterministic)

Page 141: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

1 1 1 1 1 1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)

Check if n = qr(Deterministic)

Page 142: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Compute qr(Deterministic)

Check if n = qr(Deterministic)

Guess q and r(Nondeterministic)

Nondeterministic Algorithms

1 1 1 1 1 1 1 1 1 1

1 1

1 1 1 1 1

1 1 1 1 1 1 1 1 1 1

Compute qr(Deterministic)

Check if n = qr(Deterministic)

…Guess q and r

(Nondeterministic)

Check if n = qr(Deterministic)

Page 143: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

A Nondeterministic Programming Language

● Just as we can have nondeterministic TMs, we can build a nondeterministic variant of WB.

● Define NDWB to be the language WB (the simplest version) with the addition of nondeterministic choice.

● The line of code

N : { line1, line

2, …, line

m }

● Means “nondeterministically choose to execute one of line

1, line

2, …, line

m.”

Page 144: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

A Simple NDWB Program

● Suppose we want to build an NDWB program for the following language over Σ = { 0, 1 }:

{ w | w contains 101 as a substring. }

● This is not particularly hard to do deterministically (it's a regular language), but it's interesting to see how we might do this nondeterministically.

Page 145: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

A Simple NDWB Program

// Start

0: If reading B, go to Rej.

1: If reading 0, go to Next.

2: {

If reading 1, go to Next.

// Next:

// Match

8: Move right.

9: If reading 0, go to 11

10: Reject.

11: Move right.

}

If reading 1, go to Match. 12: If reading 1, go to 14

3: Move right.

4: Go to Start.

13: Go to Rej.

14: Accept.

// Rej:

15: Reject.

Page 146: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

The Power of Nondeterminism

● In the case of finite automata, we saw that the DFA and NFA had equivalent power.

● In the case of pushdown automata, we saw that the DPDA was strictly weaker than the NPDA.

● What is the relative power of TMs and NTMs?

Turing-RecognizableLanguages

Nondeterministic Turing-Recognizable

Languages

Page 147: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

The Power of Nondeterminism

● In the case of finite automata, we saw that the DFA and NFA had equivalent power.

● In the case of pushdown automata, we saw that the DPDA was strictly weaker than the NPDA.

● What is the relative power of TMs and NTMs?

Turing-RecognizableLanguages

Nondeterministic Turing-Recognizable Languages

Page 148: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

A Rather Remarkable Theorem

● Theorem: A language is recursively enumerable iff it is accepted by a nondeterministic Turing machine.

● Theorem: A language is recursively enumerable iff there is an NDWB program for it.

● How is this possible?

Page 149: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

0 : M o v ...

...

e l e f t . 1 : G

0 1 x 0 0 A 0 <

o>

...

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr

Sketch of the Universal WB Program

>

Letter

Page 150: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

0 : M o v ...

...

e l e f t . 1 : G

0 1 x 0 0 A 0 <

o>

...

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr

Sketch of the Universal WB Program

>

Letter

Page 151: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Instantaneous Descriptions

● An instantaneous description (or ID) of the execution of a program (TM, WB program, etc.) is a string encoding of a snapshot of that program at one instant in time.

● For Turing machines, it contains● The contents of the tape,● Where the tape head is, and● What state the machine is in.

● For WB programs, it contains● The contents of the tape,● Where the tape head is, and● What line of code is next to be executed.

Page 152: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

IDs and Universal Machines

● There is a close connection between an ID and universal machines.

● The universal machines UTM and U

WB work by

repeatedly reading the ID of the machine being simulated, then executing one step of that machine.

Page 153: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

An ID for WB Programs

0 : M o v ...

...

e l e f t . 1 : G

0 1 1 0 0 0 0 <

o>

Simulated tape of the program being executed.

Program tape holding the program being executed.

>

0 1 1 0 0 0 0 <> × 1

This means “the tape head is under the next symbol.”

This means “the tape head is under the next symbol.”

We write the line number at the end

of the ID.

We write the line number at the end

of the ID.

Page 154: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Manipulating IDs

● Because IDs are strings (just like machine or program encodings), we can perform all sorts of operations on them:● Copy them to other tapes for later use.● Inspect them to see the state of the machine at any

instant in time.● Transform them to represent making changes to the

program as it is running.

Page 155: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

The Key Idea

● We can store IDs of all of the different branches of the NTM and execute them in a breadth-first search.

● This does a breadth-first walk of the “tree computation” interpretation of nondeterministic computation.

● If there is an accepting computation, eventually we will find it (though it might take an enormously long time to do so!)

Page 156: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Simulating an NTM

● Given an NTM M, we can simulate it with a deterministic TM as follows:

● “On input w:● Put the initial ID of M running on w into a separate tape.● While that tape contains IDs:

– Copy the first ID to a work tape.– If this ID is in an accepting state, accept.– If the ID is not in a rejecting state:

● For all possible next steps, use the universal TM to simulate the NTM making that choice, then append the resulting ID to the other tape.

● Reject.”

Page 157: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

0 : M o v ...

...

e l e f t . 1 : G

0 1 0 0 0 1 0 <

o>

...

Simulated tape of the program being executed.

Program tape holding the program being executed.

Scratch tape for intermediate computation.

Variables for intermediate storage.

Instr

>

Letter

...> 0 1 × < 1 3 # > × 1 1 < 2 4 #Stored IDs

Page 158: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Decidability andRecognizability

Page 159: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Some Important Terminology

● A TM/WB program accepts a string w if it enters an accept state or executes the Accept command.

● A TM/WB program rejects a string w if it enters a reject state or executes the Reject command.

● A TM/WB program loops infinitely on a string w if neither of these happens.

● A TM/WB program does not accept a string w if it either rejects w or loops infinitely on w.

● A TM/WB program does not reject a string w if it either accepts w or loops infinitely on w.

● A TM/WB program halts if it accepts or rejects.

Accept

Loop

Rejectdoes not accept

does not reject

halts

Page 160: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Recall: Language of a TM

● The language of a Turing machine M, denoted (ℒ M), is the set of all strings that M accepts:

ℒ(M) = { w | M accepts w }● For any w (∈ ℒ M), M will accept w.● For any w (∉ ℒ M), M will not accept w.

● It might loop forever, or it might explicitly reject.

● A language is called recognizable or recursively enumerable if it is the language of some TM.

Page 161: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Why “Recognizable?”

● Given TM M with language ℒ(M), running M on a string w will not necessarily tell you whether w  (∈ℒ M).

● If the machine is running, you can't tell whether● It is eventually going to halt, but just needs more time, and● It is never going to halt.

● However, if you know for a fact that w (∈ ℒ M), then the machine can confirm this.

● The machine can't decide whether or not w (∈ℒ M), but it can recognize strings that are in the language.

● We sometimes call a TM for a language L a recognizer for L.

Page 162: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Deciders

● Some Turing machines always halt; they never go into an infinite loop.

● Turing machines of this sort are called deciders.● For deciders, accepting is the same as not

rejecting and rejecting is the same as not accepting.

Accept

Reject halts

does not accept

does not reject

Page 163: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Decidable Languages

● A language L is called decidable iff there is a decider M such that (ℒ M) = L.● These languages are also sometimes called

recursive.

● Given a decider M, you can learn whether or not a string w (∈ ℒ M).● Run M on w.● Although it make take a staggeringly long time, M

will eventually accept or reject w.

Page 164: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Decidability vs. Recognizability

● All deciders are Turing machines, but not all Turing machines are deciders.

● As a result, we know that R ⊆ RE.● R is the set of all recursive (decidable) languages; RE is the set of all recursively enumerable (recognizable) languages.

● Enormously important question: Is R = RE?● This is an enormously important theoretical

question. We'll explore the answer next time...

Page 165: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Properties of R and RE Languages

Page 166: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Closure under Intersection

● The R and RE languages are closed intersection.

● If L1 ∈ R and L

2 ∈ R, then L

1 ∩ L

2 R.∈

● If L1 ∈ RE and L

2 ∈ RE, then L

1 ∩ L

2 ∈ RE.

● How would we prove this?

Page 167: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

R is Closed Under Intersection

Page 168: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

R is Closed Under Intersection

Decider for L

1

w

M1

Page 169: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

R is Closed Under Intersection

Decider for L

1

w

M1

Page 170: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

R is Closed Under Intersection

Decider for L

1

w

Decider for L

2

w

M1

M2

Page 171: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

R is Closed Under Intersection

Decider for L

1

w

Decider for L

2

w

M1

M2

Page 172: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

R is Closed Under Intersection

Decider for L

1

w

Decider for L

2

w

M1

M2

Page 173: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

R is Closed Under Intersection

Decider for L

1

w

Decider for L

2

w

M' = “On input w:Run M

1 on w.

If M1 rejects, reject.

Otherwise, run M2 on w.

If M2 accepts, accept.

Otherwise, reject.”

M1

M2

Page 174: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

R is Closed Under Intersection

Decider for L

1

w

Decider for L

2

w

M' = “On input w:Run M

1 on w.

If M1 rejects, reject.

Otherwise, run M2 on w.

If M2 accepts, accept.

Otherwise, reject.”

M1

M2

Page 175: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

R is Closed Under Intersection

Decider for L

1

w

Decider for L

2

w

M' = “On input w:Run M

1 on w.

If M1 rejects, reject.

Otherwise, run M2 on w.

If M2 accepts, accept.

Otherwise, reject.”

M1

M2

Page 176: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

R is Closed Under Intersection

Decider for L

1

w

Decider for L

2

w

M' = “On input w:Run M

1 on w.

If M1 rejects, reject.

Otherwise, run M2 on w.

If M2 accepts, accept.

Otherwise, reject.”

M1

M2

Page 177: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

R is Closed Under Intersection

Decider for L

1

w

Decider for L

2

w

M' = “On input w:Run M

1 on w.

If M1 rejects, reject.

Otherwise, run M2 on w.

If M2 accepts, accept.

Otherwise, reject.”

M1

M2

Page 178: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

R is Closed Under Intersection

Decider for L

1

w

Decider for L

2

w

M' = “On input w:Run M

1 on w.

If M1 rejects, reject.

Otherwise, run M2 on w.

If M2 accepts, accept.

Otherwise, reject.”

M1

M2

Page 179: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: R is closed under intersection.Proof: Suppose L

1 and L

2 are recursive, and let M

1 and M

2 be deciders for L

1 and

L2, respectively. Then construct the machine M' as follows:

M' = “On input w:Run M

1 on w.

If M1 rejects, reject.

Otherwise, run M2 on w.

If M2 accepts, accept.

Otherwise, reject.”

We show that M' is a decider, then show that L(M') = L1 ∩ L

2. To see that M' is a

decider, note that since M1 is a decider, when M

1 runs on w, M

1 always halts. If

M1 rejects, M' rejects. Otherwise, M' runs M

2, and since M

2 is a decider, it

always halts. Then, if M2 accepts, M' accepts, and if M

2 rejects, M' rejects. In

each case, M' halts on any input w, so M' is a decider.

To see that L(M') = L1 ∩ L

2, note that M' accepts w iff both M

1 accepts w and M

2

accepts w. M1 accepts w iff w L∈

1 and M

2 accepts w iff w L∈

2. Thus M'

accepts w iff w L∈1 and w L∈

2, so M' accepts w iff w L∈

1 ∩ L

2. Thus

L(M') = L1 ∩ L

2. ■

Page 180: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: R is closed under intersection.Proof: Suppose L

1 and L

2 are recursive, and let M

1 and M

2 be deciders for L

1 and

L2, respectively. Then construct the machine M' as follows:

M' = “On input w:Run M

1 on w.

If M1 rejects, reject.

Otherwise, run M2 on w.

If M2 accepts, accept.

Otherwise, reject.”

We show that M' is a decider, then show that L(M') = L1 ∩ L

2. To see that M' is a

decider, note that since M1 is a decider, when M

1 runs on w, M

1 always halts. If

M1 rejects, M' rejects. Otherwise, M' runs M

2, and since M

2 is a decider, it

always halts. Then, if M2 accepts, M' accepts, and if M

2 rejects, M' rejects. In

each case, M' halts on any input w, so M' is a decider.

To see that L(M') = L1 ∩ L

2, note that M' accepts w iff both M

1 accepts w and M

2

accepts w. M1 accepts w iff w L∈

1 and M

2 accepts w iff w L∈

2. Thus M'

accepts w iff w L∈1 and w L∈

2, so M' accepts w iff w L∈

1 ∩ L

2. Thus

L(M') = L1 ∩ L

2. ■

Page 181: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: R is closed under intersection.Proof: Suppose L

1 and L

2 are recursive, and let M

1 and M

2 be deciders for L

1 and

L2, respectively. Then construct the machine M' as follows:

M' = “On input w:Run M

1 on w.

If M1 rejects, reject.

Otherwise, run M2 on w.

If M2 accepts, accept.

Otherwise, reject.”

We show that M' is a decider, then show that L(M') = L1 ∩ L

2. To see that M' is a

decider, note that since M1 is a decider, when M

1 runs on w, M

1 always halts. If

M1 rejects, M' rejects. Otherwise, M' runs M

2, and since M

2 is a decider, it

always halts. Then, if M2 accepts, M' accepts, and if M

2 rejects, M' rejects. In

each case, M' halts on any input w, so M' is a decider.

To see that L(M') = L1 ∩ L

2, note that M' accepts w iff both M

1 accepts w and M

2

accepts w. M1 accepts w iff w L∈

1 and M

2 accepts w iff w L∈

2. Thus M'

accepts w iff w L∈1 and w L∈

2, so M' accepts w iff w L∈

1 ∩ L

2. Thus

L(M') = L1 ∩ L

2. ■

Page 182: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: R is closed under intersection.Proof: Suppose L

1 and L

2 are recursive, and let M

1 and M

2 be deciders for L

1 and

L2, respectively. Then construct the machine M' as follows:

M' = “On input w:Run M

1 on w.

If M1 rejects, reject.

Otherwise, run M2 on w.

If M2 accepts, accept.

Otherwise, reject.”

We show that M' is a decider, then show that L(M') = L1 ∩ L

2. To see that M' is a

decider, note that since M1 is a decider, when M

1 runs on w, M

1 always halts. If

M1 rejects, M' rejects. Otherwise, M' runs M

2, and since M

2 is a decider, it

always halts. Then, if M2 accepts, M' accepts, and if M

2 rejects, M' rejects. In

each case, M' halts on any input w, so M' is a decider.

To see that L(M') = L1 ∩ L

2, note that M' accepts w iff both M

1 accepts w and M

2

accepts w. M1 accepts w iff w L∈

1 and M

2 accepts w iff w L∈

2. Thus M'

accepts w iff w L∈1 and w L∈

2, so M' accepts w iff w L∈

1 ∩ L

2. Thus

L(M') = L1 ∩ L

2. ■

Page 183: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: R is closed under intersection.Proof: Suppose L

1 and L

2 are recursive, and let M

1 and M

2 be deciders for L

1 and

L2, respectively. Then construct the machine M' as follows:

M' = “On input w:Run M

1 on w.

If M1 rejects, reject.

Otherwise, run M2 on w.

If M2 accepts, accept.

Otherwise, reject.”

We show that M' is a decider, then show that (M') = Lℒ1 ∩ L

2. To see that M' is a

decider, note that since M1 is a decider, when M

1 runs on w, M

1 always halts. If

M1 rejects, M' rejects. Otherwise, M' runs M

2, and since M

2 is a decider, it

always halts. Then, if M2 accepts, M' accepts, and if M

2 rejects, M' rejects. In

each case, M' halts on any input w, so M' is a decider.

To see that L(M') = L1 ∩ L

2, note that M' accepts w iff both M

1 accepts w and M

2

accepts w. M1 accepts w iff w L∈

1 and M

2 accepts w iff w L∈

2. Thus M'

accepts w iff w L∈1 and w L∈

2, so M' accepts w iff w L∈

1 ∩ L

2. Thus

L(M') = L1 ∩ L

2. ■

Page 184: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: R is closed under intersection.Proof: Suppose L

1 and L

2 are recursive, and let M

1 and M

2 be deciders for L

1 and

L2, respectively. Then construct the machine M' as follows:

M' = “On input w:Run M

1 on w.

If M1 rejects, reject.

Otherwise, run M2 on w.

If M2 accepts, accept.

Otherwise, reject.”

We show that M' is a decider, then show that (M') = Lℒ1 ∩ L

2. To see that M' is a

decider, note that since M1 is a decider, when M

1 runs on w, M

1 always halts. If

M1 rejects, M' rejects. Otherwise, M' runs M

2, and since M

2 is a decider, it

always halts. Then, if M2 accepts, M' accepts, and if M

2 rejects, M' rejects. In

each case, M' halts on any input w, so M' is a decider.

To see that L(M') = L1 ∩ L

2, note that M' accepts w iff both M

1 accepts w and M

2

accepts w. M1 accepts w iff w L∈

1 and M

2 accepts w iff w L∈

2. Thus M'

accepts w iff w L∈1 and w L∈

2, so M' accepts w iff w L∈

1 ∩ L

2. Thus

L(M') = L1 ∩ L

2. ■

It is critical to prove both of these properties. If we don't show that M' is a decider, then we have proven that L1 L∩ 2 is RE, but not necessarily R!

Page 185: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: R is closed under intersection.Proof: Suppose L

1 and L

2 are recursive, and let M

1 and M

2 be deciders for L

1 and

L2, respectively. Then construct the machine M' as follows:

M' = “On input w:Run M

1 on w.

If M1 rejects, reject.

Otherwise, run M2 on w.

If M2 accepts, accept.

Otherwise, reject.”

We show that M' is a decider, then show that (M') = Lℒ1 ∩ L

2. To see that M' is a

decider, note that since M1 is a decider, when M

1 runs on w, M

1 always halts. If

M1 rejects, M' rejects. Otherwise, M' runs M

2, and since M

2 is a decider, it

always halts. Then, if M2 accepts, M' accepts, and if M

2 rejects, M' rejects. In

each case, M' halts on any input w, so M' is a decider.

To see that L(M') = L1 ∩ L

2, note that M' accepts w iff both M

1 accepts w and M

2

accepts w. M1 accepts w iff w L∈

1 and M

2 accepts w iff w L∈

2. Thus M'

accepts w iff w L∈1 and w L∈

2, so M' accepts w iff w L∈

1 ∩ L

2. Thus

L(M') = L1 ∩ L

2. ■

Page 186: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: R is closed under intersection.Proof: Suppose L

1 and L

2 are recursive, and let M

1 and M

2 be deciders for L

1 and

L2, respectively. Then construct the machine M' as follows:

M' = “On input w:Run M

1 on w.

If M1 rejects, reject.

Otherwise, run M2 on w.

If M2 accepts, accept.

Otherwise, reject.”

We show that M' is a decider, then show that (M') = Lℒ1 ∩ L

2. To see that M' is a

decider, note that since M1 is a decider, when M

1 runs on w, M

1 always halts. If

M1 rejects, M' rejects. Otherwise, M' runs M

2, and since M

2 is a decider, it

always halts. Then, if M2 accepts, M' accepts, and if M

2 rejects, M' rejects. In

each case, M' halts on any input w, so M' is a decider.

To see that L(M') = L1 ∩ L

2, note that M' accepts w iff both M

1 accepts w and M

2

accepts w. M1 accepts w iff w L∈

1 and M

2 accepts w iff w L∈

2. Thus M'

accepts w iff w L∈1 and w L∈

2, so M' accepts w iff w L∈

1 ∩ L

2. Thus

L(M') = L1 ∩ L

2. ■

Page 187: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: R is closed under intersection.Proof: Suppose L

1 and L

2 are recursive, and let M

1 and M

2 be deciders for L

1 and

L2, respectively. Then construct the machine M' as follows:

M' = “On input w:Run M

1 on w.

If M1 rejects, reject.

Otherwise, run M2 on w.

If M2 accepts, accept.

Otherwise, reject.”

We show that M' is a decider, then show that (M') = Lℒ1 ∩ L

2. To see that M' is a

decider, note that since M1 is a decider, when M

1 runs on w, M

1 always halts. If

M1 rejects, M' rejects. Otherwise, M' runs M

2, and since M

2 is a decider, it

always halts. Then, if M2 accepts, M' accepts, and if M

2 rejects, M' rejects. In

each case, M' halts on any input w, so M' is a decider.

To see that L(M') = L1 ∩ L

2, note that M' accepts w iff both M

1 accepts w and M

2

accepts w. M1 accepts w iff w L∈

1 and M

2 accepts w iff w L∈

2. Thus M'

accepts w iff w L∈1 and w L∈

2, so M' accepts w iff w L∈

1 ∩ L

2. Thus

L(M') = L1 ∩ L

2. ■

Page 188: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: R is closed under intersection.Proof: Suppose L

1 and L

2 are recursive, and let M

1 and M

2 be deciders for L

1 and

L2, respectively. Then construct the machine M' as follows:

M' = “On input w:Run M

1 on w.

If M1 rejects, reject.

Otherwise, run M2 on w.

If M2 accepts, accept.

Otherwise, reject.”

We show that M' is a decider, then show that (M') = Lℒ1 ∩ L

2. To see that M' is a

decider, note that since M1 is a decider, when M

1 runs on w, M

1 always halts. If

M1 rejects, M' rejects. Otherwise, M' runs M

2, and since M

2 is a decider, it

always halts. Then, if M2 accepts, M' accepts, and if M

2 rejects, M' rejects. In

each case, M' halts on any input w, so M' is a decider.

To see that L(M') = L1 ∩ L

2, note that M' accepts w iff both M

1 accepts w and M

2

accepts w. M1 accepts w iff w L∈

1 and M

2 accepts w iff w L∈

2. Thus M'

accepts w iff w L∈1 and w L∈

2, so M' accepts w iff w L∈

1 ∩ L

2. Thus

L(M') = L1 ∩ L

2. ■

Page 189: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: R is closed under intersection.Proof: Suppose L

1 and L

2 are recursive, and let M

1 and M

2 be deciders for L

1 and

L2, respectively. Then construct the machine M' as follows:

M' = “On input w:Run M

1 on w.

If M1 rejects, reject.

Otherwise, run M2 on w.

If M2 accepts, accept.

Otherwise, reject.”

We show that M' is a decider, then show that (M') = Lℒ1 ∩ L

2. To see that M' is a

decider, note that since M1 is a decider, when M

1 runs on w, M

1 always halts. If

M1 rejects, M' rejects. Otherwise, M' runs M

2, and since M

2 is a decider, it

always halts. Then, if M2 accepts, M' accepts, and if M

2 rejects, M' rejects. In

each case, M' halts on any input w, so M' is a decider.

To see that L(M') = L1 ∩ L

2, note that M' accepts w iff both M

1 accepts w and M

2

accepts w. M1 accepts w iff w L∈

1 and M

2 accepts w iff w L∈

2. Thus M'

accepts w iff w L∈1 and w L∈

2, so M' accepts w iff w L∈

1 ∩ L

2. Thus

L(M') = L1 ∩ L

2. ■

Page 190: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: R is closed under intersection.Proof: Suppose L

1 and L

2 are recursive, and let M

1 and M

2 be deciders for L

1 and

L2, respectively. Then construct the machine M' as follows:

M' = “On input w:Run M

1 on w.

If M1 rejects, reject.

Otherwise, run M2 on w.

If M2 accepts, accept.

Otherwise, reject.”

We show that M' is a decider, then show that (M') = Lℒ1 ∩ L

2. To see that M' is a

decider, note that since M1 is a decider, when M

1 runs on w, M

1 always halts. If

M1 rejects, M' rejects. Otherwise, M' runs M

2, and since M

2 is a decider, it

always halts. Then, if M2 accepts, M' accepts, and if M

2 rejects, M' rejects. In

each case, M' halts on any input w, so M' is a decider.

To see that (M') = Lℒ1 ∩ L

2, note that M' accepts w iff both M

1 accepts w and M

2

accepts w. M1 accepts w iff w L∈

1 and M

2 accepts w iff w L∈

2. Thus M'

accepts w iff w L∈1 and w L∈

2, so M' accepts w iff w L∈

1 ∩ L

2. Thus

L(M') = L1 ∩ L

2. ■

Page 191: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: R is closed under intersection.Proof: Suppose L

1 and L

2 are recursive, and let M

1 and M

2 be deciders for L

1 and

L2, respectively. Then construct the machine M' as follows:

M' = “On input w:Run M

1 on w.

If M1 rejects, reject.

Otherwise, run M2 on w.

If M2 accepts, accept.

Otherwise, reject.”

We show that M' is a decider, then show that (M') = Lℒ1 ∩ L

2. To see that M' is a

decider, note that since M1 is a decider, when M

1 runs on w, M

1 always halts. If

M1 rejects, M' rejects. Otherwise, M' runs M

2, and since M

2 is a decider, it

always halts. Then, if M2 accepts, M' accepts, and if M

2 rejects, M' rejects. In

each case, M' halts on any input w, so M' is a decider.

To see that (M') = Lℒ1 ∩ L

2, note that M' accepts w iff both M

1 accepts w and M

2

accepts w. M1 accepts w iff w L∈

1 and M

2 accepts w iff w L∈

2. Thus M'

accepts w iff w L∈1 and w L∈

2, so M' accepts w iff w L∈

1 ∩ L

2. Thus

L(M') = L1 ∩ L

2. ■

Remember that the language of a machine is the set of strings it accepts. To reason about the language of a TM, we only need to reason about

what strings it accepts.

Page 192: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: R is closed under intersection.Proof: Suppose L

1 and L

2 are recursive, and let M

1 and M

2 be deciders for L

1 and

L2, respectively. Then construct the machine M' as follows:

M' = “On input w:Run M

1 on w.

If M1 rejects, reject.

Otherwise, run M2 on w.

If M2 accepts, accept.

Otherwise, reject.”

We show that M' is a decider, then show that (M') = Lℒ1 ∩ L

2. To see that M' is a

decider, note that since M1 is a decider, when M

1 runs on w, M

1 always halts. If

M1 rejects, M' rejects. Otherwise, M' runs M

2, and since M

2 is a decider, it

always halts. Then, if M2 accepts, M' accepts, and if M

2 rejects, M' rejects. In

each case, M' halts on any input w, so M' is a decider.

To see that (M') = Lℒ1 ∩ L

2, note that M' accepts w iff both M

1 accepts w and M

2

accepts w. M1 accepts w iff w L∈

1 and M

2 accepts w iff w L∈

2. Thus M'

accepts w iff w L∈1 and w L∈

2, so M' accepts w iff w L∈

1 ∩ L

2. Thus

L(M') = L1 ∩ L

2. ■

Page 193: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: R is closed under intersection.Proof: Suppose L

1 and L

2 are recursive, and let M

1 and M

2 be deciders for L

1 and

L2, respectively. Then construct the machine M' as follows:

M' = “On input w:Run M

1 on w.

If M1 rejects, reject.

Otherwise, run M2 on w.

If M2 accepts, accept.

Otherwise, reject.”

We show that M' is a decider, then show that (M') = Lℒ1 ∩ L

2. To see that M' is a

decider, note that since M1 is a decider, when M

1 runs on w, M

1 always halts. If

M1 rejects, M' rejects. Otherwise, M' runs M

2, and since M

2 is a decider, it

always halts. Then, if M2 accepts, M' accepts, and if M

2 rejects, M' rejects. In

each case, M' halts on any input w, so M' is a decider.

To see that (M') = Lℒ1 ∩ L

2, note that M' accepts w iff both M

1 accepts w and M

2

accepts w. M1 accepts w iff w L∈

1 and M

2 accepts w iff w L∈

2. Thus M'

accepts w iff w L∈1 and w L∈

2, so M' accepts w iff w L∈

1 ∩ L

2. Thus

L(M') = L1 ∩ L

2. ■

Page 194: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: R is closed under intersection.Proof: Suppose L

1 and L

2 are recursive, and let M

1 and M

2 be deciders for L

1 and

L2, respectively. Then construct the machine M' as follows:

M' = “On input w:Run M

1 on w.

If M1 rejects, reject.

Otherwise, run M2 on w.

If M2 accepts, accept.

Otherwise, reject.”

We show that M' is a decider, then show that (M') = Lℒ1 ∩ L

2. To see that M' is a

decider, note that since M1 is a decider, when M

1 runs on w, M

1 always halts. If

M1 rejects, M' rejects. Otherwise, M' runs M

2, and since M

2 is a decider, it

always halts. Then, if M2 accepts, M' accepts, and if M

2 rejects, M' rejects. In

each case, M' halts on any input w, so M' is a decider.

To see that (M') = Lℒ1 ∩ L

2, note that M' accepts w iff both M

1 accepts w and M

2

accepts w. M1 accepts w iff w L∈

1 and M

2 accepts w iff w L∈

2. Thus M'

accepts w iff w L∈1 and w L∈

2, so M' accepts w iff w L∈

1 ∩ L

2. Thus

ℒ(M') = L1 ∩ L

2. ■

Page 195: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: R is closed under intersection.Proof: Suppose L

1 and L

2 are recursive, and let M

1 and M

2 be deciders for L

1 and

L2, respectively. Then construct the machine M' as follows:

M' = “On input w:Run M

1 on w.

If M1 rejects, reject.

Otherwise, run M2 on w.

If M2 accepts, accept.

Otherwise, reject.”

We show that M' is a decider, then show that (M') = Lℒ1 ∩ L

2. To see that M' is a

decider, note that since M1 is a decider, when M

1 runs on w, M

1 always halts. If

M1 rejects, M' rejects. Otherwise, M' runs M

2, and since M

2 is a decider, it

always halts. Then, if M2 accepts, M' accepts, and if M

2 rejects, M' rejects. In

each case, M' halts on any input w, so M' is a decider.

To see that (M') = Lℒ1 ∩ L

2, note that M' accepts w iff both M

1 accepts w and M

2

accepts w. M1 accepts w iff w L∈

1 and M

2 accepts w iff w L∈

2. Thus M'

accepts w iff w L∈1 and w L∈

2, so M' accepts w iff w L∈

1 ∩ L

2. Thus

ℒ(M') = L1 ∩ L

2. ■

Page 196: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

R is Closed Under Intersection

Deciderfor L

1

w

Deciderfor L

2

w

M' = “On input w:Run M

1 on w.

If M1 rejects, reject.

Otherwise, run M2 on w.

If M2 accepts, accept.

Otherwise, reject.”

M1

M2

Page 197: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

RE is Closed Under Intersection

Recognizerfor L

1

w

Recognizerfor L

2

w

M' = “On input w:Run M

1 on w.

If M1 rejects, reject.

Otherwise, run M2 on w.

If M2 accepts, accept.

Otherwise, reject.”

M1

M2

Page 198: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

RE is Closed Under Intersection

Recognizerfor L

1

w

Recognizerfor L

2

w

M' = “On input w:Run M

1 on w.

If M1 rejects, reject.

Otherwise, run M2 on w.

If M2 accepts, accept.

Otherwise, reject.”

M1

M2

Does this construction still

work?

Page 199: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: RE is closed under intersection.Proof: Suppose L

1 and L

2 are RE, and let M

1 and M

2 be recognizers for L

1

and L2, respectively. Then construct the machine M' as follows:

M' = “On input w:Run M

1 on w.

If M1 rejects, reject.

Otherwise, run M2 on w.

If M2 accepts, accept.

Otherwise, reject.”

We show that L(M') = L1 ∩ L

2. To see that L(M') = L

1 ∩ L

2, note that M'

accepts w iff both M1 accepts w and M

2 accepts w. M

1 accepts w iff

w L∈1 and M

2 accepts w iff w L∈

2. Thus M' accepts w iff w L∈

1 and

w L∈2, so M' accepts w iff w L∈

1 ∩ L

2. Thus L(M') = L

1 ∩ L

2. ■

Page 200: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: RE is closed under intersection.Proof: Suppose L

1 and L

2 are RE, and let M

1 and M

2 be recognizers for L

1

and L2, respectively. Then construct the machine M' as follows:

M' = “On input w:Run M

1 on w.

If M1 rejects, reject.

Otherwise, run M2 on w.

If M2 accepts, accept.

Otherwise, reject.”

We show that L(M') = L1 ∩ L

2. To see that L(M') = L

1 ∩ L

2, note that M'

accepts w iff both M1 accepts w and M

2 accepts w. M

1 accepts w iff

w L∈1 and M

2 accepts w iff w L∈

2. Thus M' accepts w iff w L∈

1 and

w L∈2, so M' accepts w iff w L∈

1 ∩ L

2. Thus L(M') = L

1 ∩ L

2. ■

Page 201: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: RE is closed under intersection.Proof: Suppose L

1 and L

2 are RE, and let M

1 and M

2 be recognizers for L

1

and L2, respectively. Then construct the machine M' as follows:

M' = “On input w:Run M

1 on w.

If M1 rejects, reject.

Otherwise, run M2 on w.

If M2 accepts, accept.

Otherwise, reject.”

We show that L(M') = L1 ∩ L

2. To see that L(M') = L

1 ∩ L

2, note that M'

accepts w iff both M1 accepts w and M

2 accepts w. M

1 accepts w iff

w L∈1 and M

2 accepts w iff w L∈

2. Thus M' accepts w iff w L∈

1 and

w L∈2, so M' accepts w iff w L∈

1 ∩ L

2. Thus L(M') = L

1 ∩ L

2. ■

Page 202: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: RE is closed under intersection.Proof: Suppose L

1 and L

2 are RE, and let M

1 and M

2 be recognizers for L

1

and L2, respectively. Then construct the machine M' as follows:

M' = “On input w:Run M

1 on w.

If M1 rejects, reject.

Otherwise, run M2 on w.

If M2 accepts, accept.

Otherwise, reject.”

We show that L(M') = L1 ∩ L

2. To see that L(M') = L

1 ∩ L

2, note that M'

accepts w iff both M1 accepts w and M

2 accepts w. M

1 accepts w iff

w L∈1 and M

2 accepts w iff w L∈

2. Thus M' accepts w iff w L∈

1 and

w L∈2, so M' accepts w iff w L∈

1 ∩ L

2. Thus L(M') = L

1 ∩ L

2. ■

Page 203: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: RE is closed under intersection.Proof: Suppose L

1 and L

2 are RE, and let M

1 and M

2 be recognizers for L

1

and L2, respectively. Then construct the machine M' as follows:

M' = “On input w:Run M

1 on w.

If M1 rejects, reject.

Otherwise, run M2 on w.

If M2 accepts, accept.

Otherwise, reject.”

We show that ℒ(M') = L1 ∩ L

2. To see that L(M') = L

1 ∩ L

2, note that M'

accepts w iff both M1 accepts w and M

2 accepts w. M

1 accepts w iff

w L∈1 and M

2 accepts w iff w L∈

2. Thus M' accepts w iff w L∈

1 and

w L∈2, so M' accepts w iff w L∈

1 ∩ L

2. Thus L(M') = L

1 ∩ L

2. ■

Page 204: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: RE is closed under intersection.Proof: Suppose L

1 and L

2 are RE, and let M

1 and M

2 be recognizers for L

1

and L2, respectively. Then construct the machine M' as follows:

M' = “On input w:Run M

1 on w.

If M1 rejects, reject.

Otherwise, run M2 on w.

If M2 accepts, accept.

Otherwise, reject.”

We show that ℒ(M') = L1 ∩ L

2. To see that L(M') = L

1 ∩ L

2, note that M'

accepts w iff both M1 accepts w and M

2 accepts w. M

1 accepts w iff

w L∈1 and M

2 accepts w iff w L∈

2. Thus M' accepts w iff w L∈

1 and

w L∈2, so M' accepts w iff w L∈

1 ∩ L

2. Thus L(M') = L

1 ∩ L

2. ■

Note that there is no requirement that we prove that M' halts on all

inputs. All we need to do is reason about what inputs it accepts.

Page 205: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: RE is closed under intersection.Proof: Suppose L

1 and L

2 are RE, and let M

1 and M

2 be recognizers for L

1

and L2, respectively. Then construct the machine M' as follows:

M' = “On input w:Run M

1 on w.

If M1 rejects, reject.

Otherwise, run M2 on w.

If M2 accepts, accept.

Otherwise, reject.”

We show that ℒ(M') = L1 ∩ L

2. To see that ℒ(M') = L

1 ∩ L

2, note that M'

accepts w iff both M1 accepts w and M

2 accepts w. M

1 accepts w iff

w L∈1 and M

2 accepts w iff w L∈

2. Thus M' accepts w iff w L∈

1 and

w L∈2, so M' accepts w iff w L∈

1 ∩ L

2. Thus L(M') = L

1 ∩ L

2. ■

Page 206: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: RE is closed under intersection.Proof: Suppose L

1 and L

2 are RE, and let M

1 and M

2 be recognizers for L

1

and L2, respectively. Then construct the machine M' as follows:

M' = “On input w:Run M

1 on w.

If M1 rejects, reject.

Otherwise, run M2 on w.

If M2 accepts, accept.

Otherwise, reject.”

We show that ℒ(M') = L1 ∩ L

2. To see that ℒ(M') = L

1 ∩ L

2, note that M'

accepts w iff both M1 accepts w and M

2 accepts w. M

1 accepts w iff

w L∈1 and M

2 accepts w iff w L∈

2. Thus M' accepts w iff w L∈

1 and

w L∈2, so M' accepts w iff w L∈

1 ∩ L

2. Thus L(M') = L

1 ∩ L

2. ■We only care about what strings M'

accepts, and can ignore the strings it rejects or loops infinitely on.

Page 207: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: RE is closed under intersection.Proof: Suppose L

1 and L

2 are RE, and let M

1 and M

2 be recognizers for L

1

and L2, respectively. Then construct the machine M' as follows:

M' = “On input w:Run M

1 on w.

If M1 rejects, reject.

Otherwise, run M2 on w.

If M2 accepts, accept.

Otherwise, reject.”

We show that ℒ(M') = L1 ∩ L

2. To see that ℒ(M') = L

1 ∩ L

2, note that M'

accepts w iff both M1 accepts w and M

2 accepts w. M

1 accepts w iff

w L∈1 and M

2 accepts w iff w L∈

2. Thus M' accepts w iff w L∈

1 and

w L∈2, so M' accepts w iff w L∈

1 ∩ L

2. Thus L(M') = L

1 ∩ L

2. ■

Page 208: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: RE is closed under intersection.Proof: Suppose L

1 and L

2 are RE, and let M

1 and M

2 be recognizers for L

1

and L2, respectively. Then construct the machine M' as follows:

M' = “On input w:Run M

1 on w.

If M1 rejects, reject.

Otherwise, run M2 on w.

If M2 accepts, accept.

Otherwise, reject.”

We show that ℒ(M') = L1 ∩ L

2. To see that ℒ(M') = L

1 ∩ L

2, note that M'

accepts w iff both M1 accepts w and M

2 accepts w. M

1 accepts w iff

w L∈1 and M

2 accepts w iff w L∈

2. Thus M' accepts w iff w L∈

1 and

w L∈2, so M' accepts w iff w L∈

1 ∩ L

2. Thus L(M') = L

1 ∩ L

2. ■

Page 209: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: RE is closed under intersection.Proof: Suppose L

1 and L

2 are RE, and let M

1 and M

2 be recognizers for L

1

and L2, respectively. Then construct the machine M' as follows:

M' = “On input w:Run M

1 on w.

If M1 rejects, reject.

Otherwise, run M2 on w.

If M2 accepts, accept.

Otherwise, reject.”

We show that ℒ(M') = L1 ∩ L

2. To see that ℒ(M') = L

1 ∩ L

2, note that M'

accepts w iff both M1 accepts w and M

2 accepts w. M

1 accepts w iff

w L∈1 and M

2 accepts w iff w L∈

2. Thus M' accepts w iff w L∈

1 and

w L∈2, so M' accepts w iff w L∈

1 ∩ L

2. Thus ℒ(M') = L

1 ∩ L

2. ■

Page 210: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: RE is closed under intersection.Proof: Suppose L

1 and L

2 are RE, and let M

1 and M

2 be recognizers for L

1

and L2, respectively. Then construct the machine M' as follows:

M' = “On input w:Run M

1 on w.

If M1 rejects, reject.

Otherwise, run M2 on w.

If M2 accepts, accept.

Otherwise, reject.”

We show that ℒ(M') = L1 ∩ L

2. To see that ℒ(M') = L

1 ∩ L

2, note that M'

accepts w iff both M1 accepts w and M

2 accepts w. M

1 accepts w iff

w L∈1 and M

2 accepts w iff w L∈

2. Thus M' accepts w iff w L∈

1 and

w L∈2, so M' accepts w iff w L∈

1 ∩ L

2. Thus ℒ(M') = L

1 ∩ L

2. ■

Page 211: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Proving Closure Properties of R

● To show that R is closed under some operation:● Obtain deciders M

1, M

2, …, M

n for all of the

original languages.

● Construct a new TM M' based on M1, M

2, …, M

n.

● Prove that ℒ(M') is the correct language.● Prove that M' is a decider (that it halts on all inputs)

Page 212: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Proving Closure Properties of RE

● To show that RE is closed under some operation:● Obtain recognizers M

1, M

2, …, M

n for all of the

original languages.

● Construct a new TM M' based on M1, M

2, …, M

n.

● Prove that (M') is the correct language.ℒ

Page 213: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

An Important Result

● Suppose that L and L are RE languages.● Let M and M be recognizers for L and L,

respectively.

Page 214: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

A

An Important Result

● Suppose that L and L are RE languages.● Let M and M be recognizers for L and L,

respectively.

0 1 2 x B x 1

Page 215: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

A

An Important Result

● Suppose that L and L are RE languages.● Let M and M be recognizers for L and L,

respectively.

0

Simulate M Simulate M

1 2 x B x 1

Page 216: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

A

An Important Result

● Suppose that L and L are RE languages.● Let M and M be recognizers for L and L,

respectively.

0

Simulate M Simulate M

1 2 x B x 1

M' = “On input w,Run M and M on w in parallel.If M accepts, accept.If M accepts, reject.”

Page 217: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

A

An Important Result

● Suppose that L and L are RE languages.● Let M and M be recognizers for L and L,

respectively.

0

Simulate M Simulate M

1 2 x B x 1

M' = “On input w,Run M and M on w in parallel.If M accepts, accept.If M accepts, reject.”

What happens if w L?∈

Page 218: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

A

An Important Result

● Suppose that L and L are RE languages.● Let M and M be recognizers for L and L,

respectively.

0

Simulate M Simulate M

1 2 x B x 1

M' = “On input w,Run M and M on w in parallel.If M accepts, accept.If M accepts, reject.”

What happens if w L?∈

Page 219: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

A

An Important Result

● Suppose that L and L are RE languages.● Let M and M be recognizers for L and L,

respectively.

0

Simulate M Simulate M

1 2 x B x 1

M' = “On input w,Run M and M on w in parallel.If M accepts, accept.If M accepts, reject.”

What happens if w L?∈

Page 220: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

A

An Important Result

● Suppose that L and L are RE languages.● Let M and M be recognizers for L and L,

respectively.

0

Simulate M Simulate M

1 2 x B x 1

M' = “On input w,Run M and M on w in parallel.If M accepts, accept.If M accepts, reject.”

What happens if w L?∉

Page 221: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

A

An Important Result

● Suppose that L and L are RE languages.● Let M and M be recognizers for L and L,

respectively.

0

Simulate M Simulate M

1 2 x B x 1

M' = “On input w,Run M and M on w in parallel.If M accepts, accept.If M accepts, reject.”

What happens if w ∈ L?

Page 222: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

A

An Important Result

● Suppose that L and L are RE languages.● Let M and M be recognizers for L and L,

respectively.

0

Simulate M Simulate M

1 2 x B x 1

M' = “On input w,Run M and M on w in parallel.If M accepts, accept.If M accepts, reject.”

What happens if w ∈ L?

Page 223: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

A

An Important Result

● Suppose that L and L are RE languages.● Let M and M be recognizers for L and L,

respectively.

0

Simulate M Simulate M

1 2 x B x 1

M' = “On input w,Run M and M on w in parallel.If M accepts, accept.If M accepts, reject.”

What happens if w ∈ L?

Page 224: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

A

An Important Result

● Suppose that L and L are RE languages.● Let M and M be recognizers for L and L,

respectively.

0

Simulate M Simulate M

1 2 x B x 1

M' = “On input w,Run M and M on w in parallel.If M accepts, accept.If M accepts, reject.”

M' is a decider!

Page 225: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: If L and L are RE, then L is recursive.Proof: Let M be a recognizer for L and M be a recognizer for L. Consider the TM M' defined as follows:

M' = “On input w:Run M and M on w in parallel.If M accepts w, accept.If M accepts w, reject.”

We prove that L(M') = L and that M' is a decider. To see that M' is a decider, consider any string w. Either w L or w L, but not ∈ ∉both. If w L, then w ∉ ∈ L. Thus either w L or w ∈ ∈ L, but not both. If w L, then M will eventually accept w and M' halts. If ∈w ∈ L, them M will eventually accept w and M' halts. Thus M' halts on all inputs.

To see that L(M') = L, note that M' accepts w iff M accepts w and M does not accept w. As proven above, these two cases are mutually exclusive. Thus M' accepts w iff M accepts w iff w L. Thus∈L(M') = L. ■

Page 226: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: If L and L are RE, then L is recursive.Proof: Let M be a recognizer for L and M be a recognizer for L. Consider the TM M' defined as follows:

M' = “On input w:Run M and M on w in parallel.If M accepts w, accept.If M accepts w, reject.”

We prove that L(M') = L and that M' is a decider. To see that M' is a decider, consider any string w. Either w L or w L, but not ∈ ∉both. If w L, then w ∉ ∈ L. Thus either w L or w ∈ ∈ L, but not both. If w L, then M will eventually accept w and M' halts. If ∈w ∈ L, them M will eventually accept w and M' halts. Thus M' halts on all inputs.

To see that L(M') = L, note that M' accepts w iff M accepts w and M does not accept w. As proven above, these two cases are mutually exclusive. Thus M' accepts w iff M accepts w iff w L. Thus∈L(M') = L. ■

Page 227: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: If L and L are RE, then L is recursive.Proof: Let M be a recognizer for L and M be a recognizer for L. Consider the TM M' defined as follows:

M' = “On input w:Run M and M on w in parallel.If M accepts w, accept.If M accepts w, reject.”

We prove that L(M') = L and that M' is a decider. To see that M' is a decider, consider any string w. Either w L or w L, but not ∈ ∉both. If w L, then w ∉ ∈ L. Thus either w L or w ∈ ∈ L, but not both. If w L, then M will eventually accept w and M' halts. If ∈w ∈ L, them M will eventually accept w and M' halts. Thus M' halts on all inputs.

To see that L(M') = L, note that M' accepts w iff M accepts w and M does not accept w. As proven above, these two cases are mutually exclusive. Thus M' accepts w iff M accepts w iff w L. Thus∈L(M') = L. ■

Page 228: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: If L and L are RE, then L is recursive.Proof: Let M be a recognizer for L and M be a recognizer for L. Consider the TM M' defined as follows:

M' = “On input w:Run M and M on w in parallel.If M accepts w, accept.If M accepts w, reject.”

We prove that L(M') = L and that M' is a decider. To see that M' is a decider, consider any string w. Either w L or w L, but not ∈ ∉both. If w L, then w ∉ ∈ L. Thus either w L or w ∈ ∈ L, but not both. If w L, then M will eventually accept w and M' halts. If ∈w ∈ L, them M will eventually accept w and M' halts. Thus M' halts on all inputs.

To see that L(M') = L, note that M' accepts w iff M accepts w and M does not accept w. As proven above, these two cases are mutually exclusive. Thus M' accepts w iff M accepts w iff w L. Thus∈L(M') = L. ■

Page 229: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: If L and L are RE, then L is recursive.Proof: Let M be a recognizer for L and M be a recognizer for L. Consider the TM M' defined as follows:

M' = “On input w:Run M and M on w in parallel.If M accepts w, accept.If M accepts w, reject.”

We prove that (M') = L and that M' is a decider. ℒ To see that M' is a decider, consider any string w. Either w L or w L, but not ∈ ∉both. If w L, then w ∉ ∈ L. Thus either w L or w ∈ ∈ L, but not both. If w L, then M will eventually accept w and M' halts. If ∈w ∈ L, them M will eventually accept w and M' halts. Thus M' halts on all inputs.

To see that L(M') = L, note that M' accepts w iff M accepts w and M does not accept w. As proven above, these two cases are mutually exclusive. Thus M' accepts w iff M accepts w iff w L. Thus∈L(M') = L. ■

Page 230: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: If L and L are RE, then L is recursive.Proof: Let M be a recognizer for L and M be a recognizer for L. Consider the TM M' defined as follows:

M' = “On input w:Run M and M on w in parallel.If M accepts w, accept.If M accepts w, reject.”

We prove that (M') = L and that M' is a decider. To see that M' is ℒa decider, consider any string w. Either w L or w L, but not ∈ ∉both. If w L, then w ∉ ∈ L. Thus either w L or w ∈ ∈ L, but not both. If w L, then M will eventually accept w and M' halts. If ∈w ∈ L, them M will eventually accept w and M' halts. Thus M' halts on all inputs.

To see that L(M') = L, note that M' accepts w iff M accepts w and M does not accept w. As proven above, these two cases are mutually exclusive. Thus M' accepts w iff M accepts w iff w L. Thus∈L(M') = L. ■

Page 231: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: If L and L are RE, then L is recursive.Proof: Let M be a recognizer for L and M be a recognizer for L. Consider the TM M' defined as follows:

M' = “On input w:Run M and M on w in parallel.If M accepts w, accept.If M accepts w, reject.”

We prove that (M') = L and that M' is a decider. To see that M' is ℒa decider, consider any string w. Either w L or w L, but not ∈ ∉both. If w L, then w ∉ ∈ L. Thus either w L or w ∈ ∈ L, but not both. If w L, then M will eventually accept w and M' halts. If ∈w ∈ L, them M will eventually accept w and M' halts. Thus M' halts on all inputs.

To see that L(M') = L, note that M' accepts w iff M accepts w and M does not accept w. As proven above, these two cases are mutually exclusive. Thus M' accepts w iff M accepts w iff w L. Thus∈L(M') = L. ■

Page 232: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: If L and L are RE, then L is recursive.Proof: Let M be a recognizer for L and M be a recognizer for L. Consider the TM M' defined as follows:

M' = “On input w:Run M and M on w in parallel.If M accepts w, accept.If M accepts w, reject.”

We prove that (M') = L and that M' is a decider. To see that M' is ℒa decider, consider any string w. Either w L or w L, but not ∈ ∉both. If w L, then w ∉ ∈ L. Thus either w L or w ∈ ∈ L, but not both. If w L, then M will eventually accept w and M' halts. If ∈w ∈ L, them M will eventually accept w and M' halts. Thus M' halts on all inputs.

To see that L(M') = L, note that M' accepts w iff M accepts w and M does not accept w. As proven above, these two cases are mutually exclusive. Thus M' accepts w iff M accepts w iff w L. Thus∈L(M') = L. ■

Page 233: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: If L and L are RE, then L is recursive.Proof: Let M be a recognizer for L and M be a recognizer for L. Consider the TM M' defined as follows:

M' = “On input w:Run M and M on w in parallel.If M accepts w, accept.If M accepts w, reject.”

We prove that (M') = L and that M' is a decider. To see that M' is ℒa decider, consider any string w. Either w L or w L, but not ∈ ∉both. If w L, then w ∉ ∈ L. Thus either w L or w ∈ ∈ L, but not both. If w L, then M will eventually accept w and M' halts. If ∈w ∈ L, them M will eventually accept w and M' halts. Thus M' halts on all inputs.

To see that L(M') = L, note that M' accepts w iff M accepts w and M does not accept w. As proven above, these two cases are mutually exclusive. Thus M' accepts w iff M accepts w iff w L. Thus∈L(M') = L. ■

Page 234: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: If L and L are RE, then L is recursive.Proof: Let M be a recognizer for L and M be a recognizer for L. Consider the TM M' defined as follows:

M' = “On input w:Run M and M on w in parallel.If M accepts w, accept.If M accepts w, reject.”

We prove that (M') = L and that M' is a decider. To see that M' is ℒa decider, consider any string w. Either w L or w L, but not ∈ ∉both. If w L, then w ∉ ∈ L. Thus either w L or w ∈ ∈ L, but not both. If w L, then M will eventually accept w and M' halts. ∈ If w ∈ L, them M will eventually accept w and M' halts. Thus M' halts on all inputs.

To see that L(M') = L, note that M' accepts w iff M accepts w and M does not accept w. As proven above, these two cases are mutually exclusive. Thus M' accepts w iff M accepts w iff w L. Thus∈L(M') = L. ■

Page 235: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: If L and L are RE, then L is recursive.Proof: Let M be a recognizer for L and M be a recognizer for L. Consider the TM M' defined as follows:

M' = “On input w:Run M and M on w in parallel.If M accepts w, accept.If M accepts w, reject.”

We prove that (M') = L and that M' is a decider. To see that M' is ℒa decider, consider any string w. Either w L or w L, but not ∈ ∉both. If w L, then w ∉ ∈ L. Thus either w L or w ∈ ∈ L, but not both. If w L, then M will eventually accept w and M' halts. If ∈w ∈ L, then M will eventually accept w and M' halts. Thus M' halts on all inputs.

To see that L(M') = L, note that M' accepts w iff M accepts w and M does not accept w. As proven above, these two cases are mutually exclusive. Thus M' accepts w iff M accepts w iff w L. Thus∈L(M') = L. ■

Page 236: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: If L and L are RE, then L is recursive.Proof: Let M be a recognizer for L and M be a recognizer for L. Consider the TM M' defined as follows:

M' = “On input w:Run M and M on w in parallel.If M accepts w, accept.If M accepts w, reject.”

We prove that (M') = L and that M' is a decider. To see that M' is ℒa decider, consider any string w. Either w L or w L, but not ∈ ∉both. If w L, then w ∉ ∈ L. Thus either w L or w ∈ ∈ L, but not both. If w L, then M will eventually accept w and M' halts. If ∈w ∈ L, then M will eventually accept w and M' halts. Thus M' halts on all inputs.

To see that L(M') = L, note that M' accepts w iff M accepts w and M does not accept w. As proven above, these two cases are mutually exclusive. Thus M' accepts w iff M accepts w iff w L. Thus∈L(M') = L. ■

Page 237: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: If L and L are RE, then L is recursive.Proof: Let M be a recognizer for L and M be a recognizer for L. Consider the TM M' defined as follows:

M' = “On input w:Run M and M on w in parallel.If M accepts w, accept.If M accepts w, reject.”

We prove that (M') = L and that M' is a decider. To see that M' is ℒa decider, consider any string w. Either w L or w L, but not ∈ ∉both. If w L, then w ∉ ∈ L. Thus either w L or w ∈ ∈ L, but not both. If w L, then M will eventually accept w and M' halts. If ∈w ∈ L, then M will eventually accept w and M' halts. Thus M' halts on all inputs.

To see that (M') = L, note that M' accepts w iff M accepts w and ℒ M does not accept w. As proven above, these two cases are mutually exclusive. Thus M' accepts w iff M accepts w iff w L. Thus∈L(M') = L. ■

Page 238: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: If L and L are RE, then L is recursive.Proof: Let M be a recognizer for L and M be a recognizer for L. Consider the TM M' defined as follows:

M' = “On input w:Run M and M on w in parallel.If M accepts w, accept.If M accepts w, reject.”

We prove that (M') = L and that M' is a decider. To see that M' is ℒa decider, consider any string w. Either w L or w L, but not ∈ ∉both. If w L, then w ∉ ∈ L. Thus either w L or w ∈ ∈ L, but not both. If w L, then M will eventually accept w and M' halts. If ∈w ∈ L, then M will eventually accept w and M' halts. Thus M' halts on all inputs.

To see that (M') = L, note that M' accepts w iff M accepts w and ℒ M does not accept w. As proven above, these two cases are mutually exclusive. Thus M' accepts w iff M accepts w iff w L. Thus∈L(M') = L. ■

We do have to consider this case – what if M would eventually accept

w, but M accepts it first?

Page 239: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: If L and L are RE, then L is recursive.Proof: Let M be a recognizer for L and M be a recognizer for L. Consider the TM M' defined as follows:

M' = “On input w:Run M and M on w in parallel.If M accepts w, accept.If M accepts w, reject.”

We prove that (M') = L and that M' is a decider. To see that M' is ℒa decider, consider any string w. Either w L or w L, but not ∈ ∉both. If w L, then w ∉ ∈ L. Thus either w L or w ∈ ∈ L, but not both. If w L, then M will eventually accept w and M' halts. If ∈w ∈ L, then M will eventually accept w and M' halts. Thus M' halts on all inputs.

To see that (M') = L, note that M' accepts w iff M accepts w and ℒ M does not accept w. Since M accepts w iff w L and ∈ M accepts w iff w L, if M accepts w, ∉ M does not accept w.

Page 240: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: If L and L are RE, then L is recursive.Proof: Let M be a recognizer for L and M be a recognizer for L. Consider the TM M' defined as follows:

M' = “On input w:Run M and M on w in parallel.If M accepts w, accept.If M accepts w, reject.”

We prove that (M') = L and that M' is a decider. To see that M' is ℒa decider, consider any string w. Either w L or w L, but not ∈ ∉both. If w L, then w ∉ ∈ L. Thus either w L or w ∈ ∈ L, but not both. If w L, then M will eventually accept w and M' halts. If ∈w ∈ L, then M will eventually accept w and M' halts. Thus M' halts on all inputs.

To see that (M') = L, note that M' accepts w iff M accepts w and ℒ M does not accept w. Since M accepts w iff w L and ∈ M accepts w iff w L, if M accepts w, ∉ M does not accept w. Thus M' accepts w iff M accepts w iff w L. ∈ Thus L(M') = L. ■

Page 241: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: If L and L are RE, then L is recursive.Proof: Let M be a recognizer for L and M be a recognizer for L. Consider the TM M' defined as follows:

M' = “On input w:Run M and M on w in parallel.If M accepts w, accept.If M accepts w, reject.”

We prove that (M') = L and that M' is a decider. To see that M' is ℒa decider, consider any string w. Either w L or w L, but not ∈ ∉both. If w L, then w ∉ ∈ L. Thus either w L or w ∈ ∈ L, but not both. If w L, then M will eventually accept w and M' halts. If ∈w ∈ L, then M will eventually accept w and M' halts. Thus M' halts on all inputs.

To see that (M') = L, note that M' accepts w iff M accepts w and ℒ M does not accept w. Since M accepts w iff w L and ∈ M accepts w iff w L, if M accepts w, ∉ M does not accept w. Thus M' accepts w iff M accepts w iff w L. Thus (M') = L.∈ ℒ ■

Page 242: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Theorem: If L and L are RE, then L is recursive.Proof: Let M be a recognizer for L and M be a recognizer for L. Consider the TM M' defined as follows:

M' = “On input w:Run M and M on w in parallel.If M accepts w, accept.If M accepts w, reject.”

We prove that (M') = L and that M' is a decider. To see that M' is ℒa decider, consider any string w. Either w L or w L, but not ∈ ∉both. If w L, then w ∉ ∈ L. Thus either w L or w ∈ ∈ L, but not both. If w L, then M will eventually accept w and M' halts. If ∈w ∈ L, then M will eventually accept w and M' halts. Thus M' halts on all inputs.

To see that (M') = L, note that M' accepts w iff M accepts w and ℒ M does not accept w. Since M accepts w iff w L and ∈ M accepts w iff w L, if M accepts w, ∉ M does not accept w. Thus M' accepts w iff M accepts w iff w L. Thus (M') = L. ■∈ ℒ

Page 243: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

R is Closed Under Complement

If L is recursive, then L is recursive as well.

Page 244: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

R is Closed Under Complement

If L is recursive, then L is recursive as well.

Deciderfor L

w

M

Page 245: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

R is Closed Under Complement

If L is recursive, then L is recursive as well.

Deciderfor L

w

M

Page 246: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

R is Closed Under Complement

If L is recursive, then L is recursive as well.

Deciderfor L

w

M

Page 247: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

R is Closed Under Complement

If L is recursive, then L is recursive as well.

Deciderfor L

w

M

M' = “On input w:Run M on w.If M accepts, reject.If M rejects, accept.”

Page 248: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

R is Closed Under Complement

If L is recursive, then L is recursive as well.

Deciderfor L

w

M

M' = “On input w:Run M on w.If M accepts, reject.If M rejects, accept.”

Why doesn't this work for RE languages?

Page 249: The Universal Turing Machineweb.stanford.edu/class/archive/cs/cs103/cs103.1126/...Why This Matters As a historically significant achievement. The universal Turing machine might be

Next Time

● Unsolvable Problems● What languages are not R or RE?● What problems are provably impossible to solve?● Does R = RE?