





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






Regular Expressions and Regular Languages Why do they have such similar names?
Theorem 1. L is a regular language if and only if there is a regular expression R such that L(R) = L
i.e., Regular expressions have the same “expressive power” as finite automata.
Proof. • Given regular expression R, can construct NFA N such that L(N ) = L(R)
1 Converting a DFA to an Equivalent Regular Expression
DFA to Regular Expression
Generalized NFA
Generalized NFA
Converting DFA to GNFA A DFA M = (Q, Σ, δ, q 0 , F ) can be easily converted to an equivalent GNFA G = (Q′, Σ, q 0 ′, q′ F , ρ):
, if q 1 = q′ 0 and q 2 = q 0 , if q 1 ∈ F and q 2 = q′ F ⋃ {a|δ(q 1 ,a)=q 2 } a^ otherwise
q′ 0 q 0 q′ F
q 1
q 2
Prove: L(G) = L(M ).
GNFA to Regex
q 0
q 1
qF
q 0 qF
GNFA to Regex: From k states to k − 1 states
Definition 4 (Deleting a GNFA State). Given GNFA G = (Q, Σ, q 0 , qF , ρ) with |Q| > 2, and any state q∗^ ∈ Q \ {q 0 , qF }, define GNFA rip(G, q∗) = (Q′, Σ, q 0 , qF , ρ′) as follows:
ρ′(q 1 , q 2 ) = (R 1 R∗ 2 R 3 ) ∪ R 4 ,
where R 1 = ρ(q 1 , q∗), R 2 = ρ(q∗, q∗), R 3 = ρ(q∗, q 2 ) and R 4 = ρ(q 1 , q 2 ).
Claim. For any q∗^ ∈ Q \ {q 0 , qF }, G and rip(G, q∗) are equivalent.
GNFA to Regex: From k states to k − 1 states w ∈ L(G) =⇒ w ∈ L(G′)
Proof. • w ∈ L(G) =⇒ w = x 1 x 2 x 3 · · · xt, and a sequence of states q 0 = r 0 , r 1 ,... , rt = qF s.t. xi ∈ L(ρ(ri− 1 , ri)).
· · · xi and sj− 1 = r− 1 and sj = ri, where ` = σ(j − 1) + 1 and i = σ(j).yj = x· · · xi ∈ L(ρ(r− 1 , r)ρ(r, r+1) · · · ρ(ri− 1 , ri)ρ(ri, ri+1)) = L(ρ(r− 1 , q∗)ρ(q∗, q∗)i−ρ(q∗, ri)) ⊆ L(ρ(r− 1 , r`)ρ(q∗, q∗)∗ρ(q∗, ri)) ⊆ L(ρ(sj− 1 , q∗)ρ(q∗, q∗)∗ρ(q∗, sj )) ⊆ L(ρ′(sj− 1 , sj ))
Thus w ∈ L(G′) as we set out to prove. Next we need to show that w ∈ L(G′) =⇒ w ∈ L(G). w ∈ L(G′) =⇒ ∃q 0 = s 0 , s 1 ,... , sd = qF and y 1 ,... , yd ∈ Σ∗^ such that w = y 1 y 2 y 3 · · · yd and for each j, yj ∈ L(ρ′(sj− 1 , sj )) = L ((ρ(sj− 1 , q∗)ρ(q∗, q∗)∗ρ(q∗, ri)) ∪ ρ(sj− 1 , sj )) Define σ as follows, for j = 0,... , d:
σ(j) =
0 if j = 0, σ(j − 1) + 1 if yj ∈ L(ρ(sj− 1 , sj )) σ(j − 1) + u + 2 otherwise, where u = minv (yj ∈ L(ρ(sj− 1 , q∗)ρ(q∗, q∗)vρ(q∗, sj )))
Let t = σ(d). For i = 0,... , t define ri as follows:
r(i) =
sj if there exists j such thati = σ(j), q∗^ otherwise.
Finally, define xi (i = 1,... , t) as follows: if i = σ(j) and i − 1 = σ(j − 1), then let xi = yj. For other i (σ(j − 1) < i − 1 < i ≤ σ(j) for some j), we have yj ∈ L(ρ(sj− 1 , q∗)ρ(q∗, q∗)uρ(q∗, sj )) where u = σ(j) − σ(j − 1) − 2. Therefore we can write yj = x· · · xσ(j), where = σ(j − 1) + 1, such that x∈ L(ρ(sj− 1 , q∗)), xσ(j) ∈ L(ρ(q∗, sj ) and x+1,... , xσ(j)− 1 ∈ L(ρ(q∗, q∗)). Verify that all xi (i = 1,... , t) are well-defined by this. With these definitions it can be easily verified that x 0 · · · xt = y 0 · · · yd = w and xi ∈ L(ρ(ri− 1 , ri)).
DFA to Regex: Summary
Lemma 5. For every DFA M , there is a regular expression R such that L(M ) = L(R).
DFA to Regex: Example
q 1 q 2
Figure 2: Example DFA D
q 1 q 2
q 0 qF
Figure 3: GNFA G equivalent to D, ignoring transitions labelled ∅