You are on page 1of 31

# Theory of Computation (With Automata Theory)

## The Regular Operations on

Languages
The Regular Operations on
Languages

## The Union Operation

Suppose
there
are
languages X and Y.

## The union of languages X and

Y (written as X
Y) is a
language that is composed of
all strings w such that w is a
string from language X or w is
a string from language Y.

Mathematically,
X

Y = {w w

## The Regular Operations on Languages

X or w

two

Y}

* Property of STI
Page 1 of 31

## The Concatenation Operation

Suppose
there
are
languages X and Y.

The
concatenation
of
languages X and Y (written as
X Y) is a language that is
composed of all strings w = xy
such that x is a string from
language X and y is a string
from language Y.

Mathematically,
X Y = {xy x

## The Regular Operations on Languages

X and y

two

Y}

* Property of STI
Page 2 of 31

X.

## The star of language X

(written as X*) is a language
that is composed of all strings
that
are
formed
by
concatenating 0 or more
strings of X.
The star
operation is also called the
Kleene closure.

## The star of any language

includes the empty string and
is always infinite.

## The Regular Operations on Languages

* Property of STI
Page 3 of 31

Examples

## Let language X = {aa, bb} and

language Y = {bb, cc, dd}.

X

## The concatenation of X and Y

is:
X Y = {aabb, aacc, aadd,
bbbb, bbcc, bbdd}

aabb, aabbaa,
bbbb, bbaabb, }

## The Regular Operations on Languages

* Property of STI
Page 4 of 31

## Closure Properties of Regular

Languages

Definition of Closure

## A set is said to be closed

under a certain operation if
performing that operation on
the elements of the set
produces an object that is still
a member of that set.

## For example, the set of

integers is closed under
multiplication since multiplying
integers always produces an
integer.

## The set of integers is not

closed under division since
dividing two integers does not
always
produce
another
integer.

## The Regular Operations on Languages

* Property of STI
Page 5 of 31

Operations

## Is the family of regular

languages closed under union,
concatenation
and
star
operations? Specifically,

## 1. Is the union of regular

languages also
regular?
2. Is the concatenation of
regular languages also
regular?
3. Is the star of a regular
language also regular?

## The Regular Operations on Languages

* Property of STI
Page 6 of 31

## Is the union of regular

languages also regular?
Assume that L1 is a regular
language recognized by the
NFA N1:
N1 = {Q1,

1,

1,

q 1, F1}

## Assume that L2 is also a

regular language recognized
by the NFA N2:
N2 = {Q2,

2,

2,

q 2, F2}

If the union L1
L2 is regular,
then there must be an NFA
that recognizes it.
Let this
NFA be N3:
N3 = {Q3,
The Regular Operations on Languages

3,

3,

q 3, F3}
* Property of STI
Page 7 of 31

## The following are the state

diagrams for N1 and N2:

q1
NFA N1

q2
NFA N2

## The NFA N3 for the union of L1

and L2 should be able to
accept a string if it is a
member of either L1 or L2.
In other words, N3 should
accept an input string if it is
accepted by either N1 or N2.
The Regular Operations on Languages

* Property of STI
Page 8 of 31

## For every input string, NFA N3

should be able to start two
parallel computations.
One computation will try to see
or guess if the string belongs
to L1. The other computation
will try to see or guess if the
string belongs to L2.
N3 will then be a combination
of N1 and N2.
The state
diagram for N3 will be

q1
NFA N1

q0

q2
NFA N2

## The Regular Operations on Languages

* Property of STI
Page 9 of 31

## Because of the -transitions

from the start state q0 to state
q1 (the start state of N1) and
state q2 (the start state of N2),
N3 automatically starts two
computations.
One computation simulates
N1 to determine if the input
string is a member of L1.

The
second
computation
simulates N2 to determine if
the input string is a member of
L 2.
If either computation ends up
in a final state, then N3 accepts
the input string.
The Regular Operations on Languages

* Property of STI
Page 10 of 31

## Formal construction of N3 that

recognizes L1 L2
1. The set of states Q3 for N3

Q3 = {q0}
2. The alphabet
3

Q1

Q2

x = input symbol
If q

Q1 then
3(q,

## The Regular Operations on Languages

x) =

1(q,

x)
* Property of STI
Page 11 of 31

If q

Q2 then
3(q,

If q

x) =

2(q,

x)

q0 and x = then
3(q,

x) = {q1,q2}

## 4. The Start State

The start state of N3 is q0.

F3 = F1

## The Regular Operations on Languages

F2

* Property of STI
Page 12 of 31

## Theory of Computation (With Automata Theory)

Example:
Let L1 = {w w ends with a 00}
Let L2 = {w w starts with a 1}

0, 1

q1

q2

q3

0, 1

q4

## The Regular Operations on Languages

q5

* Property of STI
Page 13 of 31

NFA N3 for L1

L 2:

0, 1

q1

q2

q3

0, 1

q0

q4

Therefore, L1
language.

## The Regular Operations on Languages

q5

L2 is a regular

* Property of STI
Page 14 of 31

## Is the concatenation of regular

languages also regular?
Assume that L1 is a regular
language recognized by the
NFA N1 defined by
N1 = {Q1,

1,

1,

q 1, F1}

## Assume that L2 is also a

regular language recognized
by the NFA N2 defined by
N2 = {Q2,

2,

2,

q 2, F2}

If the concatenation L1 L2 is
regular, then there must be an
NFA that recognizes it.
Let
this NFA be N3 defined by
N3 = {Q3,
The Regular Operations on Languages

3,

3,

q 3, F3}
* Property of STI
Page 15 of 31

## The following are the state

diagrams for N1 and N2:
q1
NFA N1

q2
NFA N2

The
NFA
N3
for
the
concatenation of L1 and L2
should be able to accept a
string if it is of the form xy
where x
L1 and y
L2. In
other words, N3 should accept
an input string if it can be
divided into two parts where
the first part is accepted by N1
and the second part is
accepted by N2.
The Regular Operations on Languages

* Property of STI
Page 16 of 31

## NFA N3 will first try to see if the

first part of the input string is
accepted by N1.
Once N1 is in a final state, N3
tries to see or guess if that is
the point where the first part
stops and the second part
begins. So N2 performs its
computation.
The state diagram for NFA N3
will be:
e

q1
NFA N1

q2
NFA N2

## The Regular Operations on Languages

* Property of STI
Page 17 of 31

## The start state of N3 is the start

state of N1.
Upon arrival of the first symbol
of the input string, N3 starts
simulating N1 to determine if
the first part of the string is a
member of L1.
Every time the computation
reaches a final state of N1, N3
assumes or guesses that this
is the point where the first part
ends and the second begins.
Hence, N3 starts simulating N2
to determine if the second part
of the string is a member of L2.
The set of final states of N3 is
the set of final states of N2.

## The Regular Operations on Languages

* Property of STI
Page 18 of 31

## Formal construction of N3 that

recognizes L1 L2
1. The set of states Q3 for N3

Q3 = Q1

Q2

2. The alphabet
3

x = input symbol
If q

Q1 and q
3(q,

## The Regular Operations on Languages

x) =

F1 then:
1(q,

x)
* Property of STI
Page 19 of 31

if q

F1 and x
3(q,

if q

1(q,

x)

F1 and x = then:
3(q,

if q

x) =

then:

x) =

1(q,

x)

{q2}

Q2 then:
3(q,

x) =

2(q,

x)

## 4. The Start State

The start state of N3 is q1.
5. The Set of Final States
F3 = F2
The Regular Operations on Languages

* Property of STI
Page 20 of 31

## Theory of Computation (With Automata Theory)

Example:
Let L1 = {w w ends with a 00}
Let L2 = {w w starts with a 1}

0, 1

q1

q2

q3

0, 1

q4

## The Regular Operations on Languages

q5

* Property of STI
Page 21 of 31

for L1 L2

0, 1

q1

q2

q3

0, 1

q4

q5

Therefore, L1
language.

## The Regular Operations on Languages

L2 is a regular

* Property of STI
Page 22 of 31

## Theory of Computation (With Automata Theory)

Is
the
star
of
regular
languages also regular?
Assume that L1 is a regular
language recognized by the
NFA N1.
N1 = {Q1,

1,

1,

q 1, F1}

## If L1* (the star of L1) is regular,

then there must be an NFA
that recognizes it.
Let this
NFA be N2.
N2 = {Q2,

2,

2,

q 2, F2}

diagram for N1:
q1
NFA N1

## The Regular Operations on Languages

* Property of STI
Page 23 of 31

## NFA N2 should be able to

accept a string if it is of the
form x1x2x3 where xi L1. In
other words, N2 should accept
an input string if it can be
divided into several parts
where each part is accepted
by N1.
NFA N2 will first try to see if the
first part of the input string is
accepted by N1.
Once N1 is in a final state, N2
tries to see or guess if the
second part is also accepted
by N1. So N2 goes back to the
start and begins computing
again.
By definition of the star
operation, N2 should also be
able to accept empty strings.
The Regular Operations on Languages

* Property of STI
Page 24 of 31

will be

q0

q1

e
`

NFA N1

## The start state of N2 is a new

state q0 which is also a final
state.
ensures that the empty string
is also accepted by N2.

## Upon arrival of the first symbol

of the input string, N2 starts
simulating N1 to determine if
the first part of the string is a
member of L1.
The Regular Operations on Languages

* Property of STI
Page 25 of 31

## Every time the computation

reaches a final state of N1, N2
assumes or guesses that this
is the point where the first part
ends and the second begins.
Hence, N2 goes back to the
start and tries to see if the next
part is also accepted by N1.
The set of final states of N2 is
the set of final states of N1 plus
state q0.
Formal construction of N2 that
can recognize L1*:
1. The set of states Q2 for N2:
Q2 = {q0} Q1
2. The alphabet
2 =
1
The Regular Operations on Languages

2:

* Property of STI
Page 26 of 31

2:

x = input symbol
If q

Q1 and q
2(q,

If q

F1 and x
2(q,

If q

x) =

1(q,

x)

then
1(q,

x)

F1 and x = then
2(q,

## The Regular Operations on Languages

x) =

F1 then

x) =

1(q,

x)

{q1}

* Property of STI
Page 27 of 31

If q

q0 and x = then
2(q,

x) = q1

F2 = {q0}

## The Regular Operations on Languages

F2

* Property of STI
Page 28 of 31

## Theory of Computation (With Automata Theory)

Example:
Let L1 = {w w ends with a 00}
NFA N1 for L1:
0, 1

q1

q2

q3

for L1*:
0, 1

q0

q1

q2

q3

## Therefore, L1* is a regular

language.
The Regular Operations on Languages

* Property of STI
Page 29 of 31

## Theory of Computation (With Automata Theory)

Theorems on Closure

Theorem 2
The
family
of
regular
languages is closed under the
union operation.

Theorem 3

The
family
of
regular
languages is closed under the
concatenation operation.

Theorem 4
The
family
of
regular
languages is closed under the
star operation.

## The Regular Operations on Languages

* Property of STI
Page 30 of 31

## Theory of Computation (With Automata Theory)

Exercise:
Let L1 = {w w contains the
substring 010} and L2 = {w w
contains no more than two
1s}.
1. Give the state diagram for
the NFA that recognizes
L 1 L 2.
2. Give the state diagram for
the NFA that recognizes
L 1 L 2.
3. Give the state diagram for
the NFA that recognizes
L 2 L 1.
4. Give the state diagram for
the NFA that recognizes
L1*.
5. Give the state diagram for
the NFA that recognizes
L2*.
The Regular Operations on Languages

* Property of STI
Page 31 of 31