/
Introduction to Algorithms Notes on Turing Machines CS  Spring  April    Denition of a Introduction to Algorithms Notes on Turing Machines CS  Spring  April    Denition of a

Introduction to Algorithms Notes on Turing Machines CS Spring April Denition of a - PDF document

test
test . @test
Follow
570 views
Uploaded On 2015-01-21

Introduction to Algorithms Notes on Turing Machines CS Spring April Denition of a - PPT Presentation

They provide a precise formal de64257nition of what it means for a function to be computable Many other de64257nitions of computation have been proposed over the years for example one could try to formalize precisely what it means to run a program ID: 33534

They provide precise

Share:

Link:

Embed:

Download Presentation from below link

Download Pdf The PPT/PDF document "Introduction to Algorithms Notes on Turi..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

NotethataTuringmachineisnotpreventedfromoverwritingtherightmostsymbolonitstapeormovingtotherightofit.Infact,thiscapabilityisnecessaryinorderforTuringmachinestoperformcomputationsthatrequiremorespacethanisgivenintheiroriginalinputstring.Havingde nedthespeci cationofaTuringmachine,wemustnowpindownade nitionofhowtheyoperate.Thishasbeeninformallydescribedabove,butit'stimetomakeitformal.Thatbeginswithformallyde ningthecon gurationoftheTuringmachineatanytime(thestateofitstape,aswellasthemachine'sownstateanditspositiononthetape)andtherulesforhowitscon gurationchangesovertime.De nition2.Thesetisthesetofall nitesequencesofelementsof.Whenanelementofisdenotedbyalettersuchasx,thentheelementsofthesequencexaredenotedbyx0;x1;x2;:::;xn�1,wherenisthelengthofx.Thelengthofxisdenotedbyjxj.Acon gurationofaTuringmachineisanorderedtriple(x;q;k)2KN,wherexdenotesthestringonthetape,qdenotesthemachine'scurrentstate,andkdenotesthepositionofthemachineonthetape.Thestringxisrequiredtobeginwith.andendwitht.Thepositionkisrequiredtosatisfy0kjxj.IfMisaTuringmachineand(x;q;k)isitscon gurationatanypointintime,thenitscon guration(x0;q0;k0)atthefollowingpointintimeisdeterminedasfollows.Let(p;;d)=(q;xk):Thestringx0isobtainedfromxbychangingxkto,andalsoappendingttotheendofx,ifk=jxj�1.Thenewstateq0isequaltop,andthenewpositionk0isequaltok�1;k+1;orkaccordingtowhetherdis ;!;or�,respectively.Weexpressthisrelationbetween(x;q;k)and(x0;q0;k0)bywriting(x;q;k)M�!(x0;q0;k0):AcomputationofaTuringmachineisasequenceofcon gurations(xi;qi;ki),whereirunsfrom0toT(allowingforthecaseT=1)thatsatis es:Themachinestartsinavalidstartingcon guration,meaningthatq0=sandk0=0.Eachpairofconsecutivecon gurationsrepresentsavalidtransition,i.e.for0iT,itisthecasethat(xi;qi;ki)M�!(xi+1;qi+1;ki+1).IfT=1,wesaythatthecomputationdoesnothalt.IfT1,werequirethatqT2fhalt,yes,nogandwesaythatthecomputationhalts.IfqT=yes(respectively,qT=no)wesaythatthecomputationoutputs\yes"(respectively,outputs\no").IfqT=haltthentheoutputofthecomputationisde nedtobethestringobtainedbyremoving.andtfromthestartandendofxT.Inallthreecases,theoutputofthecomputationisdenotedbyM(x),wherexistheinput,i.e.thestringx0withouttheinitial.and nalt.Ifthecomputationdoesnothalt,thenitsoutputisunde nedandwewriteM(x)=%. Theupshotofthisdiscussionisthatonemuststandardizeoneitherasingly-in niteordoubly-in nitetape,forthesakeofmakingaprecisede nition,butthechoicehasnoe ectonthecomputationalpowerofthemodelthatiseventuallyde ned.Aswegothroughtheotherpartsofthede nitionofTuringmachines,wewillencountermanyotherexamplesofthisphenomenon:detailsthatmustbestandardizedforthesakeofprecision,butwheretheprecisechoiceofde nitionhasnobearingonthedistinctionbetweencomputableanduncomputable. a1totheinputusingasubroutineverysimilartoExample1.We'llrefertothestatesinthatsubroutineasprepend::s;prepend::r;prepend::`:Example3.Wecancomputethebinarypre-cedessorfunctioninroughlythesameway.Wemusttakecaretode nethevalueofthepre-decessorfunctionwhenitsinputisthenum-ber0,sincewehaven'tyetspeci edhownega-tivenumbersshouldberepresentedonaTuringmachine'stapeusingthealphabetf.;t;0;1g.Ratherthanspecifyaconventionforrepresent-ingnegativenumbers,wewillsimplyde nethevalueofthepredecessorfunctiontobe0whenitsinputis0.Also,forconvenience,wewillallowtheoutputofthebinarypredecessorfunctiontohaveanynumberofinitialcopiesofthedigit0. (q;)q  state symbol direction s . z . ! z 0 z 0 !z 1 r 1 !z t t t r 0 r 0 !r 1 r 1 !r t ` t ` 0 ` 1 ` 1 t 0 t 0 t 0 t 1 t 1 t . halt . �Ourprogramtocomputethebinarypredecessorofnthusbeginswithatesttoseeifnisequalto0.Themachinemovestotheright,remaininginstatezunlessitseesthedigit1.Ifitreachestheendofitsinputinstatez,thenitsimplyrewindstothebeginningofthetape.Otherwise,itdecrementstheinputinmuchthesamewaythattheprecedingexampleincrementedit:inthiscaseweusestate`tochangethetrailing0'sto1'suntilweencountertherightmost1,andthenweenterstatettorewindtothebeginningofthetape.2.1PseudocodeforTuringmachinesTransformingevensimplealgorithmsintoTuringmachinestatetransitiondiagramscanbeanunbearablycumbersomeprocess.Itisevenmoreunbearabletoreadastatetransitiondiagramandtrytodeduceaplain-Englishdescriptionofwhatthealgorithmaccomplishes.Itisdesirabletoexpresshigher-levelspeci cationsofTuringmachinesusingpseudocode.Ofcourse,thewholepointofde ningTuringmachinesistogetawayfromtheinformalnotionof\algorithm"asexempli edbypseudocode.Inthissectionwewilldiscussastraight-forward,directtechniquefortransformingacertaintypeofpseudocodeintoTuringmachinestatediagrams.Thepseudocodetowhichthistransformationappliesmustsatisfythefollowingrestrictions:1.Theprogramhasa nite,prede nednumberofvariables.2.Eachvariablecantakeonlya nite,prede nedsetofpossiblevalues.3.Recursivefunctioncallsarenotallowed.Theword\prede ned"abovemeans,\speci edbytheprogram,notdependingontheinput."Notethatthisisreallyquiterestrictive.Forexample,ourpseudocodeisnotallowedtousepointerstolocationsonthetape.(Suchvariablescouldnotbelimitedtoaprede ned nitesetofvalues.)Integer-valuedvariablesaresimilarlyo limits,unlessthereareprede nedlowerandupperboundsonthevaluesofsaidvariables.Givenpseudocodethatmeetstheaboverestrictions,itisstraightforwardtotransformitintoanactualTuringmachine.SupposethatthepseudocodehasLlinesandnvariablesv1;:::;vn.For1inletVidenotetheprede ned nitesetofvaluesforvi.Thestatesetofthe numbersjj;jj+1;:::;jj+jKj�1(withjjrepresentingthestartingstates)andthatfhalt,yes,nog[f ;!;�gconsistsofthenumbersjj+jKj;:::;jj+jKj+5:Now,thedescriptionofTuringmachineMisde nedtobea nitestringinthealphabetf0,1,`(',`)',`,'g,determinedasfollows.M=m;n;12:::Nwheremisthenumberjjinbinary,nisthenumberjKjinbinary,andeachof1;:::;Nisastringencodingoneofthetransitionrulesthatmakeupthemachine'stransitionfunction.Eachsuchruleisencodedusingastringi=(q;;p;;d)whereeachofthe vepartsq;;p;;disastringinf0;1g`encodinganelementof[K[fhalt,yes,nog[f ;!;�gasdescribedabove.ThepresenceofiinthedescriptionofMindicatesthatwhenMisinstateqandreadingsymbol,thenittransitionsintostatep,writessymbol,andmovesindirectiond.Inotherwords,thestringi=(q;;p;;d)inthedescriptionofMindicatesthat(q;)=(p;;d):3.2De nitionofauniversalTuringmachineAuniversalTuringmachineisaTuringmachineUwithalphabetf0,1,`(',`)',`,',`;'g.Ittakesaninputoftheform.M;xt,whereMisavaliddescriptionofaTuringmachineandxisastringinthealphabetofM,encodedusing`-bitblocksasdescribedearlier.(Ifitsinputfailstomatchthisspeci cation,theuniversalTuringmachineUisallowedtobehavearbitrarily.)ThecomputationofU,giveninput.M;xt,hasthesameterminationstatus|haltinginstate\halt",\yes",or\no",orneverhalting|asthecomputationofMoninputx.Further-more,ifMhaltsoninputx(and,consequently,Uhaltsoninput.M;xt)thenthestringonU'stapeatthetimeithaltsisequaltothestringonM'stapeatthetimeithalts,againtranslatedintobinaryusing`-bitblocksasspeci edabove.ItisfarfromobviousthatauniversalTuringmachineexists.Inparticular,suchamachinemusthavea nitenumberofstates,yetitmustbeabletosimulateacomputationperformedbyaTuringmachinewithamuchgreaternumberofstates.InSection3.4wewilldescribehowtoconstructauniversalTuringmachine.First,itishelpfultoextendthede nitionofTuringmachinestoallowmultipletapes.Afterdescribingthisextensionwewillindicatehowamulti-tapeTuringmachinecanbesimulatedbyasingle-tapemachine(atthecostofaslowerrunningtime).3.3Multi-tapeTuringmachinesAmulti-tapeTuringmachinewithktapesisde nedinnearlythesamewayasaconventionalsingle-tapeTuringmachine,exceptthatitstoreskstringssimultaneously,maintainsapositionineachofthekstrings,updatesthesekpositionsindependently(i.e.itcanmoveleftinonestringwhilemovingrightinanother),anditsstatechangesarebasedontheentirek-tupleofsymbolsthatitreadsatanypointintime.Moreformally,ak-tapeTuringmachinehasa nitealphabetandstatesetKasbefore,butitstransitionfunctionis:Kk!(K[fhalt,yes,nog)(f ;!;�g)k; Algorithm1Simulationofmulti-tapeTuringmachineMbysingle-tapeTuringmachineM. 1:q s//Initializestate.2:repeat3://Simulationround4://First, ndoutwhatsymbolsMisseeing.5:repeat6:Moverightwithoutchangingcontentsofstring.7:fori=1;:::;kdo8:ifith agatcurrentlocationequals1then9:i ithsymbolatcurrentlocation.10:endif11:endfor12:untilMreachest13:repeat14:Moveleftwithoutchangingcontentsofstring.15:untilMreaches.16://Now,1;:::;kstoretheksymbolsthatMisseeing.17://EvaluatestatetransitionfunctionformachineM.18:q0;(01;d1);(02;d2);:::;(0k;dk) (q;1;:::;k)19:fori=1;:::;kdo20://Phasei21:repeat22:Moverightwithoutchangingthecontentsofthestring.23:untilalocationwhoseith agis1isreached.24:Changetheithsymbolatthislocationto0i.25:ifdi= then26:Changeith agto0atthislocation.27:Moveonestepleft28:Changeith agto1.29:elseifdi=!then30:Changeith agto0atthislocation.31:Moveonestepright.32:Changeith agto1.33:endif34:repeat35:Moveleftwithoutchangingthecontentsofthestring.36:untilthesymbol.isreached.37:endfor38:q q039:untilq2fhalt;yes;nog40://Ifthesimulationreachesthisline,q2fhalt;yes;nog:41:ifq=yesthen42:Transitionto\yes"state.43:elseifq=nothen44:Transitionto\no"state.45:else46:Transitionto\halt"state.47:endif identicaltothe`-bitstringonitsstatetapeandisidenticaltothe`-bitstringonitsworkingtape.Thesecomparisonsareperformedonebitatatime,andifeitherofthecomparisonsfails,thenUrewindsitsstatetapecursorbacktothe.anditrewindsitsworkingtapecursorbacktothecommathatmarkeditslocationatthestartofthisiterationofthemainloop.ItthenmovesitsdescriptiontapecursorforwardtothedescriptionofthenextruleinM'stransitionfunction.Whenit nallyencountersapair(q;)thatmatchesitscurrentstatetapeandworkingtape,thenitmovesforwardtoreadthecorresponding(p;;d),anditcopiespontothestatetape,ontotheworkingtape,andthenmovesitsworkingtapecursorinthedirectionspeci edbyd.Finally,toendthisiterationofthemainloop,itrewindsthecursorsonitsdescriptiontapeandstatetapebacktotheleftmostposition.Itisworthmentioningthattheuseof vetapesintheuniversalTuringmachineisoverkill.Inparticular,thereisnoneedtosavetheinput.M;xtonaseparateread-onlyinputtape.Aswehaveseen,theinputtapeisneverusedaftertheendoftheinitializationstage.Thus,forexample,wecanskiptheinitializationstepofcopyingthedescriptionofMfromtheinputtapetothedescriptiontape;instead,aftertheinitialization nishes,wecantreattheinputtapehenceforwardasifitwerethedescriptiontape. Algorithm2UniversalTuringmachine,initialization. 1://CopythetransitionfunctionofMfromtheinputtapetothedescriptiontape.2:Moverightpastthe rstandsecondcommasontheinputtape.3:whilenotreading';'oninputtapedo4:Readinputtapesymbol,copytodescriptiontape,moverightonbothtapes.5:endwhile6://Now,writetheidenti ersofthehaltingstatesandthe\directionofmotionsymbols"onthespecialtape.7:Movetostartofinputtape.8:Usingbinaryadditionsubroutine,writem+ninbinaryonworkingtape.9:fori=0;1;2;3;4;5do10:Onspecialtape,writebinaryrepresentationofm+n+i,followedby';'.11://Thisdoesn'trequirestoringm+ninmemory,becauseit'sstoredontheworkingtape.12:endfor13://Copytheinputstringxontotheworkingtape,insertingcommasbetweeneach`-bitblock.14:Writem+n+6inbinaryonthestatetape.//Inordertostorethevalueof`.15:Startingfromleftedgeofinputtape,moverightuntil';'isreached.16:Movetoleftedgeofworkingtapeandstatetape.17:Moveonesteprightonstatetape.18:repeat19:whilestatetapesymbolisnottdo20:Moverightoninputtape,workingtape,andstatetape.21:Copysymbolfrominputtapetoworkingtape.22:endwhile23:Write','onworkingtape.24:Rewindtoleftedgeofstatetape,thenmoveonestepright.25:untilinputtapesymbolist26:Copymfrominputtapetostatetape.27://Donewithinitialization! 4UndecidableproblemsInthissectionwewillseethatthereexistcomputationalproblemsthataretoodiculttobesolvedbyanyTuringmachine.SinceTuringmachinesareuniversalenoughtorepresentanyalgorithmrunningonadeterministiccomputer,thismeansthereareproblemstoodiculttobesolvedbyanyalgorithm.4.1De nitionsTobepreciseaboutthenotionofwhatwemeanby\computationalproblems"andwhatitmeansforaTuringmachineto\solve"aproblem,wede neproblemsintermsoflanguages,whichcorrespondtodecisionproblemswithayes/noanswer.Wede netwonotionsof\solving"aproblemspeci edbyalanguageL.The rstofthesede nitions(\decidingL")correspondstowhatweusuallymeanwhenwespeakofsolvingacomputationalproblem,i.e.terminatingandoutputtingacorrectyes/noanswer.Thesecondde nition(\acceptingL")isa\one-sided"de nition:iftheansweris\yes",themachinemusthaltandprovidethisansweraftera niteamountoftime;iftheansweris\no",themachineneednoteverhaltandprovidethisanswer.Finally,wegivesomede nitionsthatapplytocomputationalproblemswherethegoalistooutputastringratherthanjustasimpleyes/noanswer.De nition3.Let0=nf.;tg:AlanguageisanysetofstringsL0.SupposeMisaTuringmachineandLisalanguage.1.MdecidesLifeverycomputationofMhaltsinthe\yes"or\no"state,andListhesetofstringsoccurringinstartingcon gurationsthatleadtothe\yes"state.2.LisdecidableifthereisamachineMthatdecidesL.3.MacceptsLifListhesetofstringsoccurringinstartingcon gurationsthatleadMtohaltinthe\yes"state.4.LisrecursivelyenumerableifthereisamachineMthatacceptsL.5.Mcomputesagivenfunctionf:0!0ifeverycomputationofMhalts,andforallx20,thecomputationwithstartingcon guration(.xt;s;0)endsincon guration(.f(x)tt;halt;0);wherettdenotesanysequenceofoneormorerepetitionsofthesymbolt.6.fisacomputablefunctionifthereisaTuringmachineMthatcomputesf.4.2UndecidabilityviacountingOnesimpleexplanationfortheexistenceofundecidablelanguagesisviaacountingargument:therearesimplytoomanylanguages,andnotenoughTuringmachinestodecidethemall!Thiscanbeformalizedusingthedistinctionbetweencountableanduncountablesets.De nition4.Anin nitesetiscountableifandonlyifthereisaone-to-onecorrespondencebetweenitselementsandthenaturalnumbers.Otherwiseitissaidtobeuncountable.Lemma1.Ifisa nitesettheniscountable. Proof.ThesetoflanguagesLisuncountablebyLemmas1and2.ThesetofTuringmachineswithalphabetiscountablebecauseeachsuchTuringmachinehasadescriptionwhichisa nite-lengthstringofsymbolsinthealphabetf0,1,`(',`)',`,'g.ThereforetherearestrictlymorelanguagesthenthereareTuringmachines,sotherearelanguagesthatarenotacceptedbyanyTuringmachine. 4.3UndecidabilityviadiagonalizationTheproofofTheorem3isquiteunsatisfyingbecauseitdoesnotprovideanyexampleofaninterestinglanguagethatisnotrecursivelyenumerable.Inthissectionwewillrepeatthe\diag-onalargument"fromtheproofofTheorem2,thistimeinthecontextofTuringmachinesandlanguages,toobtainamoreinterestingexampleofasetthatisnotrecursivelyenumerable.De nition5.ForaTuringmachineM,wede neL(M)tobethesetofallstringsacceptedbyM:L(M)=fxjMhaltsandoutputs\yes"oninputxg:Supposeisa nitealphabet,andsupposewehavespeci edamappingfromf0,1,`(',`)',`,'gtostringsofsome xedlengthin,sothateachTuringmachinehasadescriptioninobtainedbytakingitsstandarddescription,usingtomapeachsymbolto,andconcatenatingtheresultingsequenceofstrings.Foreveryx2wewillnowde nealanguageL(x)0asfollows.IfxisthedescriptionofaTuringmachineMthenL(x)=L(M);otherwise,L(x)=;:WearenowinapositiontorepeatthediagonalconstructionfromtheproofofTheorem2.Consideranin nitetwo-dimensionaltablewhoserowsandcolumnsareindexedbyelementsof0. x0x1x2x3... L(x0) 0100...L(x1) 1101...L(x2) 0010...L(x3) 1011...... ............De nition6.ThediagonallanguageD0isde nedbyD=fx20jx62L(x)g:Theorem4.ThediagonallanguageDisnotrecursivelyenumerable.Proof.TheproofisexactlythesameastheproofofTheorem2.Assume,bywayofcontradiction,thatD=L(x)forsomex.Eitherx2Dorx62Dandweobtainacontradictioninbothcases.Ifx2Dthenthisviolatesthefactthatx62L(x)forallx2D.Ifx62Dthenthisviolatesthefactthatx2L(x)forallx62D. Corollary5.ThereexistsalanguageLthatisrecursivelyenumerablebutitscomplementisnot.Proof.LetLbethecomplementofthediagonallanguageD.ATuringmachineMthatacceptsLcanbedescribedasfollows:giveninputx,constructthestringx;xandrunauniversalTuringmachineonthisinput.Itisclearfromthede nitionofLthatL=L(M),soLisrecursivelyenumerable.Wehavealreadyseenthatitscomplement,D,isnotrecursivelyenumerable. 4.5Rice'sTheoremTheorem7showsthat,unfortunately,thereexistinterestinglanguagesthatarenotdecidable.Inparticular,thequestionofwhetheragivenTuringmachinehaltsonagiveninputisnotdecidable.Unfortunately,thesituationismuchworsethanthis!Ournexttheoremshowsthatessentiallyanynon-trivialpropertyofTuringmachinesisundecidable.(Actually,thisisanoverstatement;thetheoremwillshowthatanynon-trivialpropertyofthelanguagesacceptedbyTuringmachinesisundecidable.Non-trivialpropertiesoftheTuringmachineitself|e.g.,doesitrunformorethan100stepswhenpresentedwiththeinputstring.t|maybedecidable.)De nition8.LanguageL0isaTuringmachineI/Opropertyifitisthecasethatforallpairsx;y2suchthatL(x)=L(y),wehavex2L,y2L.WesaythatLisnon-trivialifbothofthesetsLand L=0nLarenonempty.Theorem8(Rice'sTheorem).IfLisanon-trivialTuringmachineI/Oproperty,thenLisundecidable.Proof.Consideranyx1suchthatL(x1)=;.Wecanassumewithoutlossofgeneralitythatx162L.Thereasonisthatalanguageisdecidableifandonlyifitscomplementisdecidable.Thus,ifx12LthenwecanreplaceLwith Landcontinuewiththerestofproof.Intheendwewillhaveproventhat LisundecidablefromwhichitfollowsthatLisalsoundecidable.SinceLisnon-trivial,thereisalsoastringx02L.Thisx0mustbeadescriptionofaTuringmachineM0.(Ifx0werenotaTuringmachinedescription,thenitwouldbethecasethatL(x0)=;=L(x1),andhencethatx062Lsincex162LandLisaTuringmachineI/Oproperty.)WearenowreadytoproveRice'sTheorembycontradiction.GivenaTuringmachineMLthatdecidesLwewillconstructaTuringmachineMHthatdecidesthehaltingproblem,incontradictiontoTheorem7.TheconstructionofMHisasfollows.OninputM;x,ittransformsthepairM;xintothedescriptionofanotherTuringmachineM,andthenitfeedsthisdescriptionintoML.Thede nitionofMisalittletricky.Oninputy,machineMdoesthefollowing.FirstitrunsMoninputx,withoutoverwritingthestringy.IfMeverhalts,theninsteadofhaltingMentersthesecondphaseofitsexecution,whichconsistsofrunningM0ony.(RecallthatM0isaTuringmachinewhosedescriptionx0belongstoL.)IfMneverhalts,thenMalsoneverhalts.ThiscompletestheconstructionofMH.Torecap,whenMHisgivenaninputM;xit rsttransformsthepairM;xintothedescriptionofarelatedTuringmachineM,thenitrunsMLontheinputconsistingofthedescriptionofManditoutputsthesameanswerthatMLoutputs.Therearetwothingswestillhavetoprove.1.ThefunctionthattakesthestringM;xandoutputsthedescriptionofMisacomputablefunction,i.e.thereisaTuringmachinethatcantransformM;xintothedescriptionofM.2.AssumingMLdecidesL,thenMHdecidesthehaltingproblem.The rstofthesefactsiselementarybuttedious.Mneedstohaveabunchofextrastatesthatappendaspecialsymbol(say,])totheendofitsinputandthenwriteoutthestringxafterthespecialsymbol,].ItalsohasthesamestatesasMwiththesametransitionfunction,withtwomodi cations: rst,thismodi edversionofMtreatsthesymbol]exactlyasifitwere..(ThisensuresthatMwillremainontherightsideofthetapeandwillnotmodifythecopyofythatsitstotheleftofthe]symbol.)Finally,wheneverMwouldhalt,themodi edversion 1.AswewillseeinSection5.1,ifthereisanondeterministicTuringmachinethatacceptslanguageLthenthereisalsoadeterministicTuringmachinethatacceptsL.Thus,ifoneignoresrunningtime,nondeterministicTuringmachineshavenomorepowerthandeterministicones.2.ThequestionofwhethernondeterministiccomputationcanbesimulateddeterministicallywithonlyapolynomialincreaseinrunningtimeisthePvs.NPquestion,perhapsthedeepestopenquestionincomputerscience.3.Nondeterminismcanfunctionasausefulabstractionforcomputationwithanuntrustedexternalsourceofadvice:thenondeterministicmachine'stransitionsareguidedbytheadvicefromtheexternalsource,butitremainsincontrolofthedecisionwhethertoacceptitsinputornot.5.1NondeterministicTuringmachinesanddeterministicveri ersOneusefulwayoflookingatnondeterministiccomputationisbyrelatingittothenotionofaveri erforalanguage.De nition10.Letbealanguagenotcontainingthesymbol`;'.Averi erforalanguageL0isadeterministicTuringmachinewithalphabet[f;g,suchthatL=fxj9ys.t.V(x;y)=yesg:Wesometimesrefertothestringyintheveri er'sinputastheevidence.WesaythatVisapolynomial-timeveri erforLifVisaveri erforLandthereexistsapolynomialfunctionpsuchthatforallx2LthereexistsaysuchthatV(x;y)outputs\yes"afteratmostp(jxj)steps.(Notethatifanysuchyexists,thenthereisonesuchysatisfyingjyjp(jxj),sincetherunningtimeboundpreventsVfromreadinganysymbolsofybeyondthe rstp(jxj)symbols.)ThefollowingtheoremdetailsthecloserelationshipbetweennondeterministicTuringma-chinesanddeterministicveri ers.Theorem9.ThefollowingthreepropertiesofalanguageLareequivalent.1.Lisrecursivelyenumerable,i.e.thereexistsadeterministicTuringmachinethatacceptsL.2.ThereexistsanondeterministicTuringmachinethatacceptsL.3.Thereexistsaveri erforL.Proof.AdeterministicTuringmachinethatacceptsLisaspecialcaseofanondeterministicTuringmachinethatacceptsL,soitistrivialthat(1)imples(2).Toseethat(2)implies(3),supposethatMisanondeterministicTuringmachinethatacceptsL.ThetransitionrelationofMisa nitesetof5-tuplesandwecannumbertheelementsofthissetas1;2;:::;KforsomeK.Theveri er'sevidencewillbeastringyencodingasequenceofelementsoff1;:::;Kg,thesequenceoftransitionsthatMundergoesinacomputationthatleadstoacceptingx.Theveri erVoperatesasfollows.Giveninputx;y,itsimulatesacomputationofMoninputx.Ineverystepofthesimulation,Vconsultstheevidencestringytoobtainthenexttransitionrule.Ifitisnotavalidtransitionruleforthecurrentcon guration(forexamplebecauseitappliestoastateotherthanthecurrentstateofMinthesimulation)thenVinstantlyoutputs\no", otherwords,cnf-satisde nedinexactlythesamewayas3satexceptthataclauseisallowedtocontainanynumberofliterals.Itisclearthatcnf-satand3satbelongtoNP:averi ermerelyneedstotakeaproposedtruthassignmentandgothrougheachclause,checkingthatatleastoneofitsliteralsissatis edbytheproposedassignment.Thereisaneasyreductionfromcnf-satto3sat.Supposewearegivenasatinstancewithvariablesx1;:::;xnandclausesC1;:::;Cm.ForeachclauseCjthatisadisjunctionofk(j)�3literals,welet`1;:::;`k(j)betheliteralsinCjandwetransformCjintoaconjunctionofk(j)�2clausesofsize3,asfollows.Firstwecreateauxiliaryvariableszj;1;:::;zj;k(j)�3,thenwerepresentCjusingthefollowingconjunction:(`1_`2_zj;1)^( zj;1_`3_zj;2)^( zj;2_`4_zj;3)^( zj;3_`5_zj;4)^^( zj;k(j)�3_`k(j)�1_`k(j)):Itisanexercisetoseethatagiventruthassignmentofvariablesx1;:::;xnsatis esCjifandonlyifthereexistsatruthassignmentofzj;1;:::;zj;k(j)�3that,whencombinedwiththegivenassignmentofx1;:::;xn,satis esalloftheclausesintheconjunctiongivenabove.Similarly,wecanuseauxiliaryvariablestoreplaceeachclausehavingk3literalswithaconjunctionofclauseshavingexactlythreeliterals.Speci cally,wetransformaclauseCjcontainingasingleliteral`1intotheconjunction(`1_zj_z0j)^(`1_ zj_z0j)^(`1_zj_ z0j)^(`1_ zj_ z0j);andwetransformaclauseCj=(`1_`2)intotheconjunction(`1_`2_zj)^(`1_`2_ zj):Onceagainitisanexercisetoseethatagiventruthassignmentofvariablesx1;:::;xnsatis esCjifandonlyifthereexistsatruthassignmentoftheauxiliaryvariablesthat,whencombinedwiththegivenassignmentofx1;:::;xn,satis esalloftheclausesintheconjunctionsgivenabove.TocompletetheproofoftheCook-LevinTheorem,wenowshowthateverylanguageinNPcanbereduced,inpolynomialtime,tocnf-sat.Theorem11.IfL20isinNPthenthereexistsapolynomial-timereductionfromLtocnf-sat.Proof.SupposeVisapolynomial-timeveri erforLandpisapolynomialfunctionsuchthatforeveryx2LthereexistsysuchthatV(x;y)outputs\yes"afteratmostp(jxj)steps.ThecomputationofVcanbeexpressedusingarectangulartablewithp(jxj)rowsandcolumns,witheachrowrepresentingacon gurationofV.Eachentryofthetableisanorderedpairin(K[fg),whereKisthestatesetofV.Themeaningofanentry(q;)intheithrowandjthcolumnofthetableisthatduringstepiofthecomputation,Vwasinstateq,visitinglocationj,andreadingsymbol.Iftheentryis(;)itmeansthatwasstoredatthatlocationduringstepi,butthelocationofVwaselsewhere.ToreduceLtocnf-sat,weuseasetofvariablesrepresentingthecontentsofthistableandasetofclausesassertingthatthetablerepresentsavalidcomputationofVthatendsinthe\yes"state.Thisissurprisinglyeasytodo.Foreachtableentry(i;j)where0i;jp(jxj),andeachpair(q;)2(K[fastg),wehaveaBooleanvariableuq;i;j.Theclausesarede nedasfollows.1.Theveri erstartsinstatesontheleftsideofitstape.Thisisrepresentedbyaclauseconsistingofasingleliteral,us;.0;0.