dfa

Post on 14-Nov-2014

485 Views

Category:

Documents

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

PRESENTED BYSHRADDHA GUPTASOPAN SHUKLA2ND C.S.E.

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.

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.

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.

R1r*

R1R2(r1.r2)

R1 U R2(r1+r2)

{a} a

{ }

{}

Finite Automata

Regular SetRegular Expression

a

CONSTRUCTION OF FA FOR REGULAR EXPRESSIONS

1LRegular language

11 LML

1M

Single accepting state

NFA 2M

2L

Single accepting state

22 LML

Regular language

NFA

Example

}{1 baL na

b

1M

baL 2ab

2M

0n

Union• NFA for

1M

2M

21 LL

Example

• a

b

ab

}{1 baL n

}{2 baL

}{}{21 babaLL n NFA for

Concatenation• NFA for 21LL

1M 2M

Example•

• NFA for

a

b ab

}{1 baL n}{2 baL

}{}}{{21 bbaababaLL nn

Star Operation

• NFA for *1L

1M

*1L

Example

• NFA for *}{*1 baL n

a

b

}{1 baL n

1

21

Lw

wwww

i

k

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

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

Union Example

suffix

length 1 11

0 mod 2

1 mod 20

1

0 0

0

0

0

11

1

11

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 }

Union Example --L1

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

0,1 0,1

Union Example –L2

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

0

1

0

0

1

1

Union Example –L1L2

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

0

1

0 0

0

0

0

11

1

11

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

• 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)*

• 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)

• 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

• 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.

• 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.

• 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

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.

Thank you.

top related