CS1010: Theory of Computation · – If you had to list the elements of A DFA what would they be?...
Transcript of CS1010: Theory of Computation · – If you had to list the elements of A DFA what would they be?...
CS1010:TheoryofComputation
LorenzoDeStefaniFall2019
Lecture11:DecidabilityandLanguages
LimitationsofAlgorithmicSolvability
• Inthispartoftheclassweinvestigatethepowerofalgorithmstosolveproblems– Somecanbesolvedalgorithmicallyandsomecannot
• Whydowestudyunsolvability?– Importantguideline
• Ifaproblemisunsolvablesearchingforanalgorithmicsolutionisawasteoftime
• Perhapstheproblemcanbesimplified– Gainunderstandingoncomputabilityanditslimits– Firststeptowardscomplexitycharacterization
• Firstweascertainwhetherthereisanalgorithmicsolutionandthenwestudywhetherthereisan“efficient”(polynomial-time)one
10/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani 1
Outline
• Decidablelanguages• Regularlanguagesaredecidable• Context-freelanguagesaredecidable• Languageshierarchy
10/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani 2
FromSipserChapter4.1
DecidableLanguages
• Westartwithproblemsthataredecidable– Wefirstlookatproblemsconcerningregularlanguagesandthenthoseforcontext-freelanguages
• …eventuallywewillmovetoproblemsconcerningTuringMachinesandshowthatsomeproblemsarenotdecidable!
10/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani 3
DecidableProblemsforRegularLanguages
• Weconsideralgorithmsfortesting– whetherafiniteautomatonacceptsastring– whetherthelanguageofafiniteautomatonisempty– whethertwofiniteautomataareequivalent
• Werepresenttheproblemsaslanguages(notFAs)– LetADFA={(B,w)|BisaDFAthatacceptsstringw}– TheproblemoftestingwhetheraDFABacceptsaspecificinputwisthesameastestingwhether(B,w)isamemberofthelanguageADFA.
– IfyouhadtolisttheelementsofADFAwhatwouldtheybe?• Allthepairs(Automata,string)suchthat“string”isacceptedby“automata”
10/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani
Showingthatthelanguageisdecidableisthesamethingasshowingthatthecomputationalproblemoftestingacceptanceisdecidable
4
ADFAisaDecidableLanguage
ProofIdea:ConstructaTuringMachineMthatdecidesADFAM=Oninput(<B>,w),whereBisaDFAandwisastring:
1. SimulateBoninputw2. Ifthesimulationendsinanacceptstate,thenaccept;else
reject
10/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani
Theorem:ADFAisadecidablelanguage
5
OutlineofProof• MmusttakeBasinput,encodedasastring,andthensimulateit
– ThealgorithmforsimulatinganyDFAmustbeembodiedintheTM’sstatetransitions
– Givenacurrentstateandinputsymbol,scanthetapefortheencodedtransitionfunctionandthenusethatinfotodeterminenewstate
• TheactualproofdescribeshowaTMsimulatesaDFA– CanassumeBisrepresentedbyits5componentsandthenwehavew
• NotethattheTMmustbeabletohandleanyDFA• Keeptrackofcurrentstateandpositioninwbywritingonthetape• Initiallycurrentstateisq0andcurrentpositionisleftmostsymbolofw
– Thestatesandpositionareupdatedusingthetransitionfunctionδ• TMM’sδnotthesameasDFAB’sδàthelatterisencodedastheinput
– WhenMfinishesprocessing,acceptifinanacceptstate;elsereject.Theimplementationwillmakeitclearthatwillcompleteinfinitetime.
10/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani 6
ANFAisaDecidableLanguage
ProofIdea:– BecausewehaveprovendecidabilityforDFAs,allweneedto
doisconverttheNFAtoaDFA.Oninput(B,w)whereBisanNFAandwisastring
1. ConvertNFABtoanequivalentDFAC,usingtheprocedureforconversiongiveninTheorem1.39
2. RunTMMoninput(C,w)usingthetheoremwejustproved3. IfMaccepts,thenaccept;elsereject
– RunningTMMinstep2meansincorporatingMintothedesignofNasasubroutine
10/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani 7
ComputingwhetheraDFAacceptsanyString
• EDFA={<A>|AisaDFAandL(A)=∅)isadecidablelanguage• Proof:
– ADFAacceptssomestringifandonlyifitispossibletoreachtheacceptstatefromthestartstate.Howcanwecheckthis?
– Wecanuseamarkingalgorithmsimilartotheoneusedtodecidethelanguageofconnectedgraphs.
– T=Oninput(A)whereAisaDFA:1. MarkthestartstateofA2. Repeatuntilnonewstatesgetmarked:
3. Markanystatethathasatransitioncomingintoitfromanystatealreadymarked
4. Ifnoacceptstateismarked,accept;otherwisereject
10/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani 8
EQDFAisaDecidableLanguage• EQDFA={(A,B)|AandBareDFAsandL(A)=L(B)}• Proofidea
– ConstructaDFACfromAandB,whereCacceptsonlythosestringsacceptedbyeitherAorBbutnotboth(symmetricdifference)• IfAandBacceptthesamelanguage,thenCwillacceptnothingandwe
canusethepreviousproof(forEDFA)tocheckforthis.• So,theproofis:
– F=Oninput(A,B)whereAandBareDFAs:1. ConstructDFACthatisthesymmetricdifferenceofAandB
(detailsonhowtodothisonnextslide)2. RunTMTfromtheprooffromlastslideoninput(C)3. IfTaccepts(sym.diff=∅)thenaccept.IfTrejectsthenreject
10/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani 9
HowtoConstructC
L(C)=(L(A)∩L(B))∪(L(A)∩L(B))– Weusedproofsbyconstructionthatregularlanguagesareclosedunder∪,∩,andcomplement
– WecanusethoseconstructionstoconstructaFAthatacceptsL(C)• Weneverprovedregularlanguagesareclosedunder∩!
L(A) L(B)
10/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani 10
RegularLanguagesClosedunderIntersection
IfLandMareregularlanguages,thensoisL∩M• Proof:LetAandBbeDFAswhoseregularlanguagesareLandM,respectively
– ConstructC,the“productautomation”ofAandB– CtracksthestatesinAandB(justlikewhenwedidtheproofofunionwithoutusingNFAs)
– MakethefinalstatesofCbethepairsconsistingoffinalstatesofbothAandB• IntheunioncasewethefinalstateanystatewithafinalstateinAorB
10/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani 11
10/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani 12
ACFGisaDecidableLanguageProofIdea:– ForCFGGandstringwwewanttodecidewhetherGgeneratesw.
– OneideaistouseGtogothroughallderivations.Thiswillnotwork,why?• ThismethodabestwillyieldaTMthatisarecognizer,notadecider.• Cangenerateinfinitestringsandifnotinthelanguage,willneverknowit.
– Canweusetheinformationonthelengthofw?– Astringwoflengthnwillhaveaderivationthatuses2n-1stepsiftheCFGisin
Chomsky-NormalForm.• FirstconverttoChomsky-NormalForm• Thenlistallderivationsoflength2n-1steps.Ifanygeneratesw,thenaccept,elsereject.
• Thisisavariantofbreadthfirstsearch,butinsteadofextendedthedepth1atatimeweallowittogo2n-1atatime.Aslongasfinitedepthextension,weareokay
10/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani 13
ECFGisaDecidableLanguage
• ECFG={<G>|GisaCFGandL(G)=∅)isadecidablelanguage
• Whatisthe“bruteforceapproach”?– Tryallpossiblestringsw.Willthiswork?
• Thenumberisnotbounded,sothiswouldnotbedecidable• Instead,thinkofthisasagraphproblemwhereyouwanttoknowifyoucanreachastringofterminalsfromthestartstate• Doyouthinkitiseasiertoworkforwardorbackwards?• Answer:backwards
10/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani 14
ECFGisaDecidableLanguage(cont)
ProofIdea:– Canthestartvariablegenerateastringofterminals?– Determineforeachvariableifitcangenerateanystringofterminalsandifso,markit
– Keepworkingbackwardssothatiftheright-sideofanyrulehasonlymarkeditems,thenmarktheLHS• Forexample,ifXàYZandYandZaremarked,thenmarkX• IfyoumarkS,thendone;ifnothingelsetomarkandSnotmarked,thenreject
• Youstartbymarkingallterminalsymbols
10/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani 15
EQCFGisnotaDecidableLanguage
• WecannotreusethesamereasoningusedtoshowthatEQDFAisadecidablelanguagesinceCFGsarenotclosedundercomplementandintersection
• Asitturnsout,EQCFGisnotdecidable!
10/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani 16
EveryContext-FreeLanguageisDecidable
• WepreviouslyshowedACFGisdecidable.• WewanttoknowifA,whichisaCFL,isdecidable.– AwillhavesomeCFGGthatgeneratesit– WhenweprovedthatACFGisdecidable,weconstructedaTMSthatwouldtellusifanyCFGacceptsaparticularinputw.
– NowweusethisTMandrunitoninput<G,w>andifitaccepts,weaccept,andifitrejects,wereject.
10/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani 17
HierarchyofClassesofLanguages
Regular
Context-Free
Decidable
Turing-recognizable
• WeprovedRegular⊆Context-freesincewecanconvertaFAintoaCFG
• WejustprovedthateveryContext-freelanguageisdecidable
• FromthedefinitionsinChapter3itisclearthateveryDecidablelanguageistriviallyTuring-recognizable.
• NoteveryTuring-recognizablelanguageisDecidable!
10/10/19 Theory of Computation - Fall'19
Lorenzo De Stefani 18