You are on page 1of 60

Theory Of Automata

Irum Feroz
Irum.feroz@superior.edu.pk
1
1. Introduction to Computer Theory, by Daniel
I. Cohen, John Wiley and Sons, Inc., 1991,
Second Edition
2. Introduction to Languages and Theory of
Computation, by J. C. Martin, McGraw Hill
Book Co., 1997, Second Edition

2
 It is the plural of automaton, and it means
“something that works automatically”

3
4
 Study of abstract computing devices, physical
processes ,theoretical machines or mathematical
model
 A mathematical model is a description of a
system using mathematical concepts and
language.
 Analyzing strength and weakness on various inputs
to get powerful machine
 Goal: Limitations
 Computability vs. Complexity

5
 Every time we introduce a new machine, we
will learn its language; and every time we
develop a new language, we will try to find a
machine that corresponds to it.
 In particular, the way we shall be studying
about computers is to build mathematical
models, called machines, and then to study
their limitations by analyzing the types of
inputs on which they can operate successfully.
 The collection of these successful inputs is
called the language of the machine
 Certain character strings DO, IF END …

 Certain Commands COPY, CUT…

 Set of commands = program

 Program -> Machine command


 How can you tell whether a given sentence
belongs to a particular languages
 Black is cat the
 The tea is hot
 I like chocolates two much
 Rules give a clue to forming as well as
validating sentences.
 Valid program statement ?
 Unlike English Machine language is strict to
rules
 All rules should be precisely described
 What symbols can occur?
 Game of symbols with formal rules

 Example ?
 Informal Language??

9
Languages Structure

 Alphabets
A finite non-empty set of symbols (letters),
is called an alphabet. It is denoted by Σ ( Greek
letter sigma).
 Example:

Σ={a,b}
Σ={0,1}

10
 Definition:
Concatenation of finite symbols from the
alphabet is called a string.
 Example:
If Σ= {a,b} then
a, abab, aaabb, ababababababababab

11
 Definition:
The length of string s, denoted by |s|, is the
number of letters in the string.
 Example:

Σ={a,b}
s=ababa
|s|=5

12
 Sometimes a string with no symbol at all is
used, denoted by (Capital Greek letter
Lambda) Λ, is called an empty string or null
string.

13
 Definition:
Words are permissible strings belonging
to some language.
Example:
If Σ= {x} then a language L can be defined
as
L={xn : n=1,3,5,7…..} or L={x,xxx,xxxxx….}
Here x,xxx,… are the words of L

14
 Example: The language {anbn }, of strings
defined over Σ={a,b}, as
{ab, aabb, aaabbb,aaaabbbb,…}
 Example: The language {anbnan }, of strings
defined over Σ={a,b}, as

{aba, aabbaa, aaabbbaaa,aaaabbbbaaaa,…}

15
 Set of words.
 Set of Rules
 English words ={All words in standard
dictionary}

16
 The languages can be defined in different
ways , such as Descriptive definition,
Recursive definition, using Regular
Expressions(RE) and using Finite
Automaton(FA) etc.

17
Descriptive definition of language:
The language is defined, describing the
conditions imposed on its words.

18
 Example 1:
The language L of strings of odd length,
defined over Σ={a}, can be written as
L={a, aaa, aaaaa,…..}

 Example 2:
The language L of strings that does not start
with a, defined over Σ={a,b,c}, can be written
as
L={b, c, ba, bb, bc, ca, cb, cc, …}

19
 Example 3:
The language L of strings of length 2,
defined over Σ={0,1,2}, can be written as
L={00, 01, 02,10, 11,12,20,21,22}
 Example 4:

The language L of strings ending in 0,


defined over Σ ={0,1}, can be written as
L={0,00,10,000,010,100,110,…}

20
 Example 5: The language EQUAL, of strings
with number of a’s equal to number of b’s,
defined over Σ={a,b}, can be written as
{Λ ,ab,aabb,abab,baba,abba,…}
 Example 6: The language EVEN-EVEN, of
strings with even number of a’s and/or even
number of b’s, defined over Σ={a,b}, can be
written as
{Λ, aa, bb, aaaa,aabb,abab, abba, baab, baba,
bbaa, bbbb,…}

21
 Example 7: The language INTEGER, of strings
defined over Σ={-,0,1,2,3,4,5,6,7,8,9}, can be
written as
INTEGER = {…,-2,-1,0,1,2,…}
 Example 8: The language EVEN, of stings
defined over Σ={-,0,1,2,3,4,5,6,7,8,9}, can be
written as
EVEN = { …,-4,-2,0,2,4,…}

22
 Definition:
The reverse of a string s denoted by Rev(s)
or sr, is obtained by writing the letters of s
in reverse order.
 Example:
If s=abc is a string defined over Σ={a,b,c}
then Rev(s) or sr = cba

23
 Example:
Σ= {B, aB, bab, d}
s=BaBbabBd
Rev(s)=dBbabBaB

24
 PALINDROME:
The language consisting of Λ and the strings
s defined over Σ such that Rev(s)=s.
It is to be denoted that the words of
PALINDROME are called palindromes.
 Example:For Σ={a,b},
PALINDROME={Λ , a, b, aa, bb, aaa, aba,
bab, bbb, ...}

25
 Previously, we defined the languages:
• L1 = {Xn for n = 1, 2, 3, . . .}
• L2 = {Xn for n = 1, 3, 5, . . .}
• L2 = {Xn for n = 1, 4, 7,10 . . .}

 But these are not very precise ways of defining


languages rather guess Work
 Remove ambiguity altogether

 Regular expressions are written in bold face letters and


are a way of specifying the language.

 *, + and ()

 + presents choice or disjunction (some time authors


used U for this purpose)

 () used for grouping


 ∑* : The set of all strings over an alphabet ∑ and
called Kleene Star Closure of alphabet. So we
have
∑* = ∑0 U ∑1 U ∑2 U ∑3 U……………
 ∑+ : The set of all strings over an alphabet ∑
excluding empty string, ε, and called plus
operation. So we have
∑+ = ∑1 U ∑2 U ∑3 U……………
 In R.E Kleene star applied 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):
a* = Λ or a or aa or aaa…

30
 The notation x* can be used to define languages
by writing, say L = language (x*)

 Since x* is any string of x’s, L is then the


language of all possible strings of x’s of any
length (including Λ).

31
 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. Prove it?

32
 Given ∑ = {a, b}, 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, …}
 Using the language-defining symbol, we may write
L = language (ab*)

33
 language L1 = {x; xx; xxx; …}, we can write
R.E = language(xx*)
which means that each word of L1 must start with an x
followed by some (or no) x’s.

 Note that we can also define L1 using the notation + (as


an exponent) introduced in previous lecture
L1 = language(x+)

34
 Given ∑ = {a, b}, define the language L that contains all words of
the form

1) At least two letters


2) Begin and end with a
3) Have nothing but b or b’s may arrive

L = {aa, aba, abba, abbba, abbbba, …}

L = language (ab*a)

35
 Strings of a’s and b’s in which all the a’s (if any) come
before all the b’s(if any)?
 ∑=(a,b)
 Language = {^ a b aa bb aab aabb … }
abab? baaaa ? bababa?

L = language (a*b*)

36
 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.

 Care should be taken so as not to confuse this


notation with the notation + (as an exponent).

37
 Consider the language L over the alphabet
Σ = {a, b, c}
 L = {a; c; ab; cb; abb; cbb; abbb; cbbb; abbbb;
cbbbb; …}
 In other words, all the words in T begin with
either an a or c and then are followed by some
number of b’s.
 Using the above plus sign notation, we may
write this as
L= language((a+ c)b*)
38
 Consider a finite language L that contains all
the strings of a’s and b’s of two exactly:
L = {aa, ab, ba, bb}
 Thus, we may write
L = language((a+ b)(a + b))

39
 Consider a finite language L that contains all
the strings of a’s and b’s of length three
exactly:
L = {aaa, aab, aba, abb, baa, bab, bba, bbb}
 Thus, we may write
L = language((a+ b)(a + b)(a + b))

40
 In general, if we want to refer to the set of all possible
strings of a’s and b’s of any length whatsoever, we
could write
language((a+ b)*)

 This is the set of all possible strings of letters from the


alphabet Σ = {a, b}, including the null string.

41
 Language having double 0
∑=(0,1)

L=(0+1)*00(0+1)*

42
all strings containing no more than three a's
 =(a,b,c)

43
 The set of regular expression is defined by
following rules
1. Every letter of  and Λ is a regular expression
2. If r1 and r2 are regular expressions, then so are
 (r1)
 r1r2
 r1+r2
 r1*
3.Nothing else is a regular expression
 Given  = {a,b}
 a* = {Λ, a,aa,aaa,aaa,aaaa,aaaaa, …}
 ab* = {a, ab,abb,abbb,abbbb, …}
 a+b = {a,b}
 (ab)* = {Λ, ab, abab, ababab, …}
 (a+b)* = {Λ, any string of as and bs}
 (0 + 10*)
 L = { 0, 1, 10, 100, 1000, 10000, … }
 (0*10*)
 L = {1, 01, 10, 010, 0010, …}
 (a+b)*
 Set of strings of a’s and b’s of any length
including the null string.
 So L = { ^, a, b, aa , ab , bb , ba, aaa…….}

46
 (a+b)*abb
 Set of strings of a’s and b’s ending with the string abb.
 So L = {abb, aabb, babb, aaabb, ababb, …………..}

 (11)*
 Set of strings consisting of even number of 1’s
 So L= {^, 11, 1111, 111111, ……….}

 (aa)*(bb)*b
 Set of strings consisting of even number of a’s followed
by odd number of b’s
 so L = {b, aab, aabbb, aabbbbb, aaaab, aaaabbb,..}

47
 what languages do they generate
 a (b + a)*
 bb(a+b)
 (a+b)(a+b)(a+b)
 (a+b)*ba
 (a+b)*a(a+b)*
 (a+b)*aa(a+b)*
 Write RE for the languages over the  ={a,b}
consisting of words that contain at least one a and
at least one b

(a+b)*a(a+b)*b(a+b)*

(a+b)*a(a+b)*b(a+b)*+(a+b)*b(a+b)*a(a+b)*
 Set consisting of even number of 1’s including
empty string
 L= {^, 11, 1111, 111111, ……….}

 R.E = (11)*

50
 Set of strings consisting of even number of a’s
followed by odd number of b’s

 L = {b, aab, aabbb, aabbbbb, aaaab, aaaabbb,


…………..}

 R.E = (aa)*(bb)*b

51
 Any language that can be represented by a regular
expression is called a regular language

 It is to be noted that if r1, r2 are regular expressions,


corresponding to the languages L1 and L2 then the
languages generated by r1+ r2, r1r2( or r2r1) and r1*(
or r2*) are also regular languages.
 All finite languages are regular
 Example
 Consider the language L, defined over Σ = {a,b}, of
strings of length 2, starting with a, then L = {aa, ab}, may
be expressed by the regular expression aa+ab.
 L is a regular language.
 The equation of a linear function has no
exponents higher than 1, and the graph of
a linear function is a straight line.
 The equation of a nonlinear function has at least
one exponent higher than 1, and the graph of
a nonlinear function is a curved line.

54
 Power is Linear
RE for an where n>=3
aaaa*= aaa*a
RE for a2n where n=0 … n
(aa)*
RE for a2n+1 where n=0 … n
 a(aa)*

55
 Power is non linear
an2

n2 is non linear, n* n is not finite.

an2 is linear if n<=5 because n is finite now


L= {a0 , a1 , a4 , a9 , a16 , a25 }

56
 Definition
 Two regular expressions are said to be
equivalent if they generate the same language.
 Example
 Consider the following regular expressions
 r1 = (a + b)* (aa + bb)
 r2 = (a + b)*aa + ( a + b)*bb then both regular
expressions define the language of strings
ending in aa or bb
 The language of all words that have at least two a’s can
be defined by the expression:
(a + b)*a(a + b)*a(a + b)*

 Another expression that defines all the words with at


least two a’s is
b*ab*a(a + b)*

 Hence, we can write


(a + b)*a(a + b)*a(a + b)* = b*ab*a(a + b)*

where by the equal sign we mean that these two


expressions are equivalent in the sense that they
describe the same language.
58
 Write Langugae and RE for the following
languages over the  ={a,b}.
 All words ending with b
 All words that start with a
 All words that contains at least two a’s
 All words that start with a double letter
 All words that contain at least one double letter
 All words that start and end with a double letter
 All words of length >=3
 All words that contain exactly one a or exactly one b
 All words that don’t end at b
 Example: Give a regular expression for each of the
following over the alphabet { 0, 1 }:

 { w | w begins with a ‘1’ and ends with a ‘0’ }

 { w | w contains exactly three 1’s}

 { w | w contains at least three 1’s}

 { w | w is a string that begin with a ‘1’ and contain


exactly two 0’s }

 Regular expression definition of a language is not


60 unique.

You might also like