Presentation is loading. Please wait.

Presentation is loading. Please wait.

David Evans CS200: Computer Science University of Virginia Computer Science Class 19: Computability Halting Problems Hockey.

Similar presentations


Presentation on theme: "David Evans CS200: Computer Science University of Virginia Computer Science Class 19: Computability Halting Problems Hockey."— Presentation transcript:

1 David Evans http://www.cs.virginia.edu/evans CS200: Computer Science University of Virginia Computer Science Class 19: Computability Halting Problems Hockey Team Logo

2 12 March 2003CS 200 Spring 20032 Menu Quiz Answers (Questions 1-6) Review: –Gödel’s Theorem –Proof in Axiomatic Systems Computability: Are there some problems that it is impossible to write a program to solve?

3 12 March 2003CS 200 Spring 20033 Quiz Answers

4 12 March 2003CS 200 Spring 20034 1. How far have you read in GEB? –Through Ch 5 or less: 3 –Through Ch 6 or 7: 10 –All of Part I: 16 –Beyond Part I: 2, Whole Book: 1 Reading GEB might not be 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 (but I hope you’ll read the rest during your summer vacation!)

5 12 March 2003CS 200 Spring 20035 2. Should Exam 2 be: ─Similar to Exam 1 17 (“but should be harder”) ─Like Exam 1, but allow DrScheme 10 ─In class, open notes 0 ─In class, closed notes 0 ─There shouldn’t be another Exam 10 Exam 2 will allow use of DrScheme, but probably not expect it (unlike last year’s Exam 2, which you can see on the web site).

6 12 March 2003CS 200 Spring 20036 3. So far, class is going: –Way too fast 1 –Too fast11 “in a good way” –Just about right22 –Too slow 1 –Way too slow 0

7 12 March 2003CS 200 Spring 20037 4. How far have you gotten in PS5: –Finished0 –Question 71 –Question 54 –Question 32 –Question 16 –Read it 13 –Haven’t started9

8 12 March 2003CS 200 Spring 20038 5. What should be different? “A couple fewer problem sets, but slightly more difficult ones would be nice.”, “Less problem sets or less questions per problem set. The problem sets are very time consuming (I spend 20 hr/ps) for a 3-credit class.”, “shorter problem sets” “More help from TA’s”, “please have more TA hours. I wish we’d have lab hours at least 2 hours a day, 4 days a week if possible.” –PS’s are long but they are as short as possible –But many of you seem to think they are too short and there are too many lab hours: 22/35 of you had not started PS5 14 days after it was handed out! Only one person came to the 2 lab hours the first week PS5 was out

9 12 March 2003CS 200 Spring 20039 5. What should be different? “Use more examples to explain concepts”, “clearer explanation of Scheme code”, “More hands-on examples”, “Now that we know we can code everything, use less coding and more theory and explanation”, “Go slower and explain new concepts slower and throughout lecture since each lecture builds on info already taught. If the first thing taught made no sense to us, either will anything else.”, “The theoretic basis is interesting and exciting, but the Scheme is slightly lacking”, “sometimes confusing but that seems to be part of the plan”, “Breaking down info more”, “Less fast”, “we tend to go a little bit too fast on certain concepts and I think incorporating some more of the concepts that we learn into real life examples would be helpful”, “More use of GEB into lecture (relevance)”, “Maybe include questions from GEB on the problem sets.”, “Something different than powerpoint, it is getting old” Best way to get more examples, clarifications, slower lectures: ask questions!

10 12 March 2003CS 200 Spring 200310 6. What is Computer Science? A liberal art covering a wide range of disciplines Computer science encompasses all 7 of the liberal arts and focuses on the manipulation of language and thought. Computer science is the epitome of a “liberal art”! It combines rhetoric, logic, geometry, grammar, etc. A combination of all the components in liberal arts. In between science and liberal arts. A huge overall topic that is really hard to define in one sentence, but brings in all parts of classical liberal arts. Not science, a liberal art.; A true liberal art. A liberal art involving a lot of theory on logic and information and a bit on the limitations of real systems or “computers” Everything in fine arts and beyond…to a certain degree the way ideas are put into code and expressed to the real world. The study of problem-solving techniques. Reasonable statements, but not really useful definitions.

11 12 March 2003CS 200 Spring 200311 6. What is Computer Science? Imperative knowledge practically employed Study of “how” things are done, rather that “what”. Understanding concepts deeper than the surface with programs, etc… Study of the use of problem-solving strategies to manipulate machines and systems to execute a given task. A way of creating logical systems to solve problems. Study of imperative knowledge. A science on the processing of information and its representation; manipulation of the representations of information. Study of systems of language and code. Also, the application of these. Ways of manipulating information. Study of the manipulation of systems and problem solving using formal languages. The study of processes and how they are written, understood and carried out. Study of mechanical reasoning and its applications. Good answers, similar to my definition in Lecture 1

12 12 March 2003CS 200 Spring 200312 6. What is Computer Science? A study of how computers function, operate in a logical programmed way. The study of how to use a computer-like system and make it do what you want it to. An attempt to solve real world problems with application of computers and reason. The manipulation of computer memory to achieve a goal. The study of logic. The use of language to represent any idea or procedure which can cover topics from almost any discipline. Study of isomorphic mappings that yield discernable results to an interpreter. Neither computers nor science, but the study and theory of formal systems. I used to think it was the study of the software in computers, but now I’m not really sure. Interesting answers, but hard to defend.

13 12 March 2003CS 200 Spring 200313 6. What is Computer Science? Recursively speaking, computer science is the study of computer science.

14 12 March 2003CS 200 Spring 200314 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.”

15 12 March 2003CS 200 Spring 200315 5. What should be different? “We should have some competitions, such as writing a program to play tic-tac-toe.” –PS6 is sort of a game; take CS201J for real competitions “We should have class in different places more often, maybe even outside”, “More field trips!”, “More trips to the AFC, so that we can be hassled again.”, “More field trips.”

16 12 March 2003CS 200 Spring 200316 Field Trip

17 12 March 2003CS 200 Spring 200317 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 12 March 2003CS 200 Spring 200318 Proof A proof of S in an axiomatic system is a sequence of strings, T 0, T 1, …, T n where: –The first string is the axioms –For all i from 1 to n, T n is the result of applying one of the inference rules to T n-1 –T n is S How much work is it to check a proof?

19 12 March 2003CS 200 Spring 200319 Proof Checking Problem Input: an axiomatic system (a set of axioms and inference rules), a statement S, and a proof P containing n steps of S Output: true if P is a valid proof of S false otherwise How much work is a proof-checking procedure? We can write a proof-checking procedure that is  (n)

20 12 March 2003CS 200 Spring 200320 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 of S with <= n steps, unprovable. How much work? At worst, we can try all possible proofs: r inference rules, 0 - n steps ~ r n possible proofs Checking each proof is  (n) So, there is a procedure that is  (nr n ) but, it might not be the best one.

21 12 March 2003CS 200 Spring 200321 Proof Finding Problem Input: an axiomatic system, a statement S Output: If S is true, output a valid proof. If S is not true, output false. How much work? It is impossible! Gödel’s theorem says it cannot be done.

22 12 March 2003CS 200 Spring 200322 Gödel’s Statement G: This statement of number theory does not have any proof in the system of Principia Mathematica. G is unprovable, but true!

23 12 March 2003CS 200 Spring 200323 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.

24 12 March 2003CS 200 Spring 200324 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.”

25 12 March 2003CS 200 Spring 200325 Computability

26 12 March 2003CS 200 Spring 200326 Algorithms What’s an algorithm? A procedure that always terminates. What’s a procedure? A precise description of a process. Question 5 answer: “Perhaps we could try to look at other elements of computer science like digital logic, algorithms, discrete math, etc.” (CS230) (CS202, CS302)

27 12 March 2003CS 200 Spring 200327 Computability Is there an algorithm that solves a problem? Decidable (computable) problems: –There is an algorithm that solves the problem. –Make a photomosaic, sorting, drug discovery, winning chess (it doesn’t mean we know the algorithm, but there is one) Undecidable problems: –There is no algorithm that solves the problem. There might be a procedure, but it doesn’t always terminate.

28 12 March 2003CS 200 Spring 200328 Are there any undecidable problems? The Proof-Finding Problem: Input: an axiomatic system, a statement S Output: If S is true, output a valid proof. If S is not true, output false.

29 12 March 2003CS 200 Spring 200329 Any others? How would you prove a problem is undecidable?

30 12 March 2003CS 200 Spring 200330 Undecidable Problems We can prove a problem is undecidable by showing it is at least as hard as the proof- finding 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.

31 12 March 2003CS 200 Spring 200331 Alan Turing (1912-1954) Published On Computable Numbers … (1936) –Introduced the Halting Problem –Formal model of computation (now known as “Turing Machine”) Codebreaker at Bletchley Park –Broke Enigma Cipher –Perhaps more important than Lorenz After the war: convicted of homosexuality (then a crime in Britain), committed suicide eating cyanide apple

32 12 March 2003CS 200 Spring 200332 Halting Problem Define a procedure halts? that takes the code for a procedure and an input evaluates to #t if the procedure would terminate on that input, and to #f if would not terminate. (define (halts? procedure input) … )

33 12 March 2003CS 200 Spring 200333 Examples > (halts? ‘(lambda (x) (+ x x)) 3) #t > (halts? ‘(lambda (x) (define (f x) (f x)) (f x)) 27) #f

34 12 March 2003CS 200 Spring 200334 Halting Examples > (halts? `(lambda (x) (define (fact n) (if (= n 1) 1 (* n (fact (- n 1))))) (fact x)) 7) #t > (halts? `(lambda (x) (define (fact n) (if (= n 1) 1 (* n (fact (- n 1))))) (fact x)) 0) #f

35 12 March 2003CS 200 Spring 200335 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 halts ?

36 12 March 2003CS 200 Spring 200336 find-proof (define (find-proof S axioms rules) ;; If S is provable, evaluates to a proof of S. ;; Otherwise, evaluates to #f. (if (halts? find-proof-exhaustive S axioms rules)) (find-proof-exhaustive S axioms rules) #f)) Where (find-proof-exhaustive S axioms rules) is a procedure that tries all possible proofs starting from the axioms that evaluates to a proof if it finds one, and keeps working if it doesn’t. I cheated a little here – we only know we can’t do this for “true”.

37 12 March 2003CS 200 Spring 200337 Another Informal Proof (define (contradict-halts x) (if (halts? contradict-halts null) (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!

38 12 March 2003CS 200 Spring 200338 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. This should remind you of…

39 12 March 2003CS 200 Spring 200339 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. Example: why virus detectors will never really work!

40 12 March 2003CS 200 Spring 200340 Virus Detection Problem Problem 7. Melissa Problem Input: A Word macro (like a program, but embedded in an email message) Output: true if the macro will forward the message to people in your address book; false otherwise. How can we show it is undecidable?

41 12 March 2003CS 200 Spring 200341 Undecidability Proof Suppose we could define is-virus? that decides the Melissa problem. Then: (define (halts? P input) (if (is-virus? ‘(begin (P input) virus-code)) #t #f)) Since it is a virus, we know virus-code was evaluated, and P must halt (assuming P wasn’t a virus). Its not a virus, so the virus-code never executed. Hence, P must not halt.

42 12 March 2003CS 200 Spring 200342 Undecidability Proof Suppose we could define is-virus? that decides the Melissa problem. Then: (define (halts? P input) (is-virus? ‘(begin ((vaccinate P) input) virus-code)) Where (vaccinate P) evaluates to P with all mail commands replaced with print commands (to make sure (is-virus? P input) is false.

43 12 March 2003CS 200 Spring 200343 Proof If we had is-virus? we could define halts? We know halts? is undecidable Hence, we can’t have is-virus? Thus, we know is-virus? is undecidable

44 12 March 2003CS 200 Spring 200344 Charge PS 5 –Even if you take into account Hofstadter’s Law and Byrd’s Law, it may be longer than you think so get cracking! Friday, Monday: Object-Oriented Programming (PS6) Wednesday, Friday (next week): More about complexity (measuring work) and computability.


Download ppt "David Evans CS200: Computer Science University of Virginia Computer Science Class 19: Computability Halting Problems Hockey."

Similar presentations


Ads by Google