David Evans CS150: Computer Science University of Virginia Computer Science Computability
2 Computability Computer Science/Mathematics Mathematics (Declarative Knowledge) –Are there true conjectures that cannot be the shown using any proof? Computer Science (Imperative Knowledge) –Are there (well-defined) problems that cannot be solved by any procedure? Wednesday Today
3 Computability Requests? No requests at all for other topics! Possible explanations: –Everyone is really excited about computability! –No one could find my address –No one has any curiosity about any other computing topics –No one wakes up before noon on Thursdays
4 Computability Is there an algorithm that solves a problem? Computable (decidable) problems: –There is an algorithm that solves the problem. –Make a fractal, sorting, drug discovery, winning chess (it doesn’t mean we know the algorithm, but there is one) Uncomputable (undecidable) problems: –There is no algorithm that solves the problem. There might be a procedure that solves it for some inputs, but not for all inputs.
5 Computability Are there any uncomputable problems?
6 Computability Recall: Gödel’s Proof Idea G: This statement does not have any proof in the system of PM. Choice 1: G is true G is not provable, so PM is incomplete. Choice 2: G is false G is provable, so PM is inconsistent. Maybe we can find an uncomputable problem using self-reference?
7 Computability Alan Turing ( ) Published On Computable Numbers, with an Application to the Entscheidungsproblem (1936) –Introduced the Halting Problem –Formal model of computation (now known as “Turing Machine”) Codebreaker at Bletchley Park –Involved in breaking Enigma Cipher After the war: convicted of homosexuality (then a crime in Britain), committed suicide eating cyanide apple 5 years after Gödel’s proof!
8 Computability
9 The Halting Problem Input: a specification of a procedure P Output: If evaluating an application of P halts, output true. Otherwise, output false.
10 Computability Halting Problem for PHP Define a procedure halts that takes a string representing PHP code and evaluates to true if evaluating the code would terminate, and to false if evaluating the code would not terminate. function halts($p) {... }
11 Computability Examples > halts(“function tt() { return 3 + 3; }; tt();”) true > halts(“function f() { return f(); }; f();”) false
12 Computability Halting Examples > halts(“function fact($n) { if ($n == 1) { return 1; } else { return $n * fact($n – 1); } }; fact(7);”) true > halts(“function fact($n) {... }; fact(0);”) false
13 Computability 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?
14 Computability Tougher Example halts(“ function isPerfectNumber($n) { // n is perfect if factors sum to n $divs = findDivisors($n); return $n == sum($divs); } $i = 3; while (not isPerfectNumber ($i)) { $i = $i + 2; } ; print $i ”) Note: it is unknown where an odd perfect number exists. (Numbers up to have been tried without finding one yet.) Unknown
15 Computability If you had halts, you could prove or disprove nearly every open mathematical problem! –Does an odd perfect number exist? –Goldbach conjecture: Every number > 2 is the sum of three primes (including 1). –Poincaré conjecture: Every simply connected closed three-manifold is homeomorphic to the three-sphere. –... This suggests it is unlikely halts exists...but doesn’t prove it (yet).
Interdisciplinary Major in Computer Science for students in the College of Arts & Sciences BA Computer Science
Why Major in Computing? Fun –Creative problem solving, collaborative design –Instant Gratification Important –World’s most important problems need CS solutions Provides Opportunity –Excellent preparation for almost any career, graduate school, professional schools –Best jobs: Money Magazine, Best Jobs in America: #1: Software Engineer, #2: College Professor, #7: Computer/IT AnalystBest Jobs in America Boston Globe, 2016: Fastest Growing Occupations: #1: Network/Data Analyst, #4: Computer Applications Engineer, #23: Computer Systems Analyst, #24: Database Expert, #25: Computer Software/Systems Engineer2016: Fastest Growing Occupations
Major Overview cs150 Next fall: cs205: Engineering Software Core courses: cs202, cs216, cs333, cs432 Computing Electives (4) Integration Electives (4) Applications and Foundations of Computing: many approved courses in Anthropology (6), Architecture (7), Art (6), Biology (14), Biomedical Engineering (4), Civil Engineering (1), Drama (5), Economics (3), Environmental Sciences (5), Linguistics (4), Math (7), Media Studies (4), Music (6), Neuroscience (1), Philosophy (5), Physics (3), Psychology (11), Statistics (3) Distinguished Major Program
Application Process Application forms available from Can submit at any time (but the earlier the better) Questions about your previous courses, short answer questions Turn in to Peggy Reed (Olsson 223) or me (Olsson 236A)
Questions BA Computer Science Information Lunch: Monday, April 28, noon-1:30pm in Newcomb Open Office Hours for students interested in BACS degree: Wednesday 3:30-5, Olsson 236A –No appointment needed, just come by Other times: for appointment
21 Computability Halting Problem Can you d efine a procedure halts that takes a string representing PHP code and evaluates to true if evaluating the code would terminate, and to false if evaluating the code would not terminate?
22 Computability Informal Proof function paradox() { if (halts(“paradox()”) { while (true) ; } else { return true; } } If paradox halts, the if test is true and it enters infinite while loop - it doesn’t halt! If paradox doesn’t halt, the if test if false, and it returns true. It halts!
23 Computability Recall: 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. With paradox, we have the same kind of contradiction!
24 Computability No halts alrogithm can exist! function paradox() { if (halts(“paradox()”) { while (true) ; } else { return true; } } If halts(“paradox()”) returns true: enters infinite while loop - doesn’t halt! If halts(“paradox()”) returns false: returns true. It halts! The only “sensible” thing for halts to do is never return.
25 Computability Robustness of Proof We did this for PHP since you are using that now, but the same proof would work for any programming language (e.g., Haskell, Java, Scheme, etc.) function paradox() { if (halts(“paradox()”) { while (true) ; } else { return true; } }
26 Computability The Halting Problem Input: a specification of a procedure P Output: If evaluating an application of P halts, output true. Otherwise, output false. Thus, no algorithm exists that can solve the halting problem.
27 Computability Charge Now we have one uncomputable problem, how do we decide if a new problem is uncomputable? –In fact, most interesting properties about programs are uncomputable! –e.g., virus scanners will never work perfectly Halting Problems Hockey Team