You are on page 1of 29

THEORY OF AUTOMATA

Lecture#02
Recursive Definition of a Language, Regular Expressions
Lecture Contents
 Recursive definition of languages
 Languages defined through recursive definition
 RE
 Recursive definition of RE
 defining languages by RE
 { x}*, { x}+, {a+b}*
Recursive Definition
It is a way of defining a set (a language) recursively.
Process:
1. Basic elements are identified and listed in rule 1. These elements are the ones
that cannot be defined recursively.
2. Rule 2 defines the way new elements are built based on existing elements
Recursive Definition of a Language
The following three steps are used in recursive definition
1. Some basic words are specified in the language
2. Rules for constructing more words are defined in the language
3. No strings except those constructed in above, are allowed to be in the language

Example
Defining language of INTEGER
Step 1: 1 is in INTEGER.
Step 2: If x is in INTEGER then x+1 and x-1 are also in INTEGER.
Step 3: No strings except those constructed in above, are allowed to be in
INTEGER.
Recursive Definition of a Language …
Example
Defining language of EVEN
Step 1: 2 is in EVEN.
Step 2: If x is in EVEN then x+2 and x-2 are also in EVEN.
Step 3: No values except those constructed in above, are allowed to be in EVEN.
 
Example
Defining the language factorial
Step 1: As 0!=1, so 1 is in factorial.
Step 2: if x! is in factorial then (x+1)*x! is also in factorial.
Step 3: No values except those constructed in above, are allowed to be in
factorial.
Recursive Definition of a Language …
Example
Defining the language PALINDROME, defined over Σ = {a, b}
Step 1: ^, a and b are in PALINDROME
Step 2: if x is in PALINDROME, so are axa, bxb
Step 3: No strings except those constructed in above, are allowed to be in
palindrome
 
Example
Defining the language {anbn }, n=1,2,3,… , of strings defined over Σ={a,b}
Step 1: ab is in {anbn}
Step 2: if x is in {anbn}, then axb is in {anbn}
Step 3: No strings except those constructed in above, are allowed to be in {anbn}.
Recursive Definition of a Language …
Example
Defining the language L, of strings ending in a , defined over Σ={a,b}
Step 1: a is in L
Step 2: if x is in L then s(x) is also in L, where s belongs to Σ*
Step 3: No strings except those constructed in above, are allowed to be in L
OR
Step 1: a is in L
Step 2: if x is in L, so are ax, bx
Step 3: No strings except those constructed in above, are allowed to be in L

 
Recursive Definition of a Language …
Example
Defining the language L, of strings beginning and ending in same letters , defined
over Σ={a, b}
Step 1: a and b are in L
Step 2: (a)s(a) and (b)s(b) are also in L, where s belongs to Σ*
Step 3: No strings except those constructed in above, are allowed to be in L
Recursive Definition of a Language …
Example
Defining the language L, of strings containing aa or bb , defined over Σ={a, b}
Step 1: aa and bb are in L
Step 2: s(aa)s and s(bb)s are also in L, where s belongs to Σ*
Step 3: No strings except those constructed in above, are allowed to be in L 
Example
Defining the language L, of strings containing exactly one a, defined over Σ={a, b}
Step 1: a is in L
Step 2: s(a)s is also in L, where s belongs to b*
Step 3: No strings except those constructed in above, are allowed to be in L
Regular Expression (RE)
As discussed earlier that a* generates Λ, a, aa, aaa, … and a+ generates a, aa, aaa,
aaaa, …, so the language L1 = {Λ, a, aa, aaa, …} and L2 = {a, aa, aaa, aaaa, …} can
simply be expressed by a* and a+, respectively.
a* and a+ are called the regular expressions (RE) for L1 and L2 respectively.

Note a+, aa* and a*a generate L2.


Regular Expression (RE)
Before defining RE, we must know following for a language L defined over alphabet Σ
1. If x is some string defined over Σ then (x) means same as x
2. If x1, x2 are define over Σ then x1x2 means x1 followed by x2
(concatenation)
3. If x1, x2 are define over Σ then x1 + x2 means any one of both x1 and x2
4. If x is some string defined over Σ then x* means Kleen Star Closure of
x
Regular Expression (RE) Definition
Regular Expression or RE can be defined recursively as:
Step 1: Every letter of Σ including Λ is a regular expression
Step 2: If r1 and r2 are regular expressions then
(r1)
r1 r2
r1 + r2 and
r1*
are also regular expressions
Step 3: Nothing else is a regular expression
Regular Expression
Consider the language L={Λ, x, xx, xxx,…} of strings, defined over Σ = {x}.
We can write this language as the Kleene star closure of alphabet Σ or
L=Σ*={x}*
This language can also be expressed by the regular expression x*
Similarly the language L={x, xx, xxx,…}, defined over Σ = {x}, can be
expressed by the regular expression x+ i.e. (xx*)
Regular Expression (Use of *)
Now consider another language L, consisting of all possible strings, defined
over Σ = {a, b}
This language can also be expressed by the regular expression (a + b)*
Regular Expression, (Use of +)
Now consider another language L, consisting of words (a, b, ab, ba, bba,
abb), defined over Σ = {a, b}

Regular Expression for above language:

a+b+ab+ba+bba+abb

Note: If a language consists of (finite number) words that have no


matching pattern, simply write them separated by ‘+’ will result
RE for that language
Regular Expression Exercises
1. Now consider another language L1, of strings having exactly one a,
defined over Σ = {a, b}, then it’s regular expression may be:
b*ab*
2. Now consider another language L2, of even length, defined over Σ = {a,
b}, then it’s regular expression may be:

((a+b)(a+b))*
3. Now consider another language L3, of odd length, defined over Σ = {a, b},
then it’s regular expression may be:

(a+b)((a+b)(a+b))* or ((a+b)
(a+b))*(a+b)
Regular Expression Examples
Consider the language, defined over Σ = {a , b} of words having at least one
a, may be expressed by a regular expression RE where RE=?

(a+b)*a(a+b)*
Regular Expression Examples
Consider the language, defined over Σ = {a, b} of words having at least one a
and one b, may be expressed by a regular expression
(a+b)*a(a+b)*b(a+b)*+ (a+b)*b(a+b)*a(a+b)*
Regular Expression Examples
Consider the language, defined over Σ ={a, b}, of words starting with double
a and ending in double b then its regular expression may be aa(a+b)*bb
Regular Expression Examples
Consider the language, defined over Σ ={a, b} of words starting with a and
ending in b OR starting with b and ending in a, then its regular expression
may be a(a+b)*b+b(a+b)*a
Languages Defined Through RE
All languages below are defined over Σ = {a,b}
Language containing no word at all
Languages containing only words aa, aba, bab, baba, baa
Language of all words containing any combination a’s only
Language of all words or length two or less
Language of all words of length four
Language of all words with count of a’s three or more
Language of all words of even length
Language of all words ending on b
Languages Defined Through RE
All languages below are defined over Σ = {a, b}
Language containing no words starting and ending on a
Languages containing only words starting and ending on same letter
Language of all words with a appears in pairs only
Language of all words not ending on b
Language of all words with count of a as multiple of three
EVEN-EVEN
23

Regular Expressions

Regular
expressions
= Finite Automata
(DFA, NFA, -NFA)

Syntactical
expressions Automata/machines

Regular
Languages

Formal language
classes
24

Precedence of Operators

Highest to lowest
* operator (star)
. (concatenation)
+ operator

Example:
01* + 1 = ( 0 . ((1)*) ) + 1
25

Algebraic Laws of Regular Expressions


Commutative:
E+F = F+E
Associative:
(E+F)+G = E+(F+G)
(EF)G = E(FG)
Identity:
E+Φ = E
^E=E^=E
Annihilator:
ΦE = EΦ = Φ
26

Algebraic Laws…
Distributive:
E(F+G) = EF + EG
(F+G)E = FE+GE
Idempotent: E + E = E
Involving Kleene closures:
(E*)* = E*
Φ* = 
* = 
E+ =EE*
27

True or False?
Let R and S be two regular expressions. Then:
1. ((R*)*)* = R* ?
2. (R+S)* = R* + S* ?
3. (RS + R)* RS = (RR*S)* ?
Difference between a*+b* AND (a+b)*
Discuss the difference between two
Equivalent REs
Two regular expressions are said to be equivalent if they generate the
same language

Consider the two regular expressions r1 & r2 as


R1 = (a + b)* (aa + bb)
R2 = (a + b)* aa + (a + b)* bb

You might also like