Defn: Let Leq be the set of all strings over {0, 1} having an equal number 0s and 1s. Question: Is Leq regular? Theorem 4.1: (The pumping lemma for regular languages) Let L be a regular language. Then there is an n ∈ N such that for every w ∈ L for which |w| ≥ n, we can write w = xyz such that: 1. y 6= ²; 2. |xy| ≤ n; and 3. ∀k ≥ 0 : xy k z ∈ L. 1 Claim: Leq is not regular. Proof: By contradiction. Assume Leq is regular. Let n be the constant guaranteed by the pumping lemma. Let w = 0n 1n . Clearly, w ∈ Leq . By the pumping lemma, we can write w = xyz such that y 6= ², |xy| ≤ n, and ∀k ∈ N : xy k z ∈ Leq . Because |xy| ≤ n, y = 0i such that 0 < i ≤ n. Then xy 0 z = 0n−i 1n 6∈ Leq — a contradiction. 2 Proof of Pumping Lemma (sketch): • Let A = (Q, Σ, δ, q0 , F ) be a DFA s.t. L(A) = L. • Let n = |Q|, w ∈ L, |w| ≥ n. • For 0 ≤ i ≤ n, let wi denote the prefix of w with length i. • By the Pigeonhole Principle, ∃ 0 ≤ i < j ≤ n : δ̂(q0 , wi ) = δ̂(q0 , wj ). • Let x = wi , xy = wj , xyz = w (note that |xy| ≤ n, y 6= ²). 3 Proof continued: • By induction on k, δ̂(q0 , xy k ) = δ̂(q0 x) for all k ∈ N. δ̂(q0 , xy k z) = δ̂(δ̂(q0 , xy k ), z) = δ̂(δ̂(q0 , x), z) = δ̂(δ̂(q0 , xy), z) = δ̂(q0 , xyz) ∈ F. • Therefore, xy k z ∈ L(A) = L. 4 Theorem 4.5: The set of regular languages over Σ is closed under complementation; i.e., if L is a regular language over Σ, then Σ∗ − L is regular. Proof: Let A = (Q, Σ, δ, q0 , F ) be a DFA s.t. L(A) = L. Let A0 = (Q, Σ, δ, q0 , Q − F ). Then Σ∗ − L = Σ∗ − {w ∈ Σ∗ | δ̂(q0 , w) ∈ F } = {w ∈ Σ∗ | δ̂(q0 , w) ∈ Q − F } = L(A0 ). Thus, Σ∗ − L is regular. 5 Theorem 4.8: The set of regular languages over Σ is closed under intersection. Proof: Let L1 and L2 be regular languages over Σ. By DeMorgan’s laws, L1 ∩ L 2 = L 1 ∪ L 2 . Because the set of regular languages over Σ is closed under union and complementation, L1 ∩ L2 is regular. 6 Defn: Let Σ and ∆ be two alphabets. A homomorphism from Σ∗ to ∆∗ is any function h : Σ∗ → ∆∗ such that ∀x, y ∈ Σ∗ , h(xy) = h(x)h(y). Defn: Let Σ and ∆ be two alphabets, and let ∗ ∗ R ⊆ Σ∗ × ∆∗ . We define R̃ : 2Σ → 2∆ such that R̃(L) = {y ∈ ∆∗ |∃x ∈ L : hx, yi ∈ R} 7 Example: Let h : {a, b}∗ → {0, 1}∗ be the homomorphism defined by h(a) = 01 h(b) = 10. Then h̃(a∗ b∗ ) = (01)∗ (10)∗ . 8 For a string w ∈ {a, b}∗ , let w denote the homomorphism defined by a=b b = a. Let L = {xxR w | x, w ∈ {0, 1}∗ , x 6= ²}. Then −1 (L) = {x ∈ {a, b}∗ | ∃y ∈ L : h(x) = y} hg = {xxR w ∈ {a, b}∗ | x 6= ²} 9 Theorem 4.14: Let h : Σ∗ → ∆∗ be a homomorphism. If L ⊆ Σ∗ is regular, then h̃(L) is also regular. Theorem 4.16: If h : Σ∗ → ∆∗ is a homomorphism and L ⊆ ∆∗ is regular, then −1 (L) is regular. hg Claim: The language L = {xxR w | x, w ∈ {0, 1}∗ , x 6= ²} is not regular. Proof idea: −1 (L) ∩ a∗ b∗ = {ai bj | 0 < i ≤ j}. hg 10 Proof of Theorem 4.14 (sketch): By induction on L ∈ R(Σ). Base Case 1: h̃(∅) = ∅. Base Case 2: h̃({²}) = {²}. Base Case 3: For a ∈ Σ, h̃({a}) = {h(a)}. IH: Assume that for L1 , L2 ∈ R(Σ), h̃(L1 ) and h̃(L2 ) are regular. IS 1: h̃(L1 ∪ L2 ) = h̃(L1 ) ∪ h̃(L2 ). IS 2: h̃(L1 L2 ) = h̃(L1 )h̃(L2 ). IS 3: h̃(L∗1 ) = h̃(L1 )∗ . 11 Proof of Theorem 4.16 (sketch): • Let A = (Q, ∆, δA , q0 , F ) be a DFA, L(A) = L. • Let B = (Q, Σ, δB , q0 , F ), where δB (q, a) = δ̂(q, h(a)). • By right induction on w ∈ Σ∗ , δ̂B (q0 , w) = δ̂A (q0 , h(w)). −1 (L) = L(B). • Therefore, hg 12