regular expressions - mahesh jangid2011/07/01  · regular expressions a) find a regular expression...

Post on 15-Mar-2020

11 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Regular expressions

Regular expressions

Regular expressions

Regular expressions

Regular expressions

Regular expressions

Regular expressions

Regular expressions

Regular expressions

Regular expressions

Regular expressions

Regular expressions

Regular expressions

Describe the following languages by regular expressions

(a) L1=set of all strings of 0s and 1s ending in 00.

(b) L2=set of all strings of 0s and 1s beginning with 0 and ending with 1.

(c) L3={ε , 11, 1111,111111,…}

Solution:

(a) (0+1)* 00.

(b) 0(0+1)*1

(c) (11)*

Regular expressions

Two regular expressions P and Q are equivalent if P and Qrepresent same set of strings. We write P = Q.

The following identities( I ) are useful for simplifying regular expressions:

1) Ø + R = R

2) ØR = RØ = Ø

3) εR = Rε = R

4) ε* = ε

5) R + R = R

6) R*R* = R*

7) RR* = R*R

8) (R*)* = R*

9) ε + RR* = R*

10) (PQ)*P = P(QP)*

11) (P+Q)* = (P*Q*)* = (P*+Q*)*

12) (P+Q)R = PR + QR

And R(P+Q) = RP + RQ

Regular expressions

a) Find a regular expression for representing the set L of strings in which every 0 is immediately followed by at least two 1s.

b) Prove that the regular expression R = ε + 1*(011)*(1*(011)*)* also describes the same set of strings.

Solution:

a) (1 + 011)*

b) R = εεεε + PP* , where P = 1*(011)*

= P* using I9

= (Q*S*)* where Q=1, S=011

= (Q + S)* using I11

= (1 + 011)*

Regular expressions

Prove (1+00*1) + (1 + 00*1)(0 +10*1)*(0 + 10*1) = 0*1(0 + 10*1)*

Solution:

L.H.S= (1 + 00*1)(εεεε + (0 + 10*1)*(0 + 10*1)) usingI 12

= (1 + 00*1)(0 + 10*1)* usingI 9

= (εεεε + 00*)1(0 + 10*1)* usingI 12

= 0*1(0+10*1)* usingI 9

= R.H.S

Arden’s Theorem

Let P and Q be two regular expressions over Σ. If P does not contain εεεε, then the following equation in R,

R = Q + RP

has a unique solution (one and only one) given by R = QP*

Finite Automata and Regular Expressions

Every regular expression R can be recognized by a transition diagram. For every string there exists a path from the initial state to a final state.

Finite Automata and Regular Expressions

A regular expression can be of the following forms:

1) R = P + Q

2) R = PQ

3) R = P*

Where P and Q are also regular expressions.

Assume that P and Q can be recognized by transition systems(FA) G and H respectively.

Finite Automata and Regular Expressions

It is important to note that some authors use Λ (Lambda) symbol instead of εεεε.

Regular Expression of a FA

Regular Expression of a FA

Regular Expression of a FA

Regular Expression of a FA

Find the regular expression recognized by the following transition diagram.

Regular Expression of a FA

We get the following equations:

As q1 is the only final state and the equation for q1 involves only q2 and q3, we use only q2 and q3 equations. Substituting for q2

and q3 in the equation for q1 , we get

Regular Expression of a FA

Describe in English the set of strings accepted by the followingfinite automata

As q1, q2 are final states

Regular Expression of a FA

Answer: Strings containing any number of 0 s followed by any number of 1 s.

Regular Expression of a FA

Construct the regular expression corresponding to the following FA

Regular Expression of a FA

Regular Expression of a FA

Find the regular expression corresponding to the following FA

Regular Expression of a FA

q1 = q10 + q30 + q40 + Λ , q2= q11 + q21 + q41

q3 = q20, q4 = q31

FA of a Regular Expression

Construct an FA corresponding to the following RE.

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

First of all we need to construct a transition graph with Λmoves. Then all the Λ moves need to be removed after the construction of the graph.

FA of a Regular Expression

FA of a Regular Expression

After removing the Λmoves

What is the DFA corresponding to the above diagram?

FA of a Regular Expression

FA of a Regular Expression

As the last two rows of the transition table are identical, the two states can be combined into a single state as shown below.

FA of a Regular Expression

Construct a DFA with reduced states equivalent to the regular expression 10 + (0 + 11)0*1

top related