19
The Halting Problem There is a specific problem that is algorithmically unsolvable! One of the most philosophically important theorems in the theory of computation In fact, ordinary/practical problems may be unsolvable Software verification: Given a computer program and a precise specification of what the program is supposed to do (e.g., sort a list of numbers). Come up with an algorithm to prove the program works as required This cannot be done! But wait, cant we prove an addition, multiplication, sorting algorithm works? Note: The proof is not only to prove it works for a specific task, like sorting numbers but that its behavior always follows the specification! 10/17/19 Theory of Computation - Fall'19 Lorenzo De Stefani 1

The Halting Problem - Brown Universitycs.brown.edu/courses/csci1010/files/doc/notes... · The Halting Problem There is a specific problem that is algorithmically unsolvable! – One

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: The Halting Problem - Brown Universitycs.brown.edu/courses/csci1010/files/doc/notes... · The Halting Problem There is a specific problem that is algorithmically unsolvable! – One

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

Page 2: The Halting Problem - Brown Universitycs.brown.edu/courses/csci1010/files/doc/notes... · The Halting Problem There is a specific problem that is algorithmically unsolvable! – One

Thefirstundecidableproblem

DoesaTMacceptagiveninputstring?– WehaveshownthataCFLisdecidableandaCFGcanbesimulatedbyaTM.

– Thisdoesnotyieldacontradiction.TMsaremoreexpressivethanCFGs.

10/17/19 Theory of Computation - Fall'19

Lorenzo De Stefani 2

Page 3: The Halting Problem - Brown Universitycs.brown.edu/courses/csci1010/files/doc/notes... · The Halting Problem There is a specific problem that is algorithmically unsolvable! – One

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

Page 4: The Halting Problem - Brown Universitycs.brown.edu/courses/csci1010/files/doc/notes... · The Halting Problem There is a specific problem that is algorithmically unsolvable! – One

ComparisonofinfinitesetsIn1873mathematicianCantorwasconcernedwiththeproblemofmeasuringthesizesofinfinitesets–  Howcanwetellifoneinfinitesetisbiggerthananotheroriftheyarethesamesize?•  Wecannotusethecountingmethodthatwewoulduseforfinitesets.Example:howmanyevenintegersarethere?

–  Cantorobservedthattwofinitesetshavethesamesizeifeachelementinonesetcanbepairedwiththeelementintheother

10/17/19 Theory of Computation - Fall'19

Lorenzo De Stefani 4

Page 5: The Halting Problem - Brown Universitycs.brown.edu/courses/csci1010/files/doc/notes... · The Halting Problem There is a specific problem that is algorithmically unsolvable! – One

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

Page 6: The Halting Problem - Brown Universitycs.brown.edu/courses/csci1010/files/doc/notes... · The Halting Problem There is a specific problem that is algorithmically unsolvable! – One

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

Page 7: The Halting Problem - Brown Universitycs.brown.edu/courses/csci1010/files/doc/notes... · The Halting Problem There is a specific problem that is algorithmically unsolvable! – One

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

Page 8: The Halting Problem - Brown Universitycs.brown.edu/courses/csci1010/files/doc/notes... · The Halting Problem There is a specific problem that is algorithmically unsolvable! – One

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

Page 9: The Halting Problem - Brown Universitycs.brown.edu/courses/csci1010/files/doc/notes... · The Halting Problem There is a specific problem that is algorithmically unsolvable! – One

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>

Page 10: The Halting Problem - Brown Universitycs.brown.edu/courses/csci1010/files/doc/notes... · The Halting Problem There is a specific problem that is algorithmically unsolvable! – One

•  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

Page 11: The Halting Problem - Brown Universitycs.brown.edu/courses/csci1010/files/doc/notes... · The Halting Problem There is a specific problem that is algorithmically unsolvable! – One

ImplicationsRbeinguncountablehasanimportantapplicationinthetheoryofcomputation•  TherearecountablymanyTuringMachines•  Thereareuncountablymanylanguages•  EachTMrecognizesonesinglelanguageàsomelanguagesarenotrecognizedbyanyTuringmachine.– Corollary:somelanguagesarenotTuring-recognizable

10/17/19 Theory of Computation - Fall'19

Lorenzo De Stefani 11

Page 12: The Halting Problem - Brown Universitycs.brown.edu/courses/csci1010/files/doc/notes... · The Halting Problem There is a specific problem that is algorithmically unsolvable! – One

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

Page 13: The Halting Problem - Brown Universitycs.brown.edu/courses/csci1010/files/doc/notes... · The Halting Problem There is a specific problem that is algorithmically unsolvable! – One

HaltingProblemisUndecidable

Provethathaltingproblemisundecidable• LetATM={<M,w>|MisaTMandacceptsw}• ProofTechnique:– AssumeATMisdecidableandobtainacontradiction– Adiagonalizationargument

10/17/19 Theory of Computation - Fall'19

Lorenzo De Stefani 13

Page 14: The Halting Problem - Brown Universitycs.brown.edu/courses/csci1010/files/doc/notes... · The Halting Problem There is a specific problem that is algorithmically unsolvable! – One

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

Page 15: The Halting Problem - Brown Universitycs.brown.edu/courses/csci1010/files/doc/notes... · The Halting Problem There is a specific problem that is algorithmically unsolvable! – One

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

Page 16: The Halting Problem - Brown Universitycs.brown.edu/courses/csci1010/files/doc/notes... · The Halting Problem There is a specific problem that is algorithmically unsolvable! – One

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

Page 17: The Halting Problem - Brown Universitycs.brown.edu/courses/csci1010/files/doc/notes... · The Halting Problem There is a specific problem that is algorithmically unsolvable! – One

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

Page 18: The Halting Problem - Brown Universitycs.brown.edu/courses/csci1010/files/doc/notes... · The Halting Problem There is a specific problem that is algorithmically unsolvable! – One

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

Page 19: The Halting Problem - Brown Universitycs.brown.edu/courses/csci1010/files/doc/notes... · The Halting Problem There is a specific problem that is algorithmically unsolvable! – One

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