meljun cortes automata lecture the regular operations on languages 1
TRANSCRIPT
8/21/2019 MELJUN CORTES Automata Lecture the Regular Operations on Languages 1
http://slidepdf.com/reader/full/meljun-cortes-automata-lecture-the-regular-operations-on-languages-1 1/31
Theory of Computation (With Automata Theory)
* Property of STI
Page 1 of 31
The Regular Operations on Languages
The Regular Operations on
LanguagesThe Regular Operations on
Languages
The Union Operation
• Suppose there are two
languages X and Y .
• The un ion of languages X andY (written as X Y ) i s 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 X or w Y }
8/21/2019 MELJUN CORTES Automata Lecture the Regular Operations on Languages 1
http://slidepdf.com/reader/full/meljun-cortes-automata-lecture-the-regular-operations-on-languages-1 2/31
Theory of Computation (With Automata Theory)
* Property of STI
Page 2 of 31
The Regular Operations on Languages
The Concatenation Operation
• Suppose there are two
languages X and Y .
• The concatenat ion of
languages X and Y (written as
X Y ) is a language that iscomposed 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 X and y Y }
8/21/2019 MELJUN CORTES Automata Lecture the Regular Operations on Languages 1
http://slidepdf.com/reader/full/meljun-cortes-automata-lecture-the-regular-operations-on-languages-1 3/31
Theory of Computation (With Automata Theory)
* Property of STI
Page 3 of 31
The Regular Operations on Languages
The Star Operation
• Suppose there is a language
X .
• The star of language X
(written as X* ) is a language
that is composed of all strings
that are formed byconcatenating 0 or more
strings of X . The star
operation is also called the
Kleene c losu re .
• The star of any language
includes the empty string ε and
is always infinite.
8/21/2019 MELJUN CORTES Automata Lecture the Regular Operations on Languages 1
http://slidepdf.com/reader/full/meljun-cortes-automata-lecture-the-regular-operations-on-languages-1 4/31
Theory of Computation (With Automata Theory)
* Property of STI
Page 4 of 31
The Regular Operations on Languages
Examples
• Let language X = {aa, bb} and
language Y = {bb, cc, dd}.
• The union of X and Y is:
X Y = {aa, bb, cc, dd}
• The concatenation of X and Y
is:
X Y = {aabb, aacc, aadd,
bbbb, bbcc, bbdd}
• The star of X is:
X * = {ε, aa, bb, aaaa,
aabb, aabbaa,
bbbb, bbaabb, …}
8/21/2019 MELJUN CORTES Automata Lecture the Regular Operations on Languages 1
http://slidepdf.com/reader/full/meljun-cortes-automata-lecture-the-regular-operations-on-languages-1 5/31
Theory of Computation (With Automata Theory)
* Property of STI
Page 5 of 31
The Regular Operations on Languages
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.
8/21/2019 MELJUN CORTES Automata Lecture the Regular Operations on Languages 1
http://slidepdf.com/reader/full/meljun-cortes-automata-lecture-the-regular-operations-on-languages-1 6/31
Theory of Computation (With Automata Theory)
* Property of STI
Page 6 of 31
The Regular Operations on Languages
Closure Under The Regular
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 alsoregular?
3. Is the star of a regular
language also regular?
8/21/2019 MELJUN CORTES Automata Lecture the Regular Operations on Languages 1
http://slidepdf.com/reader/full/meljun-cortes-automata-lecture-the-regular-operations-on-languages-1 7/31
Theory of Computation (With Automata Theory)
* Property of STI
Page 7 of 31
The Regular Operations on Languages
• Is the union of regular languages also regular?
Assume that L1 is a regular
language recognized by the
NFA N 1:
N 1 = {Q1, 1, 1, q1, F 1}
Assume that L2 is also a
regular language recognizedby the NFA N 2:
N 2 = {Q2, 2, 2, q2, F 2}
If the union L1 L2 is regular,then there must be an NFA
that recognizes it. Let this
NFA be N 3:
N 3 = {Q
3,
3,
3, q
3, F
3}
8/21/2019 MELJUN CORTES Automata Lecture the Regular Operations on Languages 1
http://slidepdf.com/reader/full/meljun-cortes-automata-lecture-the-regular-operations-on-languages-1 8/31
Theory of Computation (With Automata Theory)
* Property of STI
Page 8 of 31
The Regular Operations on Languages
The following are the statediagrams for N 1 and N 2:
The NFA N 3 for the union of L1
and L2 should be able to
accept a string if it is amember of either L1 or L2.
In other words, N 3 should
accept an input string if it is
accepted by either N 1 or N
2.
q 1
NFA N 1
q 2
NFA N 2
8/21/2019 MELJUN CORTES Automata Lecture the Regular Operations on Languages 1
http://slidepdf.com/reader/full/meljun-cortes-automata-lecture-the-regular-operations-on-languages-1 9/31
Theory of Computation (With Automata Theory)
* Property of STI
Page 9 of 31
The Regular Operations on Languages
For every input string, NFA N 3should 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.
N 3 will then be a combination
of N 1 and N 2. The statediagram for N 3 will be
q 2
NFA N 2
q 1
NFA N 1
q 0
ε
ε
8/21/2019 MELJUN CORTES Automata Lecture the Regular Operations on Languages 1
http://slidepdf.com/reader/full/meljun-cortes-automata-lecture-the-regular-operations-on-languages-1 10/31
Theory of Computation (With Automata Theory)
* Property of STI
Page 10 of 31
The Regular Operations on Languages
Because of the ε-transitionsfrom the start state q0 to state
q1 (the start state of N 1) and
state q2 (the start state of N 2),
N 3 automatically starts two
computations.
One computation “simulates”
N 1 to determine if the input
string is a member of L1.
The second computation
“simulates” N 2 to determine if
the input string is a member of L2.
If either computation ends up
in a final state, then N 3 accepts
the input string.
8/21/2019 MELJUN CORTES Automata Lecture the Regular Operations on Languages 1
http://slidepdf.com/reader/full/meljun-cortes-automata-lecture-the-regular-operations-on-languages-1 11/31
Theory of Computation (With Automata Theory)
* Property of STI
Page 11 of 31
The Regular Operations on Languages
Formal construction of N 3
that
recognizes L1 L2
1. The set of states Q3 for N 3
Q3 = {q0} Q1 Q2
2. The alphabet 3
3 = 1 2
3. The transition function 3
Let q = current state, and
x = input symbol
If q Q1 then
3(q, x ) = 1(q, x )
8/21/2019 MELJUN CORTES Automata Lecture the Regular Operations on Languages 1
http://slidepdf.com/reader/full/meljun-cortes-automata-lecture-the-regular-operations-on-languages-1 12/31
Theory of Computation (With Automata Theory)
* Property of STI
Page 12 of 31
The Regular Operations on Languages
If q Q2 then
3(q, x ) = 2(q, x )
If q q0 and x = ε then
3(q, x ) = {q1,q2}
4. The Start State
The start state of N 3 is q0.
5. The Set of Final States
F 3 = F 1 F 2
8/21/2019 MELJUN CORTES Automata Lecture the Regular Operations on Languages 1
http://slidepdf.com/reader/full/meljun-cortes-automata-lecture-the-regular-operations-on-languages-1 13/31
Theory of Computation (With Automata Theory)
* Property of STI
Page 13 of 31
The Regular Operations on Languages
Example:
Let L1 = {w w ends with a 00}
Let L2 = {w w starts with a 1}
NFA N 1 for L1:
NFA N 2 for L2:
0q 1
0, 1
q 3q 2
0
0
1q 4 q 5
0, 1
8/21/2019 MELJUN CORTES Automata Lecture the Regular Operations on Languages 1
http://slidepdf.com/reader/full/meljun-cortes-automata-lecture-the-regular-operations-on-languages-1 14/31
Theory of Computation (With Automata Theory)
* Property of STI
Page 14 of 31
The Regular Operations on Languages
NFA N 3 for L1 L2:
Therefore, L1 L2 is a regular
language.
0q 1
0, 1
q 3q 2
0
0
q 0
1q 4 q 5
0, 1
8/21/2019 MELJUN CORTES Automata Lecture the Regular Operations on Languages 1
http://slidepdf.com/reader/full/meljun-cortes-automata-lecture-the-regular-operations-on-languages-1 15/31
Theory of Computation (With Automata Theory)
* Property of STI
Page 15 of 31
The Regular Operations on Languages
• Is the concatenation of regular languages also regular?
Assume that L1 is a regular
language recognized by the
NFA N 1 defined by
N 1 = {Q1, 1, 1, q1, F 1}
Assume that L2 is also a
regular language recognizedby the NFA N 2 defined by
N 2 = {Q2, 2, 2, q2, F 2}
If the concatenation L1 L2 isregular, then there must be an
NFA that recognizes it. Let
this NFA be N 3 defined by
N 3 = {Q
3,
3,
3, q
3, F
3}
8/21/2019 MELJUN CORTES Automata Lecture the Regular Operations on Languages 1
http://slidepdf.com/reader/full/meljun-cortes-automata-lecture-the-regular-operations-on-languages-1 16/31
Theory of Computation (With Automata Theory)
* Property of STI
Page 16 of 31
The Regular Operations on Languages
The following are the state
diagrams for N 1 and N 2:
The NFA N 3 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. Inother words, N 3 should accept
an input string if it can be
divided into two parts where
the first part is accepted by N 1and the second part is
accepted by N 2.
q 1
NFA N 1
q 2
NFA N 2
8/21/2019 MELJUN CORTES Automata Lecture the Regular Operations on Languages 1
http://slidepdf.com/reader/full/meljun-cortes-automata-lecture-the-regular-operations-on-languages-1 17/31
Theory of Computation (With Automata Theory)
* Property of STI
Page 17 of 31
The Regular Operations on Languages
NFA N 3 will first try to see if the
first part of the input string isaccepted by N 1.
Once N 1 is in a final state, N 3tries to see or guess if that is
the point where the first partstops and the second part
begins. So N 2 performs its
computation.
The state diagram for NFA N 3will be:
q 2
NFA N 2
q 1
NFA N 1
8/21/2019 MELJUN CORTES Automata Lecture the Regular Operations on Languages 1
http://slidepdf.com/reader/full/meljun-cortes-automata-lecture-the-regular-operations-on-languages-1 18/31
Theory of Computation (With Automata Theory)
* Property of STI
Page 18 of 31
The Regular Operations on Languages
The start state of N 3 is the start
state of N 1.
Upon arrival of the first symbol
of the input string, N 3 starts
“simulating” N 1 to determine if
the first part of the string is a
member of L1.
Every time the computation
reaches a final state of N 1, N 3assumes or guesses that this
is the point where the first part
ends and the second begins.
Hence, N 3 starts simulating N 2
to determine if the second partof the string is a member of L2.
The set of final states of N 3 is
the set of final states of N 2.
8/21/2019 MELJUN CORTES Automata Lecture the Regular Operations on Languages 1
http://slidepdf.com/reader/full/meljun-cortes-automata-lecture-the-regular-operations-on-languages-1 19/31
Theory of Computation (With Automata Theory)
* Property of STI
Page 19 of 31
The Regular Operations on Languages
Formal construction of N 3 that
recognizes L1 L2
1. The set of states Q3 for N 3
Q3 = Q1 Q2
2. The alphabet 3
3 =
1 2
3. The transition function 3
Let q = current state, and
x = input symbol
If q Q1 and q F 1 then:
3(q, x ) = 1(q, x )
8/21/2019 MELJUN CORTES Automata Lecture the Regular Operations on Languages 1
http://slidepdf.com/reader/full/meljun-cortes-automata-lecture-the-regular-operations-on-languages-1 20/31
Theory of Computation (With Automata Theory)
* Property of STI
Page 20 of 31
The Regular Operations on Languages
if q F 1 and x ε then:
3(q, x ) = 1(q, x )
if q F 1 and x = ε then:
3(q, x ) = 1(q, x ) {q2}
if q Q2 then:
3(q, x ) = 2(q, x )
4. The Start State
The start state of N 3 is q1.
5. The Set of Final States
F 3 = F 2
8/21/2019 MELJUN CORTES Automata Lecture the Regular Operations on Languages 1
http://slidepdf.com/reader/full/meljun-cortes-automata-lecture-the-regular-operations-on-languages-1 21/31
Theory of Computation (With Automata Theory)
* Property of STI
Page 21 of 31
The Regular Operations on Languages
Example:
Let L1 = {w w ends with a 00}
Let L2 = {w w starts with a 1}
NFA N 1 for L1:
NFA N 2 for L2:
0q 1
0, 1
q 3q 2
0
0
1q 4 q 5
0, 1
8/21/2019 MELJUN CORTES Automata Lecture the Regular Operations on Languages 1
http://slidepdf.com/reader/full/meljun-cortes-automata-lecture-the-regular-operations-on-languages-1 22/31
Theory of Computation (With Automata Theory)
* Property of STI
Page 22 of 31
The Regular Operations on Languages
The state diagram of NFA N 3for L1 L2
Therefore, L1 L2 is a regular
language.
0q 1
0, 1
q 2
0
0
1q 4 q 5
0, 1
q 3
8/21/2019 MELJUN CORTES Automata Lecture the Regular Operations on Languages 1
http://slidepdf.com/reader/full/meljun-cortes-automata-lecture-the-regular-operations-on-languages-1 23/31
Theory of Computation (With Automata Theory)
* Property of STI
Page 23 of 31
The Regular Operations on Languages
• Is the star of regular
languages also regular?
Assume that L1 is a regular
language recognized by the
NFA N 1.
N 1 = {Q1, 1, 1, q1, F 1}
If L1* (the star of L1) is regular,
then there must be an NFA
that recognizes it. Let thisNFA be N 2.
N 2 = {Q2, 2, 2, q2, F 2}
The following is the statediagram for N 1:
q 1
NFA N 1
8/21/2019 MELJUN CORTES Automata Lecture the Regular Operations on Languages 1
http://slidepdf.com/reader/full/meljun-cortes-automata-lecture-the-regular-operations-on-languages-1 24/31
Theory of Computation (With Automata Theory)
* Property of STI
Page 24 of 31
The Regular Operations on Languages
NFA N 2 should be able to
accept a string if it is of theform x 1 x 2 x 3… where x i L1. In
other words, N 2 should accept
an input string if it can be
divided into several parts
where each part is acceptedby N 1.
NFA N 2 will first try to see if the
first part of the input string is
accepted by N 1.
Once N 1 is in a final state, N 2tries to see or guess if the
second part is also accepted
by N 1. So N 2 goes back to thestart and begins computing
again.
By definition of the star
operation, N 2 should also be
able to accept empty strings.
8/21/2019 MELJUN CORTES Automata Lecture the Regular Operations on Languages 1
http://slidepdf.com/reader/full/meljun-cortes-automata-lecture-the-regular-operations-on-languages-1 25/31
Theory of Computation (With Automata Theory)
* Property of STI
Page 25 of 31
The Regular Operations on Languages
The state diagram for NFA N 2will be
The start state of N 2 is a new
state q0 which is also a finalstate. Adding this state
ensures that the empty string
is also accepted by N 2.
Upon arrival of the first symbol
of the input string, N 2 starts
“simulating” N 1 to determine if
the first part of the string is a
member of L1.
q 1
NFA N 1
`
q 0
8/21/2019 MELJUN CORTES Automata Lecture the Regular Operations on Languages 1
http://slidepdf.com/reader/full/meljun-cortes-automata-lecture-the-regular-operations-on-languages-1 26/31
Theory of Computation (With Automata Theory)
* Property of STI
Page 26 of 31
The Regular Operations on Languages
Every time the computation
reaches a final state of N 1, N 2assumes or guesses that this
is the point where the first part
ends and the second begins.
Hence, N 2 goes back to the
start and tries to see if the next
part is also accepted by N 1.
The set of final states of N 2 is
the set of final states of N 1 plus
state q0.
Formal construction of N 2 that
can recognize L1*:
1. The set of states Q2 for N 2:
Q2 = {q0} Q1
2. The alphabet 2:
2 = 1
8/21/2019 MELJUN CORTES Automata Lecture the Regular Operations on Languages 1
http://slidepdf.com/reader/full/meljun-cortes-automata-lecture-the-regular-operations-on-languages-1 27/31
Theory of Computation (With Automata Theory)
* Property of STI
Page 27 of 31
The Regular Operations on Languages
3. The transition function 2:
Let q = current state and
x = input symbol
If q Q1 and q F 1 then
2(q, x ) = 1(q, x )
If q F 1 and x ε then
2(q, x ) = 1(q, x )
If q F 1 and x = ε then
2(q, x ) = 1(q, x ) {q1}
8/21/2019 MELJUN CORTES Automata Lecture the Regular Operations on Languages 1
http://slidepdf.com/reader/full/meljun-cortes-automata-lecture-the-regular-operations-on-languages-1 28/31
Theory of Computation (With Automata Theory)
* Property of STI
Page 28 of 31
The Regular Operations on Languages
If q q0 and x = ε then
2(q, x ) = q1
4. The Start State
The start state of N 2 is q0.
5. The Set of Final States
F 2 = {q0} F 2
8/21/2019 MELJUN CORTES Automata Lecture the Regular Operations on Languages 1
http://slidepdf.com/reader/full/meljun-cortes-automata-lecture-the-regular-operations-on-languages-1 29/31
Theory of Computation (With Automata Theory)
* Property of STI
Page 29 of 31
The Regular Operations on Languages
Example:
Let L1 = {w w ends with a 00}
NFA N 1 for L1:
The state diagram of NFA N 2for L1*:
Therefore, L1* is a regular
language.
0q 1
0, 1
q 3q 2
0
0
0
q 1
0, 1
q 2
0
0
q 0 q 3
8/21/2019 MELJUN CORTES Automata Lecture the Regular Operations on Languages 1
http://slidepdf.com/reader/full/meljun-cortes-automata-lecture-the-regular-operations-on-languages-1 30/31
Theory of Computation (With Automata Theory)
* Property of STI
Page 30 of 31
The Regular Operations on Languages
Theorems on Closure
• Theo rem 2
The family of regular
languages is closed under theunion operation.
• Theo rem 3
The family of regular
languages is closed under the
concatenation operation.
• Theo rem 4
The family of regular
languages is closed under the
star operation.
8/21/2019 MELJUN CORTES Automata Lecture the Regular Operations on Languages 1
http://slidepdf.com/reader/full/meljun-cortes-automata-lecture-the-regular-operations-on-languages-1 31/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
L1 L2.
2. Give the state diagram for
the NFA that recognizesL1 L2.
3. Give the state diagram for
the NFA that recognizes
L2 L1.
4. Give the state diagram for
the NFA that recognizes
L1*.
5. Give the state diagram for
the NFA that recognizesL2*.