unsolvable problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · a decider...

229
Unsolvable Problems Part Two

Upload: others

Post on 08-Oct-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Unsolvable ProblemsPart Two

Page 2: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Outline for Today

● Recap from Last Time● Where are we, again?

● A Diferent Perspective on RE● What exactly does “recognizability” mean?

● Verifers● A new approach to problem-solving.

● Beyond RE● A beautiful example of an impossible problem.

Page 3: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Recap from Last Time

Page 4: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

The Universal Turing Machine

● Theorem (Turing, 1936): There is a Turing machine UT called the universal Turing machine that, when run on an input of the form ⟨M, w⟩, where M is a Turing machine and w is a string, simulates M running on w and does whatever M does on w (accepts, rejects, or loops).

● The observable behavior of U TM is the following:

● If M accepts w, then UTM accepts ⟨M, w⟩.

● If M rejects w, then UTM rejects ⟨M, w⟩.

● If M loops on w, then UTM loops on ⟨M, w⟩.

TM

...input...

M

w Universal TM

accept!

reject!

(loop)

M does to w

what

UTM does to ⟨M, w⟩.

M does to w

what

UTM does to ⟨M, w⟩.

Page 5: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Self-Referential Programs

● Claim: Any program can be augmented to include a method called mySource() that returns a string representation of its source code.

● Theorem: It it possible to build Turing machines that get their own encodings and perform arbitrary computations on them.

Page 6: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

What does this program do?

bool willAccept(string program, string input) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

if (willAccept(me, input)) {reject();

} else {accept();

}}

bool willAccept(string program, string input) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

if (willAccept(me, input)) {reject();

} else {accept();

}}

What happens if...

… this program accepts its input?It rejects the input!

… this program doesn't accept its input?It accepts the input!

What happens if...

… this program accepts its input?It rejects the input!

… this program doesn't accept its input?It accepts the input!

Page 7: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

RegularLanguages CFLs

All Languages

R RE

ATM

Page 8: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

New Stuf!

Page 9: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

More Impossibility Results

Page 10: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

The Halting Problem

● The most famous undecidable problem is the halting problem, which asks:

Given a TM M and a string w,will M halt when run on w?

● As a formal language, this problem would be expressed as

HALT = { ⟨M, w⟩ | M is a TM that halts on w } ● This is an RE language. (We’ll see why later.)● How do we know that it’s undecidable?

Page 11: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Claim: A decider for HALT is a self-defeating object. It therefore doesn’t exist.

Page 12: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

A Decider for HALT

● Let’s suppose that, somehow, we managed to build a decider for HALT = { ⟨M, w⟩ | M is a TM that halts on w }.

● Schematically, that decider would look like this:

● We could represent this decider in software as a method

bool willHalt(string program, string input);

that takes as input a program and a string, then returns whether that program will halt on that string.

Deciderfor HALT

M

w

Yes, M halts on w.

No, M loops on w.

Page 13: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

What does this program do?

bool willHalt(string program, string input) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

if (willHalt(me, input)) {while (true) {

// loop infinitely}

} else {accept();

}}

bool willHalt(string program, string input) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

if (willHalt(me, input)) {while (true) {

// loop infinitely}

} else {accept();

}}

Page 14: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

What does this program do?

bool willHalt(string program, string input) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

if (willHalt(me, input)) {while (true) {

// loop infinitely}

} else {accept();

}}

bool willHalt(string program, string input) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

if (willHalt(me, input)) {while (true) {

// loop infinitely}

} else {accept();

}}

Page 15: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

What does this program do?

bool willHalt(string program, string input) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

if (willHalt(me, input)) {while (true) {

// loop infinitely}

} else {accept();

}}

bool willHalt(string program, string input) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

if (willHalt(me, input)) {while (true) {

// loop infinitely}

} else {accept();

}}

Imagine running this program on some input. What happens if...

… this program halts on that input?It loops on the input!

… this program loops on this input?It halts on the input!

Imagine running this program on some input. What happens if...

… this program halts on that input?It loops on the input!

… this program loops on this input?It halts on the input!

Page 16: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

What does this program do?

bool willHalt(string program, string input) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

if (willHalt(me, input)) {while (true) {

// loop infinitely}

} else {accept();

}}

bool willHalt(string program, string input) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

if (willHalt(me, input)) {while (true) {

// loop infinitely}

} else {accept();

}}

Imagine running this program on some input. What happens if...

… this program halts on that input?It loops on the input!

… this program loops on this input?It halts on the input!

Imagine running this program on some input. What happens if...

… this program halts on that input?It loops on the input!

… this program loops on this input?It halts on the input!

Page 17: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

What does this program do?

bool willHalt(string program, string input) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

if (willHalt(me, input)) {while (true) {

// loop infinitely}

} else {accept();

}}

bool willHalt(string program, string input) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

if (willHalt(me, input)) {while (true) {

// loop infinitely}

} else {accept();

}}

Imagine running this program on some input. What happens if...

… this program halts on that input?It loops on the input!

… this program loops on this input?It halts on the input!

Imagine running this program on some input. What happens if...

… this program halts on that input?It loops on the input!

… this program loops on this input?It halts on the input!

Page 18: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

What does this program do?

bool willHalt(string program, string input) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

if (willHalt(me, input)) {while (true) {

// loop infinitely}

} else {accept();

}}

bool willHalt(string program, string input) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

if (willHalt(me, input)) {while (true) {

// loop infinitely}

} else {accept();

}}

Imagine running this program on some input. What happens if...

… this program halts on that input?It loops on the input!

… this program loops on this input?It halts on the input!

Imagine running this program on some input. What happens if...

… this program halts on that input?It loops on the input!

… this program loops on this input?It halts on the input!

Page 19: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

What does this program do?

bool willHalt(string program, string input) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

if (willHalt(me, input)) {while (true) {

// loop infinitely}

} else {accept();

}}

bool willHalt(string program, string input) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

if (willHalt(me, input)) {while (true) {

// loop infinitely}

} else {accept();

}}

Imagine running this program on some input. What happens if...

… this program halts on that input?It loops on the input!

… this program loops on this input?It halts on the input!

Imagine running this program on some input. What happens if...

… this program halts on that input?It loops on the input!

… this program loops on this input?It halts on the input!

Page 20: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

What does this program do?

bool willHalt(string program, string input) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

if (willHalt(me, input)) {while (true) {

// loop infinitely}

} else {accept();

}}

bool willHalt(string program, string input) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

if (willHalt(me, input)) {while (true) {

// loop infinitely}

} else {accept();

}}

Imagine running this program on some input. What happens if...

… this program halts on that input?It loops on the input!

… this program loops on this input?It halts on the input!

Imagine running this program on some input. What happens if...

… this program halts on that input?It loops on the input!

… this program loops on this input?It halts on the input!

Page 21: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

What does this program do?

bool willHalt(string program, string input) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

if (willHalt(me, input)) {while (true) {

// loop infinitely}

} else {accept();

}}

bool willHalt(string program, string input) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

if (willHalt(me, input)) {while (true) {

// loop infinitely}

} else {accept();

}}

Imagine running this program on some input. What happens if...

… this program halts on that input?It loops on the input!

… this program loops on this input?It halts on the input!

Imagine running this program on some input. What happens if...

… this program halts on that input?It loops on the input!

… this program loops on this input?It halts on the input!

Page 22: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

What does this program do?

bool willHalt(string program, string input) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

if (willHalt(me, input)) {while (true) {

// loop infinitely}

} else {accept();

}}

bool willHalt(string program, string input) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

if (willHalt(me, input)) {while (true) {

// loop infinitely}

} else {accept();

}}

Imagine running this program on some input. What happens if...

… this program halts on that input?It loops on the input!

… this program loops on this input?It halts on the input!

Imagine running this program on some input. What happens if...

… this program halts on that input?It loops on the input!

… this program loops on this input?It halts on the input!

Page 23: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

What does this program do?

bool willHalt(string program, string input) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

if (willHalt(me, input)) {while (true) {

// loop infinitely}

} else {accept();

}}

bool willHalt(string program, string input) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

if (willHalt(me, input)) {while (true) {

// loop infinitely}

} else {accept();

}}

Imagine running this program on some input. What happens if...

… this program halts on that input?It loops on the input!

… this program loops on this input?It halts on the input!

Imagine running this program on some input. What happens if...

… this program halts on that input?It loops on the input!

… this program loops on this input?It halts on the input!

Page 24: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

What does this program do?

bool willHalt(string program, string input) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

if (willHalt(me, input)) {while (true) {

// loop infinitely}

} else {accept();

}}

bool willHalt(string program, string input) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

if (willHalt(me, input)) {while (true) {

// loop infinitely}

} else {accept();

}}

Imagine running this program on some input. What happens if...

… this program halts on that input?It loops on the input!

… this program loops on this input?It halts on the input!

Imagine running this program on some input. What happens if...

… this program halts on that input?It loops on the input!

… this program loops on this input?It halts on the input!

Page 25: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

What does this program do?

bool willHalt(string program, string input) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

if (willHalt(me, input)) {while (true) {

// loop infinitely}

} else {accept();

}}

bool willHalt(string program, string input) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

if (willHalt(me, input)) {while (true) {

// loop infinitely}

} else {accept();

}}

Imagine running this program on some input. What happens if...

… this program halts on that input?It loops on the input!

… this program loops on this input?It halts on the input!

Imagine running this program on some input. What happens if...

… this program halts on that input?It loops on the input!

… this program loops on this input?It halts on the input!

Page 26: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

What does this program do?

bool willHalt(string program, string input) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

if (willHalt(me, input)) {while (true) {

// loop infinitely}

} else {accept();

}}

bool willHalt(string program, string input) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

if (willHalt(me, input)) {while (true) {

// loop infinitely}

} else {accept();

}}

Imagine running this program on some input. What happens if...

… this program halts on that input?It loops on the input!

… this program loops on this input?It halts on the input!

Imagine running this program on some input. What happens if...

… this program halts on that input?It loops on the input!

… this program loops on this input?It halts on the input!

Page 27: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

What does this program do?

bool willHalt(string program, string input) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

if (willHalt(me, input)) {while (true) {

// loop infinitely}

} else {accept();

}}

bool willHalt(string program, string input) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

if (willHalt(me, input)) {while (true) {

// loop infinitely}

} else {accept();

}}

Imagine running this program on some input. What happens if...

… this program halts on that input?It loops on the input!

… this program loops on this input?It halts on the input!

Imagine running this program on some input. What happens if...

… this program halts on that input?It loops on the input!

… this program loops on this input?It halts on the input!

Page 28: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

What does this program do?

bool willHalt(string program, string input) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

if (willHalt(me, input)) {while (true) {

// loop infinitely}

} else {accept();

}}

bool willHalt(string program, string input) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

if (willHalt(me, input)) {while (true) {

// loop infinitely}

} else {accept();

}}

“The largest

integer n”

“The largest

integer n”

“Using n to get n+1”

“Using n to get n+1”

Page 29: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Theorem: HALT ∉ R.

Proof: By contradiction; assume that HALT ∈ R. Then there’s a deciderD for HALT, which we can represent in software as a method willHaltthat takes as input the source code of a program and an input, thenreturns true if the program halts on the input and false otherwise.

Given this, we could then construct this program P:

int main() { string me = mySource(); string input = getInput(); if (willHalt(me, input)) while (true) { /* loop! */ } else accept(); }

Choose any string w and trace through the execution of program P on input w, focusing on the answer given back by the willHalt method. If willHalt(me, input) returns true, then P must halt on its input w. However, in this case P proceeds to loop infnitely on w. Otherwise, if willHalt(me, input) returns false, then P must not halt its input w. However, in this case P proceeds to accept its input w.

In both cases we reach a contradiction, so our assumption must have been wrong. Therefore, HALT ∉ R. ■

Page 30: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

HALT ∈ RE

● Claim: HALT ∈ RE.● Idea: If you were certain that a TM M halted on a

string w, could you convince me of that?● Yes – just run M on w and see what happens!

int main() {TM M = getInputTM();string w = getInputString();

feed w into M;while (true) {

if (M is in an accepting state) accept();else if (M is in a rejecting state) accept();else simulate one more step of M running on w;

}}

int main() {TM M = getInputTM();string w = getInputString();

feed w into M;while (true) {

if (M is in an accepting state) accept();else if (M is in a rejecting state) accept();else simulate one more step of M running on w;

}}

Page 31: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

RegularLanguages CFLs

All Languages

R RE

ATM

HALT

Page 32: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

So What?

● These problems might not seem all that exciting, so who cares if we can't solve them?

● Turns out, this same line of reasoning can be used to show that some very important problems are impossible to solve.

Page 33: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Secure Voting

● Suppose that you want to make a voting machine for use in an election between two parties.

● Let Σ = {r, d}. A string in w corresponds to a series of votes for the candidates.

● Example: rrdddrd means “two people voted for r, then three people voted for d, then one more person voted for r, then one more person voted for d.”

Page 34: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Secure Voting

● A voting machine is a program that takes as input a string of r's and d's, then reports whether person r won the election.

● Question: Given a TM that someone claims is a secure voting machine, could we automatically check whether it actually is a secure voting machine?

Page 35: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

int main() { string input = getInput(); int numRs = countRsIn(input); int numDs = countDsIn(input);

if (numRs > numDs) accept(); else reject();}

int main() { string input = getInput();

if (input[0] == 'r') accept(); else reject();}

int main() { string input = getInput(); int numRs = countRsIn(input); int numDs = countDsIn(input);

if (numRs = numDs) reject(); else if (numRs < numDs) reject(); else accept();}

int main() { string input = getInput();

int n = input.length(); while (n > 1) { if (n % 2 == 0) n /= 2; else n = 3*n + 1; }

int numRs = countRsIn(input); int numDs = countDsIn(input);

if (numRs > numDs) accept(); else reject();}

A (simple) secure voting machine. A (simple) insecure voting machine.

An (evil) insecure voting machine. No one knows!

A secure voting machine is a TM M whereℒ(M) = { w ∈ Σ* | w has more r’s than d’s }

Page 36: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Secure Voting

● A voting machine is a program that takes as input a string of r's and d's, then reports whether person r won the election.

● Question: Given a TM that someone claims is a secure voting machine, could we automatically check whether it actually is a secure voting machine?

Page 37: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Claim: A program that decides whether arbitrary input programs are secure voting

machines is self-defeating. It therefore doesn’t exist.

Page 38: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

A Decider for Secure Voting

● Let’s suppose that, somehow, we managed to build a decider for the secure voting problem.

● Schematically, that decider would look like this:

● We could represent this decider in software as a method

bool isSecureVotingMachine(string program);

that takes as input a program, then returns whether that program is a secure voting machine.

Deciderfor secure

voting

M

Yes, M is a secure votingmachine.

No, M is not a secure voting machine.

Page 39: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

bool isSecureVotingMachine(string program) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

bool answer = countRs(input) > countDs(input);if (isSecureVotingMachine(me)) answer = !answer;

if (answer) accept(); else reject();}

bool isSecureVotingMachine(string program) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

bool answer = countRs(input) > countDs(input);if (isSecureVotingMachine(me)) answer = !answer;

if (answer) accept(); else reject();}

Page 40: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

bool isSecureVotingMachine(string program) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

bool answer = countRs(input) > countDs(input);if (isSecureVotingMachine(me)) answer = !answer;

if (answer) accept(); else reject();}

bool isSecureVotingMachine(string program) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

bool answer = countRs(input) > countDs(input);if (isSecureVotingMachine(me)) answer = !answer;

if (answer) accept(); else reject();}

Page 41: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

bool isSecureVotingMachine(string program) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

bool answer = countRs(input) > countDs(input);if (isSecureVotingMachine(me)) answer = !answer;

if (answer) accept(); else reject();}

bool isSecureVotingMachine(string program) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

bool answer = countRs(input) > countDs(input);if (isSecureVotingMachine(me)) answer = !answer;

if (answer) accept(); else reject();}

What happens if...

… this program is a secure voting machine?Then it's not a secure machine!

… this program is not a secure voting machine?Then it's not a secure machine!

What happens if...

… this program is a secure voting machine?Then it's not a secure machine!

… this program is not a secure voting machine?Then it's not a secure machine!

Page 42: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

bool isSecureVotingMachine(string program) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

bool answer = countRs(input) > countDs(input);if (isSecureVotingMachine(me)) answer = !answer;

if (answer) accept(); else reject();}

bool isSecureVotingMachine(string program) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

bool answer = countRs(input) > countDs(input);if (isSecureVotingMachine(me)) answer = !answer;

if (answer) accept(); else reject();}

What happens if...

… this program is a secure voting machine?Then it's not a secure machine!

… this program is not a secure voting machine?Then it's not a secure machine!

What happens if...

… this program is a secure voting machine?Then it's not a secure machine!

… this program is not a secure voting machine?Then it's not a secure machine!

Page 43: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

bool isSecureVotingMachine(string program) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

bool answer = countRs(input) > countDs(input);if (isSecureVotingMachine(me)) answer = !answer;

if (answer) accept(); else reject();}

bool isSecureVotingMachine(string program) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

bool answer = countRs(input) > countDs(input);if (isSecureVotingMachine(me)) answer = !answer;

if (answer) accept(); else reject();}

What happens if...

… this program is a secure voting machine?Then it's not a secure machine!

… this program is not a secure voting machine?Then it's not a secure machine!

What happens if...

… this program is a secure voting machine?Then it's not a secure machine!

… this program is not a secure voting machine?Then it's not a secure machine!

Page 44: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

bool isSecureVotingMachine(string program) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

bool answer = countRs(input) > countDs(input);if (isSecureVotingMachine(me)) answer = !answer;

if (answer) accept(); else reject();}

bool isSecureVotingMachine(string program) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

bool answer = countRs(input) > countDs(input);if (isSecureVotingMachine(me)) answer = !answer;

if (answer) accept(); else reject();}

What happens if...

… this program is a secure voting machine?then it's not a secure voting machine!

… this program is not a secure voting machine?Then it's not a secure machine!

What happens if...

… this program is a secure voting machine?then it's not a secure voting machine!

… this program is not a secure voting machine?Then it's not a secure machine!

Page 45: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

bool isSecureVotingMachine(string program) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

bool answer = countRs(input) > countDs(input);if (isSecureVotingMachine(me)) answer = !answer;

if (answer) accept(); else reject();}

bool isSecureVotingMachine(string program) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

bool answer = countRs(input) > countDs(input);if (isSecureVotingMachine(me)) answer = !answer;

if (answer) accept(); else reject();}

What happens if...

… this program is a secure voting machine?then it's not a secure voting machine!

… this program is not a secure voting machine?Then it's not a secure machine!

What happens if...

… this program is a secure voting machine?then it's not a secure voting machine!

… this program is not a secure voting machine?Then it's not a secure machine!

Page 46: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

bool isSecureVotingMachine(string program) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

bool answer = countRs(input) > countDs(input);if (isSecureVotingMachine(me)) answer = !answer;

if (answer) accept(); else reject();}

bool isSecureVotingMachine(string program) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

bool answer = countRs(input) > countDs(input);if (isSecureVotingMachine(me)) answer = !answer;

if (answer) accept(); else reject();}

What happens if...

… this program is a secure voting machine?then it's not a secure voting machine!

… this program is not a secure voting machine?Then it's not a secure machine!

What happens if...

… this program is a secure voting machine?then it's not a secure voting machine!

… this program is not a secure voting machine?Then it's not a secure machine!

Page 47: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

bool isSecureVotingMachine(string program) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

bool answer = countRs(input) > countDs(input);if (isSecureVotingMachine(me)) answer = !answer;

if (answer) accept(); else reject();}

bool isSecureVotingMachine(string program) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

bool answer = countRs(input) > countDs(input);if (isSecureVotingMachine(me)) answer = !answer;

if (answer) accept(); else reject();}

What happens if...

… this program is a secure voting machine?then it's not a secure voting machine!

… this program is not a secure voting machine?Then it's not a secure machine!

What happens if...

… this program is a secure voting machine?then it's not a secure voting machine!

… this program is not a secure voting machine?Then it's not a secure machine!

Page 48: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

bool isSecureVotingMachine(string program) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

bool answer = countRs(input) > countDs(input);if (isSecureVotingMachine(me)) answer = !answer;

if (answer) accept(); else reject();}

bool isSecureVotingMachine(string program) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

bool answer = countRs(input) > countDs(input);if (isSecureVotingMachine(me)) answer = !answer;

if (answer) accept(); else reject();}

What happens if...

… this program is a secure voting machine?then it's not a secure voting machine!

… this program is not a secure voting machine?then it's a secure voting machine!

What happens if...

… this program is a secure voting machine?then it's not a secure voting machine!

… this program is not a secure voting machine?then it's a secure voting machine!

Page 49: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

bool isSecureVotingMachine(string program) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

bool answer = countRs(input) > countDs(input);if (isSecureVotingMachine(me)) answer = !answer;

if (answer) accept(); else reject();}

bool isSecureVotingMachine(string program) { /* … some implementation … */}

int main() {string me = mySource();string input = getInput();

bool answer = countRs(input) > countDs(input);if (isSecureVotingMachine(me)) answer = !answer;

if (answer) accept(); else reject();}

What happens if...

… this program is a secure voting machine?then it's not a secure voting machine!

… this program is not a secure voting machine?then it's a secure voting machine!

What happens if...

… this program is a secure voting machine?then it's not a secure voting machine!

… this program is not a secure voting machine?then it's a secure voting machine!

Page 50: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Theorem: The secure voting problem is undecidable.

Proof: By contradiction; assume that the secure voting problem is decidable. Thenthere is some decider D for the secure voting problem, which we can represent insoftware as a method isSecureVotingMachine that, given as input the source code ofa program, returns true if the program is a secure voting machine and falseotherwise.

Given this, we could then construct the following program P:

int main() { string me = mySource();

string input = getInput();

bool answer = (countRs(input) > countDs(input)); if (isSecureVotingMachine(me)) answer = !answer;

if (answer) accept(); else reject(); }

Now, either P is a secure voting machine or it isn’t. If P is a secure voting machine, then isSecureVotingMachine(me) will return true. Therefore, when P is run, it will determine whether w has more r’s than d’s, fip the result, and accept strings with at least as many d’s as r’s and reject strings with more r’s than d’s. Thus, P is not a secure voting machine. On the other hand, if P is not a secure voting machine, then isSecureVotingMachine(me) will return false. Therefore, when P is run, it will accept all strings with at least as many r’s as d’s and reject all other strings, and so P is a secure voting machine.

In both cases we reach a contradiction, so our assumption must have been wrong. Therefore, the secure voting problem is undecidable. ■

Page 51: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Interpreting this Result

● The previous argument tells us that there is no general algorithm that we can follow to determine whether a program is a secure voting machine. In other words, any general algorithm to check voting machines will always be wrong on at least one input.

● So what can we do?● Design algorithms that work in some, but not all cases.

(This is often done in practice.)● Fall back on human verifcation of voting machines. (We do

that too.)● Carry a healthy degree of skepticism about electronic

voting machines. (Then again, did we even need the theoretical result for this?)

Page 52: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =
Page 53: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Beyond R and RE

Page 54: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Beyond R and RE

● We've now seen how to use self-reference as a tool for showing undecidability (fnding languages not in R).

● We still have not broken out of RE yet, though.

● To do so, we will need to build up a better intuition for the class RE.

Page 55: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

What exactly is the class RE?

Page 56: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

RE, Formally

● Recall that the class RE is the class of all recognizable languages:

RE = { L | there is a TM M where (ℒ M) = L }● Since R ≠ RE, there is no general way to

“solve” problems in the class RE, if by “solve” you mean “make a computer program that can always tell you the correct answer.”

● So what exactly are the sorts of languages in RE?

Page 57: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Does this graph contain a 4-clique?Does this graph contain a 4-clique?

Page 58: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Does this graph contain a 4-clique?Does this graph contain a 4-clique?

Page 59: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Does this graph contain a 4-clique?Does this graph contain a 4-clique?

Page 60: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Key Intuition:

A language L is in RE if, for any string w, if you are convinced that w ∈ L, there is some way you could prove that to someone else.

Page 61: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

3

6

8

1

5

1

7

7

5

2

3

4

1

2

4

6

3

1

8

3

5

7

1

9

8

5

7

5

2

2

7

9

4

8

Does this Sudoku puzzlehave a solution?

Page 62: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

2

4

3

6

7

8

1

5

9

5

9

8

4

1

3

6

7

2

7

1

6

5

9

2

3

8

4

9

8

1

7

5

6

2

4

3

6

7

2

3

4

1

5

9

8

4

3

5

2

8

9

7

6

1

1

6

9

8

3

5

4

2

7

8

5

4

1

2

7

9

3

6

3

2

7

9

6

4

8

1

5

Does this Sudoku puzzlehave a solution?

Page 63: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

Does this graph have a Hamiltonian path (a simple path that passes

through every node exactly once?)

Page 64: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

Does this graph have a Hamiltonian path (a simple path that passes

through every node exactly once?)

1

2

5

4

6

3

Page 65: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

Does the hailstone sequence terminate for this number?

11

Page 66: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

Does the hailstone sequence terminate for this number?

11

Try running fourteen steps of the Hailstone sequence.

Page 67: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

Does the hailstone sequence terminate for this number?

34

Try running fourteen steps of the Hailstone sequence.

Page 68: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

Does the hailstone sequence terminate for this number?

17

Try running fourteen steps of the Hailstone sequence.

Page 69: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

Does the hailstone sequence terminate for this number?

52

Try running fourteen steps of the Hailstone sequence.

Page 70: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

Does the hailstone sequence terminate for this number?

26

Try running fourteen steps of the Hailstone sequence.

Page 71: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

Does the hailstone sequence terminate for this number?

13

Try running fourteen steps of the Hailstone sequence.

Page 72: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

Does the hailstone sequence terminate for this number?

40

Try running fourteen steps of the Hailstone sequence.

Page 73: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

Does the hailstone sequence terminate for this number?

20

Try running fourteen steps of the Hailstone sequence.

Page 74: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

Does the hailstone sequence terminate for this number?

10

Try running fourteen steps of the Hailstone sequence.

Page 75: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

Does the hailstone sequence terminate for this number?

5

Try running fourteen steps of the Hailstone sequence.

Page 76: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

Does the hailstone sequence terminate for this number?

16

Try running fourteen steps of the Hailstone sequence.

Page 77: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

Does the hailstone sequence terminate for this number?

8

Try running fourteen steps of the Hailstone sequence.

Page 78: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

Does the hailstone sequence terminate for this number?

4

Try running fourteen steps of the Hailstone sequence.

Page 79: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

Does the hailstone sequence terminate for this number?

2

Try running fourteen steps of the Hailstone sequence.

Page 80: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

Does the hailstone sequence terminate for this number?

1

Try running fourteen steps of the Hailstone sequence.

Page 81: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

3

6

8

1

5

1

7

7

5

2

3

4

1

2

4

6

3

1

8

3

5

7

1

9

8

5

7

5

2

2

7

9

4

8

Does this Sudoku puzzlehave a solution?

Page 82: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

1

1

3

6

1

8

1

5

1

1

1

1

1

1

1

1

7

1

7

1

1

5

1

2

3

1

4

1

1

1

1

1

1

2

4

1

6

1

1

3

4

1

1

1

8

1

3

5

1

1

1

7

1

1

1

1

9

8

1

5

1

1

7

1

5

1

1

2

1

1

1

1

1

2

7

9

1

4

8

1

1

Does this Sudoku puzzlehave a solution?

Page 83: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

Does this graph have a Hamiltonian path (a simple path that passes

through every node exactly once?)

Page 84: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

6

1

5

2

3

4

Does this graph have a Hamiltonian path (a simple path that passes

through every node exactly once?)

Page 85: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

Does the hailstone sequence terminate for this number?

11

Page 86: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

Does the hailstone sequence terminate for this number?

11

Try running fve steps of the Hailstone sequence.

Page 87: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

Does the hailstone sequence terminate for this number?

34

Try running fve steps of the Hailstone sequence.

Page 88: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

Does the hailstone sequence terminate for this number?

17

Try running fve steps of the Hailstone sequence.

Page 89: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

Does the hailstone sequence terminate for this number?

52

Try running fve steps of the Hailstone sequence.

Page 90: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

Does the hailstone sequence terminate for this number?

26

Try running fve steps of the Hailstone sequence.

Page 91: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

Does the hailstone sequence terminate for this number?

13

Try running fve steps of the Hailstone sequence.

Page 92: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

● In each of the preceding cases, we were given some problem and some evidence supporting the claim that the answer is “yes.”

● Given the correct evidence, we can be certain that the answer is indeed “yes.”

● Given incorrect evidence, we aren't sure whether the answer is “yes.”● Maybe there's no evidence saying that the answer

is “yes,” or maybe there is some evidence, but just not the evidence we were given.

● Let's formalize this idea.

Page 93: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifers

● A verifer for a language L is a TM V with the following two properties:

V halts on all inputs.

∀w ∈ Σ*. (w ∈ L ↔ ∃c ∈ Σ*. V accepts ⟨w, c⟩)

● Intuitively, what does this mean?

Page 94: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Deciders and Verifers

Decider Mfor L

Verifer Vfor L

yes!

no!

yes!

notsure

input string (w)

certifcate (c)

input string (w)

“Solve the problem”

“Check the answer”

V halts on all inputs.w ∈ L ↔ ∃c ∈ Σ*. V accepts ⟨w, c⟩

M halts on all inputs.w ∈ L ↔ M accepts w

If M accepts, then w ∈ L.

If M accepts, then w ∈ L.

If M rejects, then w ∉ L.

If M rejects, then w ∉ L.

If V accepts ⟨w, c⟩, then w ∈ L.

If V accepts ⟨w, c⟩, then w ∈ L.

If V rejects ⟨w, c⟩, we don't know whether w ∈ L.

If V rejects ⟨w, c⟩, we don't know whether w ∈ L.

Page 95: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifers

● A verifer for a language L is a TM V with the following properties:

V halts on all inputs.

∀w ∈ Σ*. (w ∈ L ↔ ∃c ∈ Σ*. V accepts ⟨w, c⟩)

● Some notes about V:

● If V accepts ⟨w, c⟩, then we're guaranteed w ∈ L.

● If V rejects ⟨w, c⟩, then either– w ∈ L, but you gave the wrong c, or– w ∉ L, so no possible c will work.

Page 96: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifers

● A verifer for a language L is a TM V with the following properties:

V halts on all inputs.

∀w ∈ Σ*. (w ∈ L ↔ ∃c ∈ Σ*. V accepts ⟨w, c⟩)

● Some notes about V:

● Notice that the certifcate c is existentially quantifed. Any string w ∈ L must have at least one c that causes V to accept, and possibly more.

● V is required to halt, so given any potential certifcate c for w, you can check whether the certifcate is correct.

Page 97: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifers

● A verifer for a language L is a TM V with the following properties:

V halts on all inputs.

∀w ∈ Σ*. (w ∈ L ↔ ∃c ∈ Σ*. V accepts ⟨w, c⟩)

● Some notes about V:

● Notice that (ℒ V) ≠ L. (Good question: what is (ℒ V)?)

● The job of V is just to check certifcates, not to decide membership in L.

Page 98: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifers

● A verifer for a language L is a TM V with the following properties:

V halts on all inputs.

∀w ∈ Σ*. (w ∈ L ↔ ∃c ∈ Σ*. V accepts ⟨w, c⟩)

● Some notes about V:

● Although this formal defnition works with a string c, remember that c can be an encoding of some other object.

● In practice, c will likely just be “some other auxiliary data that helps you out.”

Page 99: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Some Verifers

● Let L be the following language:

L = { ⟨n⟩ | n ∈ ℕ and the hailstone sequence terminates for n }

● Let's see how to build a verifer for L.● This verifer will take as input

● a natural number n, and ● some certifcate c.

● The certifcate c should be some evidence that suggests that the hailstone sequence terminates for n.

● What evidence could we provide?

Page 100: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

Does the hailstone sequence terminate for this number?

11

Page 101: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

Does the hailstone sequence terminate for this number?

11

Try running fourteen steps of the Hailstone sequence.

Page 102: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

Does the hailstone sequence terminate for this number?

34

Try running fourteen steps of the Hailstone sequence.

Page 103: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

Does the hailstone sequence terminate for this number?

17

Try running fourteen steps of the Hailstone sequence.

Page 104: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

Does the hailstone sequence terminate for this number?

52

Try running fourteen steps of the Hailstone sequence.

Page 105: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

Does the hailstone sequence terminate for this number?

26

Try running fourteen steps of the Hailstone sequence.

Page 106: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

Does the hailstone sequence terminate for this number?

13

Try running fourteen steps of the Hailstone sequence.

Page 107: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

Does the hailstone sequence terminate for this number?

40

Try running fourteen steps of the Hailstone sequence.

Page 108: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

Does the hailstone sequence terminate for this number?

20

Try running fourteen steps of the Hailstone sequence.

Page 109: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

Does the hailstone sequence terminate for this number?

10

Try running fourteen steps of the Hailstone sequence.

Page 110: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

Does the hailstone sequence terminate for this number?

5

Try running fourteen steps of the Hailstone sequence.

Page 111: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

Does the hailstone sequence terminate for this number?

16

Try running fourteen steps of the Hailstone sequence.

Page 112: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

Does the hailstone sequence terminate for this number?

8

Try running fourteen steps of the Hailstone sequence.

Page 113: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

Does the hailstone sequence terminate for this number?

4

Try running fourteen steps of the Hailstone sequence.

Page 114: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

Does the hailstone sequence terminate for this number?

2

Try running fourteen steps of the Hailstone sequence.

Page 115: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

Does the hailstone sequence terminate for this number?

1

Try running fourteen steps of the Hailstone sequence.

Page 116: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Some Verifers

● Let L be the following language:

L = { ⟨n⟩ | n ∈ ℕ and the hailstone sequence terminates for n }

● Do you see why ⟨n⟩ ∈ L if there is some c such that checkHailstone(n, c) returns true?

● Do you see why checkHailstone always halts?

bool checkHailstone(int n, int c) { for (int i = 0; i < c; i++) { if (n % 2 == 0) n /= 2; else n = 3*n + 1; } return n == 1;}

bool checkHailstone(int n, int c) { for (int i = 0; i < c; i++) { if (n % 2 == 0) n /= 2; else n = 3*n + 1; } return n == 1;}

Page 117: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Some Verifers

● Let L be the following language:

L = { ⟨G⟩ | G is a graph and G has a Hamiltonian path }

● (Refresher: a Hamiltonian path is a simple path that visits every node in the graph.)

● Let's see how to build a verifer for L.● Our verifer will take as input

● a graph G, and● a certifcate c.

● The certifcate c should be some evidence that suggests that G has a Hamiltonian path.

● What information could we put into the certifcate?

Page 118: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

Is there a simple path that goes through every node exactly once?

Page 119: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifcation

Is there a simple path that goes through every node exactly once?

1

2

5

4

6

3

Page 120: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Some Verifers

● Let L be the following language:

L = { ⟨G⟩ | G is a graph with a Hamiltonian path }

● Do you see why ⟨G⟩ ∈ L if there is a c where checkHamiltonian(G, c) returns true?

● Do you see why checkHamiltonian always halts?

bool checkHamiltonian(Graph G, vector<Node> c) { if (c.size() != G.numNodes()) return false; if (containsDuplicate(c)) return false;

for (size_t i = 0; i + 1 < c.size(); i++) { if (!G.hasEdge(c[i], c[i+1])) return false; } return true;}

bool checkHamiltonian(Graph G, vector<Node> c) { if (c.size() != G.numNodes()) return false; if (containsDuplicate(c)) return false;

for (size_t i = 0; i + 1 < c.size(); i++) { if (!G.hasEdge(c[i], c[i+1])) return false; } return true;}

Page 121: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

A Very Nifty Verifer

● Consider ATM:

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

● This is a canonical example of an undecidable language. There’s no way, in general, to tell whether a TM M will accept a string w.

● Although this language is undecidable, it’s an RE language, and it’s possible to build a verifer for it!

Page 122: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

A Very Nifty Verifer

● Consider ATM:

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

● We know that UTM is a recognizer for ATM. It is also a verifer for ATM?

● No, for two reasons:

● UTM doesn’t always halt. (Do you see why?)

● UTM takes as input a TM M and a string w. A verifer also needs a certifcate.

Page 123: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

A Very Nifty Verifer

● Consider ATM:

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

● A verifer for ATM would take as input

● A TM M,● a string w, and● a certifcate c.

● The certifcate c should be some evidence that suggests that M accepts w.

● What could our certifcate be?

Page 124: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

0 → , R☐ 0 → 0, R 1 → 1, R

→ ☐ ☐, L

1 → , L☐0 → 0, L 1 → 1, L

→ ☐ ☐, R

1 → , L☐

0 → 0, R → ☐ ☐, R

→ ☐ ☐, R

qrej

qacc

start

… 0 0 1 1 …

Run this TM for ffteen

steps.

Page 125: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

0 → , R☐ 0 → 0, R 1 → 1, R

→ ☐ ☐, L

1 → , L☐0 → 0, L 1 → 1, L

→ ☐ ☐, R

1 → , L☐

0 → 0, R → ☐ ☐, R

→ ☐ ☐, R

qrej

qacc

start

… 0 0 1 1 …

Run this TM for ffteen

steps.

Page 126: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

0 → , R☐ 0 → 0, R 1 → 1, R

→ ☐ ☐, L

1 → , L☐0 → 0, L 1 → 1, L

→ ☐ ☐, R

1 → , L☐

0 → 0, R → ☐ ☐, R

→ ☐ ☐, R

qrej

qacc

start

… 0 1 1 …

Run this TM for ffteen

steps.

Page 127: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

0 → , R☐ 0 → 0, R 1 → 1, R

→ ☐ ☐, L

1 → , L☐0 → 0, L 1 → 1, L

→ ☐ ☐, R

1 → , L☐

0 → 0, R → ☐ ☐, R

→ ☐ ☐, R

qrej

qacc

start

… 0 1 1 …

Run this TM for ffteen

steps.

Page 128: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

0 → , R☐ 0 → 0, R 1 → 1, R

→ ☐ ☐, L

1 → , L☐0 → 0, L 1 → 1, L

→ ☐ ☐, R

1 → , L☐

0 → 0, R → ☐ ☐, R

→ ☐ ☐, R

qrej

qacc

start

… 0 1 1 …

Run this TM for ffteen

steps.

Page 129: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

0 → , R☐ 0 → 0, R 1 → 1, R

→ ☐ ☐, L

1 → , L☐0 → 0, L 1 → 1, L

→ ☐ ☐, R

1 → , L☐

0 → 0, R → ☐ ☐, R

→ ☐ ☐, R

qrej

qacc

start

… 0 1 1 …

Run this TM for ffteen

steps.

Page 130: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

0 → , R☐ 0 → 0, R 1 → 1, R

→ ☐ ☐, L

1 → , L☐0 → 0, L 1 → 1, L

→ ☐ ☐, R

1 → , L☐

0 → 0, R → ☐ ☐, R

→ ☐ ☐, R

qrej

qacc

start

… 0 1 1 …

Run this TM for ffteen

steps.

Page 131: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

0 → , R☐ 0 → 0, R 1 → 1, R

→ ☐ ☐, L

1 → , L☐0 → 0, L 1 → 1, L

→ ☐ ☐, R

1 → , L☐

0 → 0, R → ☐ ☐, R

→ ☐ ☐, R

qrej

qacc

start

… 0 1 …

Run this TM for ffteen

steps.

Page 132: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

0 → , R☐ 0 → 0, R 1 → 1, R

→ ☐ ☐, L

1 → , L☐0 → 0, L 1 → 1, L

→ ☐ ☐, R

1 → , L☐

0 → 0, R → ☐ ☐, R

→ ☐ ☐, R

qrej

qacc

start

… 0 1 …

Run this TM for ffteen

steps.

Page 133: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

0 → , R☐ 0 → 0, R 1 → 1, R

→ ☐ ☐, L

1 → , L☐0 → 0, L 1 → 1, L

→ ☐ ☐, R

1 → , L☐

0 → 0, R → ☐ ☐, R

→ ☐ ☐, R

qrej

qacc

start

… 0 1 …

Run this TM for ffteen

steps.

Page 134: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

0 → , R☐ 0 → 0, R 1 → 1, R

→ ☐ ☐, L

1 → , L☐0 → 0, L 1 → 1, L

→ ☐ ☐, R

1 → , L☐

0 → 0, R → ☐ ☐, R

→ ☐ ☐, R

qrej

qacc

start

… 0 1 …

Run this TM for ffteen

steps.

Page 135: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

0 → , R☐ 0 → 0, R 1 → 1, R

→ ☐ ☐, L

1 → , L☐0 → 0, L 1 → 1, L

→ ☐ ☐, R

1 → , L☐

0 → 0, R → ☐ ☐, R

→ ☐ ☐, R

qrej

qacc

start

… 1 …

Run this TM for ffteen

steps.

Page 136: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

0 → , R☐ 0 → 0, R 1 → 1, R

→ ☐ ☐, L

1 → , L☐0 → 0, L 1 → 1, L

→ ☐ ☐, R

1 → , L☐

0 → 0, R → ☐ ☐, R

→ ☐ ☐, R

qrej

qacc

start

… 1 …

Run this TM for ffteen

steps.

Page 137: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

0 → , R☐ 0 → 0, R 1 → 1, R

→ ☐ ☐, L

1 → , L☐0 → 0, L 1 → 1, L

→ ☐ ☐, R

1 → , L☐

0 → 0, R → ☐ ☐, R

→ ☐ ☐, R

qrej

qacc

start

… 1 …

Run this TM for ffteen

steps.

Page 138: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

0 → , R☐ 0 → 0, R 1 → 1, R

→ ☐ ☐, L

1 → , L☐0 → 0, L 1 → 1, L

→ ☐ ☐, R

1 → , L☐

0 → 0, R → ☐ ☐, R

→ ☐ ☐, R

qrej

qacc

start

… …

Run this TM for ffteen

steps.

Page 139: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

0 → , R☐ 0 → 0, R 1 → 1, R

→ ☐ ☐, L

1 → , L☐0 → 0, L 1 → 1, L

→ ☐ ☐, R

1 → , L☐

0 → 0, R → ☐ ☐, R

→ ☐ ☐, R

qrej

qacc

start

… …

Run this TM for ffteen

steps.

Page 140: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

0 → , R☐ 0 → 0, R 1 → 1, R

→ ☐ ☐, L

1 → , L☐0 → 0, L 1 → 1, L

→ ☐ ☐, R

1 → , L☐

0 → 0, R → ☐ ☐, R

→ ☐ ☐, R

qrej

qacc

start

… …

Run this TM for ffteen

steps.

Page 141: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Some Verifers

● Consider ATM:

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

● Do you see why M accepts w if there is some c such that checkWillAccept(M, w, c) returns true?

● Do you see why checkWillAccept always halts?

bool checkWillAccept(TM M, string w, int c) { set up a simulation of M running on w; for (int i = 0; i < c; i++) { simulate the next step of M running on w; } return whether M is in an accepting state;}

bool checkWillAccept(TM M, string w, int c) { set up a simulation of M running on w; for (int i = 0; i < c; i++) { simulate the next step of M running on w; } return whether M is in an accepting state;}

Page 142: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

What languages are verifable?

Page 143: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Theorem: If L is a language, then there is a verifer for L if and only if L ∈ RE.

Page 144: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Where We’ve Been

NFA Regex

State Elimination

Thompson’s Algorithm

Page 145: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Where We’re Going

Verifer Recognizer

Try all certifcates

Enforce a step count

Page 146: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

● Theorem: If there is a verifer V for a language L, then L ∈ RE.

● Proof goal: Given a verifer V for a language L, fnd a way to construct a recognizer M for L.

Verifers and RE

Requirements on a verifer V for L:

V halts on all inputs.∀w ∈ Σ*. (w ∈ L ↔ ∃c ∈ Σ*. V accepts ⟨w, c⟩)

Requirements on a verifer V for L:

V halts on all inputs.∀w ∈ Σ*. (w ∈ L ↔ ∃c ∈ Σ*. V accepts ⟨w, c⟩)

Requirements on a recognizer M for L:

∀w ∈ Σ*. (w ∈ L ↔ M accepts w)

Requirements on a recognizer M for L:

∀w ∈ Σ*. (w ∈ L ↔ M accepts w)

Page 147: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

● Theorem: If there is a verifer V for a language L, then L ∈ RE.

● Proof goal: Given a verifer V for a language L, fnd a way to construct a recognizer M for L.

Verifer Vfor L

yes!

notsure

input string (w)

certifcate (c)

“Check the answer”

Verifers and RE

Page 148: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

● Theorem: If there is a verifer V for a language L, then L ∈ RE.

● Proof goal: Given a verifer V for a language L, fnd a way to construct a recognizer M for L.

Verifer Vfor L

yes!

notsure

input string (w)

certifcate (c)

“Check the answer”

ε a b aa ab ba bb aaa aab aba abb baa …

Verifers and RE

Page 149: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

● Theorem: If there is a verifer V for a language L, then L ∈ RE.

● Proof goal: Given a verifer V for a language L, fnd a way to construct a recognizer M for L.

Verifer Vfor L

yes!

notsure

input string (w)

certifcate (c)

“Check the answer”

ε a b aa ab ba bb aaa aab aba abb baa …

Verifers and RE

Page 150: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

● Theorem: If there is a verifer V for a language L, then L ∈ RE.

● Proof goal: Given a verifer V for a language L, fnd a way to construct a recognizer M for L.

ε a b aa ab ba bb aaa aab aba abb baa …

Verifer Vfor L

yes!

notsure

input string (w)

certifcate (c)

“Check the answer”

Verifers and RE

Page 151: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

● Theorem: If there is a verifer V for a language L, then L ∈ RE.

● Proof goal: Given a verifer V for a language L, fnd a way to construct a recognizer M for L.

ε a b aa ab ba bb aaa aab aba abb baa …

Verifer Vfor L

yes!

notsure

input string (w)

certifcate (c)

“Check the answer”

Verifers and RE

Page 152: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

● Theorem: If there is a verifer V for a language L, then L ∈ RE.

● Proof goal: Given a verifer V for a language L, fnd a way to construct a recognizer M for L.

ε a b aa ab ba bb aaa aab aba abb baa …

Verifer Vfor L

yes!

notsure

input string (w)

certifcate (c)

“Check the answer”

Verifers and RE

Page 153: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

● Theorem: If there is a verifer V for a language L, then L ∈ RE.

● Proof goal: Given a verifer V for a language L, fnd a way to construct a recognizer M for L.

ε a b aa ab ba bb aaa aab aba abb baa …

Verifer Vfor L

yes!

notsure

input string (w)

certifcate (c)

“Check the answer”

Verifers and RE

Page 154: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

● Theorem: If there is a verifer V for a language L, then L ∈ RE.

● Proof goal: Given a verifer V for a language L, fnd a way to construct a recognizer M for L.

ε a b aa ab ba bb aaa aab aba abb baa …

Verifer Vfor L

yes!

notsure

input string (w)

certifcate (c)

“Check the answer”

Verifers and RE

Page 155: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

● Theorem: If there is a verifer V for a language L, then L ∈ RE.

● Proof goal: Given a verifer V for a language L, fnd a way to construct a recognizer M for L.

ε a b aa ab ba bb aaa aab aba abb baa …

Verifer Vfor L

yes!

notsure

input string (w)

certifcate (c)

“Check the answer”

Verifers and RE

Page 156: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

● Theorem: If there is a verifer V for a language L, then L ∈ RE.

● Proof goal: Given a verifer V for a language L, fnd a way to construct a recognizer M for L.

ε a b aa ab ba bb aaa aab aba abb baa …

Verifer Vfor L

yes!

notsure

input string (w)

certifcate (c)

“Check the answer”

Verifers and RE

Page 157: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

● Theorem: If there is a verifer V for a language L, then L ∈ RE.

● Proof goal: Given a verifer V for a language L, fnd a way to construct a recognizer M for L.

Verifer Vfor L

yes!

notsure

input string (w)

certifcate (c)

“Check the answer”

ε a b aa ab ba bb aaa aab aba abb baa …

Verifers and RE

Page 158: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

● Theorem: If there is a verifer V for a language L, then L ∈ RE.

● Proof goal: Given a verifer V for a language L, fnd a way to construct a recognizer M for L.

ε a b aa ab ba bb aaa aab aba abb baa …

Verifer Vfor L

yes!

notsure

input string (w)

certifcate (c)

“Check the answer”

Verifers and RE

Page 159: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifers and RE

● Theorem: If there is a verifer V for a language L, then L ∈ RE.

● Proof goal: Given a verifer V for a language L, fnd a way to construct a recognizer M for L.

ε a b aa ab ba bb aaa aab aba abb baa …

Verifer Vfor L

yes!

notsure

input string (w)

certifcate (c)

“Check the answer”

Page 160: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifers and RE

● Theorem: If there is a verifer V for a language L, then L ∈ RE.

● Proof goal: Given a verifer V for a language L, fnd a way to construct a recognizer M for L.

ε a b aa ab ba bb aaa aab aba abb baa …

Verifer Vfor L

yes!

notsure

input string (w)

certifcate (c)

“Check the answer”

Page 161: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifers and RE

● Theorem: If there is a verifer V for a language L, then L ∈ RE.

● Proof goal: Given a verifer V for a language L, fnd a way to construct a recognizer M for L.

ε a b aa ab ba bb aaa aab aba abb baa …

Verifer Vfor L

yes!

notsure

input string (w)

certifcate (c)

“Check the answer”

Page 162: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifers and RE

● Theorem: If there is a verifer V for a language L, then L ∈ RE.

● Proof goal: Given a verifer V for a language L, fnd a way to construct a recognizer M for L.

ε a b aa ab ba bb aaa aab aba abb baa …

Verifer Vfor L

yes!

notsure

input string (w)

certifcate (c)

“Check the answer”

Page 163: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifers and RE

● Theorem: If there is a verifer V for a language L, then L ∈ RE.

● Proof goal: Given a verifer V for a language L, fnd a way to construct a recognizer M for L.

ε a b aa ab ba bb aaa aab aba abb baa …

Verifer Vfor L

yes!

notsure

input string (w)

certifcate (c)

“Check the answer”

Page 164: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifers and RE

● Theorem: If there is a verifer V for a language L, then L ∈ RE.

● Proof goal: Given a verifer V for a language L, fnd a way to construct a recognizer M for L.

ε a b aa ab ba bb aaa aab aba abb baa …

Verifer Vfor L

yes!

notsure

input string (w)

certifcate (c)

“Check the answer”

Page 165: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifers and RE

● Theorem: If there is a verifer V for a language L, then L ∈ RE.

● Proof goal: Given a verifer V for a language L, fnd a way to construct a recognizer M for L.

ε a b aa ab ba bb aaa aab aba abb baa …

Verifer Vfor L

yes!

notsure

input string (w)

certifcate (c)

“Check the answer”

Page 166: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifers and RE

● Theorem: If there is a verifer V for a language L, then L ∈ RE.

● Proof goal: Given a verifer V for a language L, fnd a way to construct a recognizer M for L.

ε a b aa ab ba bb aaa aab aba abb baa …

Verifer Vfor L

yes!

notsure

input string (w)

certifcate (c)

“Check the answer”

Page 167: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifers and RE

● Theorem: If there is a verifer V for a language L, then L ∈ RE.

● Proof goal: Given a verifer V for a language L, fnd a way to construct a recognizer M for L.

ε a b aa ab ba bb aaa aab aba abb baa …

Verifer Vfor L

yes!

notsure

input string (w)

certifcate (c)

“Check the answer”

Page 168: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifers and RE

● Theorem: If there is a verifer V for a language L, then L ∈ RE.

● Proof goal: Given a verifer V for a language L, fnd a way to construct a recognizer M for L.

ε a b aa ab ba bb aaa aab aba abb baa …

Verifer Vfor L

yes!

notsure

input string (w)

certifcate (c)

“Check the answer”

Page 169: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifers and RE

● Theorem: If there is a verifer V for a language L, then L ∈ RE.

● Proof goal: Given a verifer V for a language L, fnd a way to construct a recognizer M for L.

ε a b aa ab ba bb aaa aab aba abb baa …

Verifer Vfor L

yes!

notsure

input string (w)

certifcate (c)

“Check the answer”

Page 170: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifers and RE

● Theorem: If there is a verifer V for a language L, then L ∈ RE.

● Proof goal: Given a verifer V for a language L, fnd a way to construct a recognizer M for L.

ε a b aa ab ba bb aaa aab aba abb baa …

Verifer Vfor L

yes!

notsure

input string (w)

certifcate (c)

“Check the answer”

Page 171: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifers and RE

● Theorem: If there is a verifer V for a language L, then L ∈ RE.

● Proof goal: Given a verifer V for a language L, fnd a way to construct a recognizer M for L.

ε a b aa ab ba bb aaa aab aba abb baa …

Verifer Vfor L

yes!

notsure

input string (w)

certifcate (c)

“Check the answer”

Page 172: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifers and RE

● Theorem: If V is a verifer for L, then L ∈ RE.● Proof sketch: Consider the following program:

If w ∈ L, there is some c ∈ Σ* where V accepts ⟨w, c⟩. The function isInL tries all possible strings as certifcates, so it will eventually fnd c (or some other certifcate), see V accept ⟨w, c⟩, then return true. Conversely, if isInL(w) returns true, then there was some string c such that V accepted ⟨w, c⟩, so w ∈ L. ■

bool isInL(string w) { for (each string c) { if (V accepts w, c ) ⟨ ⟩ return true; }}

bool isInL(string w) { for (each string c) { if (V accepts w, c ) ⟨ ⟩ return true; }}

Page 173: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifers and RE

● Theorem: If L ∈ RE, then there is a verifer for L.● Proof goal: Beginning with a recognizer M for

the language L, show how to construct a verifer V for L.

Requirements on a verifer V for L:

V halts on all inputs.∀w ∈ Σ*. (w ∈ L ↔ ∃c ∈ Σ*. V accepts ⟨w, c⟩)

Requirements on a verifer V for L:

V halts on all inputs.∀w ∈ Σ*. (w ∈ L ↔ ∃c ∈ Σ*. V accepts ⟨w, c⟩)

Requirements on a recognizer M for L:

∀w ∈ Σ*. (w ∈ L ↔ M accepts w)

Requirements on a recognizer M for L:

∀w ∈ Σ*. (w ∈ L ↔ M accepts w)

Page 174: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

We have a recognizer for a language.We want to turn it into a verifer.Where did we see this before?

Page 175: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Some Verifers

Consider ATM:

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

Do you see why M accepts w if there is some c such that checkWillAccept(M, w, c) returns true?

Do you see why checkWillAccept always halts?

bool checkWillAccept(TM M, string w, int c) { set up a simulation of M running on w; for (int i = 0; i < c; i++) { simulate the next step of M running on w; } return whether M is in an accepting state;}

bool checkWillAccept(TM M, string w, int c) { set up a simulation of M running on w; for (int i = 0; i < c; i++) { simulate the next step of M running on w; } return whether M is in an accepting state;}

Observation: This trick of enforcing a

step count limits how long M can run for!

Observation: This trick of enforcing a

step count limits how long M can run for!

Page 176: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Verifers and RE● Theorem: If L ∈ RE, then there is a verifer for L.● Proof sketch: Let L be a RE language and let M be a recognizer

for it. Consider this function:

Note that checkIsInL always halts, since each step takes only fnite time to complete. Next, notice that if there is a c where checkIsInL(w, c) returns true, then M accepted w after running for c steps, so w ∈ L. Conversely, if w ∈ L, then M accepts w after some number of steps (call that number c). Then checkIsInL(w, c) will run M on w for c steps, watch M accept w, then return true. ■

bool checkIsInL(string w, int c) { TM M = /* hardcoded version of a recognizer for L */; set up a simulation of M running on w; for (int i = 0; i < c; i++) { simulate the next step of M running on W; } return whether M is in an accepting state; }

bool checkIsInL(string w, int c) { TM M = /* hardcoded version of a recognizer for L */; set up a simulation of M running on w; for (int i = 0; i < c; i++) { simulate the next step of M running on W; } return whether M is in an accepting state; }

Page 177: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

RE and Proofs

● Verifers and recognizers give two diferent perspectives on the “proof” intuition for RE.

● Verifers are explicitly built to check proofs that strings are in the language.● If you know that some string w belongs to the

language and you have the proof of it, you can convince someone else that w ∈ L.

● You can think of a recognizer as a device that “searches” for a proof that w ∈ L.● If it fnds it, great!● If not, it might loop forever.

Page 178: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

RE and Proofs

● If the RE languages represent languages where membership can be proven, what does a non-RE language look like?

● Intuitively, a language is not in RE if there is no general way to prove that a given string w ∈ L actually belongs to L.

● In other words, even if you knew that a string was in the language, you may never be able to convince anyone of it!

Page 179: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Time-Out for Announcements!

Page 180: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Problem Sets

● Problem Set Six is due this Friday at 3:00PM.● You can use late days here to extend the deadline as

far as Sunday at 3:00PM, but we don’t recommend this.

● Problem Set Seven goes out on Friday. It’s due next Wednesday at 3:00PM.● PS7 is shorter and designed to be able to be

completed in 5 days. ● Due to university policies, no late submissions

will be accepted for PS7. Please budget at least two hours before the deadline to submit the assignment.

Page 181: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

The Last Guide

● We’ve posted the fnal guide on the course website:● The Guide to the Lava Diagram, which

provides an intuition for how diferent classes of languages relate to one another.

● Give this a read – there’s a ton of useful information in there!

Page 182: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Final Exam Logistics

● Our fnal exam is Friday, August 16th from 7PM – 10PM in Bishop Auditorium.

● The exam is cumulative. You’re responsible for topics from PS0 – PS7 and all of the lectures up through and including today’s.

● The exam is closed-book, closed-computer, and limited-note. You can bring one double-sided sheet of 8.5” × 11” notes with you to the exam, decorated any way you’d like.

● Students with OAE accommodations: if we don’t yet have your OAE letter, please send it to us ASAP.

Page 183: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Preparing for the Exam

● We’ve posted a practice fnal exam, with solutions, to the course website. It’s on the Extra Practice page under Resources.● We’ll be posting a few more practice exams

over the next day or so!● Review Session on Monday, August 12th

here during class, led by your lovely TAs! ● Practice Final on Wednesday, August

14th from 5:30-8:30 PM upstairs in Gates 104.

Page 184: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Back to CS103!

Page 185: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Finding Non-RE Languages

Page 186: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Finding Non-RE Languages

● Right now, we know that non-RE languages exist, but we have no idea what they look like.

● How might we fnd one?

Page 187: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Languages, TMs, and TM Encodings

● Recall: The language of a TM M is the set

ℒ(M) = { w ∈ Σ* | M accepts w } ● Some of the strings in this set might be

descriptions of TMs.● What happens if we list of all Turing

machines, looking at how those TMs behave given other TMs as input?

Page 188: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

M₁

M₂

M₀

M₃

M₄

M₅

Page 189: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

All Turing machines, listed in some order.All Turing machines, listed in some order.

M₁

M₂

M₀

M₃

M₄

M₅

Page 190: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

⟨M₀⟩ ⟨M₁⟩ ⟨M₂⟩ ⟨M₃⟩ ⟨M₄⟩ ⟨M₅⟩ …

M₁

M₂

M₀

M₃

M₄

M₅

Page 191: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

All descriptions of TMs, listed in the same

order.

All descriptions of TMs, listed in the same

order.

⟨M₀⟩ ⟨M₁⟩ ⟨M₂⟩ ⟨M₃⟩ ⟨M₄⟩ ⟨M₅⟩ …

M₁

M₂

M₀

M₃

M₄

M₅

Page 192: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Acc No No Acc Acc No …

⟨M₀⟩ ⟨M₁⟩ ⟨M₂⟩ ⟨M₃⟩ ⟨M₄⟩ ⟨M₅⟩ …

M₁

M₂

M₀

M₃

M₄

M₅

Page 193: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Acc No No Acc Acc No …

Acc Acc Acc Acc Acc Acc …

⟨M₀⟩ ⟨M₁⟩ ⟨M₂⟩ ⟨M₃⟩ ⟨M₄⟩ ⟨M₅⟩ …

M₁

M₂

M₀

M₃

M₄

M₅

Page 194: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Acc No No Acc Acc No …

Acc Acc Acc Acc Acc Acc …

Acc Acc Acc Acc Acc Acc …

⟨M₀⟩ ⟨M₁⟩ ⟨M₂⟩ ⟨M₃⟩ ⟨M₄⟩ ⟨M₅⟩ …

M₁

M₂

M₀

M₃

M₄

M₅

Page 195: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Acc No No Acc Acc No …

Acc Acc Acc Acc Acc Acc …

Acc Acc Acc Acc Acc Acc …

No Acc Acc No Acc Acc …

⟨M₀⟩ ⟨M₁⟩ ⟨M₂⟩ ⟨M₃⟩ ⟨M₄⟩ ⟨M₅⟩ …

M₁

M₂

M₀

M₃

M₄

M₅

Page 196: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Acc No No Acc Acc No …

Acc Acc Acc Acc Acc Acc …

Acc Acc Acc Acc Acc Acc …

No Acc Acc No Acc Acc …

Acc No Acc No Acc No …

⟨M₀⟩ ⟨M₁⟩ ⟨M₂⟩ ⟨M₃⟩ ⟨M₄⟩ ⟨M₅⟩ …

M₁

M₂

M₀

M₃

M₄

M₅

Page 197: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Acc No No Acc Acc No …

Acc Acc Acc Acc Acc Acc …

Acc Acc Acc Acc Acc Acc …

No Acc Acc No Acc Acc …

Acc No Acc No Acc No …

No No Acc Acc No No …

⟨M₀⟩ ⟨M₁⟩ ⟨M₂⟩ ⟨M₃⟩ ⟨M₄⟩ ⟨M₅⟩ …

M₁

M₂

M₀

M₃

M₄

M₅

Page 198: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Acc No No Acc Acc No …

Acc Acc Acc Acc Acc Acc …

Acc Acc Acc Acc Acc Acc …

No Acc Acc No Acc Acc …

Acc No Acc No Acc No …

No No Acc Acc No No …

… … … … … … …

⟨M₀⟩ ⟨M₁⟩ ⟨M₂⟩ ⟨M₃⟩ ⟨M₄⟩ ⟨M₅⟩ …

M₁

M₂

M₀

M₃

M₄

M₅

Page 199: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Acc No No Acc Acc No …

Acc Acc Acc Acc Acc Acc …

Acc Acc Acc Acc Acc Acc …

No Acc Acc No Acc Acc …

Acc No Acc No Acc No …

No No Acc Acc No No …

… … … … … … …

⟨M₀⟩ ⟨M₁⟩ ⟨M₂⟩ ⟨M₃⟩ ⟨M₄⟩ ⟨M₅⟩ …

M₁

M₂

M₀

M₃

M₄

M₅

Page 200: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Acc No No Acc Acc No …

Acc Acc Acc Acc Acc Acc …

Acc Acc Acc Acc Acc Acc …

No Acc Acc No Acc Acc …

Acc No Acc No Acc No …

No No Acc Acc No No …

… … … … … … …

Acc Acc Acc No Acc No …

⟨M₀⟩ ⟨M₁⟩ ⟨M₂⟩ ⟨M₃⟩ ⟨M₄⟩ ⟨M₅⟩ …

M₁

M₂

M₀

M₃

M₄

M₅

Page 201: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Acc No No Acc Acc No …

Acc Acc Acc Acc Acc Acc …

Acc Acc Acc Acc Acc Acc …

No Acc Acc No Acc Acc …

Acc No Acc No Acc No …

No No Acc Acc No No …

… … … … … … …

Acc Acc Acc No Acc No …

Flip all “accept” to

“no” and vice-versa

Flip all “accept” to

“no” and vice-versa

No No No Acc No Acc …

⟨M₀⟩ ⟨M₁⟩ ⟨M₂⟩ ⟨M₃⟩ ⟨M₄⟩ ⟨M₅⟩ …

M₁

M₂

M₀

M₃

M₄

M₅

Page 202: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Acc No No Acc Acc No …

Acc Acc Acc Acc Acc Acc …

Acc Acc Acc Acc Acc Acc …

No Acc Acc No Acc Acc …

Acc No Acc No Acc No …

No No Acc Acc No No …

… … … … … … …

No No No Acc No Acc …

⟨M₀⟩ ⟨M₁⟩ ⟨M₂⟩ ⟨M₃⟩ ⟨M₄⟩ ⟨M₅⟩ …

M₁

M₂

M₀

M₃

M₄

M₅

Page 203: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Acc No No Acc Acc No …

Acc Acc Acc Acc Acc Acc …

Acc Acc Acc Acc Acc Acc …

No Acc Acc No Acc Acc …

Acc No Acc No Acc No …

No No Acc Acc No No …

… … … … … … …

No No No Acc No Acc …

What TM has this behavior?What TM has this behavior?

⟨M₀⟩ ⟨M₁⟩ ⟨M₂⟩ ⟨M₃⟩ ⟨M₄⟩ ⟨M₅⟩ …

M₁

M₂

M₀

M₃

M₄

M₅

Page 204: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Acc No No Acc Acc No …

Acc Acc Acc Acc Acc Acc …

Acc Acc Acc Acc Acc Acc …

No Acc Acc No Acc Acc …

Acc No Acc No Acc No …

No No Acc Acc No No …

… … … … … … …

No No No Acc No Acc …

⟨M₀⟩ ⟨M₁⟩ ⟨M₂⟩ ⟨M₃⟩ ⟨M₄⟩ ⟨M₅⟩ …

M₁

M₂

M₀

M₃

M₄

M₅

Page 205: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Acc No No Acc Acc No …

Acc Acc Acc Acc Acc Acc …

Acc Acc Acc Acc Acc Acc …

No Acc Acc No Acc Acc …

Acc No Acc No Acc No …

No No Acc Acc No No …

… … … … … … …

No No No Acc No Acc …

⟨M₀⟩ ⟨M₁⟩ ⟨M₂⟩ ⟨M₃⟩ ⟨M₄⟩ ⟨M₅⟩ …

M₁

M₂

M₀

M₃

M₄

M₅

Page 206: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Acc No No Acc Acc No …

Acc Acc Acc Acc Acc Acc …

Acc Acc Acc Acc Acc Acc …

No Acc Acc No Acc Acc …

Acc No Acc No Acc No …

No No Acc Acc No No …

… … … … … … …

No No No Acc No Acc …

⟨M₀⟩ ⟨M₁⟩ ⟨M₂⟩ ⟨M₃⟩ ⟨M₄⟩ ⟨M₅⟩ …

M₁

M₂

M₀

M₃

M₄

M₅

Page 207: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Acc No No Acc Acc No …

Acc Acc Acc Acc Acc Acc …

Acc Acc Acc Acc Acc Acc …

No Acc Acc No Acc Acc …

Acc No Acc No Acc No …

No No Acc Acc No No …

… … … … … … …

No No No Acc No Acc …

⟨M₀⟩ ⟨M₁⟩ ⟨M₂⟩ ⟨M₃⟩ ⟨M₄⟩ ⟨M₅⟩ …

M₁

M₂

M₀

M₃

M₄

M₅

Page 208: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Acc No No Acc Acc No …

Acc Acc Acc Acc Acc Acc …

Acc Acc Acc Acc Acc Acc …

No Acc Acc No Acc Acc …

Acc No Acc No Acc No …

No No Acc Acc No No …

… … … … … … …

No No No Acc No Acc …

⟨M₀⟩ ⟨M₁⟩ ⟨M₂⟩ ⟨M₃⟩ ⟨M₄⟩ ⟨M₅⟩ …

M₁

M₂

M₀

M₃

M₄

M₅

Page 209: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Acc No No Acc Acc No …

Acc Acc Acc Acc Acc Acc …

Acc Acc Acc Acc Acc Acc …

No Acc Acc No Acc Acc …

Acc No Acc No Acc No …

No No Acc Acc No No …

… … … … … … …

No No No Acc No Acc …

⟨M₀⟩ ⟨M₁⟩ ⟨M₂⟩ ⟨M₃⟩ ⟨M₄⟩ ⟨M₅⟩ …

M₁

M₂

M₀

M₃

M₄

M₅

Page 210: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Acc No No Acc Acc No …

Acc Acc Acc Acc Acc Acc …

Acc Acc Acc Acc Acc Acc …

No Acc Acc No Acc Acc …

Acc No Acc No Acc No …

No No Acc Acc No No …

… … … … … … …

No No No Acc No Acc …

⟨M₀⟩ ⟨M₁⟩ ⟨M₂⟩ ⟨M₃⟩ ⟨M₄⟩ ⟨M₅⟩ …

M₁

M₂

M₀

M₃

M₄

M₅

Page 211: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Acc

No

Acc

No

No Acc

Acc No No Acc Acc No …

Acc Acc Acc Acc Acc Acc …

Acc Acc Acc Acc Acc Acc …

No Acc Acc No Acc Acc …

Acc No Acc No No …

No No Acc Acc No No …

… … … … … … …

No No No Acc Acc …

⟨M₀⟩ ⟨M₁⟩ ⟨M₂⟩ ⟨M₃⟩ ⟨M₄⟩ ⟨M₅⟩ …

M₁

M₂

M₀

M₃

M₄

M₅

Page 212: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Acc

No

No

Acc

Acc

No

No

Acc …

Acc No No Acc Acc No …

Acc Acc Acc Acc Acc Acc …

Acc Acc Acc Acc Acc Acc …

No Acc Acc No Acc Acc …

Acc No Acc No No …

No No Acc Acc No …

… … … … … … …

No No No Acc …

⟨M₀⟩ ⟨M₁⟩ ⟨M₂⟩ ⟨M₃⟩ ⟨M₄⟩ ⟨M₅⟩ …

M₁

M₂

M₀

M₃

M₄

M₅

Page 213: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

No

Acc

Acc

No

No

Acc

Acc

No

Acc No No Acc Acc No …

Acc Acc Acc Acc Acc Acc …

Acc Acc Acc Acc Acc Acc …

No Acc Acc No Acc Acc …

Acc No Acc No No …

No No Acc Acc No …

… … … … … …

No No No Acc

⟨M₀⟩ ⟨M₁⟩ ⟨M₂⟩ ⟨M₃⟩ ⟨M₄⟩ ⟨M₅⟩ …

M₁

M₂

M₀

M₃

M₄

M₅

Page 214: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

No

Acc

Acc

No

No

Acc

Acc

No

Acc No No Acc Acc No …

Acc Acc Acc Acc Acc Acc …

Acc Acc Acc Acc Acc Acc …

No Acc Acc No Acc Acc …

Acc No Acc No No …

No No Acc Acc No …

… … … … … …

No No No Acc

No TM has this

behavior!

No TM has this

behavior!

⟨M₀⟩ ⟨M₁⟩ ⟨M₂⟩ ⟨M₃⟩ ⟨M₄⟩ ⟨M₅⟩ …

M₁

M₂

M₀

M₃

M₄

M₅

Page 215: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

No

Acc

Acc

No

No

Acc

Acc

No

Acc No No Acc Acc No …

Acc Acc Acc Acc Acc Acc …

Acc Acc Acc Acc Acc Acc …

No Acc Acc No Acc Acc …

Acc No Acc No No …

No No Acc Acc No …

… … … … … …

No No No Acc

⟨M₀⟩ ⟨M₁⟩ ⟨M₂⟩ ⟨M₃⟩ ⟨M₄⟩ ⟨M₅⟩ …

M₁

M₂

M₀

M₃

M₄

M₅

Page 216: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

No

Acc

Acc

No

No

Acc

Acc

No

Acc No No Acc Acc No …

Acc Acc Acc Acc Acc Acc …

Acc Acc Acc Acc Acc Acc …

No Acc Acc No Acc Acc …

Acc No Acc No No …

No No Acc Acc No …

… … … … … …

No No No Acc

⟨M₀⟩ ⟨M₁⟩ ⟨M₂⟩ ⟨M₃⟩ ⟨M₄⟩ ⟨M₅⟩ …

M₁

M₂

M₀

M₃

M₄

M₅

Page 217: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

No

Acc

Acc

No

No

Acc

Acc

No

Acc No No Acc Acc No …

Acc Acc Acc Acc Acc Acc …

Acc Acc Acc Acc Acc Acc …

No Acc Acc No Acc Acc …

Acc No Acc No No …

No No Acc Acc No …

… … … … … …

No No No Acc

“The language of allTMs that do not accept

their descriptions.”

⟨M₀⟩ ⟨M₁⟩ ⟨M₂⟩ ⟨M₃⟩ ⟨M₄⟩ ⟨M₅⟩ …

M₁

M₂

M₀

M₃

M₄

M₅

Page 218: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

No

Acc

Acc

No

No

Acc

Acc

No

Acc No No Acc Acc No …

Acc Acc Acc Acc Acc Acc …

Acc Acc Acc Acc Acc Acc …

No Acc Acc No Acc Acc …

Acc No Acc No No …

No No Acc Acc No …

… … … … … …

No No No Acc

{ ⟨M⟩ | M is a TM that does not accept ⟨M⟩ }

⟨M₀⟩ ⟨M₁⟩ ⟨M₂⟩ ⟨M₃⟩ ⟨M₄⟩ ⟨M₅⟩ …

M₁

M₂

M₀

M₃

M₄

M₅

Page 219: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Diagonalization Revisited

● The diagonalization language, which we denote LD, is defned as

LD = { ⟨M⟩ | M is a TM and M does not accept ⟨M⟩ }

● We constructed this language to be diferent from the language of every TM.

● Therefore, LD ∉ RE! Let’s go prove this.

Page 220: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

LD = { ⟨M⟩ | M is a TM and M does not accept ⟨M⟩ }

Theorem: LD ∉ RE.

Proof: By contradiction; assume that LD ∈ RE. This means thatthere is a TM R where (ℒ R) = LD.

Now, what happens when we run R on ⟨R⟩? We know that

R accepts ⟨R⟩ if and only if ⟨R⟩ ∈ (ℒ R).

Since (ℒ R) = LD, the above expression simplifes to

R accepts ⟨R⟩ if and only if ⟨R⟩ ∈ LD.

Finally, by defnition of LD, we know that ⟨R⟩ ∈ LD if and only if R does not accept ⟨R⟩. Therefore, we see that

R accepts ⟨R⟩ if and only if R doesn’t accept ⟨R⟩.

This is impossible. We’ve reached a contradiction, so our assumption was wrong, and so LD ∉ RE. ■

Page 221: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

RegularLanguages CFLs

All Languages

R RE

LD

ATM

HALT

Page 222: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

What This Means

● On a deeper philosophical level, the fact that non-RE languages exist supports the following claim:

There are statements thatare true but not provable.

● Intuitively, given any non-RE language, there will be some string in the language that cannot be proven to be in the language.

● This result can be formalized as a result called Gödel's incompleteness theorem, one of the most important mathematical results of all time.

● Want to learn more? Take Phil 152 or CS154!

Page 223: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

What This Means

● On a more philosophical note, you could interpret the previous result in the following way:

There are inherent limits about what mathematics can teach us.

● There's no automatic way to do math. There are true statements that we can't prove.

● That doesn't mean that mathematics is worthless. It just means that we need to temper our expectations about it.

Page 224: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Where We Stand

● We've just done a crazy, whirlwind tour of computability theory:● The Church-Turing thesis tells us that TMs give us a

mechanism for studying computation in the abstract.● Universal computers – computers as we know them – are not

just a stroke of luck. The existence of the universal TM ensures that such computers must exist.

● Self-reference is an inherent consequence of computational power.

● Undecidable problems exist partially as a consequence of the above and indicate that there are statements whose truth can't be determined by computational processes.

● Unrecognizable problems are out there and can be discovered via diagonalization. They imply there are limits to mathematical proof.

Page 225: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

The Big Picture

DFA

NFA

Regex

CFG Decider

Recog-nizer

Verifer

REG

CFLR

RE

Page 226: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Where We've Been

● The class R represents problems that can be solved by a computer.

● The class RE represents problems where “yes” answers can be verifed by a computer.

The mapping reduction can be used to fnd connections between problems.

Page 227: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Where We're Going

● The class P represents problems that can be solved eficiently by a computer.

● The class NP represents problems where “yes” answers can be verifed eficiently by a computer.

Page 228: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

Next Time

● Introduction to Complexity Theory● Not all decidable problems are created

equal!

● The Classes P and NP● Two fundamental and important complexity

classes.

● The P NP Question≟

● A literal million-dollar question!

Page 229: Unsolvable Problemsweb.stanford.edu/class/archive/cs/cs103/cs103.1198/lectures/19... · A Decider for HALT Let’s suppose that, somehow, we managed to build a decider for HALT =

This is the end of the content we’ll be testing you on for the fnal exam!

The next two lectures on Complexity Theory are purely for your own interest.