Lecture#03,4
Lecture#03,4
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.
a+b+ab+ba+bba+abb
(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
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