Chapter 1
Chapter 1
Chapter 1
1.1 BASICS
1.1.1 Sets
A “set” is a collection of objects. For example, the collection of
four letters a, b, c and d is a set, which is written as
L = { a, b, c, d }
The objects comprising a set are called its “elements” or
“members”.
A set having only one element is called a “singleton”. A set
with no element at all is called the “empty set”, which is denoted
by
It is essential to have a criterion for determining, for any given
thing, whether it is or is not a member of the given set. This
criterion is called the “Membership criterion” of the set.
There are two common ways to indicate the members of a set:
(i) List all the elements, e.g, {a, e, i, o, u}.
(ii) Provide some kind of an algorithm or a rule, such as a
grammar.
Let us now take a look at the notation that is being used to denote
sets.
(a) To indicate that x is a member of the set S, we write x
S.
(b) If every element of set A is also an element of set B, we
say that A is a “subset” of B, and write A B.
(c) If every element of set A is also an element of set B, but
Compiled by Yeshanew A.
pg. 1
FORMAL LANGUAGE AND AUTOMATA THEORY
(a) Union
The “union” of two sets is the set that has objects that are elements
of at least one of the two given sets, and possibly both
That is, the union of sets A and B, written A B, is a set that
contains everything in A, or in B, or in both.
A B {x :x A or x B}
Example: A = {1, 3, 9} B = {3, 5}
Therefore,A B {1, 3, 5, 9}
(b) Intersection
The “intersection” of sets A and B, written A B, is a set that
contains exactly those elements that are in both A and B.
A B {x : x A and x B}
Example: Given A = {1, 3, 9}, B = {3, 5}, C = {a, b, c}
A B = {3}
AC={}
(d) Complement
The “complement” of set A, written as A is the set containing
everything that is not in A.
Idempotency : AAA
AAA
Commutativity : ABBA
Compiled by Yeshanew A.
pg. 2
FORMAL LANGUAGE AND AUTOMATA THEORY
ABBA
Associativity : ( A B ) C A (B C )
( A B ) C A (B C )
Distributivity :( A B ) C ( A C ) ( B C )
(AB)C(AC)(BC)
Absorption : (AB)AA
(AB)AA
DeMorgan’s Laws: A (B C ) ( A B ) ( A C )
A (B C ) ( A B ) ( A C )
S Olution
x A (B C ) x A and xBC
x A and x B and x C
(x A and x B ) and (x A and x C )
Þ x A B and x A C
Þ x(AB)(AC)
Therefore A (B C ) ( A B ) ( A C ) (1)
Conversely,
x ( A B ) ( A C ) x A B and x A C
(x A and x B ) and (x A and x C )
x A and (x B and x C )
Þ x A and x B C
Þ x A (B C )
Therefore, ( A B ) ( A C ) A (B C ).
Hence A (B C ) ( A B ) ( A C ).
Ì Example 1.1.2: Given sets A and B are the subsets of a universal set U,
prove that
(a) A B A B
(b) A B A, if and only if A B
(c) A B , if and only if A B.
Solution
(a) Let x A B. Then
x A B x A and x B
Þ x A and x B
Þ x A B
A B A B (1)
Compiled by Yeshanew A.
pg. 3
Conversely, Let x A B. Then
x A B x A and x B
x A and x B (2)
xAB
Hence from (1) and (2)
A B A B
(b) We have A B . Then
A(AB)(AB)
Þ A A B since A B
Þ A A B.
Again we have A B A. Then
A(AB)(AB)
Þ A B A A Since A B A
Þ A B .
(c) We have A B. Then
ABA
ABA(AB)
Þ A B A A Since A B A
Þ A B .
If A B , then
ABA(AB)
Þ A B A
Þ ABA
Þ A B.
Solution
(i) Let us show that
A (B C ) ( A B ) C
x A (B C )
x A or x (B C ), by definition of union
x A or (x B or x C )
(x A or x B ) or x C
Compiled by Yeshanew A.
pg. 4
x ( A B ) or x C
x ( A B ) C.
Therefore we have
A (B C ) ( A B ) C (1)
(ii) Let us now show that
( A B ) C A (B C ).
Assume that y is any element of the set ( A B ) C
y(AB)C
y ( A B ) or y C
( y A or y B ) or y C
y A or ( y B or y C )
y A (B C )
Therefore we have
( A B ) C A (B C ) (2)
From (1) and (2), we have
A (B C ) ( A B ) C
S olution
Let us prove that A (B C ) ( A B ) C
Let x be an element such that
x A (B C )
x A and x (B C )
x A and (x B and x C )
Þ (x A and x B ) and x C
Þ x ( A B ) and x C
Þ x(AB)C
Therefore A (B C ) ( A B ) C (1)
Let us prove that ( A B ) C A (B C ).
Let us assume the element y ( A B ) C
y ( A B ) and y C
Compiled by Yeshanew A.
pg. 5
( y A and y B ) and y C
y A and y B and y C
Þ y A and y ( B C )
Þ yA(BC)
Ì Example 1.1.5: For any two sets A and B, prove the DeMorgan’s Laws
(a) ( A B ) A B
(b) ( A B ) A B
Solution
(a) x ( A B ) x A B
Û x A and x B
Û x A and x B
Û x A B
(b) y ( A B ) y A B
either y A or y B
either y A or y B
y A B
Hence we have ( A B ) A B.
Additional Terminology
(a)Disjoint Sets. If A and B have no common element, that is, A
B , then the sets A and B are said to be disjoint.
(b)Cardinality. The “Cardinality” of a set A, written |A|, is the
number of elements in set A.
C. Power set. The “powerset” of a set A, written 2A, is the set of all
subsets of A; i.e., a set containing ‘n’ elements has a powerset
containing 2n elements.
(c) Cartesian Product. Let A and B be two sets. Then the set of all
ordered pairs (x, y) where x A and y B is called the “Cartesian
Product” of the sets A and B and is denoted by A B, i.e.
A B (x, y) : x A and y B
Example 1.1.6:Given= {1, 2, 3} determine (A)
(power set ofA).
Solution
As the set A = {1, 2, 3} has 3 elements the powerset P(A) will have
Compiled by Yeshanew A.
pg. 6
23 = 8 elements. P ( A) , {1}, {2}, {3}, {1, 2}, {2, 3}, {3,1},
{1, 2, 3}
Solution
3 (1, x, 3)
x
4 (1, x, 4)
1 3 (1, y, 3)
y
4 (1, y, 4)
3 (1, z, 3)
z
4 (1, z, 4)
3 (2, x, 3)
x
4 (2, x, 4)
3 (2, y, 3)
y
2 4 (2, y, 4)
3 (2, z, 3)
z
4 (2, z, 4)
Example:
A w
B x
c
y
D
e z
Set S Set T
Compiled by Yeshanew A.
pg. 7
Then a relation on S and T is
R (a, y), (c, w), (c, z), (d, y)
The four ordered pairs in the relation is represented as shown in
Fig. 2.
A w
B x
c
y
D
e z
Fig. 2 Relation R = {(a, y), (c, w), (c, w), (c, z), (d,
y)}
Equivalence Relation
A subset R of A A is called an equivalence relation on A if R
satisfies the following conditions:
(i) (a, a) R for all a A (R is reflexive)
(ii) If (a, b) R, then (b, a) R, then (a, b) R (R is
symmetric)
(iii) If (a, b) R and (b, c) R, then (a, c) R (R is
transitive)
Functions
Suppose every element of S occurs exactly once as the first element
of an ordered pair. In Fig shown, every element of S has exactly
one arrow arising from it. This kind of relation is called a
“function”.
a w
b x
c
y
d
e z
Fig 3. A Function
A function is otherwise known as “Mapping”. A function is said to
map an element in its domain to an element in its range.
Every element in S in the domain, i.e., every element of S is
mapped to some elements in the range. No element in the domain
maps to more than one element in the range.
Functions as relations
A function f : A B is a relation from A to B i.e., a subset of A
Compiled by Yeshanew A.
pg. 8
B, such that each a A belongs to a unique ordered pair (a, b) in f.
1 2
4 3
Compiled by Yeshanew A.
pg. 9
Fig. 4 A Tree
Directed Graph: The graph is said to be a “directed graph” if it has
arrows in stead of lines.
Outdegree: The number of arrows pointing from a particular node
is the “outdegree” of that node.
Indegree: The number of arrows pointing to a particular node is the
“indegree”.
A B
F C
E D
Compiled by Yeshanew A.
pg. 10
Directed graphs (as shown in fig.) are an easy way of depicting
binary relation
Solution: Given L a n b n :n 0
(a) L2 a n b n a m b m :n 0, m 0
Compiled by Yeshanew A.
pg. 12
where n and m are unrelated.
For example, the string aabbaaabbb is in L2.
(b) Reverse of L is given by
LR b n a n :n 0
(iii) abb not a string in L (since there is no n satisfying
this).
Solution
We know L* L0 L1 L2 …
and L L1 L2 L3 …
Now for given L a n b n1 :n 0, we have
L0 a 0 b 0 1 b
L1 a 1 b1 1 ab2
L2 a 2 b 2 1 a 2 b3 .
Therefore, we have L* L0 L1 L2 …
b ab 2 a 2 b3 …
Hence it is true that L = L*.
Compiled by Yeshanew A.
pg. 13
S V = Start variables
P = Finite set of Productions.
A production rule P is of the form
xy
Given a string w, of the form w = uxv, we can use the production
rule x y and obtain a new string z = uyv
Compiled by Yeshanew A.
pg. 14
Therefore n n
L(G) a b ; n 0 .
Example 1.1.12:Obtain a Grammar which generates the
language
L a n b n1 :n 0
Solution
With L a n b n :n 0, the grammar
G {S }, {a, b}, S, P
Solution
It is known from the given production rules that G has equal
number of a’s and b’s.
If w starts with an ‘a’ and ends with a ‘b’, then w L has the
form w a w1 b where w1 L.
If w starts with a ‘b’ and ends with an ‘a’ then w L has the
form w b w1 a where w1 L.
Compiled by Yeshanew A.
pg. 15
As a string in L can begin and end with the same symbol, the string
shoud be of the form
w = w1 w2
where w1 and w2 are in L, produced by S
SS. This generates the language
L w : na (w) nb (w)
where na(w) and nb(w) denotes the number of a’s and number of b’s
in the string w, respectively.
Ì Example 1.1.14: Given G1 {A, S }, {a, b}, S, P1 with P1
defined by the production rules
S aAb|
A aAb|
show that L(G1 ) a n b n : n 0.
Also show that G1 is equivalent to G where G {S }, {a, b}, S, P
where P is given by
S aSb
S .
Solution
Given P1 as
S aAb
S
S aAb
A .
S produces a string with zero length. (n = 0)
S aAb S aAb
ab aaAbb
ab aabb
a 2 b2and so on
Therefore L(G1) = {an bn : n 0}.
Given G {S }, {a , b}, S, P where P is S
aSb, S . The rule S aSb is recursive.
All sentential forms will have the forms
wi a i S bi
Compiled by Yeshanew A.
pg. 16
Applying the production rule S aSb, we get
a i S b i a i 1 S bi1
Compiled by Yeshanew A.
pg. 17
Solution
(a) Given {a , b}
We are able to write the grammar G which produces all
strings with exactly one ‘a’ whose production rules are
S aSb
S Sb
S
(b) For all strings with at least one ‘a’: Production rules of
Grammar C are
S aSb
S bSa
S
Soution
(a) For the given production rules
S aA
A bS
S
we have the language L given by
L a n b n n 1
(b) For the given production rules
S Aa
AB
B Aa
Compiled by Yeshanew A.
pg. 18
1.1.8 Types of Grammar: