Outline
• WhatareTuringMachines• TuringMachineScheme• FormalDefinition• LanguagesofaTM• Decidability
10/1/19 TheoryofComputation-Fall'19LorenzoDeStefani 1
FromSipserChapter3.1
FA,PDAandTuringMachines• FiniteAutomata:– Modelsfordeviceswithfinitememory
• PushdownAutomata:– Modelsfordeviceswithunlimitedmemory(stack)thatisaccessibleonlyinLast-In-First-Outorder
• TuringMachines(Turing1936)– Usesunlimitedmemoryasaninfinitetapewhichcanberead/writtenandmovedtoleftorright
– Onlymodelthusfarthatcanmodelgeneralpurposecomputers– Church-Turingthesis
– Still,TMcannotsolveallproblems10/1/19 TheoryofComputation-Fall'19LorenzoDeStefani 2
TuringMachineScheme
Control
a b a b – – – …
• Turingmachineincludeaninfinitetape– TapeusesitsownalphabetΓ,with– Initiallycontainstheinputstringandblankseverywhereelse
– Machinecanreadandwritefromtapeandmoveleftandrightaftereachaction
– MuchmorepowerfulthanFIFOstackofPDAs
⌃ ⇢ �(null)(null)(null)(null)
Tape
–
Head
10/1/19 TheoryofComputation-Fall'19LorenzoDeStefani 3
TuringMachineSchemeControl
a b a b – – – …
• Thecontroloperatesasastatemachine– Startsinaninitialstate– Proceedsbyaseriesoftransitionbasedonthevalueonthetape
– Themachinecontinuesuntilitentersanacceptorrejectstateatwhichpointitimmediatelyhaltsandoutputsacceptorreject
– NotethisisverydifferentfromFAsandPDAs
10/1/19 TheoryofComputation-Fall'19LorenzoDeStefani 4
TuringMachineSchemeControl
a b a b – – – …
• Themachinecanloopforever!– InthiscasewesaythattheTMdoesnothaltforagiveninput
• CanaFAoraPDAloopforever?– NO!itwillterminatewheninputstringisfullyprocessedandwillonlytakeone“action”foreachinputsymbol
10/1/19 TheoryofComputation-Fall'19LorenzoDeStefani 5
DesigningTuringMachines
DesignaTMtorecognizethelanguage:B={w#w|w∈{0,1}*}– Thinkofaninformaldescription– NOTPALINDROMES– ImaginethatyouarestandingonaninfinitetapewithsymbolsonitandwanttochecktoseeifthestringbelongstoB?• Whatprocedurewouldyouusegiventhatyoucanread/writeandmovethetapeinbothdirections?
• Youhaveafinitecontrolsocannotremembermuchandthusmustrelyontheinformationonthetape
10/1/19 TheoryofComputation-Fall'19LorenzoDeStefani 6
ATuringMachineforB ={w#w|w ∈{0,1}*}
• M1loopsandineachiterationitmatchessymbolsoneachsideofthe#– Itreadstheleftmostsymbolremainingandreplacesitwith“x”– Scanstotherightuntilthe“#”andproceedstothefirstnon-xsymbol– Isitthesame?
• Yes!Wehaveamatch!Wegobacktotheleftmostremainingsymbolandrepeat
• No!Wehaveamismatch=(theTMtransitiontoa“rejectstate”andhalts
– Ifboththesymbolstotherightandtotheleftofthe“#”arexthenwehaveacompletematch!Alsochecksamelength!!!
– TheTMhaltsandthestringisaccepted• Isloopingpossible?
– NO!Guaranteedtoterminate/haltsincemakesprogresseachiteration.
10/1/19 TheoryofComputation-Fall'19LorenzoDeStefani 7
• M1loopsandineachiterationitmatchessymbolsoneachsideofthe#– Itreadstheleftmostsymbolremainingandreplacesitwith“blank”– Scanstotherightuntilthe“#”andproceedstothefirstnon-blanked
symbol– Isitthesame?
• Yes!Wehaveamatch!Wegobacktotheleftmostremainingsymbolandrepeat
• No!Wehaveamismatch=(theTMtransitiontoa“rejectstate”andhalts
– Ifthesymboltotherightofthe“#”isblankthewehaveacompletematch!TheTMhaltsandthestringisaccepted
• Isloopingpossible?– NO!Guaranteedtoterminate/haltsincemakesprogresseach
iteration.
10/1/19 TheoryofComputation-Fall'19LorenzoDeStefani 8
ATuringMachineforB ={w#w|w ∈{0,1}*}
10/1/19 TheoryofComputation-Fall'19LorenzoDeStefani 9
qstart
q0
q1
q#1
q#0
qrevqrejectqrev2
qalmost
qbegin
0àx,R
#à#,R
0à0,R1à1,R xàx,L
0àx,L
1à1,R
xàx,L
#à#,L
0à0,L
1à1,L
1àx,R
#à#,R
1àx,L 0à0,R
_à_,R
_à_,R
xàx,L
qaccept
0à0,L1à1,L
xàx,R
0àx,R
1àx,R
#à#,R
_à_,R
xàx,R
0à0,R1à1,R
ATuringMachineforB ={w#w|w ∈{0,1}*}
Conventionsofrepresentation
• Read“aàb,R”as:ifsymbol“a”isreadonthetapethenreplaceitwith“b”andmovetotheright
• Weassumemissingtransitionsleadtorejectstate
10/1/19 TheoryofComputation-Fall'19LorenzoDeStefani 10
ExecutionExample
Inputstring011000#011000Thetapeheadisatrightofthestate qstart011000#011000-- xq111000#011000-- … X11000#qrevX11000-- qrev2X11000#X11000-- xxq11000#X11000-- … XXXXXX#XXXXXX--
10/1/19 TheoryofComputation-Fall'19LorenzoDeStefani 11
FormalDefinitionofaTuringMachine
ATuringMachineisa7-tuple{Q,Σ,Γ,δ,q0,qaccept,qreject},where:• Qsetofstates• Σistheinputalphabetnotcontainingtheblank• Γisthetapealphabet,whereblank_∈ΓandΣ⊆Γ• δ:QxΓ→QxΓx{L,R}isthetransitionfunction• q0,qaccept,andqrejectarethestart,accept,andrejectstates– Doweneedmorethanonerejectoracceptstate?– No:sinceonceentersuchastateyouterminate
10/1/19 TheoryofComputation-Fall'19LorenzoDeStefani 12
TransitionsintheTM
Thetransitionfunctionδiskey:– QxΓ→QxΓx{L,R}
• Amachineisinastateqandtheheadisoverthetapeatsymbola,thenafterthemoveweareinastaterwithbreplacingtheaonthetapeandtheheadhasmovedeitherleft(L)orright(R)
10/1/19 TheoryofComputation-Fall'19LorenzoDeStefani 13
Configurationsandtransitions• AtanystepaTMisinacertainconfigurationwhichisspecifiedby:– thestate– thecurrentheadlocation– thesymbolatthecurrentheadlocation
• WesaythataconfigurationC1yieldsC2ifthereisatransitionwhichallowsgofromC1toC2
10/1/19 TheoryofComputation-Fall'19LorenzoDeStefani 14
Typesofconfigurations• Startingconfiguration:instartingstate,headpositionatthebeginningoftheinput– Leftmostpositionofthetapeoccupiedbytheinput
• Acceptingconfiguration:inacceptingstate• Rejectingconfiguration:inrejectingstate• Haltingconfiguration:eitheracceptingorrejectingconfigurations
10/1/19 TheoryofComputation-Fall'19LorenzoDeStefani 15
TuringRecognizable&DecidableLanguages
• ThesetofstringsthataTuringMachineMacceptsisthelanguageofM,orthelanguagerecognizedbyM,L(M)– AlanguageisTuring-recognizableifsomeTuringmachinerecognizesit• Sometimesreferredas“recursivelyenumerable”
– ATuringmachinethathaltsonallinputsisadecider.Adeciderthatrecognizesalanguagedecidesit.
– AlanguageisTuring-decidableorsimplydecidableifsomeTuringmachinedecidesit.• Sometimesreferredas“recursive”
• Remarks:– DecidableifTuring-recognizableandalwayshalts– EverydecidablelanguageisTuring-recognizable– ItispossibleforaTMtohaltonlyonthosestringsitaccepts
10/1/19 TheoryofComputation-Fall'19LorenzoDeStefani 16
LimitsofTuringMachines
• Church-Turingthesis:AnythingthatcanbeprogrammedcanbeprogrammedonaTM
• NotalllanguagesareTuringDecidable– ATM={,MisadescriptionofaTuringMachineTM,wisadescriptionofaninputandTMacceptsw}• WeshallseethisinChapter4• ATMisnotevenTuring-recognizable!
10/1/19 TheoryofComputation-Fall'19LorenzoDeStefani 17
TuringMachineExampleDesignaTMM2thatdecidesA={02n|n≥0},thelanguageofallstringsof0swithlength2n.• Withoutdesigningit,doyouthinkthiscanbedone?Why?
– Yes:wecouldwriteaprogramtodoitandthereforeweknowaTMcoulddoitsincewesaidaTMcandoanythingacomputercando
• Howwouldyoudesignit?• Solution:
Idea:divideby2eachtimeandseeifresultisaone1. Sweeplefttorightacrossthetape,crossingoffeveryother0.2. Ifinstep1:
– thetapecontainsexactlyone0,thenaccept– thetapecontainsanoddnumberof0’s,rejectimmediately– Onlyalternativeiseven0’s.Inthiscasereturnheadtostartandloop
backtostep1.
10/1/19 TheoryofComputation-Fall'19LorenzoDeStefani 18
SampleExecutionofTMM20000-- Numberis4,whichis22
x000--x0x0-- Nowwehave2,or21
x0x0--x0x0-- xxx0--
xxx0-- Nowwehave1,or20xxx0-- Seekbacktostartxxx0-- Scanright;one0,soaccept
10/1/19 TheoryofComputation-Fall'19LorenzoDeStefani 19
TuringMachineExampleII
DesignTMM3todecidethelanguage:C={aibjck|ixj=kandi,j,k≥1}– WhatisthistestingaboutthecapabilityofaTM?
• Thatitcando(oratleastcheck)multiplication• Aswehaveseenbefore,weoftenuseunary
– Howwouldyouapproachthis?• Imaginethatweweretrying2x3=6
10/1/19 TheoryofComputation-Fall'19LorenzoDeStefani 20
TuringMachineExampleII
Solution:1. Firstscanthestringfromlefttorighttoverifythatitisof
forma+b+c+;ifitisscantostartoftapeandifnot,reject.2. Crossoffthefirstaandscanuntilthefirstboccurs.
Shuttlebetweenb’sandc’scrossingoffoneofeachuntilallb’saregone.Ifallc’shavebeencrossedoffandsomeb’sremain,reject.
3. Restorethecrossedoffb’sandrepeatstep2iftherearea’sremaining.Ifalla’sgone,checkifallc’sarecrossedoff;ifso,accept;elsereject.
*Usedifferentsymbolsforcrossingouttheb’ssothatiseasiertorestorethem=)
10/1/19 TheoryofComputation-Fall'19LorenzoDeStefani 21
Transducers
• Sofarwehavealwaystalkedaboutrecognizingalanguage,notgeneratingalanguage.Thisiscommoninlanguagetheory.
• Whentalkingaboutcomputationthisseemsstrangeandlimiting.– Computerstypicallytransforminputintooutput– Forexample,wearemorelikelytohaveacomputerperformmultiplicationthancheckthattheequationiscorrect.
– TuringMachinescanalsogenerate/transduce– Howwouldyoucomputeckgivenaibjandixj=k
• Inasimilarmanner.Foreverya,youscanthroughtheb’sandforeachyougototheendofthestringandaddac.Thusbyzig-zaggingatimes,youcangeneratetheappropriatenumberofc’s.
10/1/19 TheoryofComputation-Fall'19LorenzoDeStefani 22
TuringMachineExampleIV
Solvetheelementdistinctnessproblem:Givenalistofstringsover{0,1}eachseparatedbya#,acceptifallstringsaredifferent.E={#x1#x2#…#xn|eachxi∈{0,1}*andxi≠xjforeachi≠j}
10/1/19 TheoryofComputation-Fall'19LorenzoDeStefani 23
TuringMachineExampleIV• Solution:
1. Placeamarkontopoftheleft-mostsymbol.Ifitwasablank,accept.Ifitwasa#continue;elsereject
2. Scanrighttonext#andplaceamarkonit.Ifno#isencountered,weonlyhadx1soaccept.
3. Byzig-zagging,comparethetwostringtotherightofthetwomarked#s.Iftheyareequal,reject.
4. Movetherightmostofthetwomarkstothenext#symboltotheright.Ifno#symbolisencounteredbeforeablank,movetheleftmostmarktothenext#toitsrightandtherightmostmarktothe#afterthat.Thistime,ifno#isavailablefortherightmostmark,allthestringshavebeencompared,soaccept.
5. Gobacktostep3
10/1/19 TheoryofComputation-Fall'19LorenzoDeStefani 24
Decidability• Alloftheseexampleshavebeendecidable,andhenceTuring-recognizable.
• Howdoweknowthattheseexamplesaredecidable?– Ateachiterationprogressismadetowardthegoal,sothegoalitselfisreachable
– Nothardtoproveformally.Forexample,ifthetheinputiscomposedbynsymbolsandasymboliserasedateachiteration,thealgorithmwillfinishafterniterations
• ShowingthatalanguageisTuringrecognizablebutnotdecidableischallenging
10/1/19 TheoryofComputation-Fall'19LorenzoDeStefani 25