Theory of Automata Lecture#2: by Riaz Ahmad Ziar R.ziar@kardan - Edu.af

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 22

Theory of Automata

Lecture#2nd

By
Riaz Ahmad Ziar
r.ziar@kardan.edu.af
Language definitions

• In the previous lecture we studied some of the basic concepts of


automata theory and started the definition of the languages.
• We studied the descriptive definition of the language by
describing some conditions imposed on the string of the
languages. Now today we will study the 2nd and 3rd definition of
the languages.
2. Recursive definition of languages.

The following three steps are used in recursive definition


1. Some basic words are specified in the language. (Base Case)
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.
Factorial example

To define the language of factorial, the recursive definition of


language will be like as

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.
Integer example

Defining the 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.
Even number example

Defining language of even numbers.

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.
Palindrome example

Defining the language of Palindrome over Σ = {a,b}.

Step 1: a and b are in PALINDROME


Step 2: if x is palindrome, then s(x)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
Each string of language ending with a

Defining the language L of strings ending with a, defined over


Σ={a,b}.

Step 1: a is in L
Step 2: if x is in L then s(x)a is also in L, where s belongs to Σ*
Step 3: No strings except those constructed in above, are allowed
to be in L.
Starting and ending with same letter

Defining the language L, starting and ending with the same letter defined over Σ={0,1}

Step 1: 0 and 1 are in L


Step 2: (0)s(0) and (1)s(1) are also in L, where s belongs to Σ*
Step 3: No strings except those constructed in above, are allowed to be in L
Containing exactly one a or at most one a.

Defining the language L containing at most 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
Consisting of aa or bb

Defining the language L, where each string consists of 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
Regular Expression

• It is the 3rd way of defining the languages.


• As we know that there are four types of languages and for each type of
language there must be some generating devices and some recognition
devices.
• So Regular expression is the generating device of type-3 languages which
specify the structure of tokens or words.
• But first we must know about the recursive definition and some of the
operators which will frequently used in the construction of RE.
Recursive Definition of RE

• Step 1: Every letter of Σ including NULL(Λ) is a regular expression.


• Step 2: If r1 and r2 are regular expressions then
a. (r1)
b. r1 r2
c. r1 + r2 and
d. r1*
are also regular expressions.
• Step 3: Nothing else is a regular expression.
Operators used in RE

• Different types of operators are used for writing a regular


expression for specifying a language. These operators are mainly
categorized into two categories.
• Standard operators
• Non standard operators
Standard operators

• We will always try to construct a regular expression from the standard operators. These
are as under:
1. Alternation: We also call it union, plus or bar operator denoted by U, + or |. But we
will always try to use the plus sign.
Exp: Regular expression for a string consisting of either a’s or b’s defined over Σ={a, b}.
(a|b) or (a+b) or (aUb)
2. Concatenation: The concatenation operator is denoted by dot. Also the absence of an
operator between two or more operands is considered to be concatenation.
Exp: Regular expression for string consisting of a and b a.b
Con’t

3. Kleene Star Closure: It is another standard operator for writing the


regular expression. It is denoted by *. It shows the Null or more
occurrences of symbols in a string and is put in the superscript position.
Exp: The regular expression for a string consisting of Null or more a’s.
L={Λ,a,aa,aaa,aaaa…………….}
R.E=a*
Non-Standard operators

1. Positive Closure: it is denoted by + and is put at the superscript position


of an alphabet which means one or more occurrences.
Exp: Regular expression for a string consisting of one or more a’s.
L={a,aa,aaa,aaaa,aaaaa,………..}
R.E=a+
Con’t

2. Zero or one instance: It is that type of non standard operator which


represent zero or exactly one occurrence of its operand. It is denoted by ?.
Exp: Regular expression for a string consisting of zero or one b.
L={Λ, b}
R.E=b?
Some important points about Regular Expression

• We need to put parenthesis in regular expression for the sake of readability.


• We can write more than one regular expression to generate exactly one
language. But for a given regular expression there exist exactly one
language generated by that Regular expression.

If a*=L1={Λ,a,aa,aaa,aaa,aaaa…………} and
a+=L2={a,aa,aaa,aaaa,aaaaa,………….} then it
should be noted that
a+=aa*=a*a=L2
Con’t

• While writing a regular expression for a language we should not


imposed condition from our self.
Exp: Write a regular expression for the language defined over Σ={a, b} and
consisting of single a.
Now
a b* or b*a
also consisted of single a but here we imposed some conditions
from our side which were not stated in the question. So the correct
one will be
(b*ab*)
Practice On Regular Expression
• Write down the RE for the language L defined over Σ = {a, b} in which each string
consist of any number of a’s or b’s.
• Write down the RE for the language L defined over Σ = {a, b} which consist of any
number of a’s or b’s including NULL where each string ends with b.
• Write down a RE for the language L defined over Σ = {a, b} where each string start with
a.
• Write down the RE for the language L defined over Σ = {a, b} where each string start
with b and ends with a.
• Write down the RE for the language L defined over Σ = {0, 1} where each string consist
of exactly single double 1’s.
Practice on Regular Expression

• Write down a RE for the language L define over Σ = {0, 1} where each string start with 1 and
end with 0 and vice versa.
• Write down a RE for the language L defined over Σ = {0, 1} where each string has odd length.
• Write down the RE for the language L defined over Σ = {a, b} where each string has even
length.
• Write down the RE for the language defined over Σ = {a, b} where each string consist of at
least one a and one b.
• Write down the RE for a language defined over Σ = {a, b}, of words starting with double a’s
and ending with double b’s.
• Write down the RE for a language L defined over Σ = {a, b, c} where each string do not start
with c.

You might also like