T ur in g’ s Le ga cy : T h e Li m it s O f C om pu ta ti on .
Carnegie Mellon UniversityNovember 28, 2006Lecture 26CS 15-251 Fall 2006John LaffertyGreat Theoretical Ideas In Computer Science
A ny th in g sa ys i s fa ls e!
T h e H E LL O a ss ig nm en t
Write a JAVA program to output the word “HELLO”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.G ra d in g S cr ip t T h e gr ad in g sc ri pt G m us t b e ab le t o ta ke a ny J av a pr og ra m P a nd g ra d e it . Pa ss , if P p ri nt s on ly t h e w or d G (P )= “H E LL O ” an d h al ts . F ai l, ot h er w is e. H ow e x ac tl y m ig h t su ch a s cr ip t w or k?
W h at d oe s th is d o?
#include <stdio.h> main(t,_,a)char*a;{return!0<t?t<3?main(-79,- 13,a+main(-87,1-_, main(- 86,0,a+1)+a)):1,t<_?main(t+1,_,a):3,main(-94,- 27+t,a)&&t==2?_<13? main(2,_+1,"%s %d %d\n"):9:16:t<0?t<- 72?main(_,t, "@n'+,#'/*{}w+/w#cdnr/+,{}r/*de}+,/*{*+,/w{%+,/w#q#n+,/#{l,+,/n{n+,/ +#n+,/#\;#q#n+,/+k#;*+,/'r :'d*'3,}{w+K w'K:'+}e#';dq#'l\ q#'+d'K#!/+k#;q#'r}eKK#}w'r}eKK{nl]'/#;#q#n'){)#}w'){){nl]'/+#n';d}rw' i;# \){nl]!/n{n#'; r{#w'rnc{nl]'/#{l,+'K{rw' iK{;[{nl]'/w#q#n'wknw' \ iwk{KK{nl]!/w{%'l##w#' i; :{nl]'/*{q#'ld;r'}{nlwb!/*de}'c\;;{nl'- {}rw]'/+,}##'*}#nc,',#nw]'/+kd'+e}+;#'rdq#w! nr'/ ') }+}{rl#'{n' ')# \ }'+}##(!!/") :t<-50?_==*a?putchar(31[a]):main(- 65,_,a+1):main((*a=='/')+t,_,a+1) :0<t?main(2,2,"%s"):*a=='/'||main(0,main(-61,*a, "!ek;dci@bK'(q)- [w]*%n+r3#l,{}:\nuwloca-O;m .vpbks,fxntdCeghiry"),a+1);}W h at k in d o f pr og ra m co ul d a s tu d en t w h o h at ed h is /h er T A h an d i n?
N as ty P ro gr am
n:=0; while(nisnotacounter-example totheRiemannHypothesis){ n++; } print“Hello”; The nasty program is a PASS if and only if the Riemann Hypothesis is false.D es pi te t h e si m pl ic it y of th e H E LL O a ss ig nm en t, th er e is n o pr og ra m t o co rr ec tl y gr ad e it ! A nd w e w ill p ro ve th is .
T h e th eo ry o f w h at c an an d c an ’t b e co m pu te d b y an i d ea l co m pu te r is ca lle d C om pu ta b ili ty T h eo ry or R ec ur si on T h eo ry .
Are all realsdescribable? Are all realscomputable? We saw that computable⇒describable, but do we also have describable ⇒computable?
NO NO
From Lecture 25: The “grading function”we just described is not computable! (We’ll see a proof soon.)
In fi ni te R A M M od el
Platonic Version: One memory location for each natural number 0, 1, 2, … Aristotelian Version: Whenever you run out of memory, the computer contacts the factory. A maintenance person is flown by helicopter and attaches 100 Gig of RAM and all programs resume their computations, as if they had never been interrupted.C om pu ta b le F un ct io n
Fix any finite set of symbols, Σ. Fix any precise programming language, e.g., Java. A program is any finite string of characters that is syntactically valid. A function f : Σ* →Σ* iscomputableif 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).C om pu ta b le F un ct io n
Fix anyfinite set of symbols, Σ. Fix any precise programming language, e.g., Java. A program is any finite string of charactersthat is syntactically valid. A function f : Σ* →Σ* iscomputableif 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). Hence: countablymanycomputable functions!T h er e ar e on ly co un ta b ly m an y J av a pr og ra m s. H en ce , th er e ar e on ly co un ta b ly m an y co m pu ta b le f un ct io ns .
U nc ou nt ab ly m an y fu nc ti on s
The functions f: Σ* →{0,1} are in 1-1 onto correspondence with the subsets of Σ* (the powersetof Σ* ). Subset S of Σ* ⇔Function f S x in S⇔f S(x) = 1 x not in S⇔f S(x) = 0U nc ou nt ab ly m an y fu nc ti on s
The functions f: Σ* →{0,1} are in 1-1 onto correspondence with the subsets of Σ* (the powersetof Σ* ). Hence, the set of all f: Σ* →{0,1} has the same size as the power set of Σ* . And since Σ* is countablyinfinite, its power set is uncountablyinfinite.C ou nt ab ly m an y co m pu ta b le f un ct io ns . U nc ou nt ab ly m an y fu nc ti on s fr om Σ
*to { 0 ,1 }. T h us , m os t fu nc ti on s fr om Σ
*to { 0 ,1 } ar e no t co m pu ta b le .
C an w e ex pl ic it ly d es cr ib e an u nc om pu ta b le fu nc ti on ? C an w e d es cr ib e an in te re st in g un co m pu ta b le fu nc ti on ?
N ot at io n A nd C on ve nt io ns
Fix a single programming language (Java) When we writeprogram Pwe are talking about the text of the source code for P P(x) meansthe outputthat arises from running program P on input x, assuming that P eventually halts. P(x) = ⊥means P did not halt on xT h e m ea ni ng o f P( P) It f ol lo w s fr om o ur c on ve nt io ns t h at P( P) m ea ns t h e ou tp ut o b ta in ed w h en w e ru n P on t h e te x t of i ts o w n so ur ce co d e.
P( P) … S o th at ’s w h at I l oo k lik e
T h e H al ti ng S et K D ef in it io n : K i s th e se t of a ll pr og ra m s P su ch th at P (P ) h al ts . K = { J av a P | P( P) h al ts }
T h e H al ti ng P ro b le m Is t h er e a pr og ra m H A LT s uc h t h at : H A LT (P ) = ye s, i f P( P) h al ts H A LT (P ) = no , if P (P ) d oe s no t h al t
T h e H al ti ng P ro b le m K = { P | P( P) h al ts } Is t h er e a pr og ra m H A LT s uc h t h at : H A LT (P ) = ye s, i f P ∈ K H A LT (P ) = no , if P ∉ K H A LT d ec id es w h et h er o r no t an y gi ve n pr og ra m i s in K .
T H E O R E M : T h er e is n o pr og ra m t o so lv e th e h al ti ng p ro b le m (A la n T ur in g 19 3 7 )
Suppose a program HALT existed that solved the halting problem. HALT(P)= yes, if P(P) halts HALT(P)= no, if P(P) does not halt We will call HALT as a subroutine in a new program called CONFUSE.C O N F U S E
CONFUSE(P) { if (HALT(P)) then loop forever;//i.e., we donthalt else exit;//i.e., we halt // text of HALT goes here } Does CONFUSE(CONFUSE) halt?C O N F U S E
CONFUSE(P) { if (HALT(P)) then loop forever;//i.e., we donthalt else exit;//i.e., we halt // text of HALT goes here } Suppose CONFUSE(CONFUSE) halts then HALT(CONFUSE) = TRUE ⇒CONFUSE will loop forever on input CONFUSE Suppose CONFUSE(CONFUSE) does not halt then HALT(CONFUSE) = FALSE ⇒CONFUSE will halt on input CONFUSECONTRADICTIONA la n T ur in g (1 9 12 -1 9 5 4 ) T h eo re m : [1 9 3 7 ] T h er e is n o pr og ra m t o so lv e th e h al ti ng pr ob le m
T ur in g’ s ar gu m en t is es se nt ia lly t h e re in ca rn at io n of C an to r’ s D ia go na liz at io n ar gu m en t th at w e sa w in t h e pr ev io us l ec tu re .
P 2… P 1
…P jP 1P 0 …P i
…P 0
All Pro
gra ms
All Programs (the input) Programs (computable functions) are countable, so we can put them in a (countablylong) list
P 2… P 1
…P jP 1P 0 …P i
…P 0 YES, if P i(P j) halts No, otherwise
All Pro
gra ms
All Programs (the input)
…P 2 d i
… d 1P 1
…P jP 1P 0 … …P i
…
d 0P 0 CONFUSE(P i) halts iff d i= no (The CONFUSE function is the negation of the diagonal.) Hence CONFUSE cannot be on this list.
Let d i= HALT(P i)
All Pro
gra ms
All Programs (the input)
A la n T ur in g (1 9 12 -1 9 5 4 ) T h eo re m : [1 9 3 7 ] T h er e is n o pr og ra m t o so lv e th e h al ti ng pr ob le m
Is t h er e a re al nu m b er t h at c an b e d es cr ib ed , b ut n ot co m pu te d ?
From last lecture:
C on si d er t h e re al nu m b er R
Kw h os e b in ar y ex pa ns io n h as a 1 i n th e j
thpo si ti on i ff P
j∈∈∈∈ ∈∈∈∈ K (i .e ., if t h e j
thpr og ra m h al ts ).
Pr oo f th at R
Kca nn ot b e co m pu te d
Suppose it is, and programFREDcomputes it. then consider the following program: MYSTERY(programtext P) for j = 0 to forever do { if (P == P j) then useFREDto compute jth bit of R K return YES if (bit == 1), NO if (bit == 0) } MYSTERY solves the halting problem!C om pu ta b ili ty T h eo ry : V oc ab ul ar y Le ss on
We call a set S⊆Σ* decidableorrecursiveif there is a program P such that: P(x) = yes, if x∈S P(x) = no, if x∉S We already know: the halting set K is undecidableD ec id ab le a nd C om pu ta b le
Subset S of Σ* ⇔Function f S x in S⇔f S(x) = 1 x not in S⇔f S(x) = 0 Set S is decidable ⇔function f Sis computable Sets are “decidable”(or undecidable), whereas functions are “computable”(or not)O ra cl es a nd R ed uc ti on s
Oracle for S
O ra cl e F or S et S Is x ∈ S ?
YES/NOE x am pl e O ra cl e S = O d d N at ur al s
Oracle for S4 ?
No8 1?
YesK 0= the set of programs that take no input and halt GIVEN: Oracle for K 0
Hey, I ordered an oracle for the famous halting set K, but when I opened the package it was an oracle for the different set K 0. But you can use this oracle for K 0 to build an oracle for K.
GIVEN: Oracle for K 0
P = [input I; Q] Does P(P) halt? BUILD: Oracle for K
Does [I:=P;Q] halt?
K 0= the set of programs that take no input and halt
W e’ ve r ed uc ed th e pr ob le m of d ec id in g m em b er sh ip i n K to t h e pr ob le m o f d ec id in g m em b er sh ip i n K
0. H en ce , d ec id in g m em b er sh ip fo r K
0m us t b e at l ea st a s h ar d as d ec id in g m em b er sh ip f or K .
T h us i f K
0w er e d ec id ab le th en K w ou ld b e as w el l. W e al re ad y kn ow K i s no t d ec id ab le , h en ce K
0is n ot d ec id ab le .
HELLO = the set of programs that print hello and halt GIVEN: HELLO Oracle
Does P halt? BUILD: Oracle for K 0
Let P’be P with all print statements removed. Is [P’; print HELLO] a hello program?
H en ce , th e se t H E LL O i s no t d ec id ab le .
EQUAL = All <P,Q> such that P and Q have identical output behavior on all inputs GIVEN: EQUAL Oracle
Is P in set HELLO? BUILD: HELLO OracleLet HI = [print HELLO] Are P and HI equal?
H al ti ng w it h i np ut , H al ti ng w it h ou t in pu t, H E LL O , an d E Q U A L ar e al l un d ec id ab le .
D io ph an ti ne E qu at io ns
Does polynomial 4X2 Y + XY2 = 0 have an integer root? I.e., does it have a zero at a point where all variables are integers? D = {multi-variant integer polynomials P | P has a root where all variables are integers} Famous Theorem:D is undecidable! [This is the solution to Hilbert’s 10th problem] HilbertResolution of Hilbert’s 10th Problem: Dramatis Personae Martin Davis, Julia Robinson, Yuri Matiyasevich(1982) and…
htt p:/
/w ww .go ld enm use um .co m/1 612 Hilb ert _en gl.h tm l
G oo d o ld F ib on ac ci m al …
Zeckendorf’sTheorem:Every number can be represented uniquely in the Fibonaccimalrepresentation!Po ly no m ia ls c an e nc od e pr og ra m s.
There is a computable function F: Java programs that take no input → Polynomials over the integers Such that program P halts ⇔F(P) has an integer rootD = the set of all integer polynomials with integer roots GIVEN: Oracle for D
Does program P halt? BUILD: HALTING Oracle
F(P) has integer root?