Lecture 3a and 3b
Lecture 3a and 3b
s0 =
si = si-1s for i > 0
note that s = s = s
Language Operations
• Union
L M = {s s L or s M}
• Concatenation
LM = {xy x L and y M}
• Exponentiation
L0 = {}; Li = Li-1L
• Kleene closure
L* = i=0,…, Li
• Positive closure
L+ = i=1,…, Li
Continue..
• The set of all strings over is denoted
Regular Expressions
• Basic symbols:
– is a regular expression denoting language {}
– a is a regular expression denoting language {a}
• If r and s are regular expressions denoting languages
L(r) and M(s) respectively, then
– rs is a regular expression denoting L(r) M(s)
– rs is a regular expression denoting L(r)M(s)
– r* is a regular expression denoting L(r)*
– (r) is a regular expression denoting L(r)
• A language defined by a regular expression is called a
Regular set or a Regular Language
8
Regular Definitions
• Regular definitions introduce a naming convention:
d1 r 1
d2 r 2
…
dn r n
where each ri is a regular expression over
{d1, d2, …, di-1 }
9
• Example:
letter AB…Zab…z
digit 01…9
id letter ( letterdigit )*
r+ = rr*
r? = r
[a-z] = abc…z
• Examples:
digit [0-9]
num digit+ (. digit+)? ( E (+-)? digit+ )?
REGULAR EXPRESSION
L = {00,11} M = {1,01,11}
L ∪ M = {00,11,1,01}
L.M = {001,0001,0011,111,1101,1111}
L0 = {} L1= L ={00,11} L2={0000,0011,1100,1111}
L*={, 00, 11, 0000, 0011, 1100, 1111, 000000, 000011, ...}
Notations
If r and s are regular expressions denoting the languages Lr and
Ls, then
• Union : r|s is a regular expression denoting Lr U Ls
• Concatenation : rs is a regular expression denoting LrLs
• Kleene closure : r* is a regular expression denoting L(r)*
• r is a regular expression denoting Lr
Precedence and Associativity
Given Alphabet X = {0, 1}. Write regular expressions for the languages over X that
contain the following
(i) (0 + 1)* = the set of all binary strings
(ii) 031*04 = all strings consisting of three 0’s, followed by any number of 1’s,
followed by four 0’s
(iii) 0*1001* = all strings starting with any number of 0’s, followed by 100,
followed by and number of 1’s
EXERCISES