15-251Great Theoretical Ideas in Computer ScienceforSomeWhat does this do?_(__,___,____){___/__<=1?_(__,___+1,____):!(___%__)?_(__,___+1,0):___%__==___/ __&&!____?(printf("%d\t",___/__),_(__,___+1,0)):___%__>1&&___%__<___/__?_(__,1+ ___,____+!(___/__%(___%__))):___<__*__?_(__,___+1,____):0;}main(){_(100,0,0);}1. 0 K. 2. If x K, then S(x) K. 3. x K, S(x) != 0. 4. If x, y K and S(x) = S(y) then x = y.5. If a set of numbers T contains 0 and also xT S(x) T, then T = K.What is K?Axioms of Peano Arithmetic1. Zero is a natural number. 2. If x is a natural number, the successor of xis a natural number. 3. Zero is not the successor of a natural number. 4. Two natural numbers of which the successors are equal are themselves equal. 5. If a set of natural numbers T contains zero and also the successor of every number in T, then every natural number is in T.Turing’s Legacy: The Limits Of ComputationAnything I say say is false!Lecture 25 (April 9, 2009)This lecture will change the way you think about computer programs…Many questions which appear easy at first glance are impossible to solve in generalThe HELLO assignmentWrite a JAVA program to output the words “HELLO WORLD” on the screen and halt.Space and time are not an issue. The program is for an ideal computer. PASS for any working HELLO program, no partial credit.Grading ScriptHow exactly might such a script work?The grading script G must be able to take any Java program P and grade it.G(P)=Pass, if P prints only the words “HELLO WORLD” and halts.Fail, otherwise.What does this do?_(__,___,____){___/__<=1?_(__,___+1,____):!(___%__)?_(__,___+1,0):___%__==___/ __&&!____?(printf("%d\t",___/__),_(__,___+1,0)):___%__>1&&___%__<___/__?_(__,1+ ___,____+!(___/__%(___%__))):___<__*__?_(__,___+1,____):0;}main(){_(100,0,0);}Nasty Programn:=0;while (n is not a counter-example to the Riemann Hypothesis) {n++;}print “Hello World”;The nasty program is a PASS if and only if theRiemann Hypothesis is false.A TA nightmare: Despite the simplicity of the HELLO assignment, there is no program to correctly grade it! And we will prove this.The theory of what can and can’t be computed by an ideal computer is called Computability Theory or Recursion Theory.From the last lecture:The “grading function” we just describedis not computable! (We’ll see a proof soon.)Are all reals describable?Are all reals computable?NONOWe saw that computable describablebut do we also have describable computable?Computable FunctionHence: countably many computable functions!Fix a finite set of symbols, Fix a precise programming language, e.g., Java A program is any finite string of characters that is syntactically valid.A function f : Σ*Σ*is computable if there is a program P that when executed on an ideal computer, computes f. That is, for all strings x in Σ*, f(x) = P(x).There are only countably many Java programs. Hence, there are only countably manycomputable functions.Uncountably Many FunctionsThe functions f: * {0,1} are in 1-1 onto correspondence with the subsets of * (the powerset of *).Subset S of * Function fSx in S fS(x) = 1x not in S fS(x) = 0Hence, the set of all f:Σ* {0,1} has the same size as the power set of Σ*, which is uncountable.Countably many computable functions.Uncountably manyfunctions from *to {0,1}.Thus, most functions from *to {0,1} are not computable.Can we explicitly describe an uncomputable function?Notation And ConventionsFix a single programming language (Java)When we write program P we are talking about the text of the source code for PP(x) means the output that arises from running program P on input x, assuming that P eventually halts.P(x) = means P did not halt on xThe meaning of P(P)It follows from our conventions that P(P) means the output obtained when we run P on the text of its own source codeThe Halting ProblemIs there a program HALT such that:HALT(P) = yes, if P(P) haltsHALT(P) = no, if P(P) does not haltTHEOREM: There is no program to solve the halting problem(Alan Turing 1937)Suppose a program HALT existed that solved the halting problem.HALT(P) = yes, if P(P) haltsHALT(P) = no, if P(P) does not haltWe will call HALT as a subroutine in a new program called CONFUSE.CONFUSEDoes CONFUSE(CONFUSE) halt?CONFUSE(P){ if (HALT(P)) then loop forever; //i.e., we dont haltelse exit; //i.e., we halt// text of HALT goes here}CONFUSECONFUSE(P){ if (HALT(P)) then loop forever; //i.e., we dont haltelse exit; //i.e., we halt// text of HALT goes here }Suppose CONFUSE(CONFUSE) halts:then HALT(CONFUSE) = TRUE CONFUSE will loop forever on input CONFUSESuppose CONFUSE(CONFUSE) does not haltthen HALT(CONFUSE) = FALSE CONFUSE will halt on input CONFUSECONTRADICTIONAlan Turing (1912-1954)Theorem: [1937]There is no program to solve the halting problemTuring’s argument is essentially the reincarnation of Cantor’s Diagonalization argument that we saw in the previous lecture.P0P1P2… Pj…P0P1…Pi…All ProgramsAll Programs (the input)Programs (computable functions) are countable,so we can put them in a (countably long) listP0P1P2… Pj…P0P1…Pi…All ProgramsAll Programs (the input)YES, if Pi(Pj) haltsNo, otherwiseP0P1P2… Pj…P0d0P1d1……Pidi……All ProgramsAll Programs (the input)Let di = HALT(Pi) CONFUSE(Pi) halts iff di= no(The CONFUSE function is the negation of the diagonal.)Hence CONFUSE cannot be on this list.Is there a real number that can be described, but not computed?Consider the real number R whose binary expansion has a 1 in the jth position iff the jth program halts on input itself.Proof that R cannot be computedMYSTERY solves the halting problem!Suppose it is, and program FRED computes it.then consider the following program:MYSTERY(program text P)for j = 0 to forever do {if (P == Pj) then use FRED to compute jthbit of Rreturn YES if (bit == 1), NO if (bit == 0)}The Halting Set KDefinition:K is the set of all programs P such that P(P) halts.K = { Java P | P(P) halts }Computability Theory:Vocabulary LessonWe call a set S*decidable or recursive if there is a program P such that:P(x) = yes, if xSP(x) = no, if xSWe already know: the halting set K is undecidableDecidable and ComputableSubset S of * Function fSx in S fS(x) = 1x not in S fS(x) = 0Set S is decidable function fSis computableSets are “decidable” (or undecidable), whereasfunctions are “computable”
View Full Document