4 regular properties

Upload: arslan-munir

Post on 03-Apr-2018

216 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/28/2019 4 Regular Properties

    1/56

    1

    Properties of

    Regular Languages

  • 7/28/2019 4 Regular Properties

    2/56

    2

    1L 2L

    21LLConcatenation:

    *1LStar:

    21 LL Union:

    Are regular

    Languages

    For regular languages and

    we will prove that:

    1L

    21 LL

    Complement:

    Intersection:

    R

    L1Reversal:

  • 7/28/2019 4 Regular Properties

    3/56

    3

    We say: Regular languages are closed under

    21LLConcatenation:

    *1LStar:

    21 LL Union:

    1L

    21 LL

    Complement:

    Intersection:

    R

    L1Reversal:

  • 7/28/2019 4 Regular Properties

    4/56

    4

    a

    b

    b

    aNFA

    Equivalent

    NFA

    a

    b

    b

    a

    A useful transformation: use one accept state

    2 accept states

    1 accept state

  • 7/28/2019 4 Regular Properties

    5/56

    5

    NFA

    Equivalent NFA

    Singleaccepting

    state

    In General

  • 7/28/2019 4 Regular Properties

    6/56

    6

    NFA without accepting state

    Add an accepting state

    without transitions

    Extreme case

  • 7/28/2019 4 Regular Properties

    7/567

    1LRegular language

    11 LML

    1

    Single accepting state

    NFA 2

    2L

    Single accepting state

    22 LML

    Regular language

    NFA

    Take two languages

  • 7/28/2019 4 Regular Properties

    8/568

    }{1 baLn

    a

    b

    1

    baL 2ab

    2

    0n

    Example

  • 7/28/2019 4 Regular Properties

    9/569

    Union

    NFA for

    1

    2

    21 LL

  • 7/28/2019 4 Regular Properties

    10/5610

    a

    b

    ab

    }{1 baLn

    }{2 baL

    }{}{21 babaLLn

    NFA for

    Example

  • 7/28/2019 4 Regular Properties

    11/5611

    Concatenation

    NFA for 21LL

    1 2

  • 7/28/2019 4 Regular Properties

    12/5612

    NFA for

    a

    b ab

    }{1 baLn

    }{2 baL

    }{}}{{21 bbaababaLL nn

    Example

  • 7/28/2019 4 Regular Properties

    13/5613

    Star Operation

    NFA for *1L

    1

    *1L

    1

    21

    Lw

    wwww

    i

    k

  • 7/28/2019 4 Regular Properties

    14/5614

    NFA for *}{*1 baL n

    a

    b

    }{1 baLn

    Example

  • 7/28/2019 4 Regular Properties

    15/5615

    Reverse

    R

    L1

    1

    NFA for1

    1. Reverse all transitions

    2. Make initial state accepting state

    and vice versa

    1L

    E l

  • 7/28/2019 4 Regular Properties

    16/5616

    }{1 baLn

    a

    b

    1

    }{1nR

    baL a

    b

    1

    Example

  • 7/28/2019 4 Regular Properties

    17/5617

    Complement

    1. Take the DFAthat accepts 1L

    11L

    11L

    2. Make accepting states non-final,

    and vice-versa

  • 7/28/2019 4 Regular Properties

    18/5618

    }{1 baLn

    a

    b

    1

    ba,

    ba,

    }{*},{1 babaL n a

    b

    1

    ba,

    ba,

    Example

  • 7/28/2019 4 Regular Properties

    19/5619

    Intersection

    1L regular

    2L regularWe show 21

    LL

    regular

  • 7/28/2019 4 Regular Properties

    20/5620

    DeMorgans Law: 2121 LLLL

    21 , LL regular

    21 , LL regular

    21 LL regular

    21 LL regular

    21 LL regular

  • 7/28/2019 4 Regular Properties

    21/5621

    Example

    }{1 baLn

    },{2 baabL

    regular

    regular

    }{21 abLL

    regular

  • 7/28/2019 4 Regular Properties

    22/56

    22

    Regular Expressions

  • 7/28/2019 4 Regular Properties

    23/56

    23

    Regular Expressions

    Regular expressions

    describe regular languages

    Example:

    describes the language

    *)( cba

    ,...,,,,,*, bcaabcaabcabca

  • 7/28/2019 4 Regular Properties

    24/56

    24

    Recursive Definition

    1

    1

    21

    21

    *

    r

    r

    rr

    rr

    Are regular expressions

    2r1rGiven regular expressions and

  • 7/28/2019 4 Regular Properties

    25/56

    25

    Examples

    )(* ccbaA regular expression:

    baNot a regular expression:

  • 7/28/2019 4 Regular Properties

    26/56

    26

    Languages of Regular Expressions

    : language of regular expression

    Example

    rL r

    ,...,,,,,*)( bcaabcaabcacbaL

  • 7/28/2019 4 Regular Properties

    27/56

    27

    Definition

    For primitive regular expressions:

    aaL

    L

    L

  • 7/28/2019 4 Regular Properties

    28/56

    28

    Definition (continued)

    For regular expressions and1r 2r

    2121 rLrLrrL

    2121 rLrLrrL

    ** 11 rLrL

    11 rLrL

  • 7/28/2019 4 Regular Properties

    29/56

    29

    Example

    Regular expression: *aba

    *abaL *aLbaL

    *aLbaL

    *aLbLaL

    *aba

    ,...,,,, aaaaaaba

    ,...,,,...,,, baababaaaaaa

  • 7/28/2019 4 Regular Properties

    30/56

    30

    Example

    Regular expression bbabar *

    ,...,,,,, bbbbaabbaabbarL

  • 7/28/2019 4 Regular Properties

    31/56

    31

    Example

    Regular expression bbbaar **

    }0,:{ 22 mnbbarL mn

  • 7/28/2019 4 Regular Properties

    32/56

    32

    Example

    Regular expression *)10(00*)10( r

    )(rL = { all strings containing substring 00 }

    E l

  • 7/28/2019 4 Regular Properties

    33/56

    33

    Example

    Regular expression )0(*)011( r

    )(rL = { all strings without substring 00 }

    E l l E

  • 7/28/2019 4 Regular Properties

    34/56

    34

    Equivalent Regular Expressions

    Definition:

    Regular expressions and

    are equivalent if

    1r 2r

    )()( 21 rLrL

    E l

  • 7/28/2019 4 Regular Properties

    35/56

    35

    Example

    L = { all strings without substring 00 }

    )0(*)011(1 r

    )0(*1)0(**)011*1(2 r

    LrLrL )()( 211r 2rand

    are equivalent

    regular expressions

  • 7/28/2019 4 Regular Properties

    36/56

    36

    Regular Expressionsand

    Regular Languages

    Th

  • 7/28/2019 4 Regular Properties

    37/56

    37

    Theorem

    LanguagesGenerated by

    Regular Expressions

    Regular

    Languages

    P f

  • 7/28/2019 4 Regular Properties

    38/56

    38

    LanguagesGenerated by

    Regular Expressions

    RegularLanguages

    Languages

    Generated by

    Regular Expressions

    RegularLanguages

    Proof:

    P f P t 1

  • 7/28/2019 4 Regular Properties

    39/56

    39

    Proof - Part 1

    r

    )(rL

    For any regular expression

    the language is regular

    LanguagesGenerated by

    Regular Expressions

    Regular

    Languages

    Proof by induction on the size of r

    I d ti B i

  • 7/28/2019 4 Regular Properties

    40/56

    40

    Induction Basis

    Primitive Regular Expressions: ,,

    CorrespondingNFAs

    )()( 1 LML

    )(}{)( 2 LML

    )(}{)( 3 aLaML

    regular

    languages

    a

    I d ti H th i

  • 7/28/2019 4 Regular Properties

    41/56

    41

    Inductive Hypothesis

    Supposethat for regular expressions and ,

    and are regular languages1r 2r

    )( 1rL )( 2rL

    I d ti St

  • 7/28/2019 4 Regular Properties

    42/56

    42

    Inductive Step

    We will prove:

    1

    1

    21

    21

    *

    rL

    rL

    rrL

    rrL

    Are regular

    Languages

    d f f l

  • 7/28/2019 4 Regular Properties

    43/56

    43

    By definition of regular expressions:

    11

    11

    2121

    2121

    **

    rLrL

    rLrL

    rLrLrrL

    rLrLrrL

    B d h h k

  • 7/28/2019 4 Regular Properties

    44/56

    44

    )( 1rL )( 2rL

    By inductive hypothesis we know:

    and are regular languages

    Regular languages are closed under:

    *1

    21

    21

    rL

    rLrL

    rLrL Union

    Concatenation

    Star

    We also know:

    Th f :

  • 7/28/2019 4 Regular Properties

    45/56

    45

    Therefore:

    ** 11

    2121

    2121

    rLrL

    rLrLrrL

    rLrLrrL

    Are regular

    languages

    )())(( 11 rLrL is trivially a regular language(by induction hypothesis)

    End of Proof-Part 1

    U i h l l f h i

  • 7/28/2019 4 Regular Properties

    46/56

    46

    Using the regular closure of these operations,

    we can construct recursively the NFA

    that accepts

    M

    )()( rLML

    Example:21 rrr

    )()( 11rLML

    )()( 22 rLML

    )()( rLML

    Pr f P rt 2

  • 7/28/2019 4 Regular Properties

    47/56

    47

    For any regular language there is

    a regular expression with

    Proof - Part 2

    LanguagesGenerated by

    Regular Expressions

    Regular

    Languages

    L

    rLrL )(

    We will convert an NFA that accepts

    to a regular expression

    L

  • 7/28/2019 4 Regular Properties

    48/56

    48

    Since is regular, there is a

    NFA that accepts it

    L

    LML )(

    Take it with a single final state

  • 7/28/2019 4 Regular Properties

    49/56

    49

    From construct the equivalent

    Generalized Transition Graphin which transition labels are regular expressions

    Example:

    a

    ba,

    c a

    ba

    c

    Corresponding

    Generalized transition graph

  • 7/28/2019 4 Regular Properties

    50/56

    50

    Another Example:

    ba a

    b

    b

    0q 1q 2q

    ba,a

    b

    b

    0q 1q 2q

    b

    bTransition labels

    are regularexpressions

  • 7/28/2019 4 Regular Properties

    51/56

    51

    Reducing the states:

    ba

    ab

    b

    0q 1q 2q

    b

    0q 2q

    babb

    *

    )(* babb

    Transition labels

    are regularexpressions

  • 7/28/2019 4 Regular Properties

    52/56

    52

    Resulting Regular Expression:

    0q 2q

    babb*

    )(* babb

    *)(**)*( bbabbabbr

    LMLrL )()(

    In General

  • 7/28/2019 4 Regular Properties

    53/56

    53

    In General

    Removing a state:

    iq q jq

    a b

    cd

    e

    iq jq

    dae* bce*

    dce*

    bae*

    By repeating the process until

  • 7/28/2019 4 Regular Properties

    54/56

    54

    0q fq

    1r

    2r

    3r4r

    *)*(* 213421 rrrrrrr

    LMLrL )()(

    The resulting regular expression:

    y r p at ng th proc ss unt

    two states are left, the resulting graph is

    Initial graph Resulting graph

    End of Proof-Part 2

    Stan ar epresentations

  • 7/28/2019 4 Regular Properties

    55/56

    55

    Stan ar epresentationsof Regular Languages

    Regular Languages

    DFAs

    NFAs RegularExpressions

  • 7/28/2019 4 Regular Properties

    56/56

    When we say: We are given

    a Regular Language

    We mean:

    L

    Language is in a standard

    representation

    L

    (DFA, NFA, or Regular Expression)