Download as pdf or txt
Download as pdf or txt
You are on page 1of 23

Properties of regular languages

• What happens when we perform operations on regular


languages?
– E.g., if we concatenate two regular languages, is the resulting
language also regular?
• Can we decide whether a given language has a certain
property or not?
– E.g., Can we tell if a certain language is finite or not?
• Can we tell whether a given language is regular or not?

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

• L1 = {0x | x ∈ {0,1}*} L2 = {x0 | x ∈ {0,1}*}


• M1 = (Q, Σ, δ1, q0, F1) M2 = (R, Σ, δ2, r0, F2)
• L1 = L(M1) L2 = L(M2)

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

Eventually state-pairs repeat; then we’re almost done:

22
Language Intersection

For intersection, both original DFAs must accept:

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

• L1 = {0x | x ∈ {0,1}*} L2 = {x0 | x ∈ {0,1}*}


• M1 = (Q, Σ, δ1, q0, F1) M2 = (R, Σ, δ2, r0, F2)
• L1 = L(M1) L2 = L(M2)

25
Language union

For union, any original DFAs enough to accept:

26
Language difference

• L1 = {0x | x ∈ {0,1}*} L2 = {x0 | x ∈ {0,1}*}


• M1 = (Q, Σ, δ1, q0, F1) M2 = (R, Σ, δ2, r0, F2)
• L1 = L(M1) L2 = L(M2)

27
Language difference

For difference L1  L2 = L1  L¯2 , any original DFAs enough to


accept:

28
Reversal

If L is a regular language, construct an NDFA with a single


final state that accepts it.

Now change the initial vertex into a final vertex, the final
vertex into the initial vertex, and reverse the direction on all
the edges.

For every string w accepted by the original NDFA, the


modified version of the NDFA accepts wR.
29
Reversal

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

Add a new initial state

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

You might also like