Presentation on Regular Languages

download Presentation on Regular Languages

of 35

Transcript of Presentation on Regular Languages

  • 8/18/2019 Presentation on Regular Languages

    1/35

    1

    Regular Languages,Regular OperationsSeptember 11, 2001

  • 8/18/2019 Presentation on Regular Languages

    2/35

    2

    Agenda

    TodayRegular languages

    Finite languages are regular

    Regular operations on languagesUnion ( ∪ )Concatenation ( • )

    leene star (!)

    For next time:Read 1"# and $andout on minimi%ation

    Thursday, 9/20 ( revised ) : &'1 collected

  • 8/18/2019 Presentation on Regular Languages

    3/35

    3

    e nition o* RegularLanguage

    Recall t$e de nition o* a regular language+F+ -$e language accepted by an FA M is t$e set o* all strings .$ic$ are acceptedb/ M and is denoted b/ L (M)"

    'ould li e to understand .$at t/pes o*languages are regular" Languages o* t$ist/pe are amenable to super *astrecognition o* t$eir elements

    'ould be nice to no. *or e ample, .$ic$o* t$e *ollo.ing are regular+

  • 8/18/2019 Presentation on Regular Languages

    4/35

    4

    Language amples

    Unar/ prime numbers+3 11, 111, 11111, 1111111, 11111111111, 4 56 31 2 , 1 # , 1 7 , 1 8 , 1 11 , 1 1# , 4 5

    6 3 1 p

    9 p

    is a prime number 5Unar/ s:uares+3 ε , 1, 1 ; , 1 alindromic bit strings+

    3 ε , 0, 1, 00, 11, 000, 010, 101, 111, 456 3 x ∈ 30,15! 9 x 6 x R 5 o

    'ill e plore .$et$er or not t$ese are regularin *uture"

  • 8/18/2019 Presentation on Regular Languages

    5/35

    5

    Finite Languages

    All t$e pre?ious e amples $ad t$e *ollo.ingpropert/ in common+ infnite cardinalit/

    @O- + -$e strings .$ic$ made up t$elanguage .ere nite (as t$e/ al.a/s .illbe in t$is course) $o.e?er, t$e collectiono* suc$ strings .as in nite"

    Be*ore loo ing at in nite languages, s$ouldde nitel/ loo at nite languages"

  • 8/18/2019 Presentation on Regular Languages

    6/35

    6

    Languages o* Cardinalit/ 1

    + Ds t$e singleton languagecontaining one string regularE For

    e ample, is3 banana 5

    regularE

  • 8/18/2019 Presentation on Regular Languages

    7/35

    7

    Languages o* Cardinalit/ 1

    A+ es"

    + '$atGs, .rong .it$ t$ise ampleE

  • 8/18/2019 Presentation on Regular Languages

    8/35

    8

    Languages o* Cardinalit/ 1

    A+ @ot$ing, reall/" -$is an e ample o* anondeterministic FA" -$is turns out to bet$e most concise .a/ to encapsulate t$elanguage 3 banana 5

    But .e .ill deal .it$ nondeterminism incoming lectures" So+

    + Ds t$ere a .a/ o* ing t$is and ma ing itdeterministicE

  • 8/18/2019 Presentation on Regular Languages

    9/35

    9

    Languages o* Cardinalit/ 1A+ es, Hust add a fail state :8 D"e", put

    a state t$at suc s in all strings diIerent*rom JbananaK *or all eternit/ unlesst$e/ $appen to be t$e JbananaK

    pre xes 3 ε , b, ba, ban, bana, banan5"

  • 8/18/2019 Presentation on Regular Languages

    10/35

    11

    -.o Strings

    + &o. about t.o stringsE Fore ample

    3 banana, nab 5 E

  • 8/18/2019 Presentation on Regular Languages

    11/35

    12

    -.o Strings

    A+ Must add anot$er route+

  • 8/18/2019 Presentation on Regular Languages

    12/35

    13

    Arbitrar/ Finite @umber o*Strings

    1+ &o. about moreE For e ample3 banana, nab, ban, babba 5 E

    2+ Or less (t$e empt/ set)+N 6 35 E

  • 8/18/2019 Presentation on Regular Languages

    13/35

    14

    Arbitrar/ Finite @umber o*StringsA1+

  • 8/18/2019 Presentation on Regular Languages

    14/35

    15

    Arbitrar/ Finite @umber o*Strings+ mpt/ Language

    A2+ Build a 1 state automaton.$ose accept states set F is

    empty!

  • 8/18/2019 Presentation on Regular Languages

    15/35

    16

    Arbitrar/ Finite @umber o*Strings

    -& + All nite languages are regular"Proo + Can al.a/s construct a tree .$ose lea?es

    are .ord ending" Dn our e ample t$e tree is+

    @o. ma e .ord endings into accept states, add a

    *ail sin state and add lin s to t$e *ail state tonis$ t$e construction"

    ba a

    b

    a

    n b

    a

    n

    b

    an

  • 8/18/2019 Presentation on Regular Languages

    16/35

    17

    Dn nite Cardinalit/

    + Are all regular languages niteE

  • 8/18/2019 Presentation on Regular Languages

    17/35

    18

    Dn nite Cardinalit/

    A+ @oP an/ in nite languages are regular"Common ista e 1+ -$e strings o* regular

    languages are nite, t$ere*ore t$e regularlanguages must be nite"

    Common ista e 2+ Regular languages areb/ de nition accepted b/ fnite

    automata, t$ere*ore regular languages arenite"

    + Qi?e an e ample o* a infnite but regularlanguage"

  • 8/18/2019 Presentation on Regular Languages

    18/35

    19

    Dn nite Cardinalit/bit strings .it$ an e?en number o* bGs

    Simplest e ample is Σ∗

    man/, man/ more&ome e ercise+ t$in o* a criterion *or

    non niteness

  • 8/18/2019 Presentation on Regular Languages

    19/35

    20

    Regular Operations ou ma/ $a?e come across t$e regular

    operations .$en doing ad?anced searc$esutili%ing programs suc$ as emacs , egrep , perl , python , etc" -$ere are t$ree basic

    operations .e .ill .or .it$+1" Union2" Concatenation#" leene star

    And a *ourt$ de nable in terms o* t$e pre?ious+;" leene plus

  • 8/18/2019 Presentation on Regular Languages

    20/35

    21

    Regular Operations Summari%ing -able

    Operation

    S/mbol

    U@D?ersion

    eaning

    Union ∪ 9 matc$ one o*t$e patterns

    Concatenation •

    implicit inU@D

    matc$patterns inse:uence

    leenestar ! !

    atc$ pattern0 or more

    times

    leene atc$ pattern1 or more

  • 8/18/2019 Presentation on Regular Languages

    21/35

    22

    Regular operations Union

    U@D + to searc$ *or all lines containing?o.els in a te t one could use t$e

    commandegrep -i

    `

    a|e|i|o|u’

    &ere t$e pattern J vowel K is matc$ed

    b/ an/ line containing one o* a, e, i,o or u"+ '$at is a string patternE

  • 8/18/2019 Presentation on Regular Languages

    22/35

    23

    String >atterns

    A+ A good .a/ to de ne a pattern isas a set o* strings, i"e" a language"

    -$e language *or a gi?en pattern ist$e set o* all strings satis*/ing t$epredicate o* t$e pattern"Q+ vowel-pattern 63 t$e set o* strings .$ic$contain at least one o*+ a e i o u 5

  • 8/18/2019 Presentation on Regular Languages

    23/35

    24

    U@D patterns ?s"Computabilit/ patterns

    Dn U@D , a pattern is implicitl/assumed to occur as a substring o*

    t$e matc$ed strings"Dn our course, $o.e?er, a pattern

    needs to speci*/ t$e whole string,

    and not Hust a substring"

  • 8/18/2019 Presentation on Regular Languages

    24/35

    25

    Regular operations Union

    Computabilit/+ union is e actl/ .$at.e e pect" D* /ou $a?e patterns

    A 6 3aard?ar 5, 6 3bobcat5,6 3c$impan%ee5

    union t$e patterns toget$er to get A∪ ∪ 6 3aard?ar , bobcat,

    c$impan%ee5

  • 8/18/2019 Presentation on Regular Languages

    25/35

    26

    Regular operations Concatenation

    U@D + to searc$ *or all consecuti?edouble occurrences o* ?o.els, use+egrep -i

    `

    (a|e|i|o|u)(a|e|i|o|u)’&ere t$e pattern J vowel K $as been

    repeated" >arent$eses $a?e been

    introduced to speci*/ .$ere e actl/in t$e pattern t$e concatenation isoccurring"

  • 8/18/2019 Presentation on Regular Languages

    26/35

    27

    Regular operations Concatenation

    Computabilit/" Consider t$epre?ious result+

    L 6 3aard?ar , bobcat, c$impan%ee5

    + '$at language results .$en .econcatenate L .it$ itsel* obtaining

    L• L E

  • 8/18/2019 Presentation on Regular Languages

    27/35

    28

    Regular operations Concatenation

    A+L• L 63aard?ar , bobcat, c$impan%ee5 • 3aard?ar , bobcat, c$impan%ee5

    63aard?ar aard?ar , aard?ar bobcat, aard?ar c$impan%ee, bobcataard?ar , bobcatbobcat, bobcatc$impan%ee, c$impan%eeaard?ar , c$impan%eebobcat,

    c$impan%eec$impan%ee5

    1+ '$at is L•{ε} E2+ '$at is L• N E

  • 8/18/2019 Presentation on Regular Languages

    28/35

    29

    Algebra o* LanguagesA1+ L•{ε} 6 L" Dn general, {ε} is t$e identity in

    t$e JalgebraK o* languages" D"e", i* .e t$in o*concatenation as being li e multiplication,{ε} acts li e t$e number 1"

    A2+ L• N 6 N" Opposite to {ε} , N acts li e t$enumber %ero obliterating e?er/t$ing it isconcatenated .it$"

    @ote+ 'e can carr/ on t$e analog/ bet.eennumbers and languages" Addition becomesunion, multiplication becomes concatenation"

    -$is *orms a so called JalgebraK"

  • 8/18/2019 Presentation on Regular Languages

    29/35

    30

    Regular operations leene !

    U@D + searc$ *or lines consisting purel/ o*?o.els (including t$e empt/ line)+

    egrep -i `^(a|e|i|o|u)*$’

    @O- + ^ and $ are special s/mbols in U@Dregular e pressions .$ic$ respecti?el/anc$or t$e pattern at t$e beginning and

    end o* a line" -$e tric abo?e can be usedto con?ert an/ Computabilit/ regulare pression into an e:ui?alent U@D *orm"

  • 8/18/2019 Presentation on Regular Languages

    30/35

    31

    Regular operations leene !

    Computabilit/+ Suppose .e $a?e alanguage

    6 3 ba, na 5

    + '$at is t$e language ! E

  • 8/18/2019 Presentation on Regular Languages

    31/35

    32

    Regular operations leene !

    A+! 6 3 ba, na 5!6

    3 ε ,ba, na,

    baba, bana, naba, nana,

    bababa, babana, banaba, banana,nababa, nabana, nanaba, nanana,babababa, bababana, 4 5

  • 8/18/2019 Presentation on Regular Languages

    32/35

    33

    Regular operations leene

    leene is Hust li e leene ! e cept t$at t$epattern is *orced to occur at least once "

    U@D + searc$ *or lines consisting purel/ o* ?o.els(not including t$e empt/ line)+

    egrep -i `^(a|e|i|o|u)+$’

    Computabilit/+ 6 3 ba, na 5 63 ba, na, baba, bana, naba, nana, bababa, babana, banaba, banana,

    nababa, nabana, nanaba, nanana,babababa, bababana, 4 5

  • 8/18/2019 Presentation on Regular Languages

    33/35

    34

    Qenerating t$e Regular

    Languages -$e real reason t$at regular languages arecalled regular is t$e *ollo.ing+

    -& + -$e regular languages are all t$oselanguages .$ic$ can be generatedstarting *rom t$e nite languages b/appl/ing t$e regular operations"

    -$is .ill be pro?ed in t$e coming lectures"+ Can .e start .it$ e?en more basiclanguages t$an arbitrar/ nitelanguagesE

  • 8/18/2019 Presentation on Regular Languages

    34/35

    35

    Qenerating t$e Regular

    LanguagesA+ es" 'e can start .it$ languages consistingo* single strings .$ic$ are t$emsel?es Hust asingle c$aracter" -$ese are t$e JatomicKregular languages"

    Q+ -o generate t$e nite languageL 6 3 banana, nab 5.e can start .it$ t$e atomic languages

    A 6 3a5, 6 3b5, " 6 3n5"

    -$en .e can e press L as+L 6 ( • A • " • A • " • A ) ∪ ( " • A • )

  • 8/18/2019 Presentation on Regular Languages

    35/35

    36

    Blac board ercises

    press t$e FA patterns *rom t$epre?ious board e ercises using

    regular operations in bot$ U@Dst/le and Computabilit/ st/le"