Simple properties can be arbitrarily hard to test
Suppose there’s an interesting fact in number theory, or combinatorics, or whatever, and we want
to know if it’s always true, for all integers
i
,
j
,
k
.
•
Write a test for that property.
•
Enumerate over all possible choices of
i
,
j
,
k
.
•
If the test is false, return 1.
•
If the function ever returns, then the property is false.
If we could write a program that can test other functions for a speciﬁc result, then it can verify
any math result.
8.5
Another reason it’s not easy to solve
Suppose we have a Python function,
H
that determines if a computer program,
P
will return 1,
when it’s run with the input
I
.
•
If
P does
return 1,
H
does, too.
•
If not,
H
returns 0.
P,I
H
1 or 0
Here’s a new program,
H
1
, which uses
H
:
def H1 (program, input):
if H (program, input):
return 0
else:
return 1
8.6
What’s so weird about
H
1
?
Our program
H
1
, when run on a program
P
and an input
I
, returns either 0 or 1, depending on
whether
P
returns 1 or not.
•
If
P does
return 1 on input
I
,
H
1
doesn’t.
•
If
P doesn’t
return 1 on input
I
,
H
1
does.
Let’s have one more program,
H
2
:
def H2 (program):
if H (program, program):
return 0
else:
return 1
Here,
H
2
behaves just like
H
1
, except that the program
P
is used as the input. That’s okay.
8.7
Now, we reach the end
What happens when we call
H2 (H2)
?
Consider the test in the