Upload
others
View
6
Download
0
Embed Size (px)
Citation preview
Outline• WhatisaFiniteStateAutomata• DFAdefinition• ExampleDFAconstruction• ThelanguageofaDFA• RegularOperations• Closureunderunion• Closureunderconcatenation
1
FromSipserChapter1.1
9/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani
WhatisaComputer?
• Westartwithacomputationalmodel– Differentmodelswillhavedifferentfeaturesandmaymatcharealcomputerbetterinsomewaysandworseinothers
– Tradeoffbetweengeneralityandprecision• Ourfirstmodelisthefinitestatemachineorfiniteautomata– Modelformachineswithfinitememory
9/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani 2
FiniteAutomataModelsofcomputerswithextremelylimitedmemory
– Manysimplecomputershaveextremelylimitedmemoriesandareinfactfinitestatemachines
– Canyounameany?Sareinthisbuildingbuthavenothingspecificallytodowithourdepartment
• Vendingmachine• Elevator• Thermostat• Automaticdooratsupermarket
9/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani 3
AutomaticDoor
• Whatisthedesiredbehavior?Describetheactionsandthenlistthestates.– Personapproaches,doorshouldopen– Doorshouldstayopenwhilepersongoingthrough– Doorshouldshutifnoonenearthedoorway– Statesareopenandclosed
• Moredetailsaboutautomaticdoor– FrontpadDoorRearPad– Describebehaviornow
• Hint:actiondependsnotjustonwhathappens,butwhatstateyouarecurrentlyin
• Ifyouwalkthrough,thedoorshouldstayopenwhileyouareonrearpad• Butifdoorisclosedandsomeonestepsonrearpad,doordoesnotopen
9/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani 4
AutomaticDoor
NEITHER FRONT REAR BOTH
CLOSED CLOSED OPEN CLOSED CLOSED
OPEN CLOSED OPEN OPEN OPEN
5 Theory of Computation - Fall'19 Lorenzo De Stefani
Closed Open
FRONT
NEITHER
REAR, BOTH, NEITHER
FRONT, REAR, BOTH
9/10/19
MoreonFiniteAutomata
• HowmanybitsofdatadoesthisFSMstore?– 1bit:openorclosed
• Whataboutstateinformationforelevators,thermostats,vendingmachines,etc?
• FSMusedinspeechprocessing,opticalcharacterrecognition,etc.
9/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani 6
Afiniteautomata
AfiniteautomataM1with3states– Statediagram
• Startstateq0(enteringarrowfromnostate),• acceptstateq1(doublecircle),• andseveraltransitions(arrows)
– M1willaccept(orrecognize)astringlike“1101”ifitendsinacceptstate.Otherwisethestringisrejected!Whatwillitdo?
– Canyoudescribeallstringthatthismodelwillaccept?• Itwillacceptallstringsendingina1andanystringwithanevennumberof0’sfollowingthelast1
0 0
1 1
0,1
q0 q2 q1
9/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani 7
FormalDefinitionofFiniteAutomata
• Afiniteautomataisa5-tuple(Q,Σ,δ,q0,F)– Qisafinitesetcalledstates– Σisafinitesetcalledthealphabet– δ:QxΣ→Qisthetransitionfunction– q0∈Qisthestartstate– F⊆Qisthesetofacceptstates
9/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani 8
FormalDefinition
• M1=(Q,Σ,δ,q0,F)– Q=– Σ=– q0isthestartstate– F=
0 1q0 q0 q1q1 q2 q1q2 q1 q1
0 0
1 1
0,1
q0 q2 q1
Transitionfunctionδ
{q0,q1,q2}{0,1}
{q1}
9/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani 9
TheLanguageofM1
• ThelanguageofDFAMisthesetAofallstringsacceptedbytheDFAM– L(M)=A– WealsosaythatMrecognizesAorMacceptsA
• Amachinemayacceptmanystrings,butonlyonelanguage
• Convention:Macceptsstringandrecognizesalanguage
9/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani 10
WhatistheLanguageofM1?
• L(M1)=AorM1recognizesA• WhatisA?
– A={w|…….}– A={w|wcontainsatleastone1andanevennumberof0’sfollowsthelast1}
9/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani 11
WhatistheLanguageofM2?
• M2={{q0,q1},{0,1},δ,q0,{q1}}– Ileaveδasanexercise– WhatisthelanguageofM2?
• L(M2)={w|?}• L(M2)={w|wendsina1}
0
1
q0 q1
1
0
9/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani 12
WhatistheLanguageofM3?
• M3isM2withdifferentacceptstate• WhatisthelanguageofM3?
– L(M3)={w|?}– L(M3)={w|wendsin0}[Notquiteright!Why?]– L(M3)={w|wistheemptystringεorendsin0}
0
1
q1
1
0
q0
9/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani 13
WhatistheLanguageofM4?WhatlanguagedoesM4accept?
s
r1
r2
q1
q2
Figure1.12onpage38
a b
b
b b
b
a
a a
a
9/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani 14
WhatistheLanguageofM4?
• WhatdoesM4accept?– Allstringsthatstartandendwithaorstartandendwithb
– Moresimply,languageisallstringstartingandendingwiththesamesymbol
• Notethatlengthof1isokay
9/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani 15
ConstructM5todoModuloArithmetic
• Let∑={RESET,0,1,2}• ConstructM5toacceptastringonlyifthesumofeachinputsymbolmodulo3is0andRESETsetsthesumbackto0(1.13,page39)
9/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani 16
NowGeneralizeM5
• GeneralizeM5toacceptifsumofsymbolsisamultipleofiinsteadof3– ({q0,q1,q2,q3,…,qi-1},{0,1,2,RESET},δi,q0,{q0})
• δi(qj,0)=qj• δi(qj,1)=qkwherek=j+1moduloi• δi(qj,2)=qkwherek=j+2moduloi• δi(qj,RESET)=qo
• Note:aslongasiisfinite,weareokayandonlyneedfinitememory(log#ofstates)
• Couldyougeneralizeon∑={1,2,3,…k}?
9/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani 17
FormalDefinitionofAccept
• LetM=(Q,Σ,δ,q0,F)beafiniteautomataandletw=w1w2…wnbeastringwherewi∈∑.
• ThenMacceptswifasequenceofstatesr0,r1,…,rninQexistswith3conditions– r0=q0– δ(ri,wi+1)=ri+1,fori=0,1,…,n-1– rn∈F
9/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani 18
RegularLanguages
Definition:Alanguageiscalledaregularlanguageifsomefiniteautomatarecognizesit• Thatis,ifthereexistsafiniteautomatathatrecognizesallandonlythestringsinthelanguage
9/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani 19
DesigningFiniteAutomata• YouwillneedtodesignFAstoacceptalanguage• Strategies
– Determinewhatyouneedtoremember(thestates)• Howmanystatestodetermineeven/oddnumberof1’sinaninput?
• Whatdoeseachstaterepresent– Setthestartandacceptstatesbasedonwhateachstaterepresents
– Assignthetransitions– Checkyoursolution:itshouldacceptw∈LandnotacceptwnotinL
– Becarefulabouttheemptystring
9/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani 20
DesigningFAs
• DesignaFAtoacceptthelanguageofbinarystringswherethenumberof1’sisodd,zerocountsaseven(page43)
• DesignaFAtoacceptallstringwith001asasubstring(page44)
• DesignaFAtoacceptastringwithsubstringabab
9/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani 21
ALWAYSstartbyasking:“WhatdoIneedtoremember?”
RegularOperations
LetAandBbelanguages.Wedefine3regularoperations:• Union:A∪B={x|x∈Aorx∈B}• Concatenation:A⋅Bwhere{xy|x∈Aandy∈B}• Star:A*={x1x2….xk|k≥0andeachxi∈A}
– Starisaunaryoperatoronasinglelanguage– Starrepeatsastring0ormoretimes
9/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani 22
ExamplesofRegularOperations
• LetA={0,1}andB={c,d}• Thenwhatis:
– AUB={0,1,c,d}– A⋅B={0c,0d,1c,1d}– A*={ε,0,1,00,01,10,11,000,…}
9/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani 23
Closure
• Acollectionofobjectsisclosedunderanoperationifapplyingthatoperationtomembersofthecollectionreturnsanobjectinthecollection
• Thesetofnaturalnumbersisclosedunderadditionandmultiplication(butnotdivisionandsubtraction)
9/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani 24
ClosureforRegularLanguages
• Regularlanguagesareclosedunderthe3regularoperatorswejustintroduced
• Whywecare?– Iftheseoperatorsareclosed,thenifwecanimplementeachoperatorusingaFA,thenwecanbuildaFAtorecognizearegularexpression
9/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani 25
ClosureofUnionTheorem1.25:Theclassofregularlanguagesisclosedundertheunionoperation• IfA1andA2areregularlanguagesthensoisA1∪A2
• Howcanweprovethis?Useproofbyconstruction.– AssumeM1acceptsA1andM2acceptsA2
– ConstructM3usingM1andM2toacceptA1∪A2
– WeneedtosimulateM1andM2runninginparallelandstopifeitherreachesanacceptstate
• Thislastpartisfeasiblesincewecanhavemultipleacceptstates
• Youneedtorememberwhereyouwouldbeinbothmachines
9/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani 26
ClosureofUnion• YouneedtogenerateastatetorepresentthestateyouwouldbeinforbothM1andM2
• LetM1=(Q1,Σ,δ1,q1,F1)andM2=(Q2,Σ,δ2,q2,F2)• BuildM3=(Q,Σ,δ,q0,F)asfollows:
– Q={(r1,r2)|r1∈Q1andr2∈Q2(Cartesianproduct)• Careful:orderof(r1,r2)doesnotmatter!• Morecorrect:QisthesetofunorderedpairssuchthatonestateisinQ1andtheotherisinQ2
– Σ=Σ1∪Σ2
– q0isthepair(q1,q2)– F={(r1,r2)|r1∈F1orr2∈F2}– δ((r1,r2),a)=(δ(r1,a),δ2(r2,a))
9/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani 27
ClosureofConcatenation
Theorem1.26:Theclassofregularlanguagesisclosedundertheconcatenationoperator
– IfA1andA2areregularlanguagesthensoisA1⋅A2– Canyouseehowtodothissimply?
• NottrivialsincecannotjustconcatenateM1andM2,wherestartstatesofM2becomethefinishstatesofM1
– Becausewedonotacceptastringassoonasitentersthefinishstate(waituntilstringisdone)itcanleaveandcomeback
– ThuswedonotknowwhentostartusingM2;ifwemakethewrongchoicewillnotacceptastringthatcanbeaccepted
– ThisproofiseasyifwehavenondeterministicFA
9/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani 28
Concatenation:SimpleExample
• Concatenationofthefollowing:– L(M1)=A,whereΣ={0,1}andA=binarystringwithexactly21’s
– L(M2)=B,whereΣ={0,1}andB=binarystringwithexactly31’s
• M1willenteracceptstateassoonassees21’s.Itcanthenloopbackonany0’sormovetoM2withoutissue.ItcanmoveimmediatelytoM2ona1,andnothaveanissuesinceitcannotloopback,sinceAacceptsonlyexactly21’s.OnceinM2everythingwillworkokay.
9/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani 29
Concatenation:HardExample• L(M1)=A,whereΣ={0,1}andA=binarystringwithatleast21’s• L(M2)=B,whereΣ={0,1}andB=binarystringwithexactly21’s• Thisdoesnotwork(buteasywithNFAormorecomplicatedDFA)
– IfinM1andsee21’s,enteracceptstate.Whenseeanother1,havechoicetoloopbackintoacceptstateinM1,orstartmovingintoM2,tothestatethatrepresentssawfirst1forstringinB.
• Iftheconcatenatedstringhasexactly41’stotal,thenwillonlyacceptifmoveintoM2asearlyaspossible(afterseeingthefirst21’s)
• Iftheconcatenatedstringhasmorethan41’s,thenwillonlyacceptifloopinM1acceptstateuntilonly21’sleft.
• NotethatthegeneralprocedureforputtingM1andM2togetherinvolvessuperimposingthestartstateforM2ontoacceptstateofM1andremovingtheoriginalarcsinM1forthatstate.
9/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani 30