stanford universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/guid… · what does...
TRANSCRIPT
![Page 1: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/1.jpg)
The Guide to Self-Reference
☺
![Page 2: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/2.jpg)
Hi everybody!
![Page 3: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/3.jpg)
Self-reference proofs can bepretty hard to understand the
first time you see them.
![Page 4: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/4.jpg)
If you're confused – that's okay!It's totally normal. This stuff is
tricky.
![Page 5: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/5.jpg)
Once you get a better sense forhow to structure these proofs,
I think you'll find that they're notas bad as they initially seem.
![Page 6: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/6.jpg)
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();
}}
Try running this program on any input. What happens if
… this program accepts its input?It rejects the input!
… this program doesn't accept its input?It accepts the input!
Try running this program on any input. What happens if
… this program accepts its input?It rejects the input!
… this program doesn't accept its input?It accepts the input!
This lecture slide was the first time that we really saw self-reference,and a lot of you got pretty tripped
up by what was going on.
![Page 7: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/7.jpg)
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();
}}
Try running this program on any input. What happens if
… this program accepts its input?It rejects the input!
… this program doesn't accept its input?It accepts the input!
Try running this program on any input. What happens if
… this program accepts its input?It rejects the input!
… this program doesn't accept its input?It accepts the input!
Part of the reason why this can betricky is that what you're looking atis a finished product. If you don't
have a sense of where it comes from,it's really hard to understand!
![Page 8: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/8.jpg)
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();
}}
Try running this program on any input. What happens if
… this program accepts its input?It rejects the input!
… this program doesn't accept its input?It accepts the input!
Try running this program on any input. What happens if
… this program accepts its input?It rejects the input!
… this program doesn't accept its input?It accepts the input!
Let's see where it comes from!
We'll take it from the top.
![Page 9: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/9.jpg)
Let's try to use self-referenceto prove that ATM is undecidable.
![Page 10: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/10.jpg)
At a high level, we're going to doa proof by contradiction.
![Page 11: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/11.jpg)
ATM ∈ R
We're going to start off byassuming that ATM is decidable.
![Page 12: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/12.jpg)
ATM ∈ R
Somehow, we're going to try touse this to get to a contradiction.
Contradiction!
![Page 13: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/13.jpg)
ATM ∈ R
If we can get a contradiction –any contradiction – we'll see
that our assumption was wrong.
Contradiction!
![Page 14: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/14.jpg)
ATM ∈ R
The challenge is figuring outexactly how to go and do this.
Contradiction!
![Page 15: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/15.jpg)
ATM ∈ R
Rather than just jumping all theway to the end, let's see whatour initial assumption tells us.
Contradiction!
![Page 16: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/16.jpg)
ATM ∈ R
We're assuming that ATM isdecidable. What does that mean?
Contradiction!
![Page 17: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/17.jpg)
ATM ∈ R
Well, a language is decidable ifthere's a decider for it, so that
means there's some decider for ATM.Let's call that decider D.
Contradiction!
There is a decider D for ATM
![Page 18: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/18.jpg)
ATM ∈ R
What might this decider look like?
Contradiction!
There is a decider D for ATM
![Page 19: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/19.jpg)
ATM ∈ R
A decider for a language is aTuring machine with a few key
properties.
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
![Page 20: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/20.jpg)
ATM ∈ R
First, it has to always halt.
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
![Page 21: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/21.jpg)
ATM ∈ R
That means that if you give itany input, it has to either accept
or reject it. We'll visualize thiswith these two possible outputs.
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
![Page 22: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/22.jpg)
ATM ∈ R
Next, the decider has to tell ussomething about ATM.
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
![Page 23: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/23.jpg)
ATM ∈ R
Next, the decider has to tell ussomething about ATM.
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
As a reminder, ATM is the language
{ ⟨M, w⟩ | M is a TM and M accepts w }
![Page 24: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/24.jpg)
ATM ∈ R
Specifically, the decider D needsto take in an input and tell uswhether that input is in ATM
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
As a reminder, ATM is the language
{ ⟨M, w⟩ | M is a TM and M accepts w }
![Page 25: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/25.jpg)
ATM ∈ R
ATM is a language of pairs ofTMs and strings, so D will
take in two inputs, a machineM and a string w.
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
As a reminder, ATM is the language
{ ⟨M, w⟩ | M is a TM and M accepts w }
M
w
![Page 26: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/26.jpg)
ATM ∈ R
If D accepts its input, itmeans that ⟨M, w⟩ is in ATM.
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
As a reminder, ATM is the language
{ ⟨M, w⟩ | M is a TM and M accepts w }
M
w
Yes, M accepts w.
![Page 27: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/27.jpg)
ATM ∈ R
Otherwise, if D rejects its input,it means that M doesn't accept w.
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
As a reminder, ATM is the language
{ ⟨M, w⟩ | M is a TM and M accepts w }
M
w
Yes, M accepts w.
No, M does not accept w.
![Page 28: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/28.jpg)
ATM ∈ R
So now we've got this TM Dlying around. What can we do
with it?
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
![Page 29: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/29.jpg)
ATM ∈ R
We've seen the idea that TMs canrun other TMs as subroutines. Thismeans we can write programs that
use D as a subroutine.
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
![Page 30: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/30.jpg)
ATM ∈ R
Since TMs are kinda like programs,we can imagine that D is a helper
method that looks like this.
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
bool willAccept(string program, string input)
![Page 31: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/31.jpg)
ATM ∈ R
In mathematics, the convention isto use single-letter variable names
for everything, which isn't goodprogramming style.
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
bool willAccept(string program, string input)
![Page 32: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/32.jpg)
ATM ∈ R
Here, the method name(willAccept) is just a fancier and
more descriptive name for D.
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
bool willAccept(string program, string input)
willAccept
![Page 33: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/33.jpg)
ATM ∈ R
The two arguments to willAcceptthen correspond to the inputs to
the decider D.
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
bool willAccept(string program, string input)
willAcceptprogram
input
![Page 34: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/34.jpg)
ATM ∈ R
When thinking of D as a decider,we think of it accepting or
rejecting. In programming-speak,it's like returning a boolean.
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
bool willAccept(string program, string input)
willAcceptprogram
input
![Page 35: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/35.jpg)
ATM ∈ R
So at this point we've just set upthe fact that this subroutine exists.
What exactly are we going to dowith it?
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
bool willAccept(string program, string input)
willAcceptprogram
input
![Page 36: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/36.jpg)
ATM ∈ R
Ultimately, we're trying to geta contradiction.
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
bool willAccept(string program, string input)
willAcceptprogram
input
![Page 37: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/37.jpg)
ATM ∈ R
Specifically, we're going to builda program – which we'll call P –
that has some really brokenbehavior... it will accept its input
if and only if it doesn't acceptits input!
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
bool willAccept(string program, string input)
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
![Page 38: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/38.jpg)
ATM ∈ R
If you're wondering how on earthyou were supposed to figure outthat that's the next step, don't
panic. The first time you see it, itlooks totally crazy. Once you've
done this a few times, you'llget a lot more comfortable with it.
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
bool willAccept(string program, string input)
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
![Page 39: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/39.jpg)
ATM ∈ R
Now, we haven't actually writtenthis program P yet. That's the
next step.
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
bool willAccept(string program, string input)
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
![Page 40: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/40.jpg)
ATM ∈ R
If you look at what we've said,right now we have a goal of whatP should do, not how P actually
does that.
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
bool willAccept(string program, string input)
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
![Page 41: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/41.jpg)
ATM ∈ R
You can think of this requirementas a sort of “design specification.”
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
bool willAccept(string program, string input)
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
![Page 42: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/42.jpg)
ATM ∈ R
Let's actually go write out a specfor what P needs to do!
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
bool willAccept(string program, string input)
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:
![Page 43: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/43.jpg)
ATM ∈ R
Since this requirement is an “if andonly if,” we can break it down into
two cases.
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
bool willAccept(string program, string input)
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:
![Page 44: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/44.jpg)
ATM ∈ R
First, if this program P is supposedto accept its input, then it needs
to not accept its input.
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
bool willAccept(string program, string input)
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.
![Page 45: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/45.jpg)
ATM ∈ R
Next, if this program P is supposedto not accept its input, then it
needs to accept its input.
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
bool willAccept(string program, string input)
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
![Page 46: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/46.jpg)
ATM ∈ R
We now have a specification forwhat program P is supposed to do.
Let's see how to write it!
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
bool willAccept(string program, string input)
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
![Page 47: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/47.jpg)
// Program P
int main() { string me = mySource(); string input = getInput();
if (willAccept(me, input)) { reject(); } else { accept(); }}
ATM ∈ R
We'll write it in the spaceover to the left.
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
bool willAccept(string program, string input)
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
![Page 48: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/48.jpg)
// Program P
int main() { string me = mySource(); string input = getInput();
if (willAccept(me, input)) { reject(); } else { accept(); }}
ATM ∈ R
Like most programs, ourprogram begins execution
in main().
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
bool willAccept(string program, string input)
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
![Page 49: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/49.jpg)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { reject(); } else { accept(); }}
ATM ∈ R
Our program needs toget some input, so let's
do that here.
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
bool willAccept(string program, string input)
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
![Page 50: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/50.jpg)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { reject(); } else { accept(); }}
ATM ∈ R
Now, we somehow need tomeet the design spec given
above.
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
bool willAccept(string program, string input)
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
![Page 51: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/51.jpg)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { reject(); } else { accept(); }}
ATM ∈ R
That means we need to beable to figure out whether
we're going to accept.
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
bool willAccept(string program, string input)
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
![Page 52: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/52.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { reject(); } else { accept(); }}
ATM ∈ R
We've got this handy methodlying around that will let us
know whether any program willaccept any input.
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
![Page 53: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/53.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { reject(); } else { accept(); }}
ATM ∈ R
What if we had program P askwhether it was going to accept
something?
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
![Page 54: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/54.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { reject(); } else { accept(); }}
ATM ∈ R
Crazy as it seems, that'ssomething we can actually do!
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
![Page 55: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/55.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { reject(); } else { accept(); }}
ATM ∈ R
First, let's have our programget its own source code.
(We know this is possible! Wesaw how to do it in class.)
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
![Page 56: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/56.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { reject(); } else { accept(); }}
ATM ∈ R
Next, let's call this magicwillAccept method to ask whether
we (program P) are going toaccept our input.
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
![Page 57: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/57.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { reject(); } else { accept(); }}
ATM ∈ R
Now, let's look back at ourdesign specification and see what
we need to do.
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
![Page 58: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/58.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { reject(); } else { accept(); }}
ATM ∈ R
Our specification says that, ifthis program is supposed to
accept its input, then it needsto not accept its input.
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
![Page 59: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/59.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { reject(); } else { accept(); }}
ATM ∈ R
What's something we can do tonot accept our input?
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
![Page 60: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/60.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { reject(); } else { accept(); }}
ATM ∈ R
There's a couple of optionshere, actually. One of them is
to just go and reject!
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
![Page 61: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/61.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { reject(); } else { accept(); }}
ATM ∈ R
So we've taken care of thatpart of the design.
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
![Page 62: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/62.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { reject(); } else { accept(); }}
ATM ∈ R
What about this part?
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
![Page 63: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/63.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { reject(); } else { accept(); }}
ATM ∈ R
This says that if we aren'tsupposed to accept the input,
then we should accept theinput.
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
![Page 64: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/64.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { reject(); } else { accept(); }}
ATM ∈ R
So let's go add this line toour program.
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
![Page 65: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/65.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { reject(); } else { accept(); }}
ATM ∈ R
And hey! We're done with thispart of the design spec.
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
![Page 66: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/66.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { reject(); } else { accept(); }}
ATM ∈ R
So let's take a quick look overour program P.
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
![Page 67: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/67.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { reject(); } else { accept(); }}
ATM ∈ R
This is what we said that Pwas supposed to do.
And hey! That's what it does.
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
![Page 68: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/68.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { reject(); } else { accept(); }}
ATM ∈ R
The whole point of this exercisewas to get a contradiction.
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
![Page 69: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/69.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { reject(); } else { accept(); }}
ATM ∈ R
And, indeed, that's what we'vedone! There's a contradictionhere because P accepts if and
only if it doesn't accept.
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
![Page 70: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/70.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { reject(); } else { accept(); }}
ATM ∈ R
So if you trace through theimplications here...
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
![Page 71: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/71.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { reject(); } else { accept(); }}
ATM ∈ R
So if you trace through theimplications here...
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
![Page 72: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/72.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { reject(); } else { accept(); }}
ATM ∈ R
So if you trace through theimplications here...
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
![Page 73: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/73.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { reject(); } else { accept(); }}
ATM ∈ R
So if you trace through theimplications here...
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
![Page 74: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/74.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { reject(); } else { accept(); }}
ATM ∈ R
You can see that the startingassumption that ATM isdecidable leads to a
contradiction – we're done!
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
![Page 75: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/75.jpg)
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();
}}
Try running this program on any input. What happens if
… this program accepts its input?It rejects the input!
… this program doesn't accept its input?It accepts the input!
Try running this program on any input. What happens if
… this program accepts its input?It rejects the input!
… this program doesn't accept its input?It accepts the input!
Here's that initial lectureslide again.
![Page 76: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/76.jpg)
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();
}}
Try running this program on any input. What happens if
… this program accepts its input?It rejects the input!
… this program doesn't accept its input?It accepts the input!
Try running this program on any input. What happens if
… this program accepts its input?It rejects the input!
… this program doesn't accept its input?It accepts the input!
Take a look at it moreclosely.
![Page 77: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/77.jpg)
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();
}}
Try running this program on any input. What happens if
… this program accepts its input?It rejects the input!
… this program doesn't accept its input?It accepts the input!
Try running this program on any input. What happens if
… this program accepts its input?It rejects the input!
… this program doesn't accept its input?It accepts the input!
Recognize this code? Now youknow where it comes from!
![Page 78: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/78.jpg)
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();
}}
Try running this program on any input. What happens if
… this program accepts its input?It rejects the input!
… this program doesn't accept its input?It accepts the input!
Try running this program on any input. What happens if
… this program accepts its input?It rejects the input!
… this program doesn't accept its input?It accepts the input!
We created it to get thesecontradictions.
![Page 79: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/79.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { reject(); } else { accept(); }}
ATM ∈ R
This might seem like a lot – andin many ways it is.
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
![Page 80: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/80.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { reject(); } else { accept(); }}
ATM ∈ R
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
The key idea here is what'sgiven over there on the left
column.
![Page 81: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/81.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { reject(); } else { accept(); }}
ATM ∈ R
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
This progression comes up inall the self-reference proofs
we've done this quarter.
![Page 82: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/82.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { reject(); } else { accept(); }}
ATM ∈ R
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
We'll do another example ofthis in a little bit.
![Page 83: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/83.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { reject(); } else { accept(); }}
ATM ∈ R
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
Before we move on, though,I thought I'd take a minute to
talk about a few commonquestions we get.
![Page 84: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/84.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { reject(); } else { accept(); }}
ATM ∈ R
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
First, let's jump back to thispart of the program P that
we wrote.
![Page 85: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/85.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { reject(); } else { accept(); }}
ATM ∈ R
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
This is the case where programP is supposed to accept its
input. We need to program itso that it doesn't.
![Page 86: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/86.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { reject(); } else { accept(); }}
ATM ∈ R
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
Here, the specific way we endedup doing that was by havingprogram P reject its input.
![Page 87: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/87.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { reject(); } else { accept(); }}
ATM ∈ R
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
I mentioned that there wereother things we could do here
as well.
![Page 88: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/88.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { while (true) { } } else { accept(); }}
ATM ∈ R
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
Here's another option. We couldhave the program go into an
infinite loop in this case.
![Page 89: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/89.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { while (true) { } } else { accept(); }}
ATM ∈ R
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
The design spec here says thatP needs to not accept in thiscase, and indeed, that's what
happens!
![Page 90: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/90.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { while (true) { } } else { accept(); }}
ATM ∈ R
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
A lot of people ask us whetherthis is allowed, since we wereassuming we had a decider
and deciders can't loop.
![Page 91: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/91.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { while (true) { } } else { accept(); }}
ATM ∈ R
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
Turns out, this is totally fine!
![Page 92: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/92.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { while (true) { } } else { accept(); }}
ATM ∈ R
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
There are two differentprograms here.
![Page 93: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/93.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { while (true) { } } else { accept(); }}
ATM ∈ R
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
First, there's this decider D.D is a decider, so it's
required to halt on all inputs.
![Page 94: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/94.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { while (true) { } } else { accept(); }}
ATM ∈ R
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
There's also this program P.Program P isn't the deciderfor ATM, so it's not required
to halt on all inputs.
![Page 95: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/95.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { while (true) { } } else { accept(); }}
ATM ∈ R
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
Going forward, remember thatthese proofs involve two
different programs: the deciderfor the language, and theself-referential program.
![Page 96: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/96.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { while (true) { } } else { accept(); }}
ATM ∈ R
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
The decider is always requiredto halt, but the program P
is not.
![Page 97: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/97.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { while (true) { } } else { accept(); }}
ATM ∈ R
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
Let's undo all these changesso that we can talk about
the next common question.
![Page 98: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/98.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { reject(); } else { accept(); }}
ATM ∈ R
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
Much better!
![Page 99: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/99.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { reject(); } else { accept(); }}
ATM ∈ R
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
On to the next question.
![Page 100: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/100.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { reject(); } else { accept(); }}
ATM ∈ R
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
A lot of people take a look atthe program we've written...
![Page 101: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/101.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { reject(); } else { accept(); }}
ATM ∈ R
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
… and ask what happens if wetake these two lines...
![Page 102: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/102.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { accept(); } else { reject(); }}
ATM ∈ R
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
… and swap them like this.
![Page 103: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/103.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { accept(); } else { reject(); }}
ATM ∈ R
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
Usually, people ask whether wecould have just done this and
ended up proving that ATM ∈ R.
![Page 104: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/104.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { accept(); } else { reject(); }}
ATM ∈ R
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
Turns out, that doesn't work.Let's see why.
![Page 105: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/105.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { accept(); } else { reject(); }}
ATM ∈ R
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
Notice that this program Pdoesn't have the behavior given
over here.
![Page 106: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/106.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { accept(); } else { reject(); }}
ATM ∈ R
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does accept its input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
If you think about the behaviorit does have, it looks more
like this.
![Page 107: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/107.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { accept(); } else { reject(); }}
ATM ∈ R
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does accept its input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
Notice that this is a truestatement.
![Page 108: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/108.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { accept(); } else { reject(); }}
ATM ∈ R
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does accept its input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
Originally, we got a contradictionhere.
![Page 109: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/109.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { accept(); } else { reject(); }}
ATM ∈ R
⊤
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does accept its input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
Instead, we've shown thatwe end up at a true statement.
![Page 110: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/110.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { accept(); } else { reject(); }}
ATM ∈ R
⊤
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does accept its input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
However, take a minute to lookat the giant implication given
here.
![Page 111: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/111.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { accept(); } else { reject(); }}
ATM ∈ R
⊤
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does accept its input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
Overall, this shows that
ATM ∈ R → ⊤
![Page 112: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/112.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { accept(); } else { reject(); }}
ATM ∈ R
⊤
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does accept its input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
Does this statement say anythingabout whether ATM is decidable?
ATM ∈ R → ⊤
![Page 113: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/113.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { accept(); } else { reject(); }}
ATM ∈ R
⊤
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does accept its input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
Nope! Remember, anythingimplies a true statement.
ATM ∈ R → ⊤
![Page 114: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/114.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { accept(); } else { reject(); }}
ATM ∈ R
⊤
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does accept its input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
We have no way of knowingwhether ATM ∈ R or not just
by looking at this statement.ATM ∈ R → ⊤
![Page 115: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/115.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { accept(); } else { reject(); }}
ATM ∈ R
⊤
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does accept its input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
The fact that we didn't geta contradiction doesn't mean
that ATM is decidable.ATM ∈ R → ⊤
![Page 116: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/116.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { accept(); } else { reject(); }}
ATM ∈ R
⊤
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does accept its input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
Just so we don't get confused,let's reset everything back to
how it used to be.
![Page 117: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/117.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { reject(); } else { accept(); }}
ATM ∈ R
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
Much better!
![Page 118: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/118.jpg)
bool willAccept(string program, string input)
// Program P
int main() { string input = getInput(); string me = mySource();
if (willAccept(me, input)) { reject(); } else { accept(); }}
ATM ∈ R
Contradiction!
There is a decider D for ATM
Decider Dfor ATM
M
w
Yes, M accepts w.
No, M does not accept w.
We can write programs that
use D as a helper method
willAcceptprogram
input
Program P accepts its input
if and only ifprogram P does not accept its
input
Program P design specification:If P accepts its input, then
P does not accept its input.If P does not accept its input, then
P accepts its input.
✓
✓
Take a look at the generalstructure of how we got here.
Then, let's go do anotherexample.
![Page 119: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/119.jpg)
Do you remember the securevoting problem from lecture?
![Page 120: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/120.jpg)
We said that a TM M is asecure voting machine if it
obeys the above rule.
M is a secure voting machine
if and only if
ℒ(M) = { w ∈ {r, d}* | w has more r's than d's }
![Page 121: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/121.jpg)
That's kind of a lot to takein at once.
M is a secure voting machine
if and only if
ℒ(M) = { w ∈ {r, d}* | w has more r's than d's }
![Page 122: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/122.jpg)
Remember – the language of a TMis the set of all the strings it
accepts.
M is a secure voting machine
if and only if
ℒ(M) = { w ∈ {r, d}* | w has more r's than d's }
![Page 123: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/123.jpg)
So really this statement means thatM accepts every string with more
r's than d's and nothing else.
M is a secure voting machine
if and only if
ℒ(M) = { w ∈ {r, d}* | w has more r's than d's }
![Page 124: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/124.jpg)
Our goal was to show that it'snot possible to build a program
that can tell whether an arbitraryTM is a secure voting machine.
M is a secure voting machine
if and only if
ℒ(M) = { w ∈ {r, d}* | w has more r's than d's }
![Page 125: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/125.jpg)
Notice that our goal was not toshow that you can't build a secure
voting machine.
M is a secure voting machine
if and only if
ℒ(M) = { w ∈ {r, d}* | w has more r's than d's }
![Page 126: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/126.jpg)
It's absolutely possible to dothat.
M is a secure voting machine
if and only if
ℒ(M) = { w ∈ {r, d}* | w has more r's than d's }
int main() { string input = getInput(); if (countRs(input) > countDs(input)) { accept(); } else { reject(); }}
int main() { string input = getInput(); if (countRs(input) > countDs(input)) { accept(); } else { reject(); }}
![Page 127: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/127.jpg)
The hard part is being able totell whether an arbitrary program
is a secure voting machine.
M is a secure voting machine
if and only if
ℒ(M) = { w ∈ {r, d}* | w has more r's than d's }
int main() { string input = getInput(); if (countRs(input) > countDs(input)) { accept(); } else { reject(); }}
int main() { string input = getInput(); if (countRs(input) > countDs(input)) { accept(); } else { reject(); }}
![Page 128: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/128.jpg)
Here's a program where no oneknows whether it's a secure
voting machine.
M is a secure voting machine
if and only if
ℒ(M) = { w ∈ {r, d}* | w has more r's than d's }
int main() { string input = getInput();
int n = countRs(input); while (n > 1) { if (n % 2 == 0) n = n / 2; else n = 3*n + 1; }
if (countRs(input) > countDs(input)) { accept(); } else { reject(); }}
int main() { string input = getInput();
int n = countRs(input); while (n > 1) { if (n % 2 == 0) n = n / 2; else n = 3*n + 1; }
if (countRs(input) > countDs(input)) { accept(); } else { reject(); }}
![Page 129: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/129.jpg)
You can see this because no oneknows whether this part will
always terminate.
M is a secure voting machine
if and only if
ℒ(M) = { w ∈ {r, d}* | w has more r's than d's }
int main() { string input = getInput();
int n = countRs(input); while (n > 1) { if (n % 2 == 0) n = n / 2; else n = 3*n + 1; }
if (countRs(input) > countDs(input)) { accept(); } else { reject(); }}
int main() { string input = getInput();
int n = countRs(input); while (n > 1) { if (n % 2 == 0) n = n / 2; else n = 3*n + 1; }
if (countRs(input) > countDs(input)) { accept(); } else { reject(); }}
![Page 130: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/130.jpg)
It's entirely possible that thisgoes into an infinite loop onsome input – we're honestly
not sure!
M is a secure voting machine
if and only if
ℒ(M) = { w ∈ {r, d}* | w has more r's than d's }
int main() { string input = getInput();
int n = countRs(input); while (n > 1) { if (n % 2 == 0) n = n / 2; else n = 3*n + 1; }
if (countRs(input) > countDs(input)) { accept(); } else { reject(); }}
int main() { string input = getInput();
int n = countRs(input); while (n > 1) { if (n % 2 == 0) n = n / 2; else n = 3*n + 1; }
if (countRs(input) > countDs(input)) { accept(); } else { reject(); }}
![Page 131: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/131.jpg)
So, to recap:Building a secure voting machine isn't hard.Checking whether an arbitrary program is a
secure voting machine is really hard.
M is a secure voting machine
if and only if
ℒ(M) = { w ∈ {r, d}* | w has more r's than d's }
int main() { string input = getInput();
int n = countRs(input); while (n > 1) { if (n % 2 == 0) n = n / 2; else n = 3*n + 1; }
if (countRs(input) > countDs(input)) { accept(); } else { reject(); }}
int main() { string input = getInput();
int n = countRs(input); while (n > 1) { if (n % 2 == 0) n = n / 2; else n = 3*n + 1; }
if (countRs(input) > countDs(input)) { accept(); } else { reject(); }}
![Page 132: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/132.jpg)
Our goal is to show that the secure votingproblem – the problem of checking whether a
program is a secure voting machine – isundecidable.
![Page 133: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/133.jpg)
Following our pattern from before, we'llassume that the secure voting problem is
decidable.
The secure voting problem is decidable.
![Page 134: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/134.jpg)
We're ultimately trying to get some kind ofcontradiction here.
The secure voting problem is decidable.
Contradiction!
![Page 135: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/135.jpg)
As before, we'll take it one step at a time.
The secure voting problem is decidable.
Contradiction!
![Page 136: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/136.jpg)
First, since we're assuming that the securevoting problem is decidable, we're assuming
that there's a decider for it.
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
![Page 137: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/137.jpg)
So what does that look like?
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
![Page 138: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/138.jpg)
A decider for the secure voting problem willtake in some TM M, which is the machine
we want to specifically check.
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
M
![Page 139: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/139.jpg)
The decider will then accept if M is a securevoting machine and reject otherwise.
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
![Page 140: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/140.jpg)
Following our pattern from before, we'llthen say that we can use this decider as a
subroutine in other TMs.
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
![Page 141: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/141.jpg)
In software, that decider D might looksomething like what's given above.
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
bool isSecure(string program)
![Page 142: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/142.jpg)
Here, isSecure is just another name for thedecider D, but with a more descriptive
name.
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
bool isSecure(string program)
isSecure
![Page 143: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/143.jpg)
Its argument (program) is just a moredescriptive name for the TM (program) given
as input.
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
bool isSecure(string program)
isSecureprogram
![Page 144: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/144.jpg)
This was the point in the previous proof wherewe started to write a design spec for some
self-referential program P.
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
bool isSecure(string program)
isSecureprogram
![Page 145: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/145.jpg)
Previously, we wrote P to get this contradiction:“P accepts if and only if it doesn't accept.”
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
bool isSecure(string program)
isSecureprogram
![Page 146: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/146.jpg)
That was a great contradiction to get whenwe had a decider that would tell us whether
a program would accept a given input.
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
bool isSecure(string program)
isSecureprogram
![Page 147: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/147.jpg)
The problem here is that our decider doesn'tdo that. Instead, it tells us whether a program
is a secure voting machine.
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
bool isSecure(string program)
isSecureprogram
![Page 148: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/148.jpg)
Following the maxim of “do what you can withwhat you have where you are,” we'll try to
set up a contradiction concerning whether aprogram is or is not a voting machine.
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
bool isSecure(string program)
isSecureprogram
![Page 149: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/149.jpg)
Specifically, we're going to build a program Pthat is a secure voting machine if and only if
it's not a secure voting machine.
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
bool isSecure(string program)
isSecureprogram
Program P is secure if and only
if program P is not secure.
![Page 150: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/150.jpg)
Generally speaking, you'll try to set up acontradiction where the program has the property
given by the decider if and only if it doesn'thave the property given by the decider.
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
bool isSecure(string program)
isSecureprogram
Program P is secure if and only
if program P is not secure.
![Page 151: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/151.jpg)
Generally speaking, you'll try to set up acontradiction where the program has the property
given by the decider if and only if it doesn'thave the property given by the decider.
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
bool isSecure(string program)
isSecureprogram
Program P is secure if and only
if program P is not secure.
Pay attention to that other guy! That'sreally, really good advice!
![Page 152: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/152.jpg)
So now we have to figure out how to write thisprogram P.
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
bool isSecure(string program)
isSecureprogram
Program P is secure if and only
if program P is not secure.
![Page 153: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/153.jpg)
As before, let's start by writing out a designspecification for what it's supposed to do.
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
bool isSecure(string program)
isSecureprogram
Program P is secure if and only
if program P is not secure.
Program P design specification:
![Page 154: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/154.jpg)
This first part takes care of the first half ofthe biconditional.
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
bool isSecure(string program)
isSecureprogram
Program P is secure if and only
if program P is not secure.
Program P design specification:If P is a secure voting machine, then
P is not a secure voting machine.
![Page 155: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/155.jpg)
This second part takes care of the otherdirection.
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
bool isSecure(string program)
isSecureprogram
Program P is secure if and only
if program P is not secure.
Program P design specification:If P is a secure voting machine, then
P is not a secure voting machine.If P is not a secure voting machine, then
P is a secure voting machine.
![Page 156: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/156.jpg)
At this point, we have written out a specfor what we want P to do. All that's left to
do now is to code it up!
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
bool isSecure(string program)
isSecureprogram
Program P is secure if and only
if program P is not secure.
Program P design specification:If P is a secure voting machine, then
P is not a secure voting machine.If P is not a secure voting machine, then
P is a secure voting machine.
![Page 157: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/157.jpg)
In lecture, we wrote one particular programthat met these requirements. For the sake ofsimplicity, I'm going to write a different one
here. Don't worry! It works just fine.
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
bool isSecure(string program)
isSecureprogram
Program P is secure if and only
if program P is not secure.
Program P design specification:If P is a secure voting machine, then
P is not a secure voting machine.If P is not a secure voting machine, then
P is a secure voting machine.
![Page 158: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/158.jpg)
// Program P
int main() { string input = getInput(); string me = mySource();
if (isSecure(me)) { accept(); } else { if (countRs(input) > countDs(input)) accept(); else reject(); }}
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
bool isSecure(string program)
isSecureprogram
Program P is secure if and only
if program P is not secure.
Program P design specification:If P is a secure voting machine, then
P is not a secure voting machine.If P is not a secure voting machine, then
P is a secure voting machine.
Our program starts off inmain().
![Page 159: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/159.jpg)
// Program P
int main() { string input = getInput(); string me = mySource();
if (isSecure(me)) { accept(); } else { if (countRs(input) > countDs(input)) accept(); else reject(); }}
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
bool isSecure(string program)
isSecureprogram
Program P is secure if and only
if program P is not secure.
Program P design specification:If P is a secure voting machine, then
P is not a secure voting machine.If P is not a secure voting machine, then
P is a secure voting machine.
Ultimately, we need to figureout if we're a secure voting
machine or not.
![Page 160: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/160.jpg)
// Program P
int main() { string input = getInput(); string me = mySource();
if (isSecure(me)) { accept(); } else { if (countRs(input) > countDs(input)) accept(); else reject(); }}
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
bool isSecure(string program)
isSecureprogram
Program P is secure if and only
if program P is not secure.
Program P design specification:If P is a secure voting machine, then
P is not a secure voting machine.If P is not a secure voting machine, then
P is a secure voting machine.
The best tool we have for thatis some kind of self-reference
trick.
![Page 161: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/161.jpg)
bool isSecure(string program)
// Program P
int main() { string input = getInput(); string me = mySource();
if (isSecure(me)) { accept(); } else { if (countRs(input) > countDs(input)) accept(); else reject(); }}
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
isSecureprogram
Program P is secure if and only
if program P is not secure.
Program P design specification:If P is a secure voting machine, then
P is not a secure voting machine.If P is not a secure voting machine, then
P is a secure voting machine.
As before, we'll use the fact that we have this decider lying
around to make P figure outwhat exactly it does.
![Page 162: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/162.jpg)
bool isSecure(string program)
// Program P
int main() { string input = getInput(); string me = mySource();
if (isSecure(me)) { accept(); } else { if (countRs(input) > countDs(input)) accept(); else reject(); }}
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
isSecureprogram
Program P is secure if and only
if program P is not secure.
Program P design specification:If P is a secure voting machine, then
P is not a secure voting machine.If P is not a secure voting machine, then
P is a secure voting machine.
Specifically, let's have programP ask what it's going to do.
![Page 163: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/163.jpg)
bool isSecure(string program)
// Program P
int main() { string input = getInput(); string me = mySource();
if (isSecure(me)) { accept(); } else { if (countRs(input) > countDs(input)) accept(); else reject(); }}
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
isSecureprogram
Program P is secure if and only
if program P is not secure.
Program P design specification:If P is a secure voting machine, then
P is not a secure voting machine.If P is not a secure voting machine, then
P is a secure voting machine.
Let's take it one step at atime.
![Page 164: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/164.jpg)
bool isSecure(string program)
// Program P
int main() { string input = getInput(); string me = mySource();
if (isSecure(me)) { accept(); } else { if (countRs(input) > countDs(input)) accept(); else reject(); }}
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
isSecureprogram
Program P is secure if and only
if program P is not secure.
Program P design specification:If P is a secure voting machine, then
P is not a secure voting machine.If P is not a secure voting machine, then
P is a secure voting machine.
Oddly enough, let's look at thesecond requirement first.
Why? I ask: why not?
![Page 165: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/165.jpg)
bool isSecure(string program)
// Program P
int main() { string input = getInput(); string me = mySource();
if (isSecure(me)) { accept(); } else { if (countRs(input) > countDs(input)) accept(); else reject(); }}
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
isSecureprogram
Program P is secure if and only
if program P is not secure.
Program P design specification:If P is a secure voting machine, then
P is not a secure voting machine.If P is not a secure voting machine, then
P is a secure voting machine.
This requirement says that ifthe program is supposed to not
be a secure voting machine,then it needs to be a secure
voting machine.
![Page 166: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/166.jpg)
bool isSecure(string program)
// Program P
int main() { string input = getInput(); string me = mySource();
if (isSecure(me)) { accept(); } else { if (countRs(input) > countDs(input)) accept(); else reject(); }}
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
isSecureprogram
Program P is secure if and only
if program P is not secure.
Program P design specification:If P is a secure voting machine, then
P is not a secure voting machine.If P is not a secure voting machine, then
P is a secure voting machine.
This case is the part thatdrops us in the “else” branch ofthis if statement, so let's focus
on that part for now.
![Page 167: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/167.jpg)
bool isSecure(string program)
// Program P
int main() { string input = getInput(); string me = mySource();
if (isSecure(me)) { accept(); } else { if (countRs(input) > countDs(input)) accept(); else reject(); }}
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
isSecureprogram
Program P is secure if and only
if program P is not secure.
Program P design specification:If P is a secure voting machine, then
P is not a secure voting machine.If P is not a secure voting machine, then
P is a secure voting machine.
In this specific case, we'resuppose to make P be asecure voting machine.
![Page 168: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/168.jpg)
bool isSecure(string program)
// Program P
int main() { string input = getInput(); string me = mySource();
if (isSecure(me)) { accept(); } else { if (countRs(input) > countDs(input)) accept(); else reject(); }}
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
isSecureprogram
Program P is secure if and only
if program P is not secure.
Program P design specification:If P is a secure voting machine, then
P is not a secure voting machine.If P is not a secure voting machine, then
P is a secure voting machine.
That means we need to make Paccept all strings with more r's
than d's and not acceptanything else.
![Page 169: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/169.jpg)
bool isSecure(string program)
// Program P
int main() { string input = getInput(); string me = mySource();
if (isSecure(me)) { accept(); } else { if (countRs(input) > countDs(input)) accept(); else reject(); }}
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
isSecureprogram
Program P is secure if and only
if program P is not secure.
Program P design specification:If P is a secure voting machine, then
P is not a secure voting machine.If P is not a secure voting machine, then
P is a secure voting machine.
The good news is that, awhile back, we already saw
how to do that!
![Page 170: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/170.jpg)
bool isSecure(string program)
// Program P
int main() { string input = getInput(); string me = mySource();
if (isSecure(me)) { accept(); } else { if (countRs(input) > countDs(input)) accept(); else reject(); }}
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
isSecureprogram
Program P is secure if and only
if program P is not secure.
Program P design specification:If P is a secure voting machine, then
P is not a secure voting machine.If P is not a secure voting machine, then
P is a secure voting machine.
The code looks something likethis.
![Page 171: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/171.jpg)
bool isSecure(string program)
// Program P
int main() { string input = getInput(); string me = mySource();
if (isSecure(me)) { accept(); } else { if (countRs(input) > countDs(input)) accept(); else reject(); }}
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
isSecureprogram
Program P is secure if and only
if program P is not secure.
Program P design specification:If P is a secure voting machine, then
P is not a secure voting machine.If P is not a secure voting machine, then
P is a secure voting machine.
Just to confirm that thisworks – notice that if the
input has more r's than d's,we accept it, and otherwise
we reject.
![Page 172: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/172.jpg)
bool isSecure(string program)
// Program P
int main() { string input = getInput(); string me = mySource();
if (isSecure(me)) { accept(); } else { if (countRs(input) > countDs(input)) accept(); else reject(); }}
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
isSecureprogram
Program P is secure if and only
if program P is not secure.
Program P design specification:If P is a secure voting machine, then
P is not a secure voting machine.If P is not a secure voting machine, then
P is a secure voting machine.
Okay! So that's one of tworequirements down.
✓
![Page 173: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/173.jpg)
bool isSecure(string program)
// Program P
int main() { string input = getInput(); string me = mySource();
if (isSecure(me)) { accept(); } else { if (countRs(input) > countDs(input)) accept(); else reject(); }}
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
isSecureprogram
Program P is secure if and only
if program P is not secure.
Program P design specification:If P is a secure voting machine, then
P is not a secure voting machine.If P is not a secure voting machine, then
P is a secure voting machine.
Let's move on to the otherone.
✓
![Page 174: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/174.jpg)
bool isSecure(string program)
// Program P
int main() { string input = getInput(); string me = mySource();
if (isSecure(me)) { accept(); } else { if (countRs(input) > countDs(input)) accept(); else reject(); }}
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
isSecureprogram
Program P is secure if and only
if program P is not secure.
Program P design specification:If P is a secure voting machine, then
P is not a secure voting machine.If P is not a secure voting machine, then
P is a secure voting machine.
This says that if P is supposedto be a secure voting
machine, it needs to not bea secure voting machine.
✓
![Page 175: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/175.jpg)
bool isSecure(string program)
// Program P
int main() { string input = getInput(); string me = mySource();
if (isSecure(me)) { accept(); } else { if (countRs(input) > countDs(input)) accept(); else reject(); }}
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
isSecureprogram
Program P is secure if and only
if program P is not secure.
Program P design specification:If P is a secure voting machine, then
P is not a secure voting machine.If P is not a secure voting machine, then
P is a secure voting machine.
There are a lot of ways to getP to not be a secure voting
machine.
✓
![Page 176: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/176.jpg)
bool isSecure(string program)
// Program P
int main() { string input = getInput(); string me = mySource();
if (isSecure(me)) { accept(); } else { if (countRs(input) > countDs(input)) accept(); else reject(); }}
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
isSecureprogram
Program P is secure if and only
if program P is not secure.
Program P design specification:If P is a secure voting machine, then
P is not a secure voting machine.If P is not a secure voting machine, then
P is a secure voting machine.
We can literally do anythingwe want except accepting
all strings with more r's thand's and not accepting
anything else.
✓
![Page 177: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/177.jpg)
bool isSecure(string program)
// Program P
int main() { string input = getInput(); string me = mySource();
if (isSecure(me)) { accept(); } else { if (countRs(input) > countDs(input)) accept(); else reject(); }}
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
isSecureprogram
Program P is secure if and only
if program P is not secure.
Program P design specification:If P is a secure voting machine, then
P is not a secure voting machine.If P is not a secure voting machine, then
P is a secure voting machine.
Among the many things we cando that falls into the “literally
anything else” camp would be tojust accept everything.
✓
![Page 178: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/178.jpg)
bool isSecure(string program)
// Program P
int main() { string input = getInput(); string me = mySource();
if (isSecure(me)) { accept(); } else { if (countRs(input) > countDs(input)) accept(); else reject(); }}
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
isSecureprogram
Program P is secure if and only
if program P is not secure.
Program P design specification:If P is a secure voting machine, then
P is not a secure voting machine.If P is not a secure voting machine, then
P is a secure voting machine.
Notice that in this case, P isnot a secure voting machine:
it accepts everything, includinga ton of strings it's not
supposed to.
✓
![Page 179: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/179.jpg)
bool isSecure(string program)
// Program P
int main() { string input = getInput(); string me = mySource();
if (isSecure(me)) { accept(); } else { if (countRs(input) > countDs(input)) accept(); else reject(); }}
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
isSecureprogram
Program P is secure if and only
if program P is not secure.
Program P design specification:If P is a secure voting machine, then
P is not a secure voting machine.If P is not a secure voting machine, then
P is a secure voting machine.
So we're done with this partof the design!
✓
✓
![Page 180: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/180.jpg)
bool isSecure(string program)
// Program P
int main() { string input = getInput(); string me = mySource();
if (isSecure(me)) { accept(); } else { if (countRs(input) > countDs(input)) accept(); else reject(); }}
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
isSecureprogram
Program P is secure if and only
if program P is not secure.
Program P design specification:If P is a secure voting machine, then
P is not a secure voting machine.If P is not a secure voting machine, then
P is a secure voting machine.
Putting it all together, take alook at what we accomplished.This program is a secure voting
machine if and only if it isn'ta secure voting machine!
✓
✓
![Page 181: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/181.jpg)
bool isSecure(string program)
// Program P
int main() { string input = getInput(); string me = mySource();
if (isSecure(me)) { accept(); } else { if (countRs(input) > countDs(input)) accept(); else reject(); }}
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
isSecureprogram
Program P is secure if and only
if program P is not secure.
Program P design specification:If P is a secure voting machine, then
P is not a secure voting machine.If P is not a secure voting machine, then
P is a secure voting machine.
That gives us the contradictionthat we needed to get.
✓
✓
![Page 182: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/182.jpg)
bool isSecure(string program)
// Program P
int main() { string input = getInput(); string me = mySource();
if (isSecure(me)) { accept(); } else { if (countRs(input) > countDs(input)) accept(); else reject(); }}
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
isSecureprogram
Program P is secure if and only
if program P is not secure.
Program P design specification:If P is a secure voting machine, then
P is not a secure voting machine.If P is not a secure voting machine, then
P is a secure voting machine.
We're done! We've shownthat starting with the assumptionthat the secure voting problem
is decidable, we reach acontradiction.
✓
✓
![Page 183: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/183.jpg)
bool isSecure(string program)
// Program P
int main() { string input = getInput(); string me = mySource();
if (isSecure(me)) { accept(); } else { if (countRs(input) > countDs(input)) accept(); else reject(); }}
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
isSecureprogram
Program P is secure if and only
if program P is not secure.
Program P design specification:If P is a secure voting machine, then
P is not a secure voting machine.If P is not a secure voting machine, then
P is a secure voting machine.
You might have noticed thatthis program isn’t the one we
used in lecture. But that’sokay!
✓
✓
![Page 184: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/184.jpg)
bool isSecure(string program)
// Program P
int main() { string input = getInput(); string me = mySource();
if (isSecure(me)) { accept(); } else { if (countRs(input) > countDs(input)) accept(); else reject(); }}
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
isSecureprogram
Program P is secure if and only
if program P is not secure.
Program P design specification:If P is a secure voting machine, then
P is not a secure voting machine.If P is not a secure voting machine, then
P is a secure voting machine.
There can be all sorts ofprograms that meet the designspecification we set out above.
✓
✓
![Page 185: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/185.jpg)
bool isSecure(string program)
// Program P
int main() { string input = getInput(); string me = mySource();
if (isSecure(me)) { accept(); } else { if (countRs(input) > countDs(input)) accept(); else reject(); }}
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
isSecureprogram
Program P is secure if and only
if program P is not secure.
Program P design specification:If P is a secure voting machine, then
P is not a secure voting machine.If P is not a secure voting machine, then
P is a secure voting machine.
That’s great news for you,because it means that these sorts
of proofs aren’t about findinga needle in a haystack.
✓
✓
![Page 186: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/186.jpg)
bool isSecure(string program)
// Program P
int main() { string input = getInput(); string me = mySource();
if (isSecure(me)) { accept(); } else { if (countRs(input) > countDs(input)) accept(); else reject(); }}
The secure voting problem is decidable.
Contradiction!
There is a decider D for the secure voting problem
Decider Dfor the securevoting problem
MYes, M is a secure votingmachine.
No, M is not a secure voting machine.
We can write programs that
use D as a helper method
isSecureprogram
Program P is secure if and only
if program P is not secure.
Program P design specification:If P is a secure voting machine, then
P is not a secure voting machine.If P is not a secure voting machine, then
P is a secure voting machine.
As long as you meet thedesign criteria, you should be
good to go!
✓
✓
![Page 187: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/187.jpg)
Let's take a minute to reviewthe general process that we
followed to get theseresults to work.
![Page 188: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/188.jpg)
Let's take a minute to reviewthe general process that we
followed to get theseresults to work.
That other guy is going to tellyou a general pattern tofollow. You might want to
take notes.
![Page 189: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/189.jpg)
Let's suppose that you wantto prove that some language
about TMs is undecidable.
![Page 190: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/190.jpg)
Start off by assuming it'sdecidable.
The problem in question is decidable
![Page 191: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/191.jpg)
The goal is to get acontradiction.
The problem in question is decidable
Contradiction!
![Page 192: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/192.jpg)
To get there...
The problem in question is decidable
Contradiction!
![Page 193: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/193.jpg)
…the first step is to supposethat you have a decider forthe language in question.
The problem in question is decidable
Contradiction!
There is a decider D for that problem.
![Page 194: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/194.jpg)
It's often a good idea todraw a picture showing what
that decider looks like.
The problem in question is decidable
Contradiction!
There is a decider D for that problem.
Decider Dfor thisproblem
![Page 195: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/195.jpg)
Think about what the inputsto the decider are going tolook like. That depends on
the language.
The problem in question is decidable
Contradiction!
There is a decider D for that problem.
Decider Dfor thisproblem
![Page 196: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/196.jpg)
In the cases we're exploringin this class, there will always
be at least one input that'sa TM of some sort.
The problem in question is decidable
Contradiction!
There is a decider D for that problem.
Decider Dfor thisproblem
M
![Page 197: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/197.jpg)
Next, think about what thedecider is going to tell youabout those inputs. That
depends on the problem athand.
The problem in question is decidable
Contradiction!
There is a decider D for that problem.
Decider Dfor thisproblem
M
![Page 198: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/198.jpg)
For example, if your languageis the set of TMs that havesome property X, then the
decider will tell you whetherthe TM has property X.
The problem in question is decidable
Contradiction!
There is a decider D for that problem.
Decider Dfor thisproblem
MYes, M has property X.
No, M doesn't haveproperty X.
![Page 199: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/199.jpg)
The next step is to think abouthow to use that decider as
a subroutine in some program.
The problem in question is decidable
Contradiction!
There is a decider D for that problem.
Decider Dfor thisproblem
MYes, M has property X.
No, M doesn't haveproperty X.
We can write programs that
use D as a helper method
![Page 200: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/200.jpg)
Think about what the deciderwould look like as a method
in some high-level programminglanguage.
The problem in question is decidable
Contradiction!
There is a decider D for that problem.
Decider Dfor thisproblem
MYes, M has property X.
No, M doesn't haveproperty X.
We can write programs that
use D as a helper method
![Page 201: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/201.jpg)
You already know what inputs it'sgoing to take and what it says,so try to come up with a nice,
descriptive name for the method.
The problem in question is decidable
Contradiction!
There is a decider D for that problem.
Decider Dfor thisproblem
MYes, M has property X.
No, M doesn't haveproperty X.
We can write programs that
use D as a helper method
![Page 202: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/202.jpg)
In this case, since our decidersays whether the program hassome property X, a good name
would be something likehasPropertyX.
The problem in question is decidable
Contradiction!
There is a decider D for that problem.
Decider Dfor thisproblem
MYes, M has property X.
No, M doesn't haveproperty X.
We can write programs that
use D as a helper method
bool hasPropertyX(string program)
![Page 203: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/203.jpg)
It doesn't hurt to label thedecider D to show what parts
of the decider correspondwith the method.
The problem in question is decidable
Contradiction!
There is a decider D for that problem.
Decider Dfor thisproblem
MYes, M has property X.
No, M doesn't haveproperty X.
We can write programs that
use D as a helper method
bool hasPropertyX(string program)
hasPropertyXprogram
![Page 204: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/204.jpg)
The next step is to build aself-referential program that
gives you some sort ofcontradiction.
The problem in question is decidable
Contradiction!
There is a decider D for that problem.
Decider Dfor thisproblem
MYes, M has property X.
No, M doesn't haveproperty X.
We can write programs that
use D as a helper method
bool hasPropertyX(string program)
hasPropertyXprogram
![Page 205: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/205.jpg)
You're going to want toget a contradiction by building aprogram that has some property
X if and only if it doesn't havesome property X.
The problem in question is decidable
Contradiction!
There is a decider D for that problem.
Decider Dfor thisproblem
MYes, M has property X.
No, M doesn't haveproperty X.
We can write programs that
use D as a helper method
bool hasPropertyX(string program)
Program P has property X if and only if P doesn't have property X
hasPropertyXprogram
![Page 206: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/206.jpg)
Now, you have to figure outhow to write program P.
The problem in question is decidable
Contradiction!
There is a decider D for that problem.
Decider Dfor thisproblem
MYes, M has property X.
No, M doesn't haveproperty X.
We can write programs that
use D as a helper method
bool hasPropertyX(string program)
Program P has property X if and only if P doesn't have property X
hasPropertyXprogram
![Page 207: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/207.jpg)
We recommend writing outa design specification for theprogram that you're going to
write.
The problem in question is decidable
Contradiction!
There is a decider D for that problem.
Decider Dfor thisproblem
MYes, M has property X.
No, M doesn't haveproperty X.
We can write programs that
use D as a helper method
bool hasPropertyX(string program)
Program P has property X if and only if P doesn't have property X
Program P design specification:
hasPropertyXprogram
![Page 208: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/208.jpg)
You can fill out that spec byreasoning about both directions
of the implication.
The problem in question is decidable
Contradiction!
There is a decider D for that problem.
Decider Dfor thisproblem
MYes, M has property X.
No, M doesn't haveproperty X.
We can write programs that
use D as a helper method
bool hasPropertyX(string program)
Program P has property X if and only if P doesn't have property X
Program P design specification:If P has property X, then
P does not have property X.If P does not have property X, then
P has property X.
hasPropertyXprogram
![Page 209: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/209.jpg)
Finally, you have to go andwrite a program that gives
you a contradiction.
The problem in question is decidable
Contradiction!
There is a decider D for that problem.
Decider Dfor thisproblem
MYes, M has property X.
No, M doesn't haveproperty X.
We can write programs that
use D as a helper method
bool hasPropertyX(string program)
Program P has property X if and only if P doesn't have property X
Program P design specification:If P has property X, then
P does not have property X.If P does not have property X, then
P has property X.
hasPropertyXprogram
![Page 210: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/210.jpg)
If you follow the design spec,you'll likely get something likethis. Filling in the blanks takes
some creativity.
The problem in question is decidable
Contradiction!
There is a decider D for that problem.
Decider Dfor thisproblem
MYes, M has property X.
No, M doesn't haveproperty X.
We can write programs that
use D as a helper method
bool hasPropertyX(string program)
Program P has property X if and only if P doesn't have property X
Program P design specification:If P has property X, then
P does not have property X.If P does not have property X, then
P has property X.
hasPropertyXprogram
// Program P
int main() { string input = getInput(); string me = mySource();
if (hasPropertyX(me)) { // do something so you don't // have property X. } else { // Do something so you do // have property X. }}
![Page 211: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/211.jpg)
And now you have acontradiction!
The problem in question is decidable
Contradiction!
There is a decider D for that problem.
Decider Dfor thisproblem
MYes, M has property X.
No, M doesn't haveproperty X.
We can write programs that
use D as a helper method
bool hasPropertyX(string program)
Program P has property X if and only if P doesn't have property X
Program P design specification:If P has property X, then
P does not have property X.If P does not have property X, then
P has property X.
hasPropertyXprogram
// Program P
int main() { string input = getInput(); string me = mySource();
if (hasPropertyX(me)) { // do something so you don't // have property X. } else { // Do something so you do // have property X. }}
![Page 212: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/212.jpg)
Hope this helps!
Please feel free to askquestions if you have them.
![Page 213: Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1194/handouts/Guid… · What does this program do? bool willAccept(string program, string input) { /* … some implementation](https://reader034.vdocuments.us/reader034/viewer/2022050519/5fa296ccf321ee54ca496206/html5/thumbnails/213.jpg)
Did you find this useful? Ifso, let us know! We can go
and make more guides like these.