Course6 Finite Automata/Finite State Machines · 2020-06-02 · 2 FA with e-Transitions n We can...

12
1 Course 6 Finite Automata/Finite State Machines The structure and the content of the lecture is based on http://www.eecs.wsu.edu/~ananth/CptS317/Lectures/index.htm

Transcript of Course6 Finite Automata/Finite State Machines · 2020-06-02 · 2 FA with e-Transitions n We can...

Page 1: Course6 Finite Automata/Finite State Machines · 2020-06-02 · 2 FA with e-Transitions n We can allow explicite-transitions in finite automata n i.e., a transition from one state

1

Course 6Finite Automata/Finite State Machines

The structure and the content of the lecture is based on http://www.eecs.wsu.edu/~ananth/CptS317/Lectures/index.htm

Page 2: Course6 Finite Automata/Finite State Machines · 2020-06-02 · 2 FA with e-Transitions n We can allow explicite-transitions in finite automata n i.e., a transition from one state

2

FA with e-Transitions n We can allow explicit e-transitions in finite automata

n i.e., a transition from one state to another state without consuming any additional input symbol (then an NFA is allowed to make a transition spontaneously, without receiving an input symbol).

n Explicit e-transitions between different states introduce non-determinism.

n Makes it easier sometimes to construct NFAsDefinition: e -NFAs are those NFAs with at least one

explicit e-transition defined.n e -NFAs have one more column in their transition

table

Page 3: Course6 Finite Automata/Finite State Machines · 2020-06-02 · 2 FA with e-Transitions n We can allow explicite-transitions in finite automata n i.e., a transition from one state

3

Example of an e-NFAL = {w | w is empty, or if non-empty will end in 01}

δE 0 1 e*q’0 Ø Ø {q’0,q0}

q0 {q0,q1} {q0} {q0}

q1 Ø {q2} {q1}

*q2 Ø Ø {q2}

ECLOSE(q’0)

ECLOSE(q0)

n e-closure of a state q, ECLOSE(q), is the set of all states (including itself) that can be reached from q by repeatedly making an arbitrary number of e-transitions (all states reached by making an etransition).

start

q0 q10

0,1

1q2

q’0

e

ECLOSE(q1)

ECLOSE(q2)

Page 4: Course6 Finite Automata/Finite State Machines · 2020-06-02 · 2 FA with e-Transitions n We can allow explicite-transitions in finite automata n i.e., a transition from one state

4

Example of an e-NFAL = {w | w is empty, or if non-empty will end in 01}

δE 0 1 e*q’0 Ø Ø {q’0,q0}

q0 {q0,q1} {q0} {q0}

q1 Ø {q2} {q1}

*q2 Ø Ø {q2}

ECLOSE(q’0)

ECLOSE(q0)

Simulate for w=101:

start

q0 q10

0,1

1q2

q’0

e q0’

q0q0’

ee

q1

0

q21

q01

Ø

1

x

To simulate any transition:Step 1) Go to all immediate destination states.Step 2) From there go to all their e-closure states as well.

Page 5: Course6 Finite Automata/Finite State Machines · 2020-06-02 · 2 FA with e-Transitions n We can allow explicite-transitions in finite automata n i.e., a transition from one state

5

Example of another e-NFA

δE 0 1 e*q’0 Ø Ø {q’0,q0,q3}

q0 {q0,q1} {q0} {q0,q3}

q1 Ø {q2} {q1}

*q2 Ø Ø {q2}

q3 Ø {q2} {q3}

Simulate for w=101:

start

q0 q10

0,1

1q2

q’0

e e

q3

1

To simulate any transition:Step 1) Go to all immediate destination states.Step 2) From there go to all their e-closure states as well.

Page 6: Course6 Finite Automata/Finite State Machines · 2020-06-02 · 2 FA with e-Transitions n We can allow explicite-transitions in finite automata n i.e., a transition from one state

6

Equivalency of DFA, NFA, e-NFAn Theorem: A language L is accepted by

some e-NFA if and only if L is accepted by some DFA (𝐿 𝐷𝐹𝐴 = 𝐿(e−NFA)).

n We have:n DFA ≡ NFA ≡ e-NFAn (all accept Regular Languages)

Page 7: Course6 Finite Automata/Finite State Machines · 2020-06-02 · 2 FA with e-Transitions n We can allow explicite-transitions in finite automata n i.e., a transition from one state

7

Equivalency of DFA, NFA, e-NFA (cont’d)

n Direction: 𝐿 𝐷𝐹𝐴 ⊆ 𝐿 e−NFA . We turn a DFA into a e−NFA by adding transitions 𝛿 𝑞, e = ∅ for each 𝑞 ∈ 𝑄 (states of the DFA).

n Direction: 𝐿 𝐷𝐹𝐴 ⊇ 𝐿 e−NFA (see next slide).

Page 8: Course6 Finite Automata/Finite State Machines · 2020-06-02 · 2 FA with e-Transitions n We can allow explicite-transitions in finite automata n i.e., a transition from one state

8

Eliminating e-transitionsLet E = {QE,∑,δE,q0,FE} be an e-NFAGoal: To build DFA D={QD,∑,δD,{qD},FD} s.t.

L(D)=L(E)Construction:

1. QD= all reachable subsets of QE factoring in e-closures2. qD = ECLOSE(q0)3. FD=subsets S in QD s.t. S∩FE≠Φ4. δD: for each subset S of QE and for each input symbol

aÎ∑: n Let R= U δE(p,a) // go to destination states

n δD(S,a) = U ECLOSE(r) // from there, take a unionof all their e-closures

p in s

r in R

Page 9: Course6 Finite Automata/Finite State Machines · 2020-06-02 · 2 FA with e-Transitions n We can allow explicite-transitions in finite automata n i.e., a transition from one state

9

Eliminating e-transitions (cont’d)In other words:1. Compute all e-closures of all states of the

e-NFA2. Compute a transition table T of the e-NFA3. From T compute the DFA transition table

from the first state and take the resulting states as the next state in each step.

Page 10: Course6 Finite Automata/Finite State Machines · 2020-06-02 · 2 FA with e-Transitions n We can allow explicite-transitions in finite automata n i.e., a transition from one state

10

Example 1: e-NFA è DFAL = {w | w is empty, or if non-empty will end in 01}

start

q0 q10

0,1

1q2

q’0

e

δE 0 1 e*q’0 Ø Ø {q’0,q0}

q0 {q0,q1} {q0} {q0}

q1 Ø {q2} {q1}

*q2 Ø Ø {q2}

δD 0 1

*{q’0,q0} Ø∪{q0,q1} Ø∪{q0}

{q0,q1} {q0,q1}∪Ø {q0}∪{q2}

{q0} {q0,q1} {q0}

*{q0,q2} {q0,q1}∪Ø {q0}∪Ø

{q’0, q0}

0

start

{q0,q1} {q0,q2}1

0

q0

11

0

0

1

Page 11: Course6 Finite Automata/Finite State Machines · 2020-06-02 · 2 FA with e-Transitions n We can allow explicite-transitions in finite automata n i.e., a transition from one state

Example 2: e-NFA è DFA

Page 12: Course6 Finite Automata/Finite State Machines · 2020-06-02 · 2 FA with e-Transitions n We can allow explicite-transitions in finite automata n i.e., a transition from one state

12

Summaryn e-NFA conversionn Expresive power of e-NFAs and DFAs.