chapter 7 turing machines - adamant.kaist.ac.kradamant.kaist.ac.kr/cs322_2011/tp/08~1ma07.pdf ·...
TRANSCRIPT
Chapter7
TuringMachines
Copyright © 2011 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
1
2
AGeneralModelofComputation
• Bothfiniteautomataandpushdownautomataaremodelsofcomputation– Eachreceivesaninputstringandexecutesanalgorithmtoobtainananswer,followingasetofrulesspecifictothemachinetype
• Itiseasytofindexamplesoflanguagesthatcannotbeacceptedbecauseofthemachine’slimitations:– AnFAcannotaccept{xcxr |x {a,b}*}– APDAcannotacceptAnBnCn ={anbncn |n 0}orL ={xcx |x {a,b}*}
Introduction to Computation 2
3
AGeneralModelofComputation(cont’d.)
• APDA‐likemachinewithtwo stackscanacceptAnBnCn
• AnFAwithaqueue insteadofastackcanacceptL• Inbothcases,itmightseemthatamachineisbeingspecificallydevelopedtohandleonelanguage,butitturnsoutthatboththesedeviceshavesubstantiallymorecomputingpowerthaneitheranFAoraPDA
• Eitheroneisareasonablecandidateforamodelofgeneral‐purposecomputation
Introduction to Computation 3
4
AGeneralModelofComputation(cont’d.)
• TheabstractmodelwewillstudyinsteadistheTuringmachine– Itisnotobtainedbyaddingdatastructuresontoafiniteautomaton
– Rather,itpredatestheFAandPDAmodels(AlanTuring’scontributionsdatefromthe1930’s)
• ATuringmachineisnotjust thenextstepbeyondapushdownautomaton– AccordingtotheChurch‐Turingthesis,itisageneralmodelofcomputation,potentiallyabletoexecuteanyalgorithm
Introduction to Computation 4
5
AGeneralModelofComputation(cont’d.)
• Turing’sobjectivewastodemonstratetheinherentlimitationsofalgorithmicmethods.Thisiswhyhewantedhisdevicetobeabletoexecuteanyalgorithmthatahumancomputercould
• Toformulatehiscomputationalmodel,heconsideredahumanbeingworkingwithapencilandpaper
• Asaresult,hepostulatedthatthestepsacomputertakesshouldincludethese:– Examineanindividualsymbolonthepaper– Eraseasymbolorreplaceitbyanother– Transferattentionfromonesymboltoanearbyone
Introduction to Computation
6
AGeneralModelofComputation(cont’d.)
• Forsimplicity,Turingspecifiedalineartapewhichhasaleftendandispotentiallyinfinitetotheright– Thetapeismarkedoffintosquareseachofwhichholdsonesymbol
– Wewillsometimesassignconsecutivenumberstothesquares,butthat’snotpartofthemodel
• Wevisualizethereadingandwritingasbeingdonebyatapehead,whichatanytimeiscenteredonasinglesquare
Introduction to Computation 6
7
AGeneralModelofComputation(cont’d.)
• InourversionofaTuringmachine,asinglemoveisdeterminedbythecurrentstate(correspondingtothe“stateofmind”ofthehumancomputer)andthecurrenttapesymbolandhasthreeparts– Changingfromthecurrentstatetoanotherstate– Replacingthesymbolinthesquarebyanother– Leavingthetapeheadwhereitis,movingitonesquaretotheleft,ormovingitonesquaretotheright
• Theinputstringisassumedtobeonthetapeinitially
Introduction to Computation 7
8
AGeneralModelofComputation(cont’d.)
• Thetapeprovidesthememoryneededduringcomputationandservesastheoutputdevice
• OnecrucialdifferencebetweenaTuringmachineandanFAorPDAisthataTuringmachineisnotrestrictedtoasinglepassthroughtheinput
• WewillfocusontwoprimaryobjectivesofaTuringmachine– Acceptingalanguage– Computingafunction
• Thefirstissimilartowhatwe’vedonesofar
Introduction to Computation 8
9
AGeneralModelofComputation(cont’d.)
• ATuringmachinewillhavetwohalt states,onedenotingacceptanceandtheotherrejection.(Morethantwoareunnecessary;unlikeanFA,thecompleteinputstringisonthetapeinitially,andaseparateanswerforeachprefixisnotrequired)
• UnlikeFAsandPDAs(oratleastPDAswithoutΛ‐transitions),Turingmachinesmayneverstop– Thiswillturnouttobeimportant
Introduction to Computation 9
10
AGeneralModelofComputation(cont’d.)
• Definition7.1:ATuringMachine(TM)isa5‐tupleT =(Q,,,q0,),where:– Q isafinitesetofstates
• Thetwohaltstatesha andhr arenotelementsofQ– Theinputalphabet andthetapealphabet arebothfinitesets,with • Theblanksymbol isnotanelementof
– q0,theinitialstate,isanelementofQ– Thetransitionfunctionis
:Q ( ∪ {}) (Q ∪ {ha,hr}) ( ∪ {}) {R,L,S}
Introduction to Computation 10
11
AGeneralModelofComputation(cont’d.)
• Weinterpret(p,X)=(q,Y,D)tomean:whenT isinstatep andthesymbolinthecurrentsquareisX,theTMreplacesX byY inthatsquare,changestostateq,andmovesthetapeheadonesquaretotheright,ormovesonesquaretotheleft,ordoesn’tmove– Ifthestateq iseitherha orhrwesaythatthismovecausesT tohalt• Onceithalts,itcannotmove
– WereturntodrawingtransitiondiagramssimilartobutmorecomplicatedthanthediagramsforFAs
Introduction to Computation 11
12
AGeneralModelofComputation(cont’d.)
• Thetransition(p,X)=(q,y,D)willberepresentedbythefollowingdiagram– IftheTMattemptstomovethetapeheadtotheleftwhenitisonsquare0,wewillsaythattheTMhaltsinstatehr ,leavingthetapeheadinsquare0andleavingthetapeunchanged
Introduction to Computation 12
13
AGeneralModelofComputation(cont’d.)
• NormallyaTMbeginswithaninputstringstartinginsquare1andallothersquares(square0andalltheonesfollowingtheinputstring)blank
• Inanycase,thesetofnonblanksquaresonthetapemustalwaysbefinite
• Wedescribethecurrentconfiguration ofaTMbyasinglestringxqywhereq isthecurrentstate,x isthestringofsymbolstotheleftofthecurrentsquare,y iseithernullorstartsinthecurrentsquare,andeverythingafterxy onthetapeisblank
Introduction to Computation 13
14
AGeneralModelofComputation(cont’d.)
• Wetraceasequenceofmovesbyspecifyingtheconfigurationateachstep
• Ifq isanon‐haltingstateandr isanystate,wewritexqy T zrw orxqy T* zrw tomeanthatTmovesfromthefirstconfigurationtothesecondinonemove,orinzeroormoremoves,respectively
• Theinitialconfigurationcorrespondingtoinputx isgivenbyq0x
Introduction to Computation 14
15
TuringMachinesasLanguageAcceptors
• Definition7.2:IfT=(Q,,,q0,)isaTMandx *,x isacceptedbyT ifq0 x⊢ T*whay forsomew,y ( {})*
• AlanguageL *isacceptedbyT ifL =L(T)={x *|x isacceptedbyT}
• ThefollowingtransitiondiagramsshowanFAandaTMthatacceptthesamelanguage
Introduction to Computation 15
16
TuringMachinesasLanguageAcceptors(cont’d.)
• Ifthelanguagewerenotregular,theTMcouldnotmoveitstapeheadtotherightoneverymove.
• The(b)diagramonthepreviousslidedoesnotshowanyofthemovestotherejectstate– Theyallhavethesameform,andthereisonefromeachofthestatesp,q,ands(thenonhaltingstatesotherthanq0 thatcorrespondtononacceptingstatesintheFA),asshownbelow
Introduction to Computation 16
17
TuringMachinesthatComputePartialFunctions
• ATuringmachinethatproducesanoutputstringforeverylegalinputstringissaidtocomputeapartialfunctionon*
• We’llalsoconsiderTMsthatcomputepartialfunctionson(*)k,i.e.,functionsofk variables
• Themostimportantissueiswhatoutputstringsareproducedforinputstringsinthedomainoff
• However,wewanttheTMtoacceptonlyinputsinthedomainoff,inordertobeabletosaythatitcomputesf andnotsomeotherfunctionwithlargerdomain
Introduction to Computation 17
18
TuringMachinesthatComputePartialFunctions(cont’d.)
• Definition7.9:– LetT=(Q,,,q0,)beaTuringmachine,k anaturalnumber,andf apartialfunctionfrom(*)k to*
– WesaythatT computesf ifforevery(x1,x2,…,xk)inthedomainoff,q0 x1 x2… xk ⊢T*haf(x1,x2,…xk)
andnootherinputthatisak‐tupleofstringsisacceptedbyT
• Apartialfunctionf isTuring‐computableifthereisaTMthatcomputesf
Introduction to Computation 18
19
TuringMachinesthatComputePartialFunctions(cont’d.)
• Forourpurposes,itwillbesufficienttoconsiderpartialfunctionson kwithvaluesin
• Wewilluseunarynotationfornumbers• TheofficialdefinitionissimilartoDefinition7.9,exceptthattheinputalphabetis{1},andtheinitialconfigurationlookslikeq01n11n2…1nk
Introduction to Computation 19
20
CombiningTuringMachines
• Justasalargealgorithmcanbedescribedasanumberofsubalgorithmsworkingincombination,wecancombineseveralTuringmachinesintoalargercompositeTM
• Inthesimplestcase,ifT1 andT2 areTMs,wecanconsiderthecompositionT1T2:“firstexecuteT1,thenexecuteT2 ontheresult”– ThesetofstatesofT1T2 istheunionofthesetsofstatesofT1 andT2 (relabeledifnecessary)
– TheinitialstateistheinitialstateofT1
Introduction to Computation 20
21
CombiningTuringMachines(cont’d.)
• ThetransitionsofT1T2 includeallofthoseofT2 andallofthoseofT1 thatdon’tgotoha
• AtransitioninT1 thatgoestoha isreplacedbyasimilartransitionthatgoestothestartstateofT2
• ItisimportantthattheoutputofT1 beavalidinputconfigurationforT2
• WemayusetransitiondiagramscontainingnotationssuchasT1 T2, inordertoavoidshowingallthestatesexplicitly
Introduction to Computation 21
22
CombiningTuringMachines(cont’d.)
• Wemightuseanyoftheabovenotationstomean“instatep,ifthecurrentsymbolisa,thenexecutetheTMT”
• Similarlywemightuseanyofthefollowingtomean“executeT1,andifT1 haltsinhawithcurrentsymbola,thenexecuteT2”
Introduction to Computation 22
23
MultitapeTuringMachines
• SomealgorithmscanbeunwieldytoimplementonaTM,becauseofthebookkeepingnecessary
• Awayofsimplifyingthemistohavemultipletapeswithindependentheads– Thisisadifferentmodelofcomputation,amultitapeTuringmachine
– Itwillturnoutthatthat,justasnondeterminismand‐transitionsdonotincreasethepowerofFAs,allowingaTuringmachinemultipletapesdoesnotincreaseitspower
Introduction to Computation 23
24
MultitapeTuringMachines(cont’d.)
• WewillshowthatforeverymultitapeTMT thereisasingle‐tapeTMthatacceptsexactlythesamestringsasT,rejectsthesamestrings,andproducesexactlythesameoutputforeveryinputstringitaccepts
• Tosimplifythediscussionwewillonlyconsidertwo‐tapemachines,butitiseasytoseethattheprinciplesarethesameiftherearemorethantwo
Introduction to Computation 24
25
MultitapeTuringMachines(cont’d.)
• A2‐tapeTMcanalsobedescribedbya5‐tupleT =(Q,,,q0,),wherethistime :Q ( ∪ {})2 (Q ∪ {ha,hr}) ( ∪ {})2 {R,L,S}2
• Asinglemovecanchangethestate,thesymbolsinthecurrentsquaresonbothtapes,andthepositionsofthetwotapeheads
• Wewillrepresentaconfigurationbya3‐tuple(q,x1a1y1,x2a2y2)whereq isthecurrentstate,xiaiyiisthecontentsoftapei,andai isinthecurrentsquareoftapei
• Theinputconfigurationforinputxwillbe(q0, x,)
Introduction to Computation 25
26
MultitapeTuringMachines(cont’d.)
• Theorem7.26:Forevery2‐tapeTMT=(Q,,,q0,)thereisanordinary1‐tapeTMT1=(Q1,,1,q1,1),with 1,suchthat:– L(T)=L(T1)– Foreveryx *,if(q0, x,)⊢T*(ha,yaz,ubv),thenq1x ⊢T1*yhaaz
• Proof:byconstruction– Thetapeisdividedintotwo“tracks”,assuggestedbythisdiagram:
Introduction to Computation 26
27
MultitapeTuringMachines(cont’d.)
• Insquare0,thereisamarkertomakeiteasytolocatethebeginningofthetape– Itwillalsobehelpfultohaveamarkerattheotherendofthenonblankportionofthetape
• Startingwiththeinitialconfigurationq1xwithinputx=a1a2…an,T1 placesthe$markerinsquare0,insertsblanksbetweenconsecutivesymbolsofx andplacesthe#markerafterthelastnonblanksymbol,toproducethetape
$a1a2…an#
Introduction to Computation 27
28
MultitapeTuringMachines(cont’d.)
• Fromthispointon,the#ismovedifnecessarytomarkthefarthestrightthatT hasmovedoneitherofitstapes
• TheonlysignificantcomplicationinT1 simulatingT isthatitmustbeabletokeeptrackofbothofthetapeheads
• WehandlethisbyincludinginT1’stapealphabetanextracopy’ofeverysymbol (including)thatcanappearonT’stape
• Theprimedsymbolgivesthelocationofthehead
Introduction to Computation 28
29
MultitapeTuringMachines(cont’d.)
• ByusingextrastatesT1 can“remember”thecurrentstateofT andalsowhattheprimedsymbolonthefirsttrackiswhileitislookingfortheprimedsymbolonthesecondtrack(orvice‐versa)
• ThestepsT1 makestosimulateamoveofT are:– Movethetapeheadlefttothe$,thenrighttoaprimedsymbol’;remember andmovebackto$
– Moverighttoaprimedsymbol’onthesecondtrack;ifthemovethatisnowdeterminedis(p,,)=(q,1,1,D1,D2)thenrejectifq=hr,elsechange’to1 andmoveindirectionD2 totheappropriatesquare
Introduction to Computation 29
30
MultitapeTuringMachines(cont’d.)
• ThestepsT1 makes(cont’d,)– Ifinmovingthetapeheadthisway,the$isencountered,thenreject,otherwise(movingthe#ifnecessary)changethesymbolinthenewsquareontrack2tothecorrespondingprimedsymbolandmovebacktothe$
– Locate’onthefirsttrackagain,changeitto1,andmovethetapeheadindirectionD1 totheappropriatesquareonthefirsttrack
– Afterallowingforeithermarker,asabove,changethenewsymbolonthefirsttracktothecorrespondingprimedsymbol
Introduction to Computation 30
31
MultitapeTuringMachines(cont’d.)
• AslongasT hasnothalted,iteratingthesestepsallowsT1 tosimulatethemovesofT correctly
• IfT finallyaccepts,thenT1 mustcarryoutthesestepsinordertoendupintherightconfiguration:– Deleteeverysquareinthesecondtracktotheleftof#– Deletebothend‐of‐tapemarkers– Movethetapeheadtotheprimedsymbol,changeittothecorrespondingunprimedsymbol,andhaltinhawiththetapeheadonthatsquare
Introduction to Computation 31
32
MultitapeTuringMachines(cont’d.)
• Corollary7.27:– Everylanguagethatisacceptedbya2‐tapeTMcanbeacceptedbyanordinary1‐tapeTM,andeveryfunctionthatiscomputedbya2‐tapeTMcanbecomputedbyanordinaryTM
Introduction to Computation 32
33
TheChurch‐TuringThesis
• TosaythattheTMisageneralmodelofcomputationimpliesthatanyalgorithmicprocedurethatcanbecarriedoutatall,byahumancomputerorateamofhumansoranelectroniccomputer,canbecarriedoutbyaTM– ThestatementwasformulatedbyAlonzoChurchinthe30’s
– ItisreferredtoasChurch’sthesisortheChurch‐Turingthesis
– Itisn’tastatementthatcanbeproved,butthereisalotofevidenceforit
Introduction to Computation 33
34
TheChurch‐TuringThesis(cont’d.)
• ThenatureofthemodelmakesitseemthataTMcanexecuteanyalgorithmahumancan
• EnhancementstotheTMhavebeenshownnottoincreaseitspower
• OthertheoreticalmodelsofcomputationproposedhavebeenshowntobeequivalenttoaTM
• NoonehaseversuggestedanykindofcomputationthatcannotbeimplementedonaTM
• Fromnowon,wewillconsiderthatbydefinition,an“algorithmicprocedure”iswhataTMcando
Introduction to Computation 34
35
NondeterministicTuringMachines
• WecanaddnondeterminismtoTuringmachines:asusual,(q,a)becomesasubset,notanelement
• Theorem7.31:ForeverynondeterministicTMTthereisanordinary(deterministic)TMT1 withL(T1)=L(T)
• Proof:– Theideaistouseanalgorithmthatcantest,ifnecessary,everypossiblesequenceofmovesofT onaninputstringx
– Seebookfordetails
Introduction to Computation 35
36
UniversalTuringMachines
• TheTMswehavestudiedsofarhavebeenspecial‐purposecomputerscapableofexecutingasinglealgorithm
• Wecanconsidera“universal”Turingmachine,whichiscapableofexecutingaprogramstoredinitsmemory– Itreceivesaninputstringthatspecifiesboththealgorithmitistoexecuteandtheinputthatistobeprovidedtothealgorithm
Introduction to Computation 36
37
UniversalTuringMachines(cont’d.)
• Definition7.32:Auniversal TuringmachineisaTuringmachineTu thatworksasfollows– Itisassumedtoreceiveaninputstringoftheforme(T)e(z),whereT isanarbitraryTM,z isastringovertheinputalphabetofT,ande isanencodingfunctionwhosevaluesarestringsin{0,1}*
– ThecomputationperformedbyTu onthisinputstringsatisfiesthesetwoproperties• Tu acceptse(T)e(z)ifandonlyifT acceptsz• IfT acceptsz andproducesoutputy, thenTu producesoutpute(y)
Introduction to Computation 37
38
UniversalTuringMachines(cont’d.)
• Wediscussasimpleencodingfunctione,andthensketchoneapproachtoconstructingauniversalTM
• Theencodingfunctionhasseveralcrucialfeatures:– Itispossibletodecidealgorithmically,foranarbitrarystringw {0,1}*,whetherw isalegitimatevalueofe
– Astringw shouldrepresentatmostoneTM,oratmostonestring
– Thereshouldbeanalgorithmfordecodingstringsoftheforme(T)ore(z)andreconstructingtheTMorstringitrepresents
Introduction to Computation 38
39
UniversalTuringMachines(cont’d.)
• Statelabelswillbereplacedbynumbers,andwewillbasetheencodingonthesenumbers
• Inordertousenumbertoencodesymbolsaswell,weadoptthisconvention:thereisaninfinitesetS={a1,a2,…}ofsymbols,includinga1 = ,suchthatthetapealphabetofeveryTMT isasubsetofS
• TheideaoftheencodingistorepresentaTMasasetofmovesandeachmoveisassociatedwitha5‐tupleofnumbers– Eachnumberisinunaryfollowedbya0
Introduction to Computation 39
40
UniversalTuringMachines(cont’d.)
• Definition7.33:IfT=(Q,,,q0,)isaTMandz isastring,definethestringse(T)ande(z)asfollows– Firstassignnumberstoeachstate,tapesymbol,andtapeheaddirectionofT;n(ha)=1,n(hr)=2,andn(q0)=3• Theotherelementsofq getdistinctnumbers 4,andn(R)=1,n(L)=2,n(S)=3
– Foreachmovem oftheform(p,)=(q,,D),e(m)=1n(p)01n()01n(q)01n()01n(D)0
– ListthemovesofT asm1,…,mk(theorderisarbitrary),andlete(T)=e(m1)0e(m2)0…0e(mk)0
Introduction to Computation 40
41
UniversalTuringMachines(cont’d.)
• Definition7.33:(cont’d.)– Ifz=z1z2…zj isastring,thene(z)=01n(z1)01n(z2)0…01n(zj)0
• Theorem7.36:LetE={e(T)|T isaTM}– Thenforeveryx {0,1}*,x E ifandonlyif:
• xmatchestheregularexpression(11*0)50((11*0)50)*,sothatitisasequenceof5‐tuples
• Notwosubstringsofx representing5‐tupleshavethesamefirsttwoparts
• Noneofthe5‐tupleshavefirstpart1or11• Thelastpartofeach5‐tuplemustbe1,11,or111
Introduction to Computation 41
42
UniversalTuringMachines(cont’d.)
• Thoseconditionsdon’tguaranteethatthestringrepresentsaTMthatcarriesoutameaningfulcomputation– ButtheydoensurethatwecandrawatransitiondiagramcorrespondingtotheencodedTM
• Testingastringtodeterminewhetheritsatisfiestheseconditionsisstraightforward,sowehaveverifiedthate satisfiestheminimalrequirementsforsuchafunction
• Detailsofthesimulationareinthebook
Introduction to Computation 42