Lecture 23 - University of Virginia, Department of Computer Science

Download Report

Transcript Lecture 23 - University of Virginia, Department of Computer Science

Lecture 23:
Computability
CS200: Computer Science
University of Virginia
Computer Science
David Evans
http://www.cs.virginia.edu/~evans
Menu
• Review: Gödel’s Theorem, Proof in
Axiomatic Systems
• Are there some problems that it is
impossible to write a program to solve?
18 March 2002
CS 200 Spring 2002
2
Review
• Axiomatic System
– Set of axioms
– Set of inference rules
• Example: MIU-System from GEB
– Axioms: MI
– Inference rules: 4 rules for making new strings
• An axiomatic system is a formal system
where the string we can generate are
meant to represent “true theorems”
18 March 2002
CS 200 Spring 2002
3
Proof
• A proof of S in an axiomatic system is a
sequence of strings, T0, T1, …, Tn where:
– The first string is the axioms
– For all i from 1 to n, Tn is the result of applying
one of the inference rules to Tn-1
– Tn is S
• What is the proof-checking problem?
18 March 2002
CS 200 Spring 2002
4
Proof Checking Problem
• Input: an axiomatic system (a set of
axioms and inference rules), a statement
S, and a proof P of S
• Output:
true if P is a valid proof of S
false otherwise
How much work is the proof-checking problem?
n = length of the proof (number of steps)
Checking a proof is O(n)
18 March 2002
CS 200 Spring 2002
5
Finite-Length Proof Finding Problem
• Input: an axiomatic system (a set of
axioms and inference rules), a statement
S, n (the maximum number of proof steps)
• Output:
A valid proof of S with no more then n steps if
there is one. If there is no proof, unprovable.
How much work? At worst, we can try all possible proofs:
Finite-Length ProofFinding Problem is
NP-Complete.
O(rn) and (n)
18 March 2002
r inference rules
0 - n steps
~ rn possible proofs
Checking each proof is O(max-steps)
CS 200 Spring 2002
6
Proof Finding Problem
• Input: an axiomatic system, a statement S
• Output:
A valid proof of S if S is true. If there is no
proof, false.
How much work?
It is impossible!
Gödel’s theorem says it cannot be done.
18 March 2002
CS 200 Spring 2002
7
Quiz Answers
18 March 2002
CS 200 Spring 2002
8
What is Computer Science?
• “Correct” answers:
– “The most wonderful thing in the world!”
• Okay answers:
– “a liberal art (the only legitimate one) that
incorporates how into figuring things out. It is
the only class I have that can hurt my head.”
– “Study of systems and their actions through
the use of language systems.”
18 March 2002
CS 200 Spring 2002
9
What is Computer Science?
• More Okay answers:
– “A combination of logic, math, and other
disciplines to create systems.”
– “Study of language, math, logic, and all kinds of
good stuff… (music, cognition, etc.)”
– Neither “about” computers nor a science, more
of a liberal art.
– “Complicated, but nothing to with computers or
science.”
• Actually, it has a lot to do with computers. Like
chemistry has a lot to do with beekers.
18 March 2002
CS 200 Spring 2002
10
What is Computer Science?
• My answer would be:
“Study of ways to describe procedures and
reason about the processes they produce?”
• My alternate answer:
“Playing with procedures.”
18 March 2002
CS 200 Spring 2002
11
Reading GEB?
– Don’t remember: 1 (?)
– Through Ch 5 or less: 4
– All of Part I: 1
– All of Part I and some in Part II: 2
• Reading GEB is probably not necessary to
get a good grade in this class, but I really
hope you will read it and enjoy reading it!
• Ch 13 is the last assigned reading in it for
this class
18 March 2002
CS 200 Spring 2002
12
Exam 2
─ Similar to Exam 1
─ Like Exam 1, but allow DrScheme
─ In class, open notes
─ In class, closed notes
─ There shouldn’t be another Exam
225
111222
5555
1112
Exam 2 will involve:
- Questions about axiomatic systems, complexity and computability
(some practice questions on Friday)
- Questions about evaluation models (environments, evaluation rules)
- Writing a program that uses everything up through and including PS7
18 March 2002
CS 200 Spring 2002
13
What does it mean for an axiomatic
system to be complete and consistent?
Derives all true
statements, and no false
statements starting from a
finite number of axioms
and following mechanical
inference rules.
18 March 2002
CS 200 Spring 2002
14
What does it mean for an axiomatic
system to be complete and consistent?
It means the axiomatic system is
weak.
Its is so weak, it cannot express
“This statement has no proof.”
18 March 2002
CS 200 Spring 2002
15
Computability
18 March 2002
CS 200 Spring 2002
16
Computability
• Is there a procedure that solves a problem?
• Decidable (computable) problems:
– There is a procedure that solves the problem
– Make a photomosaic, sorting, drug discovery,
who will win NCAA tournament (it doesn’t mean
we know the procedure, but there is one)
• Undecidable problems:
– There is no possible procedure that solves the
problem
18 March 2002
CS 200 Spring 2002
17
Are there any undecidable
problems?
The Proof-Finding Problem:
Input: an axiomatic system, a statement S
Output:
A valid proof of S if S is true. If there is no
proof, false.
18 March 2002
CS 200 Spring 2002
18
Any others?
18 March 2002
CS 200 Spring 2002
19
Undecidable Problems
• We can prove a problem is undecidable by
showing it is at least as hard as the prooffinding problem
• Here’s a famous one:
Halting Problem
Input: a procedure P (described by a Scheme
program)
Output: true if P always halts (finishes
execution), false otherwise.
18 March 2002
CS 200 Spring 2002
20
Alan Turing (1912-1954)
• Published On Computable
Numbers … (1936)
– Introduced the Halting Problem
– Also: formal model of computation
and design for computers
• WWII: codebreaker at Bletchley
Park (broke Enigma Cipher)
– Even more important than Lorenz
• After the war: convicted of
homosexuality (then a crime in Britian),
commited suicide eating cyanide apple
18 March 2002
CS 200 Spring 2002
21
Halting Problem
Can we define a procedure always-halts
that takes the code for a procedure and
evaluates to #t if the procedure always
terminates, and to #f if it may not
terminate?
(define (always-halts procedure) … )
18 March 2002
CS 200 Spring 2002
22
Examples
> (always-halts ‘(lambda (x) (+ x x)))
#t
> (always-halts ‘(lambda (x)
(define (f x) (f x))
(f x)))
#f
> (always-halts ‘(lambda (x)
(define (fact n)
(if (= n 1) 1 (* n (fact (- n 1)))))
(fact x)))
#f
18 March 2002
CS 200 Spring 2002
23
Can we define halts??
• We could try for a really long time, get
something to work for simple examples,
but could we solve the problem? (Make it
work for all possible inputs.)
• Could we compute find-proof if we had
always-halts?
18 March 2002
CS 200 Spring 2002
24
find-proof
I cheated a little here –
we only know we can’t
do this for “true”.
(define (find-proof S axioms rules)
;; If S is provable, evaluates to a proof of S.
;; Otherwise, evaluates to #f.
(if (always-halts?
(find-proof-exhaustive S axioms rules))
((find-proof-exhaustive S axioms rules)))
#f))
Where (find-proof-exhaustive S axioms rules) evaluates to a procedure
that tries all possible proofs starting from the axioms.
18 March 2002
CS 200 Spring 2002
25
Another Informal Proof
(define (contradict-halts)
(if (always-halts contradict-halts)
(loop-forever)
#t))
If contradict-halts halts, the if test is true and
it evaluates to (loop-forever) - it doesn’t halt!
If contradict-halts doesn’t halt, the if test if false,
and it evaluates to #t. It halts!
18 March 2002
CS 200 Spring 2002
26
This should remind you of…
Russell’s Paradox
• S: set of all sets that are not members of
themselves
• Is S a member of itself?
– If S is an element of S, then S is a member of
itself and should not be in S.
– If S is not an element of S, then S is not a
member of itself, and should be in S.
18 March 2002
CS 200 Spring 2002
27
Undecidable Problems
• If solving a problem P would allow us to
solve the halting problem, then P is
undecidable – there is no solution to P,
since we have proved there is no solution
to the halting problem!
• There are lots of practical problems like
this…we’ll practice on them Friday.
18 March 2002
CS 200 Spring 2002
28
Charge
• Friday
– Practice determining if problems are
decidable (in P, in NP, not in NP) or
undecidable
• PS 6
– Even if you take into account Hofstadter’s
Law and Byrd’s Law, it may be longer than
you think so get cracking!
18 March 2002
CS 200 Spring 2002
29