Professional Documents
Culture Documents
Formal Languages - Lec6 - P1
Formal Languages - Lec6 - P1
12
4.1 Closure properties of regular languages
• Definition: A regular language is any language that is
accepted by a finite automaton
• Theorem 4.1 : The class of regular languages is closed
under the following operations (that is, performing these
operations on regular languages creates other regular
languages)
1. Union
2. Complement
3. Intersection
4. difference
13
Complements
For any language L over an alphabet , the
complement of L is
L = {x ∈ Σ* | x ∉ L}
Example
L ={ 0x | x ∈ {0,1}*}= strings that start with 0
L¯= {1x | x ∈ {0,1}*}∪{ε} = strings that don’ t start with 0
Given a DFA for any language, it is easy to construct a DFA for its
complement
14
Complements
15
Unions, Intersections, and Difference
Suppose that
M1 = (Q1, , q1, A1, 1) accepts language L1, and
M2 = (Q2, , q2, A2, 2) accepts language L2
Let M be an FA defined by M = (Q, , q0, A, ) where
Q = Q1 Q2
q0 = (q1, q2)
and the transition function is defined by:
((p, q), a) = (1(p, a), 2(q, a)),
for any p Q1, q Q2, and a
16
Unions, Intersections, and Difference:
Then:
1. If A = {(p, q) p A1 or q A2}, M
accepts the language L1 L2
2. If A = {(p, q) p A1 and q A2}, M
accepts the language L1 L2
3. If A = {(p, q) p A1 and q A2}, M
accepts the language L1 L2
17
Language Intersection
• L1 L2 = {x | x L1 and x L2}
• Example:
– L1 = {0x | x {0,1}*} = strings that start with 0
– L2 = {x0 | x {0,1}*} = strings that end with 0
– L1 L2 = {x {0,1}* | x starts and ends with 0}
• Usually we will consider intersections of languages with the
same alphabet, but it works either way
• Given two DFAs, it is possible to construct a DFA for the
intersection of the two languages
18
Language Intersection
19
Language Intersection
• We'll make a DFA that keeps track of the pair of states (qi, rj) the two original DFAs
are in Initially, they are both in their start states:
20
Language Intersection
Working from there, we keep track of the pair of states (qi, rj):
21
Language Intersection
22
Language Intersection
23
Language union
• L1 L2 = {x | x L1 or x L2 (or both)}
• Example:
– L1 = {0x | x {0,1}*} = strings that start with 0
– L2 = {x0 | x {0,1}*} = strings that end with 0
– L1 L2 = {x {0,1}* | x starts with 0 or ends with 0 (or both)}
• Usually we will consider intersections of languages with the same
alphabet, but it works either way
• Given two DFAs, it is possible to construct a DFA for the union of the
two languages
24
Language union
25
Language union
26
Language difference
27
Language difference
28
Reversal
Now change the initial vertex into a final vertex, the final
vertex into the initial vertex, and reverse the direction on all
the edges.
Example:
b
L ab * ba
a
b
a 30
Reversal
Invert Transitions
a
b
a 31
Reversal
Make old initial state a final state and final state initial state
a
b
a
32
Reversal
a
b
a
33
Reversal
Resulting machine accepts LR
LR
is regular
L ab * ba
b
L b * a ab
R
a
b
a
34