Top Banner
CS1010: Theory of Computation Lorenzo De Stefani Fall 2019 Lecture 11: Decidability and Languages
19

CS1010: Theory of Computation · – If you had to list the elements of A DFA what would they be? • All the pairs (Automata, string) such that “string” is accepted by “automata”

Jul 13, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CS1010: Theory of Computation · – If you had to list the elements of A DFA what would they be? • All the pairs (Automata, string) such that “string” is accepted by “automata”

CS1010:TheoryofComputation

LorenzoDeStefaniFall2019

Lecture11:DecidabilityandLanguages

Page 2: CS1010: Theory of Computation · – If you had to list the elements of A DFA what would they be? • All the pairs (Automata, string) such that “string” is accepted by “automata”

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

Page 3: CS1010: Theory of Computation · – If you had to list the elements of A DFA what would they be? • All the pairs (Automata, string) such that “string” is accepted by “automata”

Outline

•  Decidablelanguages•  Regularlanguagesaredecidable•  Context-freelanguagesaredecidable•  Languageshierarchy

10/10/19 Theory of Computation - Fall'19

Lorenzo De Stefani 2

FromSipserChapter4.1

Page 4: CS1010: Theory of Computation · – If you had to list the elements of A DFA what would they be? • All the pairs (Automata, string) such that “string” is accepted by “automata”

DecidableLanguages

•  Westartwithproblemsthataredecidable– Wefirstlookatproblemsconcerningregularlanguagesandthenthoseforcontext-freelanguages

•  …eventuallywewillmovetoproblemsconcerningTuringMachinesandshowthatsomeproblemsarenotdecidable!

10/10/19 Theory of Computation - Fall'19

Lorenzo De Stefani 3

Page 5: CS1010: Theory of Computation · – If you had to list the elements of A DFA what would they be? • All the pairs (Automata, string) such that “string” is accepted by “automata”

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

Page 6: CS1010: Theory of Computation · – If you had to list the elements of A DFA what would they be? • All the pairs (Automata, string) such that “string” is accepted by “automata”

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

Page 7: CS1010: Theory of Computation · – If you had to list the elements of A DFA what would they be? • All the pairs (Automata, string) such that “string” is accepted by “automata”

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

Page 8: CS1010: Theory of Computation · – If you had to list the elements of A DFA what would they be? • All the pairs (Automata, string) such that “string” is accepted by “automata”

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

Page 9: CS1010: Theory of Computation · – If you had to list the elements of A DFA what would they be? • All the pairs (Automata, string) such that “string” is accepted by “automata”

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

Page 10: CS1010: Theory of Computation · – If you had to list the elements of A DFA what would they be? • All the pairs (Automata, string) such that “string” is accepted by “automata”

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

Page 11: CS1010: Theory of Computation · – If you had to list the elements of A DFA what would they be? • All the pairs (Automata, string) such that “string” is accepted by “automata”

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

Page 12: CS1010: Theory of Computation · – If you had to list the elements of A DFA what would they be? • All the pairs (Automata, string) such that “string” is accepted by “automata”

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

Page 13: CS1010: Theory of Computation · – If you had to list the elements of A DFA what would they be? • All the pairs (Automata, string) such that “string” is accepted by “automata”

10/10/19 Theory of Computation - Fall'19

Lorenzo De Stefani 12

Page 14: CS1010: Theory of Computation · – If you had to list the elements of A DFA what would they be? • All the pairs (Automata, string) such that “string” is accepted by “automata”

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

Page 15: CS1010: Theory of Computation · – If you had to list the elements of A DFA what would they be? • All the pairs (Automata, string) such that “string” is accepted by “automata”

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

Page 16: CS1010: Theory of Computation · – If you had to list the elements of A DFA what would they be? • All the pairs (Automata, string) such that “string” is accepted by “automata”

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

Page 17: CS1010: Theory of Computation · – If you had to list the elements of A DFA what would they be? • All the pairs (Automata, string) such that “string” is accepted by “automata”

EQCFGisnotaDecidableLanguage

•  WecannotreusethesamereasoningusedtoshowthatEQDFAisadecidablelanguagesinceCFGsarenotclosedundercomplementandintersection

•  Asitturnsout,EQCFGisnotdecidable!

10/10/19 Theory of Computation - Fall'19

Lorenzo De Stefani 16

Page 18: CS1010: Theory of Computation · – If you had to list the elements of A DFA what would they be? • All the pairs (Automata, string) such that “string” is accepted by “automata”

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

Page 19: CS1010: Theory of Computation · – If you had to list the elements of A DFA what would they be? • All the pairs (Automata, string) such that “string” is accepted by “automata”

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