0% found this document useful (0 votes)
75 views36 pages

H (A A ... A) H (A) H (A) ... H (A)

The document discusses various properties of regular languages, including that regular languages are closed under union, intersection, complement, difference, reversal, Kleene closure, and homomorphisms. It presents proofs that these operations on regular languages result in regular languages by giving constructions to build finite automata that recognize the resulting languages. The document also covers decision properties of regular languages like testing for emptiness, membership, equivalence, and minimization of automata.

Uploaded by

johnny kalue
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views36 pages

H (A A ... A) H (A) H (A) ... H (A)

The document discusses various properties of regular languages, including that regular languages are closed under union, intersection, complement, difference, reversal, Kleene closure, and homomorphisms. It presents proofs that these operations on regular languages result in regular languages by giving constructions to build finite automata that recognize the resulting languages. The document also covers decision properties of regular languages like testing for emptiness, membership, equivalence, and minimization of automata.

Uploaded by

johnny kalue
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

Closure Properties of Regular Languages

Let L and M be regular languages. Then the


following languages are all regular:
Union: L M
Intersection: L M
Complement: N
Difference: L \ M
Reversal: LR = {wR : w L}
Closure: L.
Concatenation: L.M
h(a1 a2 ... an) = h(a1)h(a2)...h(an)
Homomorphism:
h(L) = {h(w) : w L, h is a homom. }

Inverse homomorphism:
h1(L) = {w : h(w) L, h : * is a homom. }
97

Theorem 4.4. For any regular L and M , LM


is regular.
Proof. Let L = L(E) and M = L(F ). Then
L(E + F ) = L M by definition.
Theorem 4.5. If L is a regular language over
, then so is L = \ L.
Proof. Let L be recognized by a DFA
A = (Q, , , q0, F ).
Let B = (Q, , , q0, Q \ F ). Now L(B) = L.

98

Example:
Let L be recognized by the DFA below
1
Start
{q0}

0
0

{q0, q1}

{q0, q2}

0
1

Then L is recognized by
1
Start
{q0}

0
0

{q0, q1}

{q0, q2}

0
1

Question: What are the regexs for L and L


99

Theorem 4.8. If L and M are regular, then


so is L M .
Proof. By DeMorgans law L M = L M .
We already that regular languages are closed
under complement and union.

We shall shall also give a nice direct proof, the


Cartesian construction from the e-commerce
example.

100

Theorem 4.8. If L and M are regular, then


s L M.
so in
Proof. Let L be the language of
AL = (QL, , L, qL, FL)
and M be the language of
AM = (QM , , M , qM , FM )
We assume w.l.o.g. that both automata are
deterministic.
We shall construct an automaton that simulates AL and AM in parallel, and accepts if and
only if both AL and AM accept.

101

If AL goes from state p to state s on reading a,


and AM goes from state q to state t on reading
a, then ALM will go from state (p, q) to state
(s, t) on reading a.
Input a

AL
Start

AND

Accept

AM

102

Formally
ALM = (QL QM , , LM , (qL, qM ), FL FM ),
where
LM ((p, q), a) = (L(p, a), M (q, a))
It will be shown in the tutorial by and induction
on |w| that


LM ((qL, qM ), w) = L(qL, w), M (qM , w)

The claim then follows.


Question: Why?

103

Example: (c) = (a) (b)


1
Start

0,1
q

(a)
0
Start

0,1
s

(b)
1
Start

pr

ps
0
0,1

qr

qs

0
(c)
Another example?
104

Theorem 4.10. If L and M are regular lanS L \ M.


guages, then so in
Proof. Observe that L \ M = L M . We
already know that regular languages are closed
under complement and intersection.

105

Theorem 4.11.
then so is LR .

If L is a regular language,

Proof 1: Let L be recognized by an FA A.


Turn A into an FA for LR , by
1. Reversing all arcs.
2. Make the old start state the new sole accepting state.
3. Create a new start state p0, with (p0, ) = F
(the old accepting states).

106

Theorem 4.11.
then so is LR .

If L is a regular language,

Proof 2: Let L be described by a regex E.


We shall construct a regex E R , such that
L(E R ) = (L(E))R .
We proceed by a structural induction on E.
Basis: If E is , , or a, then E R = E.
Induction:
1. E = F + G. Then E R = F R + GR
2. E = F.G. Then E R = GR .F R
3. E = F . Then E R = (F R )
We will show by structural induction on E on
blackboard in class that
L(E R ) = (L(E))R
107

Homomorphisms
A homomorphism on is a function h : ,
where and are alphabets.
Let w = a1a2 an . Then
h(w) = h(a1)h(a2) h(an)
and
h(L) = {h(w) : w L}
Example: Let h : {0, 1} {a, b} be defined by
h(0) = ab, and h(1) = . Now h(0011) = abab.
Example: h(L(101)) = L((ab)).

108

Theorem 4.14: h(L) is regular, whenever L


is.
Proof:

E.g., h(0*1+(0+1)*0) = h(0)*h(1)+(h(0)+h(1))*h(0)

Let L = L(E) for a regex E. We claim that


L(h(E)) = h(L).
Basis: If E is  or . Then h(E) = E, and
L(h(E)) = L(E) = h(L(E)).
If E is a, then L(E) = {a}, L(h(E)) = L(h(a)) =
{h(a)} = h(L(E)).
Induction:
G = E + F . Now L(h(E + F )) =
Case 1: L
L(h(E)+h(F )) = L(h(E))L(h(F )) = h(L(E))
h(L(F )) = h(L(E) L(F )) = h(L(E + F )).
G = E.F . Now L(h(E.F )) = L(h(E)).L(h(F ))
Case 2: L
= h(L(E)).h(L(F )) = h(L(E).L(F )) = h(L(E.F))

Case 3: GL = E . Now L(h(E )) = L(h(E)) =


L(h(E)) = h(L(E)) = h(L(E)*) = h(L(E*))

h(L(E )).

109

Inverse Homomorphism
Let h : be a homom. Let L ,
and define

h1(L) = {w : h(w) L}

h(L)

(a)

h-1 (L)

(b)

110

Example: Let h : {a, b} {0, 1} be defined by


h(a) = 01, and h(b) = 10. If L = L((00 + 1)),
then h1(L) = L((ba)).
Claim: h(w) L if and only if w = (ba)n
Proof: Let w = (ba)n. Then h(w) = (1001)n
L.
Let h(w) L, and suppose w
/ L((ba)). There
are four cases to consider.
1. w begins with a. Then h(w) begins with
01 and
/ L((00 + 1)).
2. w ends in b. Then h(w) ends in 10 and

/ L((00 + 1)).
3. w = xaay. Then h(w) = z0101v and
/
L((00 + 1)).
4. w = xbby. Then h(w) = z1010v and
/
L((00 + 1)).
111

Theorem 4.16: Let h : be a homom., and L regular. Then h1(L) is


regular.
Proof: Let L be the language of A = (Q, , , q0, F ).
We define B = (Q, , , q0, F ), where
(q, a) = (q, h(a))
It will be shown by induction on |w| in the tutorial that
(q0, w) = (q0, h(w))
Input a

h
Input
h(a) to A

Start

Accept/reject
A

112

Decision Properties
We consider the following:

1. Converting among representations for regular languages.

2. Is L = ?

3. Is w L?

4. Do two descriptions define the same language?

113

From NFAs to DFAs


Suppose the -NFA has n states.
To compute ECLOSE(p) we follow at most n2
arcs.
The DFA has 2n states, for each state S and
each a we compute D (S, a) in n3 steps.
Grand total is O(n32n) steps.
If we compute for reachable states only, we
need to compute D (S, a) only s times, where s
is the number of reachable states. Grand total
is O(n3s) steps.

114

From DFA to NFA


All we need to do is to put set brackets around
the states. Total O(n) steps.
From FA to regex
We need to compute n3 entries of size up to
4n. Total is O(n34n).
The FA is allowed to be a NFA. If we first
wanted to convert the NFA to a DFA, the total
time would be doubly exponential
From regex to FAs We can build an expression tree for the regex in n steps.
We can construct the automaton in n steps.
Eliminating -transitions takes O(n3) steps.
If you want a DFA, you might need an exponential number of steps.
115

Testing emptiness
L(A) 6= for FA A if and only if a final state
is reachable from the start state in A. Total
O(n2) steps.
Alternatively, we can inspect a regex E and tell
if L(E) = . We use the following method:
E = F + G. Now L(E) is empty if and only if
both L(F ) and L(G) are empty.
E = F.G. Now L(E) is empty if and only if
either L(F ) or L(G) is empty.
E = F . Now L(E) is never empty, since 
L(E).
E = . Now L(E) is not empty.
E = a. Now L(E) is not empty.
E = . Now L(E) is empty.
116

Testing membership
To test w L(A) for DFA A, simulate A on w.
If |w| = n, this takes O(n) steps.
If A is an NFA and has s states, simulating A
on w takes O(ns2) steps.
If A is an -NFA and has s states, simulating
A on w takes O(ns3) steps.
If L = L(E), for regex E of length s, we first
convert E to an -NFA with 2s states. Then we
simulate w on this machine, in O(ns3) steps.
Does L((0+1)*0(0+1)31*) contain 10101011 or 101011101?

Finiteness: How to decide if L(A) is finite for DFA A?


117

Equivalence and Minimization of Automata

Let A = (Q, , , q0, F ) be a DFA, and {p, q} Q.


We define

p q w : (p, w) F iff (q, w) F


If p q we say that p and q are equivalent
If p 6 q we say that p and q are distinguishable
IOW (in other words) p and q are distinguishable iff

w : (p, w) F and (q, w)


/ F, or vice versa

118

Example:
1

0
Start

0
0

1
H

0
0

(C, ) F, (G, )
/ F C 6 G
(A, 01) = C F, (G, 01) = E
/ F A 6 G

119

What about A and E?


1

0
Start

A
1

0
0

(A, ) = A
/ F, (E, ) = E
/F
(A, 1) = F
K = (E, 1)
Therefore (A, 1x) = (E, 1x) = (F,
K x)
(A, 00) = G = (E, 00)
(A, 01) = C = (E, 01)
Conclusion: A E.
120

We can compute distinguishable pairs with the


following inductive table filling algorithm:
Basis: If p F and q 6 F , then p 6 q.
Induction: If a : (p, a) 6 (q, a),
then p 6 q.
Example: Applying the table filling algo to A:
B

C D E

K G
F

121

Theorem 4.20: If p and q are not distinguished by the TF-algo, then p q.


Proof: Suppose to the contrary that that there
is a bad pair {p, q}, s.t.
/ F , or vice versa.
1. w : (p, w) F, (q, w)

2. The TF-algo does not distinguish between


p and q.

Let w = a1a2 an be the shortest string that


identifies a bad pair {p, q}.
Now w 6=  since otherwise the TF-algo would
in the basis distinguish p from q. Thus n 1.

122

Consider states r = (p, a1) and s = (q, a1).


Now {r, s} cannot be a bad pair since {r, s}
would be indentified by a string shorter than w.
Therefore, the TF-algo must have discovered
that r and s are distinguishable.
But then the TF-algo would distinguish p from
q in the inductive part.
Thus there are no bad pairs and the theorem
is true.

123

Testing Equivalence of Regular Languages

Let L and M be reg langs (each given in some


form).
To test if L = M

1. Convert both L and M to DFAs.

a DFA that is the union of the


2. Imagine the
two DFAs (never mind there are two start
states)

3. If TF-algo says that the two start states


are distinguishable, then L 6= M , otherwise
L = M.

124

Example:
0

Start

0
Start

E
1

We can see that both DFA accept


L( + (0 + 1)0). The result of the TF-algo is
B

x
A

x
B

C D

Therefore the two automata are equivalent.


125

Minimization of DFAs

We can use the TF-algo to minimize a DFA


by merging all equivalent states. IOW, replace
each state p by p/ .
Example: The DFA on slide 119 has equivalence classes {{A, E}, {B, H}, {C}, {D, K}, {G}}.
The union DFA on slide 125 has equivalence
classes {{A, C, D}, {B, E}}.
Note: In order for p/ to be an equivalence
class, the relation has to be an equivalence
relation (reflexive, symmetric, and transitive).

126

Theorem 4.23: If p q and q r, then p r.


Proof: Suppose to the contrary that p 6 r.
Then w such that (p, w) F and (r, w) 6 F ,
or vice versa.
OTH, (q, w) is either accpeting or not.
Case 1: (q, w) is accepting. Then q 6 r.
(q, w) is not accepting. Then p 6 q.
2
Case 1:
The vice versa case is proved symmetrically
Therefore it must be that p r.

127

Assume A has no inaccessible states.

To minimize a DFA A = (Q, , , q0, F ) construct a DFA B = (Q/ , , , q0/ , F/ ), where


(p/ , a) = (p, a)/
In order for B to be well defined we have to
show that
If p q then (p, a) (q, a)
If (p, a) 6 (q, a), then the TF-algo would conclude p 6 q, so B is indeed well defined. Note
also that F/ contains all and only the accepting states of A.

128

Example: We can minimize


1

0
Start

D
1

0
0

0
0

to obtain
1
0

D,K

1
Start
A,E

0
0
B,H

129

NOTE: We cannot apply the TF-algo to NFAs.


For example, to minimize
0,1
Start

0
A
1

B
0

we simply remove state C.


However, A 6 C.

130

Why the Minimized DFA Cant Be Beaten

Let B be the minimized DFA obtained by applying the TF-algo to DFA A.


We already know that L(A) = L(B).
What if there existed a DFA C, with
L(C) = L(B) and fewer states than B?
Then run the TF-algo on B union C.
Since L(B) = L(C) we have q0B q0C .
Also, (q0B , a) (q0C , a), for any a.

131

Claim: For each state p in B there is at least


one state q in C, s.t. p q.
Proof of claim: There are no inaccessible states,
so p = (q0B , a1a2 ak ), for some string a1a2 ak .
Now q = (q0C , a1a2 ak ), and p q.
Since C has fewer states than B, there must be
two states r and s of B such that r t s, for
some state t of C. But then r s (why?)
which is a contradiction, since B was constructed by the TF-algo.

132

You might also like