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 Q represent same set of strings. We write P = Q. The following identities( I ) are useful for simplifying regular expressions: 7) RR* = R*R 1) Ø + R = R 8) (R*)* = R* 2) ØR = RØ = Ø 9) ε + RR* = R* 3) εR = Rε = R 10) (PQ)*P = P(QP)* 4) ε* = ε 11) (P+Q)* = (P*Q*)* = (P*+Q*)* 5) R + R = R 12) (P+Q)R = PR + QR 6) R*R* = R* 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)) using I12 = (1 + 00*1)(0 + 10*1)* using I9 = (εε + 00*)1(0 + 10*1)* using I12 = 0*1(0+10*1)* = R.H.S using I9 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 following finite automata Regular Expression of a FA As q1, q2 are final states 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 + Λ , q3 = q20, q4 = q31 q2= q11 + q21 + q41 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