03-RegularExpression 112422
03-RegularExpression 112422
03-RegularExpression 112422
• Introducing EVEN-EVEN
3
Language-Defining Symbols
• We now introduce the use of the Kleene star, applied not to a
set, but directly to the letter x and written as a superscript: x*.
• This simple expression indicates some sequence of x’s (may
be none at all):
x* = Λ or x or x2 or x3…
= xn for some n = 0, 1, 2, 3, …
4
• The notation x* can be used to define languages by
writing, say L4 = language (x*)
• Since x* is any string of x’s, L4 is then the
language of all possible strings of x’s of any
length (including Λ).
5
• Given the alphabet = {a, b}, suppose we wish to define the language L
that contains all words of the form one a followed by some number of b’s
(maybe no b’s at all); that is
L = {a, ab, abb, abbb, abbbb, …}
• This equation obviously means that L is the language in which the words
are the concatenation of an initial a with some or no b’s.
• From now on, for convenience, we will simply say some b’s to mean
some or no b’s. When we want to mean some positive number of
b’s, we will explicitly say so.
6
• We can apply the Kleene star to the whole string ab
if we want:
(ab)* = Λ or ab or abab or ababab…
• Observe that
(ab)* ≠ a*b*
• because the language defined by the expression on
the left contains the word abab, whereas the
language defined by the expression on the right does
not.
7
• If we want to define the language L1 = {x; xx; xxx; …}
using the language-defining symbol, we can write
L1 = language(xx*)
which means that each word of L1 must start with an x
followed by some (or no) x’s.
8
Plus Sign
• Let us introduce another use of the plus sign. By the
expression
x+y
where x and y are strings of characters from an
alphabet, we mean either x or y.
9
Example
12
Formal Definition of Regular Expressions
• The set of regular expressions is defined by the following rules:
14
Example contd.
• This language is the set of all words over the
alphabet Σ = {a, b} that have at least one a.
• The only words left out are those that have only b’s
and the word Λ.
These left out words are exactly the language
defined by the expression b*.
• If we combine this language, we should provide a
language of all strings over the alphabet Σ =
{a, b}. That is,
(a + b)* = (a + b)*a(a + b)* + b*
15
Example
• Let V be the language of all strings of a’s and b’s in which
either the strings are all b’s, or else an a followed by some
b’s. Let V also contain the word Λ. Hence,
V = {Λ, a, b, ab, bb, abb, bbb, abbb, bbbb, …}
• We can define V by the expression b*
+ ab*
where Λ is included in b*.
• Alternatively, we could define V by
(Λ + a)b*
which means that in front of the string of some b’s, we have
either an a or nothing.
16
Example contd.
• Hence,
(Λ + a)b* = b* + ab*
18
Example
• If S = {a, aa, aaa} and T = {bb, bbb} then
+ aaa)(bb + bbb)
= abb + abbb + aabb + aabbb + aaabb + aaabbb
19
Example
• If M = {λ, x, xx} and N = {λ, y, yy, yyy, yyyy, …}
then
• MN ={λ, y, yy, yyy, yyyy,…x, xy, xyy, xyyy,
xyyyy, …xx, xxy, xxyy, xxyyy, xxyyyy, …}
20
Finite Languages Are Regular
• Useful Reading
22