Vous êtes sur la page 1sur 27

THEORY OF AUTOMATA

Lecture#02
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 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 strings 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: n!=n*(n-1)! is in factorial.
Step 3: No strings 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 palindrome, then s(x)Rev(s) i.e. s followed by x
followed by Rev(s) and xx will also be palindrome, where s belongs to *
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
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(aa)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 langauge:

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 its regular expression may
be: b*ab*
2. Now consider another language L2, of even length, defined
over = {a, b}, then its regular expression may be:
((a+b)(a+b))*
3. Now consider another language L3, of odd length, defined over
= {a, b}, then its 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 as only
Language of all words or length two or less
Language of all words of length four
Language of all words with count of as 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
21

Regular Expressions

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

Syntactical
expressions Automata/machines

Regular
Languages

Formal language
classes
22

Precedence of Operators
Highest to lowest
* operator (star)
. (concatenation)
+ operator

Example:
01* + 1 = ( 0 . ((1)*) ) + 1
23

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 =
24

Algebraic Laws
Distributive:
E(F+G) = EF + EG
(F+G)E = FE+GE
Idempotent: E + E = E
Involving Kleene closures:
(E*)* = E*
* =
* =
E+ =EE*
E? = +E
25

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