Top Banner
PRESENTED BY SHRADDHA GUPTA SOPAN SHUKLA 2 ND C.S.E.
43
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Dfa

PRESENTED BYSHRADDHA GUPTASOPAN SHUKLA2ND C.S.E.

Page 2: Dfa

REGULAR EXPRESSION

Regular expression can define exactly the same languages that the various forms of automata describe: the regular languages. Regular expression offer something that automata do not: a declarative way to express the strings, we want to accept.

The set of regular expressions is defined by the following rules:Let be a given alphabet. Then1. , and a are all regular expressions.These are called primitive regular expressions.2. If r1 and r2 are regular expressions, so are r1+r2, r1.r2 , r1* and (r1).3. A string is a regular expression if and only if it can be derived from the primitive regular expressions by a finite number applications of the rules in 2.

Page 3: Dfa

OPERATORS OF REGULAR EXPRESSION

1. UNION : L1 U L2

It denotes the set of string that are in either L1 or L2 or both.

L1={001,10,111) and L2 ={ ,001} then L1 U L2 = { ,10,001,111}.

2. CONCATENATION: L1.L2

It is a set of strings that can be formed by taking any string in L1 and concatenating it with any strings in L2. It is denoted by ‘.’.

3. STAR: L*

It represents a set of those strings that can be formed by taking any number of strings from L, possibly with repetitions and concatenating all of them.

Note : L+ represents the positive closure.

Page 4: Dfa

EXAMPLE: L(a*.(a+b))

If r1 and r2 are regular expressions, then1. L(r1+r2) = L(r1) U L(r2)2. L(r1.r2) = L(r1).L(r2)3. L(r1*) = (L(r1))*

L(a*.(a+b)) = L(a*).L(a+b) (L(a))*.(L(a) U L(b)) { ,a,aa,aaa, …}{a,b} {a,aa,aaa,…,b,ab,aab,…}

r1 = (a+b)*(a+bb)L(r1) = {a,bb,aa,abb,ba,bbb,…}L(r1) is the set of all strings on {a,b}, terminated by either an a or a bb.

Page 5: Dfa

R1r*

R1R2(r1.r2)

R1 U R2(r1+r2)

{a} a

{ }

{}

Finite Automata

Regular SetRegular Expression

a

CONSTRUCTION OF FA FOR REGULAR EXPRESSIONS

Page 6: Dfa

1LRegular language

11 LML

1M

Single accepting state

NFA 2M

2L

Single accepting state

22 LML

Regular language

NFA

Page 7: Dfa

Example

}{1 baL na

b

1M

baL 2ab

2M

0n

Page 8: Dfa

Union• NFA for

1M

2M

21 LL

Page 9: Dfa

Example

• a

b

ab

}{1 baL n

}{2 baL

}{}{21 babaLL n NFA for

Page 10: Dfa

Concatenation• NFA for 21LL

1M 2M

Page 11: Dfa

Example•

• NFA for

a

b ab

}{1 baL n}{2 baL

}{}}{{21 bbaababaLL nn

Page 12: Dfa

Star Operation

• NFA for *1L

1M

*1L

Page 13: Dfa

Example

• NFA for *}{*1 baL n

a

b

}{1 baL n

1

21

Lw

wwww

i

k

Page 14: Dfa

ALGEBRAIC LAWS

• Associativity and Commutativity (P+Q)+R = P+(Q+R) P+Q = Q+P• Identity Law +L =L+ =L L = L =L• Distributed Law x * (y+z) = x*y + x*z• Idempotent Law L+L = L; L*L = L

Page 15: Dfa

Union Example

EX: Draw the DFA for L = { x {0,1}* | }

The solution involved making a table of states with rows keeping track of parity, and columns keeping track of the progress towards achieving the 11 pattern:

x has even length or ends with 11

Page 16: Dfa

Union Example

suffix

length 1 11

0 mod 2

1 mod 20

1

0 0

0

0

0

11

1

11

Page 17: Dfa

Union Example

We could have arrived at this result methodically by noticing that L is the union of two easier languages:

L = L1 L2

L1 = { x {0,1}* | x has even length}

L2 = { x {0,1}* | x ends with 11 }

Page 18: Dfa

Union Example --L1

L1 = { x {0,1}* | x has even length}

0,1 0,1

Page 19: Dfa

Union Example –L2

L2 = { x {0,1}* | x ends with 11 }

0

1

0

0

1

1

Page 20: Dfa

Union Example –L1L2

Which together form the union, using the Cartesian Product Construction:

0

1

0 0

0

0

0

11

1

11

Page 21: Dfa

Union Example Upshot: To tell if string is in union, just kept track of active

states in both automata. At end, string is in union if it is accepted by at least one automaton. It would be nice if could keep track of both sets of states in a single automaton.

0

1

0

0

1

1

0,1 0,1

Page 22: Dfa

Union Example 1. Assign labels to the states in the two

machines

x y z

0

1

0

0

1

1

b

a

0,1 0,1

Page 23: Dfa

Union Example 2. Keep track of states of both machines by

using spliced states.

x y z

0

1

0

0

1

1

b

a

0,1 0,1

Page 24: Dfa

Union Example

0

1

0

0

1

1

0,1 0,1

1 1 1 0 1 0 1

Current spliced state: (a,x)

x y z

b

a

Page 25: Dfa

Union Example

0

1

0

0

1

1

0,1 0,1

1 1 1 0 1 0 1

Current spliced state: (b,y)

x y z

b

a

Page 26: Dfa

Union Example

0

1

0

0

1

1

0,1 0,1

1 1 1 0 1 0 1

Current spliced state: (a,z)

x y z

b

a

Page 27: Dfa

Union Example

0

1

0

0

1

1

0,1 0,1

1 1 1 0 1 0 1

Current spliced state: (b,z)

x y z

b

a

Page 28: Dfa

Union Example

0

1

0

0

1

1

0,1 0,1

1 1 1 0 1 0 1

Current spliced state: (a,x)

x y z

b

a

Page 29: Dfa

Union Example

0

1

0

0

1

1

0,1 0,1

1 1 1 0 1 0 1

Current spliced state: (b,y)

x y z

b

a

Page 30: Dfa

Union Example

0

1

0

0

1

1

0,1 0,1

1 1 1 0 1 0 1

Current spliced state: (a,z)

x y z

b

a

Page 31: Dfa

Union Example

0

1

0

0

1

1

0,1 0,1

1 1 1 0 1 0 1Rejected!

Rejected!

Current spliced state: (b,y)

x y z

b

a

Page 32: Dfa

Union Example

0

1

0

0

1

1

0,1 0,1

Q: What splice states should be accepting states?

x y z

b

a

Page 33: Dfa

Union Example –Accept States

0

1

0

0

1

1

0,1 0,1

A: Any splices that included at least one accept state.

F = {(a,x),(a,y),(a,z),(b,z)}

x y z

b

a

Page 34: Dfa

Back to our Examplex y z

0

1

0

0

1

1

b

a

0,1 0,1

Unioner Construction:

(b,y)(b,x)

(a,x) (a,y) (a,z)

(b,z)

0

1

0 0

0

0

0

11

1

11

Page 35: Dfa

Q. Construct a finite automata equivalent to the regular expression.

(0+1)*(00+11)(0+1)*

Answer:

q0q1

(0+1)*(00+11)(0+1)*

MISCELLANEOUS EXAMPLE

Page 36: Dfa

• First we draw the state transition as above:

• Then in step 2 we eliminate the concatenations by introducing new vertices q2 and q3.

• Inter-mediate vertices is shown :

q0 q1q2 q3

(0+1)*(00+11)

(0+1)*

Page 37: Dfa

• Now we eliminate * operation by introducing two new vertices q5 and q6 and different moves are shown.

q0

q5

q2

q3

q6q1

(0+1)

(0+1)(00+11)

Page 38: Dfa

• Now we eliminate concatenations and + (where concatenation is by different states and + i.e.0+1 by (0,1).)

q0 q5 q2

q7

q8

q3 q6 q1

0,10

1

0

1

0,1

Page 39: Dfa

• After reducing the above operated constructions we get FA equivalent to (0+1)*(00+11)(0+1)*.

• Here we are using rules:• For reductions.. 1.Find all edges starting from V2.• 2.Duplicate all edges starting from V1without

changing the edge labels.• 3.If V1 is initial state make V2 also initial state and if

V2 final state make V1 also final state.

Page 40: Dfa

• Above is construction of FA equivalent to (0+1)*(00+11)(0+1)*.

• After making the transition and successor table we get the required DFA.

Page 41: Dfa

• This is the required DFA.

[q0]

[q0,q9]

[q0,q10]

[q0,q9,q1]

[q0,q10,q1]

0

1

0 1

0

1

10

1

0

Page 42: Dfa

Conclusion

We can now say that regular expressions are very useful for representing certain sets of strings in an algebraic fashion. Actually these describe the languages accepted by finite state automata. And the operations used in the expressions are the only tools for doing that without which it is not possible.

Page 43: Dfa

Thank you.