150 likes | 293 Views
a, b. b. a, b. a, b. a, b. 0. 1. 2. 3. 4. . . 2. 4. . a. 0. 1. . 5. 3. b. . Examples. Definition of regular sets Basis: , { } and {a}, for every a are regular sets over .
E N D
a, b b a, b a, b a, b 0 1 2 3 4 2 4 a 0 1 5 3 b Examples
Definition of regular sets • Basis: , {} and {a}, for every a are regular sets over . • Recursive step: Let X and Y be regular sets over . Then the sets XY, XY, and X* are regular sets over . • Closure: X is a regular set over only if it can be obtained from the basis elements by a finite number of applications of the recursive step • Examples: Let = {0, 1} • Following are some regular sets over : • , {}, {0}, {1}, {00, 11}, {0}*, {0, 1}*
Definition of regular expressions • Let be an alphabet. The regular expressions over are defined recursively as follows: • Basis: is a regular expression denoting the regular set . is a regular expression denoting {}. For every a , a is a regular expression denoting {a}. • Recursive step: Let x and y be regular expressions over . Then the expressions x+y , xy , x* are regular expressions over . • Closure: x is a regular expression over only if it can be obtained from the basis elements by a finite number of applications of the recursive step. • If x represents X and y represents Y, x+y represents XY, xy represents XY, and x* represents X*. (x) represents X.
Examples: Let = {0, 1} Regular expression Regular set 0 {0} 00 {00} 0 + 0 {0} 0* {0}* (0+1) {0, 1} 0(0+1) {00, 01} (00)* {00}*
Regular expression identities: • x = x = • x = x= x • * = • * = • x + y = y + x • x + = x • x + x = x • (x*)* = x* • x(y+z) = xy + xz • (x+y)z = xz + yz • (xy)*x = x(yx)* • (x+y)* = (x*+y)* = x*(x+y)* = (x+yx*)* = (x*y*)* =x*(yx*)*=(x*y)*x*
Example (construction of regular sets): Construct a regular expression to represent the set of strings over {a, b} that contain the substring ba and the substring ab. ---ba---ab--- ---bab--- ---ab---ba-- ---aba---
-NFA NFA RE DFA Theorem: NFA, DFA, and Regular Expressions are Equivalent
Example: Construct an NFA equivalent to the regular expression 0(1+0)*
2 a 1 Example: Construct equivalent DFA 4 a b 0 b a 3
Rij(k) – regular expression representing the set of labels of all paths from state i to state j going through intermediate states {1, 2, 3, …, k} only (defined recursively) R1f(n) – regular expression representing strings accepted by f, f is in F Equivalent regular expression is the union of all R1f(n) Construction: BASE: Rij(0) = a1 + a2 + … + ak where i j and am are labels of arcs from state i to state j. Rij(0) = + a1 + a2 + … + ak where i = j and am are labels of arcs from state i to state j. INDUCTON: Rij(k) = Rij(k-1) + Rik(k-1)(Rkk(k-1))*Rkj(k-1) Construction of regular expression from FA
a,b Example: Find equivalent regular expression for the following NFA: a 3 start 2 1 b b
0.1 start A B C D 1 0,1 0,1 State elimination method - example
Applications of Finite Automata: • Software for digital circuit design • Lexical Analyzer • Keyword search • Software for verifying finite state systems
Key word search e n d b e g i n
Pattern matching (KMP Algorithm) procedure fsasearch; begin state := 0; for i := 1 to N do begin state := next(state, a[i]); if (state = final) then return true; end; return false; end; e.g. search for 10100110