06L2

download 06L2

of 29

Transcript of 06L2

  • 8/13/2019 06L2

    1/29

    2014/2/3 CSC 3130 Formal Languages and Automata Theory 1

    Informal Proof of Correctness

    Each state in the DFA represents a set of

    states in the original NFA.

    After reading an input string , the DFA is ina state that represents the set of all states the

    original NFA could be in after reading .

    If a string is accepted by the NFA, has apath in the NFA leading to a final states.

  • 8/13/2019 06L2

    2/29

    2014/2/3 CSC 3130 Formal Languages and Automata Theory 2

    Informal Proof of Correctness

    (contd)

    Then, will also have a path in the DFA

    leading to a state containing a final state of

    the NFA. The opposite is also true.

    Since any state in the DFA that includes a

    final state of the NFA is a final state, the

    DFA and the NFA will accept the same set

    of strings.

  • 8/13/2019 06L2

    3/29

    2014/2/3 CSC 3130 Formal Languages and Automata Theory 3

    Note on NFA DFA

    Sometimes we do not need to consider all

    possible subsets of the states in the original

    NFA (especially when the original NFA iscomplicated). We can construct the states in

    the DFA one by one whenever needed,

    starting from the initial state {q0} where q0is the initial state of the original NFA.

  • 8/13/2019 06L2

    4/29

    2014/2/3 CSC 3130 Formal Languages and Automata Theory 4

    Example

    Construct a DFA equivalent to this NFA:

    Start

    0,1

    q0 q10 q2

    1

  • 8/13/2019 06L2

    5/29

    2014/2/3 CSC 3130 Formal Languages and Automata Theory 5

    NFA with -Transitions (-NFA)

    There exist -transitions that allow state

    changes without consuming any input

    symbol.

    Similar to NFA, an input is accepted if there

    is a path leading from the start state to a

    final state after the whole string is read.

  • 8/13/2019 06L2

    6/29

    2014/2/3 CSC 3130 Formal Languages and Automata Theory 6

    Examples of -NFA

    q0 q1 q2 q3

    a,b

    q1 q2 q3 q4b a y

    q5 q6 q7 q8b a c

    q9k

    b,c

    a-z,

    q0Start

    Start

  • 8/13/2019 06L2

    7/29

  • 8/13/2019 06L2

    8/29

    2014/2/3 CSC 3130 Formal Languages and Automata Theory 8

    -NFA and NFA

    NFA -NFATrivial

    Constructive

    Proof

  • 8/13/2019 06L2

    9/29

    2014/2/3 CSC 3130 Formal Languages and Automata Theory 9

    -NFA NFA

    Given any -NFA M=(Q,,,q0,F)recognizing

    a language L over , we can construct an NFA

    N=(Q,,,q0,F)that also recognizes L:(qi,a) = qjiff there is a path from qito qjusing

    exactly one edge labeled a and zero or more edges

    labeled in M.

    F = F {q0} if a final state is reachable from q0

    using some -transitions in M. Otherwise, F = F.

  • 8/13/2019 06L2

    10/29

    2014/2/3 CSC 3130 Formal Languages and Automata Theory 10

    Example of -NFA NFA

    q0 q1

    q2

    ,ba

    M N

    Start q0 q1

    q2

    a,b

    a,b

    a,bStart

    a,b

    a,b

    a,b

  • 8/13/2019 06L2

    11/29

    2014/2/3 CSC 3130 Formal Languages and Automata Theory 11

    Informal Proof of CorrectnessIn the -NFA, the acceptance of the string

    a1a2an

    causes it to go through a sequence of states:

    q0q1q2 qm

    where m n. Some -transitions may be in the sequence:q0... qi1... qi2 qin

    where qin=qm. In the NFA, each sequence of states of the

    form:qik... qik+1

    will be represented by a single transition qikqik+1

    because of the way we construct the NFA.

    a1 a2

    ak+1

    ak+1

  • 8/13/2019 06L2

    12/29

    2014/2/3 CSC 3130 Formal Languages and Automata Theory 12

    Informal Proof of Correctness

    (contd)

    Therefore, every path in the -NFA M will have a

    corresponding path in the constructed NFA N, and

    vice versa.

    If a string is accepted by the -NFA, hasa pathin M leading to a final state. The corresponding path

    in the constructed NFA will also lead to a final state

    (since F F). The opposite is also true. Therefore, the original -NFA will accept the same

    set of strings as the constructed NFA.

  • 8/13/2019 06L2

    13/29

    2014/2/3 CSC 3130 Formal Languages and Automata Theory 13

    -Closures

    In an -NFA, the ECLOSE(q) of a state q isthe set of states that can be reached from q

    by following a path whose edges are all

    labeled by .

    q0 q1

    q2

    q3

    b

    a

    b

    Start

    ECLOSE(q1) = {q1,q3}

    ECLOSE(q2) = {q1,q2,q3}

  • 8/13/2019 06L2

    14/29

    2014/2/3 CSC 3130 Formal Languages and Automata Theory 14

    -NFA NFA

    The transition function (qi,a) in the NFA

    can also be constructed systematically:

    Find ECLOSE(qi) in M.

    Find the set of states S reachable from the

    states in ECLOSE(qi) using exactly one

    a-transition in M. S = (qk,a).Find Y = ECLOSE(qk). Put (qi,a) = Y.qkS

    qkECLOSE(qi)

  • 8/13/2019 06L2

    15/29

    2014/2/3 CSC 3130 Formal Languages and Automata Theory 15

    Class Discussion

    -NFA

    Construct an NFA equivalent to this -NFA:

    q0 q1

    q2

    ,b

    b

    a

    Start

  • 8/13/2019 06L2

    16/29

    2014/2/3 CSC 3130 Formal Languages and Automata Theory 16

    DFA, NFA and -NFA

    DFA NFA -NFA

  • 8/13/2019 06L2

    17/29

    2014/2/3 CSC 3130 Formal Languages and Automata Theory 17

    Regular Expression (RE)

    Let be an alphabet, a RE over can be

    defined recursively as:

    = {} is a RE= {} is a RE

    a , a = {a} is a RE

    If r, s are RE over denoting the set R, Sover , then (r+s), (rs) and (r*) are RE over

    denoting RS, RS and R* respectively.

  • 8/13/2019 06L2

    18/29

    2014/2/3 CSC 3130 Formal Languages and Automata Theory 18

    Regular Expression (RE)

    Note:

    If R is a set of strings, R* denotes the set

    of all strings formed by concatenating

    zero or more strings from R.

    We can neglect the parentheses assuming

    that * has a higher precedence than

    concatenation and concatenation has ahigher precedence than +

    e.g., (0((1*) + 1)) = 0(1* + 1)

  • 8/13/2019 06L2

    19/29

    2014/2/3 CSC 3130 Formal Languages and Automata Theory 19

    Examples of RE

    01* = {0, 01, 011, 0111, ..}

    (01*)(01) = {001, 0101, 01101, 011101, ..}

    (0+1)* = {, 0, 1, 00, 01, 10, 11, ..}, i.e., allstrings of 0 and 1

    (0+1)*00(0+1)* = {00, 1001, ..}, i.e., all 0

    and 1 strings containing a 00

  • 8/13/2019 06L2

    20/29

    2014/2/3 CSC 3130 Formal Languages and Automata Theory 20

    More Examples of RE

    (1+10)* = all strings starting with 1 and

    containing no 00

    (0+1)*011 = all strings ending with 011

    0*1* = all strings with no 0 after 1

    00*11* = all strings with at least one 0

    and one 1, and no 0 after 1

  • 8/13/2019 06L2

    21/29

    2014/2/3 CSC 3130 Formal Languages and Automata Theory 21

    Class Discussion

    What languages do the following RE

    represent?

    (1+01+001)*(+0+00)

    ((0+1)(0+1)+(0+1)(0+1)(0+1))*

    ((0+1)(0+1))*+((0+1)(0+1)(0+1))*

  • 8/13/2019 06L2

    22/29

    2014/2/3 CSC 3130 Formal Languages and Automata Theory 22

    Class Discussion

    Construct a RE over ={0,1} such that

    It contains all strings that have two

    consecutive 0s.

    It contains all strings except those with

    two consecutive 0s.

    It contains all strings with an even

    number of 0s.

  • 8/13/2019 06L2

    23/29

    2014/2/3 CSC 3130 Formal Languages and Automata Theory 23

    DFA, NFA, -NFA and RE

    DFA NFA -NFA RE

    RE can describe all the languages represented by

    DFA, NFA or -NFA.

  • 8/13/2019 06L2

    24/29

    2014/2/3 CSC 3130 Formal Languages and Automata Theory 24

    -NFA and RE

    RE

    Constructive

    Proof

    Constructive

    Proof

    -NFA

    Both constructive proofs are based on induction.

    DFA

  • 8/13/2019 06L2

    25/29

    2014/2/3 CSC 3130 Formal Languages and Automata Theory 25

    An Example of RE -NFA

    -NFA for 0

    -NFA for 1

    -NFA for 0+1

    Start q0 q10

    Start q0 q11

    Start q0 q1

    q2 q30

    q4 q51

  • 8/13/2019 06L2

    26/29

    2014/2/3 CSC 3130 Formal Languages and Automata Theory 26

    = {} is a RE,

    = {} is a RE,

    a , a = {a} is a RE,

    Proof of RE -NFA (Base Cases)

    Start q0 -NFA for

    Start q0 -NFA for

    Start q0 -NFA for aq1a

  • 8/13/2019 06L2

    27/29

    2014/2/3 CSC 3130 Formal Languages and Automata Theory 27

    If r and s are RE represented by -NFA, MrandMs, respectively, the -NFA for r+s, rs and r* can

    be constructed as:

    Proof of RE -NFA (Induction)

    Start q0 -NFA for r+sq1

    Mr

    Ms

    q0is connected to

    the start states of Mr

    and Ms, labeled by .

    All final states of Mrand

    Msare connected to q1,

    labeled by . q1becomes

    the only final state.

  • 8/13/2019 06L2

    28/29

    2014/2/3 CSC 3130 Formal Languages and Automata Theory 28

    Proof of RE -NFA (Induction)

    Start q0 -NFA for rsq1Mr Ms

    q0is connected to

    the start state of

    Mr, labeled by .

    Final states of Mrare

    connected to thestart

    state of Ms, labeled

    by .

    Final states of Msare

    connected to q1, labeled

    by . q1becomes the

    only final state.

    Start q0 -NFA for r*q1Mr

    q0is connected to

    the start state of

    Mr, labeled by .

    Final states of Mrare

    connected to q1, labeled

    by . q1becomes the

    only final state.

  • 8/13/2019 06L2

    29/29

    2014/2/3 CSC 3130 Formal Languages and Automata Theory 29

    Class Discussion

    Construct an -NFA for the RE 1*(0+1) over {0,1}

    according to the above base cases and inductive steps.