130 likes | 339 Views
Lecture 3. Chapter 4 Regular Expressions. Important Terms. Regular Expressions Regular Languages Finite Representations. Recursive Definition of Regular expressions. Rule 1: Every letter of ∑ can be made into a regular expression by writing it in boldface; ^ is a regular expression.
E N D
Lecture 3 Chapter 4 Regular Expressions
Important Terms • Regular Expressions • Regular Languages • Finite Representations
Recursive Definition of Regular expressions • Rule 1: Every letter of ∑ can be made into a regular expression by writing it in boldface; ^ is a regular expression. • Rule 2 :If r1, and r2 are regular expressions, then so are: • (rl) • r1r2 • r1 + r 2 • rl* • Rule 3 :Nothing else is a regular expression.
Important definitions • S + T = {w : w € S or w € T}(Union) • ST = {w = w1w2 : w1 € S,w2 € T} (Concatenation or Product) • S* = S0 + S1 + S2 + · · · (Kleene’s Closure) • S+ = S1 + S2 + · · · (Positive Closure)
Example • Suppose that we wished to describe the language L over the alphabet ∑ = {a,b} where L = {a ababbabbbabbbb ... } • R.E= ab*
(ab)* = ^ or ab or abab or ababab ... • XX* = X+
Example • ab*a • language (ab*a) = {aa aba abba abbba abbbba ... .}
Example • The language of the expression a*b* • contains all the strings of a's and b's in which all the a's (if any) come before all the b's (if any). • language (a*b*) = {^ a b aaab bb aaaaababbbbbaaaa . . . } • Notice that ba and aba are not in this language. Notice also that there need not be the same number of a's and b's. • Here we should again be very careful to observe that a*b* ≠ (ab)*
Example • The following expressions both define the language L2 = {xodd} • x(xx)* or (xx)*x • but the expression x*xx* does not since it includes the word (xx) x (x).
Another use plus (+) sign • By the expression x + y where x and y are strings of characters from an alphabet, we mean "either x or y".
example • Consider the language T defined over the alphabet ∑ {a, b, c} • T = {a c abcbabbcbbabbbcbbbabbbbcbbbb ... } • All the words in T begin with an a or a c and then are followed by some number of b's. Symbolically, we may write this as T = language ((a + c)b*)= language (either a or c then some b's)
example • Now let us consider a finite language L that contains all the strings of a's and b's of length exactly three. • L = {aaaaababaabb baa babbbabbb} • The first letter of each word in L is either an a or a b. The second letter of each word in L is either an a or a b. The third letter of each word in L is either an a or a b. So we may write • L = language ((a + b)(a + b)(a + b)) • or for short, L = language ((a + b)3) •
Example cont… • If we want to define the set of all seven letter strings of a's and b's, we could write (a + b)7 . In general, if we want to refer to the set of all possible strings of a's and b's of any length whatsoever we could write, (a + b)* • This is the set of all possible strings of letters from the alphabet ∑ = {a, b} • (a+b)*= {^ a b abbaaa bb abaabb…}