Download - The Halting Problem - Brown University
TheHaltingProblemThereisaspecificproblemthatisalgorithmicallyunsolvable!– Oneofthemostphilosophicallyimportanttheoremsinthetheoryofcomputation
– Infact,ordinary/practicalproblemsmaybeunsolvable– Softwareverification:Givenacomputerprogramandaprecisespecificationofwhattheprogramissupposedtodo(e.g.,sortalistofnumbers).Comeupwithanalgorithmtoprovetheprogramworksasrequired
– Thiscannotbedone!– Butwait,can’tweproveanaddition,multiplication,sortingalgorithmworks?
– Note:Theproofisnotonlytoproveitworksforaspecifictask,likesortingnumbersbutthatitsbehavioralwaysfollowsthespecification!
10/17/19 Theory of Computation - Fall'19
Lorenzo De Stefani 1
Thefirstundecidableproblem
DoesaTMacceptagiveninputstring?– WehaveshownthataCFLisdecidableandaCFGcanbesimulatedbyaTM.
– Thisdoesnotyieldacontradiction.TMsaremoreexpressivethanCFGs.
10/17/19 Theory of Computation - Fall'19
Lorenzo De Stefani 2
Why“Halting”problem?
• ATM={(M,w)|MisaTMandMacceptsw}• ATMisundecidable– ItcanonlybeundecidableduetoaloopofMonw.– Ifwecoulddetermineifitwillloopforever,thencouldreject.HenceATMisoftencalledthehaltingproblem.• AsitisimpossibletodetermineifaTMwillalwayshaltoneverypossibleinput
– NotethatthisisTuringrecognizable!WecansimulateMoninputw• IfMacceptswthenaccept(M,w)• IfMrejectswthenreject(M,w)
10/17/19 Theory of Computation - Fall'19
Lorenzo De Stefani 3
ComparisonofinfinitesetsIn1873mathematicianCantorwasconcernedwiththeproblemofmeasuringthesizesofinfinitesets– Howcanwetellifoneinfinitesetisbiggerthananotheroriftheyarethesamesize?• Wecannotusethecountingmethodthatwewoulduseforfinitesets.Example:howmanyevenintegersarethere?
– Cantorobservedthattwofinitesetshavethesamesizeifeachelementinonesetcanbepairedwiththeelementintheother
10/17/19 Theory of Computation - Fall'19
Lorenzo De Stefani 4
FunctionPropertyDefinitionsGivenasetAandBandafunctionffromAtoB– fisone-to-oneifitnevermapstwoelementsinAtothesameelementinB• Thefunctionadd-twoisone-to-onewhereasabsolute-valueisnot
– fisontoifeveryiteminBisreachedfromsomevalueina(i.e.,f(a)=bforeveryb∈B).• Forexample,ifAandBarethesetofintegers,thenadd-twoisontobutifAandBarethepositiveintegers,thenitisnotontosinceb=1isneverhit.
– Afunctionthatisone-to-oneandontohasa(one-to-one)correspondence• ThisallowsallitemsinAandBtobepaired
10/17/19 Theory of Computation - Fall'19
Lorenzo De Stefani 5
AnExampleofPairingSetItems• LetNbethesetofnaturalnumbers{1,2,3,…}andletEbethesetofevennaturalnumbers{2,4,6,…}.
• UsingCantor’sdefinitionofsizewehavethatNandEhavethesamesize.– ThecorrespondenceffromNtoEisf(n)=2n.
• ThisissomehowcounterintuitivesinceEisapropersubsetofN!!
• Focusononthedefinition:sincef(n)isa1:1correspondence,sowesaytheyarethesamesize.
• Definition:AsetiscountableifeitheritisfiniteorithasthesamesizeasN,thesetofnaturalnumbers(infinitelycountable)
10/17/19 Theory of Computation - Fall'19
Lorenzo De Stefani 6
Example:RationalNumbers
• Q={m/n:m,n∈N},thesetofpositiveRationalNumbers
• QseemsmuchlargerthanN,butaccordingtoourdefinition,theyarethesamesize.– Hereisthe1:1correspondencebetweenQandN– WeneedtolistalloftheelementsofQandthenlabelthefirstwith1,thesecondwith2,etc.• WeneedtomakesureeachelementinQislistedonlyonce
10/17/19 Theory of Computation - Fall'19
Lorenzo De Stefani 7
CorrespondencebetweenNandQ
– Writingthelistbygoingrow-to-
roworcolumnbycolumnisabadidea!• Since1strowisinfinite,wouldnevergettothesecondrow
– Weusediagonals,notaddingthevaluesthatareequivalent• Sotheorderis1/1,2/1,½,3/1,1/3,…
– ThisyieldsacorrespondencebetweenQandN• Thatis,N=1correspondsto1/1,N=2correspondsto2/1,N=3correspondsto½etc.
1/1 1/2 1/3 1/4 1/5 2/1 2/2 2/3 2/4 2/5 3/1 3/2 3/3 3/4 3/5 4/1 4/2 4/3 4/4 4/5 5/1 5/2 5/3 5/4 5/5
10/17/19 Theory of Computation - Fall'19
Lorenzo De Stefani
Tobuildourcorrespondence,webuildaninfinitematrixcontainingallthepositiverationalnumbers
8
RisUncountable
• ArealnumberisonethathasadecimalrepresentationandRissetofRealNumbers– Includesthosethatcannotberepresentedwithafinitenumberofdigits(e.g.,)
• Willshowthattherecanbenopairing-nopossibleone-to-onecorrespondence-ofelementsbetweenRandN– Proofbycontradiction:Givenanypossibleparingwewillfindsomevaluexthatnotinthepairing
10/17/19 Theory of Computation - Fall'19
Lorenzo De Stefani 9
⇡,p2, 3.3̄
<latexit sha1_base64="(null)">(null)</latexit><latexit sha1_base64="(null)">(null)</latexit><latexit sha1_base64="(null)">(null)</latexit><latexit sha1_base64="(null)">(null)</latexit>
• Assumethatonecompletemappingexits• Wenowdescribearecipetoobtainavaluex
between0and1whichisnotintheinfinitelist– Toensurethatx≠f(1),pickadigitnotequaltothe
firstdigitafterthedecimalpoint.Anyvaluenotequalto1willwork.Pick4sowehave.4
– Tox≠f(2),pickadigitnotequaltotheseconddigit.Anyvaluenotequalto5willwork.Pick6.Wehave.46
– Continue,choosingvaluesalongthe“diagonal”ofdigits(i.e.,ifwetookthef(n)columnandputonedigitineachcolumnofanewtable).
• Theselectedvaluexisguaranteedtonotalreadybeinthelistsinceitdiffersinatleastonepositionwitheveryothernumberinthelist.
n f(n)
1 3.14159…
2 55.5555…
3 0.12345…
4 0.500000
. .
10/17/19 Theory of Computation - Fall'19
Lorenzo De Stefani
RisUncountable
10
ImplicationsRbeinguncountablehasanimportantapplicationinthetheoryofcomputation• TherearecountablymanyTuringMachines• Thereareuncountablymanylanguages• EachTMrecognizesonesinglelanguageàsomelanguagesarenotrecognizedbyanyTuringmachine.– Corollary:somelanguagesarenotTuring-recognizable
10/17/19 Theory of Computation - Fall'19
Lorenzo De Stefani 11
SomeLanguagesareNotTuring-recognizableProof:
– Theset∑*iscountable:thereareonlyafinitenumberofstringsofeachlength,wemayformalistof∑*bywritingdownallstringsoflength0,length1,length2,etc.
– ThesetofallTuringMachinesMiscountablesinceeachTMMhasanencodingintoastring<M>• ThesetofvalidTM’sisasubsetofthesetofpossiblestrings.• Asthelatteriscountable,soistheformer.
– ThesetofalllanguagesLover∑isuncountable• thesetofallinfinitebinarysequencesBisuncountable(eachsequenceisinfinitelylong)– ThesamediagonalizationproofweusedtoproveRisuncountable
• LisuncountablebecauseithasacorrespondencewithB– Assume∑*={s1,s2,s3…}.Wecanencodeanylanguageasacharacteristicbinary
sequence,wherethebitindicateswhetherthecorrespondingsiisamemberofthelanguage.Thus,thereisa1:1mapping.
• SinceBisuncountableandLandBareofequalsize,Lisuncountable– SincethesetofTMsiscountableandthesetoflanguagesisnot,we
cannotputthesetoflanguagesintoacorrespondencewiththesetofTuringMachines.ThusthereexistssomelanguageswithoutacorrespondingTuringmachine
10/17/19 Theory of Computation - Fall'19
Lorenzo De Stefani 12
HaltingProblemisUndecidable
Provethathaltingproblemisundecidable• LetATM={<M,w>|MisaTMandacceptsw}• ProofTechnique:– AssumeATMisdecidableandobtainacontradiction– Adiagonalizationargument
10/17/19 Theory of Computation - Fall'19
Lorenzo De Stefani 13
Proof:HaltingProblemisUndecidable
• AssumeATMisdecidable• LetHbeadeciderforATM
– Oninput<M,w>,whereMisaTMandwisastring,HhaltsandacceptsifMacceptsw;otherwiseitrejects
• ConstructaTMDusingHasasubroutine– DcallsH(M,<M>)todeterminewhatMdoeswhentheinputstringisits
owndescription<M>.– DthenoutputstheoppositeofH’sanswer– D(<M>)acceptsifMdoesnotaccept<M>andrejectsifMaccepts<M>
• AssumewerunDonitsowndescriptionD(<D>)– DinvokesH(D,<D>)whichacceptsifDaccepts<D>;otherwiseitrejects– D(<D>)=acceptifDdoesnotaccept<D>andrejectifDaccepts<D>– AcontradictionsoHcannotbeadeciderforATM
10/17/19 Theory of Computation - Fall'19
Lorenzo De Stefani 14
ConstructingDbydiagonalization
<M1>
<M2> <M3> <M4> … <D>
M1 Accept Reject Accept Reject … Accept
M2 Accept Accept Accept Accept … Accept
M3 Reject Reject Reject Reject … Reject
M4 Accept Accept Reject Reject … Accept
.
D Reject Reject Accept Accept … Contradiction
.
10/17/19 Theory of Computation - Fall'19
Lorenzo De Stefani 15
Softwarechecking• Youwriteaprogram,halts(P,X)thattakesasinputanyprogram,P,andtheinputtothatprogram,X– Yourprogramhalts(P,X)analyzesPandreturns“yes”ifPwillhaltonXand“no”ifPwillnothaltonX
• Younowwriteaprocedurelul(X)withassingleinstruction:lul(X){a:ifhalts(X,X)thengotoaelsehalt}ThisprogramhaltsifPdoesnothaltonX;otherwiseitdoeshalt
• Doeslul(lul)halt?– Ithaltsifandonlyifhalts(lul,lul)returnsno
• Ithaltsifandonlyifitdoesnothalt.Contradiction.• Thuswehaveproventhatyoucannotwriteaprogramtodetermineifanarbitraryprogramwillhaltorloop
10/17/19 Theory of Computation - Fall'19
Lorenzo De Stefani 16
Whatdoesthismean?• Thehaltingproblemaskswhetherwecantellif
someTMMwillacceptaninputstring• Weareaskingifthelanguagebelowisdecidable– ATM={(M,w)|MisaTMandMacceptsw}
• Itisnotdecidable– Misainputvariabletoo!– Somealgorithmsaredecidable,likesorting
algorithms• ItisTuring-recognizable– SimulatetheTMonwandifitaccepts/rejects,
thenaccept/reject.10/17/19
Theory of Computation - Fall'19 Lorenzo De Stefani 17
Co-TuringRecognizable• Alanguageisco-TuringrecognizableifitisthecomplementofaTuring-recognizablelanguage
• Theorem:AlanguageisdecidableifandonlyifitisTuring-recognizableandco-Turing-recognizable– IfalanguageLisTuring-recognizablethenthereexistsaTM1whichacceptsitsstringsinfinitetime• IftheTM1doesnotaccept,itmayrejectorloop(itwhichcaseitmaybenotdecidable).
– IfLisco-Turing-recognizablethenitscomplementLisTuring-recognizable• HencethereexistTM2whichacceptsstringsfromLinfinitetime• IfastringisacceptedbyTM2thenwehavethatitisnotinL
– Lisdecidable10/17/19
Theory of Computation - Fall'19 Lorenzo De Stefani 18
ComplementofATMisnotTuring-recognizable
• Ifalanguageisundecidable,theneitherthelanguageoritscomplementisnotTuring-recognizable!
• ATMisnotTuring-recognizableProof:– WeknowthatATMisTuring-recognizablebutnotdecidable
– IfATMwerealsoTuring-recognizable,thenATMwouldbedecidable,whichitisnot
– ThusATMisnotTuring-recognizable
10/17/19 Theory of Computation - Fall'19
Lorenzo De Stefani 19