7 - rs2-cb

download 7 - rs2-cb

of 24

Transcript of 7 - rs2-cb

  • 7/28/2019 7 - rs2-cb

    1/24

    1

    Closure Properties of Regular

    Languages

    Union, Intersection, Difference,

    Concatenation, Kleene Closure,Reversal, Homomorphism, InverseHomomorphism

  • 7/28/2019 7 - rs2-cb

    2/24

    2

    Closure Properties

    Recall a closure property is a statementthat a certain operation on languages,

    when applied to languages in a class(e.g., the regular languages), producesa result that is also in that class.

    For regular languages, we can use anyof its representations to prove a closureproperty.

  • 7/28/2019 7 - rs2-cb

    3/24

    3

    Closure Under Union

    If L and M are regular languages, so isL M.

    Proof: Let L and M be the languages ofregular expressions R and S,respectively.

    Then R+S is a regular expressionwhose language is L M.

  • 7/28/2019 7 - rs2-cb

    4/24

    4

    Closure Under Concatenation

    and Kleene Closure

    Same idea:

    RS is a regular expression whose languageis LM.

    R* is a regular expression whose language

    is L*.

  • 7/28/2019 7 - rs2-cb

    5/24

    5

    Closure Under Intersection

    If L and M are regular languages, thenso is L M.

    Proof: Let A and B be DFAs whoselanguages are L and M, respectively.

    Construct C, the product automaton of A

    and B.

    Make the final states of C be the pairsconsisting of final states of both A and B.

  • 7/28/2019 7 - rs2-cb

    6/24

    6

    Example: Product DFA forIntersection

    A

    C

    B

    D

    0

    1

    0, 1

    1

    1

    00

    [A,C] [A,D]0

    [B,C]

    1

    0

    10

    1

    [B,D]

    0

    1

  • 7/28/2019 7 - rs2-cb

    7/24

    7

    Closure Under Difference

    If L and M are regular languages, thenso is LM = strings in L but not M.

    Proof: Let A and B be DFAs whoselanguages are L and M, respectively.

    Construct C, the product automaton of A

    and B.

    Make the final states of C be the pairswhere A-state is final but B-state is not.

  • 7/28/2019 7 - rs2-cb

    8/24

    8

    Example: Product DFA forDifference

    A

    C

    B

    D

    0

    1

    0, 1

    1

    1

    00

    [A,C] [A,D]0

    [B,C]

    1

    0

    10

    1

    [B,D]

    0

    1

    Notice: differenceis the empty language

  • 7/28/2019 7 - rs2-cb

    9/24

    9

    Closure Under Complementation

    The complement of a language L (withrespect to an alphabet such that *

    contains L) is * L.Since * is surely regular, the

    complement of a regular language is

    always regular.

  • 7/28/2019 7 - rs2-cb

    10/24

    10

    Closure Under Reversal

    Recall example of a DFA that acceptedthe binary strings that, as integers were

    divisible by 23.We said that the language of binary

    strings whose reversal was divisible by

    23 was also regular, but the DFAconstruction was very tricky.

    Good application of reversal-closure.

  • 7/28/2019 7 - rs2-cb

    11/24

    11

    Closure Under Reversal (2)

    Given language L, LR is the set of stringswhose reversal is in L.

    Example: L = {0, 01, 100};LR= {0, 10, 001}.

    Proof: Let E be a regular expression for L.

    We show how to reverse E, to provide aregular expression ER for LR.

  • 7/28/2019 7 - rs2-cb

    12/24

    12

    Reversal of a Regular Expression

    Basis: If E is a symbol a, , or , then

    ER= E.

    Induction: If E is F+G, then ER= FR+ GR.

    FG, then ER= GRFR

    F*, then ER= (FR)*.

  • 7/28/2019 7 - rs2-cb

    13/24

    13

    Example: Reversal of a RE

    Let E = 01* + 10*.

    ER= (01* + 10*)R= (01*)R+ (10*)R

    = (1*)R0R+ (0*)R1R

    = (1R)*0 + (0R)*1

    =1

    *0

    +0

    *1

    .

  • 7/28/2019 7 - rs2-cb

    14/24

    14

    Homomorphisms

    Ahomomorphism on an alphabet is afunction that gives a string for each

    symbol in that alphabet.Example: h(0) = ab; h(1) = .

    Extend to strings by h(a1an) =

    h(a1)h(an).

    Example: h(01010) = ababab.

  • 7/28/2019 7 - rs2-cb

    15/24

    15

    Closure Under Homomorphism

    If L is a regular language, and h is ahomomorphism on its alphabet, then h(L)

    = {h(w) | w is in L} is also a regularlanguage.

    Proof: Let E be a regular expression for L.

    Apply h to each symbol in E.

    Language of resulting RE is h(L).

  • 7/28/2019 7 - rs2-cb

    16/24

    16

    Example: Closure under

    HomomorphismLet h(0) = ab; h(1) = .

    Let L be the language of regular

    expression 01* + 10*.

    Then h(L) is the language of regularexpression ab* + (ab)*.

    Note: use parenthesesto enforce the propergrouping.

  • 7/28/2019 7 - rs2-cb

    17/24

    17

    Example Continued

    ab* + (ab)* can be simplified.

    * = , so ab* = ab.

    is the identity under concatenation. That is, E = E = E for any RE E.

    Thus, ab* + (ab)* = ab + (ab)*

    = ab + (ab)*.Finally, L(ab) is contained in L((ab)*),

    so a RE for h(L) is (ab)*.

  • 7/28/2019 7 - rs2-cb

    18/24

    18

    Inverse Homomorphisms

    Let h be a homomorphism and L alanguage whose alphabet is the output

    language of h.h-1(L) = {w | h(w) is in L}.

  • 7/28/2019 7 - rs2-cb

    19/24

    19

    Example: Inverse Homomorphism

    Let h(0) = ab; h(1) = .

    Let L = {abab, baba}.

    h-1(L) = the language with two 0s andany number of 1s = L(1*01*01*).

    Notice: no string maps tobaba; any string with exactlytwo 0s maps to abab.

  • 7/28/2019 7 - rs2-cb

    20/24

    20

    Closure Prooffor Inverse

    HomomorphismStart with a DFA A for L.

    Construct a DFA B for h-1(L) with:

    The same set of states.

    The same start state.

    The same final states.

    Input alphabet = the symbols to whichhomomorphism h applies.

  • 7/28/2019 7 - rs2-cb

    21/24

    21

    Proof (2)

    The transitions for B are computed byapplying h to an input symbol a and

    seeing where A would go on sequenceof input symbols h(a).

    Formally, B(q, a) = A(q, h(a)).

  • 7/28/2019 7 - rs2-cb

    22/24

    22

    Example: Inverse Homomorphism

    Construction

    A

    C

    B

    a

    a

    a

    b b

    b

    C

    B

    A

    h(0) = abh(1) =

    1

    1

    1 Sinceh(1) =

    0

    0

    , 0

    Since

    h(0) = ab

  • 7/28/2019 7 - rs2-cb

    23/24

    23

    Proof (3)

    Induction on |w| shows that B(q0, w)= A(q0, h(w)).

    Basis: w = .B(q0, ) = q0, and A(q0, h()) =A(q0, ) = q0.

  • 7/28/2019 7 - rs2-cb

    24/24

    24

    Proof (4)

    Induction: Let w = xa; assume IH for x.

    B(q0, w) = B(B(q0, x), a).

    = B(A(q0, h(x)), a) by the IH.= A(A(q0, h(x)), h(a)) by definition of

    the DFA B.

    = A(q0, h(x)h(a)) by definition of theextended delta.

    = A(q0, h(w)) by def. of homomorphism.