Sei sulla pagina 1di 35

CSE2243TheoryofComputation andCompilers

Lecture1: RegularLanguages
FiniteAutomata

AreasintheTheoryofComputation

Whatarethefundamentalcapabilitiesand limitationsofcomputers? Areas:

Automata Computability Complexity

CSE2243Lecture1

Complexity

Howcomputationallyhardaproblemis Problem1:Arrangingalistofnumbersinascendingorder

Evenasmallcomputercansortamillionnumbersratherquickly

Problem2:Findingascheduleofclassesfortheentireuniversitytosatisfy somereasonableconstraintslikenotwoclassescanbescheduledinthe sameroomatthesametime

Muchharder!Iftherearethousandclasses,findingthebestschedulemaytake centuries,evenonasupercomputer

Whatmakessomeproblemscomputationallyhardandotherseasy? Classifyproblemsaseasyorhard

CSE2243Lecture1

Computability

Certainbasicproblemscannotbesolvedby computers

Example:determiningwhetheramathematical statementistrueorfalsenocomputeralgorithm canperformthistask!

Classifyproblemsasthosewhichcanbesolved andthosewhichcannot

CSE2243Lecture1

Automata

Dealswiththedefinitionsandpropertiesof mathematicalmodelsofcomputation Examplesofmodels:

Finiteautomatonusedintextprocessing, compilersandhardwaredesign Contextfreegrammarusedinprogramming languagesandartificialintelligence

Practicewithformaldefinitionsofcomputation
CSE2243Lecture1 5

RegularLanguages

Whatisacomputer? Useanidealizedcomputercalleda computationalmodel Wewilluseseveraldifferentcomputational modelsdependingonthefeatureswewantto focuson Webeginwiththesimplestmodel:finitestate machineorfiniteautomaton


CSE2243Lecture1 6

FiniteAutomata

Modelscomputerswithanextremelylimited amountofmemory(finitememory) Example:Controllerforanautomaticdoor

Padsoneachsideofthedoor Dooropenswhensomeonestepsonthefrontpad, ifnooneisstandingontherearpad

CSE2243Lecture1

AutomaticDoorExample

Twostatesofthecontrollerrepresentingthecondition ofthedoor:

OPEN CLOSED FRONTsomeoneisstandingonthefrontpad REARsomeoneisstandingontherearpad BOTHpeoplearestandingonbothpads NEITHERnooneisstandingoneitherpad


CSE2243Lecture1 8

Fourpossibleinputconditions

AutomaticDoorStateDiagram

StateDiagram:

StateTransitionTable:

Thiscontrollerisacomputerthathasjustasinglebitofmemory,capableof recordingwhichofthetwostatesthecontrollerisin. Otherexamplesofcomputerswithlimitedmemories:elevators,dishwashers, electronicthermostats,partsofdigitalwatchesandcalculators


CSE2243Lecture1 9

StateDiagram:

DFAM1(1)

3States:q1,q2andq3 Startstate:q1(indicatedbyanarrowpointingatitfromnowhere) Acceptstate:q2(indicatedbyadoublecircle) Transitions:thearrowsgoingfromonestatetoanotherlabelled byinputs


CSE2243Lecture1 10

DFAM1(2)

HowdoestheFAcompute?

Itisgivenandinputstring Itprocessesthestring Itproducesanoutput Startinthestartstate Readtheinputstring,lefttoright

Processing:

Afterreadingasymbol,M1movesfromcurrentstatetoanewstateby followingthetransitionlabeledwiththeinputsymbol

Afteritprocessesthelastsymbol,M1producesanoutput

AcceptifM1isnowinanacceptstate,otherwisereject
CSE2243Lecture1 11

DFAM1(3)

HowdoesM1compute?

On1101?

Answer:Itvisits(inorder)q1,q2,q2,q3,q2Accept

On01? On101000?

DoesM1acceptorreject:0?1?100?01?10?Anystring thatendsin1?
CSE2243Lecture1 12

FormalDefinitionofDFA(1)

DefinitionofaDFAbyastatediagram (Previousslide) FormalDefinitionofDFA Whyformaldefinition

Itisprecise Noambiguity Itprovidesnotation

CSE2243Lecture1

13

FormalDefinitionofDFA(2)

ADFAisa5tuple(Q,,,q0,F),where

Qisafinitesetcalledthestates isafinitesetcalledthealphabet :QxQisthetransitionfunction

Qxisthesetofpairs(a,b)whereaQandb

q0 Qisthestartstate FQisthesetofacceptstates(sometimescalledthefinal states)


CSE2243Lecture1 14

FormalDefinitionofM1

M1=(Q,,,q1,F)

Q={q1,q2,q3} ={0,1} isdescribedbythetable

q1isthestartstate F={q2}
CSE2243Lecture1 15

LanguageofaMachineM

IfAisthesetofallstringsthatmachineMaccepts,then wesay:

AisthelanguageofmachineM L(M)=A MrecognizesA MacceptsA

Amachinemayacceptseveralstrings,butitalways recognizesonlyonelanguage IfMacceptsnostrings,itrecognizesonelanguage, namelytheemptylanguage,


CSE2243Lecture1 16

LanguageofM1

WhatisthelanguageofM1?

Answer:L(M1)=A,where

A={w|wcontainsatleastone1andanevennumberof 0sfollowsthelast1} M1recognisesA


CSE2243Lecture1 17

ExampleM2

WhatistheformaldescriptionofM2?

WhatisthelanguageofM2?

CSE2243Lecture1

18

ExampleM3

WhatisthelanguageofM3?

CSE2243Lecture1

19

ExampleM4

FormalDescriptionofM4: M4=({s,q1,q2,r1,r2},{a,b},, s,{q1,r1}) whereisgivenby


a s q1 q2 r1 r2 q1 q1 q1 r2 r2 b r1 q2 q2 r1 r1

WhatisthelanguageofM4?
CSE2243Lecture1 20

FormalDefinitionofComputation

LetM=(Q,,,q0,F)beaDFA Letw=w1w2wnbeastringoverthealphabet ThenMacceptswifasequenceofstatesr0,r1, rnexistsinQwiththefollowingthreeconditions:

r0=q0 (ri,wi+1) = ri+1 rn F


CSE2243Lecture1 21

DesigningDFAs(1)

HowtodesignaDFAtodoaspecifictask?

Putyourselfintheplaceofthemachineyouaredesigning Ask:Whatstatesareneeded?WhatdoIneedtoremember? Thendothetransitionsandtherestofthestatediagram Supposethealphabetis{0,1}andthelanguageisthesetofall stringswithanoddnumberof1s. DesignaDFAtorecognizethislanguage

Exercise

CSE2243Lecture1

22

DesigningDFAs(2)

Twostates:

qeven:evennumberof1s qodd:oddnumberof1s

Notethecountingideainthisexample
CSE2243Lecture1 23

DesigningDFAs(3)

Exercise

Supposethealphabetis{0,1}andthelanguageisthe setofallstringsthatcontain001asthesubstring

Eg:0010,1001,001,1111100111110areinthelanguage Eg:11,1101,0000arenotinthelanguage Howmanystates?

DesignaDFAtorecognizethislanguage

Notethesubstringideainthisexample
CSE2243Lecture1 24

RegularLanguagesandRegular Operations

Definition:

LanguageLisregularifL=L(M)forsomeDFAM GiveaDFAforit

Onewaytoshowalanguageisregular:

Atoolforshowingalanguageisregular:regular operations

Ifyouhavetworegularlanguages Andyoucombinethembyaregularoperation, Thentheresultisanotherregularlanguage


CSE2243Lecture1 25

RegularOperationsContext

Inarithmetic:

Basicobjectsarenumbers Basictools(addition,multiplication,etc.)operateon numbers Basicobjectsarelanguages Basictools(regularoperations)operateon languages


CSE2243Lecture1 26

Intheoryofcomputation:

RegularOperationsDefinition

LetAandBbelanguages Wedefineregularoperationsasfollows:

Union:AB={x|xAorxB} Concatenation:AB={xy|xAandyB} Star:A*={x1x2...xk|k0andeachxiA}

CSE2243Lecture1

27

RegularOperationsExample

Letthealphabetbe{a,b,z} IfA={good,bad}andB={boy,girl},then

A B={good,bad,boy,girl} AB={goodboy,goodgirl,badboy,badgirl} A*={, good,bad,goodgood,goodbad,badgood, badbad,goodgoodgood,goodgoodbad, goodbadgood,...}

CSE2243Lecture1

28

RegularOperationsClosure

Acollectionofobjectsisclosedunderoperation XifapplyingoperationXtomembersofthe collectionreturnsanobjectstillinthecollection Thenaturalnumbersareclosedunder multiplication(Meaningforanynaturalnumbersx andy,theproductxxyisalsoanaturalnumber) Theclassofregularlanguagesisclosedunder eachoftheregularoperations


CSE2243Lecture1 29

ProvingtheClosureTheorem

Theorem:theclassofregularlanguagesis closedunder

Union Concatenation Star

The3proofsarebyconstruction

CSE2243Lecture1

30

Proofv/sTheorem

Aproofofamathematicalstatementisanargumentthat convincesthereaderthatthestatementistrue.

Differentreadersimplydifferentproofs

Atheoremisamathematicalstatementthathasbeen provedtrue.

Ifweneedthestatementtoproveanotherstatementofgreater interest,wecallthefirststatementalemma Ifthetheoremletsuseasilyconcludeother,relatedstatements, wecalltheseotherstatementscorollariesofthetheorem

CSE2243Lecture1

31

TypesofProofs

Proofbycontradiction

Assumethatthestatementisfalse Showthatthisleadstoanobviouslyfalseconsequence, calledacontradiction Ifthetheoremsaysanobjectofacertaintypeexists, demonstratehowtoconstructtheobject Advancedmethodtoshowthatallelementsofaninfinite sethaveaspecifiedproperty


CSE2243Lecture1 32

Proofbyconstruction

Proofbyinduction

Theorem:Theclassofregular languagesisclosedunderunion

Thatis:

IfA1andA2areregularlanguages,thensoisA1 A2 Proofidea

WeknowthatA1andA2areregular

So,thereisanM1whichrecognizesA1andanM2whichrecognizesA2

WeconstructanMfromM1andM2thatrecognizesA1 A2 MsimulatesbothM1andM2andacceptsifeitheraccepts

CSE2243Lecture1

33

IfA1andA2areregularlanguages,

MsimulatesbothM1andM2andacceptsifeitheraccepts

thensoisA1 A2

Mdoesnotknow(inadvance)whetherM1orM2willaccept So,itmustrememberthestateofeach,i.e.,apairofstates So,astateinMisapair(x,y),wherexisthestateM1wouldbein andyisthestateM2wouldbein TransitionsinMgofrompairtopair TheacceptstatesinMarepairs(x,y)whereeitherxisanaccept stateofM1oryisanacceptstateofM2

CSE2243Lecture1

34

IfA1andA2areregularlanguages,

Proof

thensoisA1 A2

LetM1recognizeA1whereM1=(Q1,,1,q1,F1) LetM2recognizeA2whereM2=(Q2,,2,q2,F2) WeconstructMthatrecognizesA1 A2whereM=(Q,,,q,F)where

Q={(r1,r2)|r1Q1andr2Q2}

isthesameasthelanguagesforM1andM2 isdefinedasfollows:Foreach(r1,r2)Qandeachain,let

((r1,r2),a)=(1(r1,a),2(r2,a))

q=(q1,q2) F={(r1,r2)|r1F1orr2F2} ItisevidentfromtheconstructionofMthatMrecognizesA1 A2 CSE2243Lecture1


35

Potrebbero piacerti anche