Second Course in Formal Languages and Automata Theory
Total Page:16
File Type:pdf, Size:1020Kb
1 2FLT transparencies made for Second Course in Formal Languages and Automata Theory based on the book by Jeffrey Shallit of the same title Hendrik Jan Hoogeboom, Leiden http://www.liacs.nl/~hoogeboo/second/ LIACS — Second Course ... I Chapter 1 Review of Formal Languages and Automata Theory I 1 Chomsky hierarchy grammar automaton 3 regular right-linear finite state A aB a → 2 context-free A α pushdown → (+lifo stack) 1 context-sensitive (β ,A,βr) α linear bounded ℓ → α β β α → | |≥| | monotone 0 recursively enumerable α β turing machine → I 2 review of formal languages and automata theory 1.1 Sets 1.2 Symbols, strings, and languages 1.3 Regular expressions and regular languages 1.4 Finite automata 1.5 Context-free grammars and languages 1.6 Turing machines 1.7 Unsolvability 1.8 Complexity theory Moved to respective chapters LIACS — Second Course ... III Chapter 3 Finite Automata and Regular Languages III 1 finite automata and regular languages 3.0 Review 3.1 Moore and Mealy machines closure 3.2 Quotients 3.3 Morphisms and substitutions 3.4 Advanced closure properties of regular lan- guages 3.5 Transducers machines 3.6 Two-way finite automata 3.7 The transformation automaton 3.8 Automata, graphs, and Boolean matrices algebra 3.9 The Myhill-Nerode theorem 3.10 Minimization of finite automata 3.11 State complexity 3.12 Partial orders and regular languages 3.0 Review III 2 deterministic finite automaton = (Q, Σ, δ, q , F ) A 0 finite Q states p, q control δ q Q initial state 0 ∈ p F Q final states Σ ⊆ input alphabet a,b w,x δ : Q Σ Q transition function a × → ··· ··· input tape δ : Q Σ Q ∗ × ∗ → b δ∗(q,ε)= q b p q δ∗(q,xa)= δ( δ∗(q,x), a) a a b L( )= x Σ∗ δ(q0,x) F b A { ∈ | ∈ } r s a a III 3 run run on aababb b a a b a b b b p q p r s q r q p a a b does not accept b r s a a a b p r p q r p r s q s s q initial state p final states q, s III 4 nondeterministic finite automaton = (Q, Σ, δ, q , F ) A 0 finite Q states p, q control δ q Q initial state 0 ∈ p F Q final states Σ ⊆ input alphabet a,b w,x δ : Q Σ 2Q transition function a × → ··· ··· input tape δ : Q Σ 2Q ∗ × ∗ → a,b δ (q,ε)= q ∗ { } δ∗(q,xa)= δ(r, a) a,b r δ∗(q,x) 0 a 1 2 ∈ L( )= x Σ δ(q ,x) F = ∅ A { ∈ ∗ | 0 ∩ } Q Q δ(0, a) = 0, 1 δ′ : 2 Σ 2 (deterministic) { } × → (2 a) = ∅ δ , δ′(U, a)= p U δ(p, a) ∈ III 5 subset construction a,b a a,b 0 1 2 b b 0 0, 2 { } { } a a b a b b a 0 0 0 0 0 0 0 a b a a a b 1 1 1 0, 1 0, 1, 2 a a b b { } { } 2 2 2 a 0 0 0 0 0 0 0 1 1 1 a,b 2 2 2 1 2 { } { } deterministic δ : 2Q Σ 2Q a,b ′ × → δ′(U, a)= p U δ(p, a) a,b ∈ 1, 2 a,b { } ∅ III 6 nfa regular expression E E + E E E p 0 q p 0 1 · 2∗ · 3 q E1 E3 r r E2 bb a a p q p q a a a+b(aa)*ab b b b b b ab p q b ba a a+ba(aa)*b r s r b(aa)*b bb+ba(aa)*ab a aa III 7 pumping lemma long words ’loop’ and can be pumped for every regular language L ∀ there exists a constant n 1 ∃ ≥ such that for every z L ∀ ∈ with z n | |≥ there exists a decomposition z = uvw ∃ with uv n, v 1 | |≤ | |≥ such that for all i 0, uviw L ∀ ≥ ∈ Lemma 1.4.4 III 8 proofs - clever idea, intuition - formal construction, specification - show it works, e.g., induction once the idea is understood, the other parts might be boring but essential to test intuition examples help to get the message III 9 closure properties RLIN CF MON TYPE0 REG DPDA PDAe DLBA LBA REC RE intersection + – – +++ + complement + + – +++ – union + – + +++ + concatenation + – + +++ + star, plus + – + +++ + ε-free morphism + – + +++ + morphism + – + ––– + inverse morphism + + + +++ + intersect reg lang + + + +++ + mirror + – + +++ + fAFL fAFL AFL AFL AFL fAFL , c, boolean operations ∩ ∪ , , regular operations ∪ · ∗ h, h 1, R (full) trio operations − ∩ 3.1 Moore and Mealy machines 3.2 Quotients III 10 quotient L 1 L , L Σ 1 2 ⊆ ∗ L /L = x Σ xy L for some y L x 1 2 { ∈ ∗ | ∈ 1 ∈ 2 } L2 + + + + Ex. L1 = a bc , L2 = bc , L3 = c + L1/L2 = a + L1/L3 = a bc∗ Ex. Pref(L)= L/Σ∗ Example 3.2.1 and 3.2.5 III 11 quotient L 1 L , L Σ 1 2 ⊆ ∗ L /L = x Σ xy L for some y L x 1 2 { ∈ ∗ | ∈ 1 ∈ 2 } L2 2 Ex. L = an n 0 { | ≥ } 2 2 L/L = an m n m 0 = a(aa) +(a4) { − | ≥ ≥ } ∗ ∗ ‘ ’ m2 n2 = (m + n)(m n) ⊆ − − m n m + n m n m2 n2 − − ee e e mult four eo o o odd oe o o odd oo e e mult four ‘ ’ (k + 1)2 k2 = 2k + 1 odd ⊇ − (k + 2)2 k2 = 4k +4 multipleoffour − Example 3.2.2 III 12 example L 1 L , L Σ 1 2 ⊆ ∗ L /L = x Σ xy L for some y L x 1 2 { ∈ ∗ | ∈ 1 ∈ 2 } L2 can ’hide’ computations Ex. L = a2ncban n 1 ba2nban n 1 ba 1 { | ≥ }{ | ≥ }∗ L = c banban n 1 2 ·{ | ≥ }∗ n L /L = a2 n 1 1 2 { | ≥ } a16 c ba8 ba8 ba4 ba4 ba2 ba2 ba ba cf. Thm 4.1.6 III 13 quotient Thm. L, R Σ If R regular, then R/L regular. ⊆ ∗ F = q Q δ(q,y) F for some y L . ′ { ∈ | ∈ ∈ } noncomputable ! (L arbitrary) REG closed under quotient REG / REG = REG (see Ch.4) CF not closed, even CF / CF = RE CF / REG = CF Theorem 3.2.2 3.3 Morphisms and substitutions III 14 morphism ‘monoid’ h : Σ ∆ → ∗ h : Σ ∆ h(xy)= h(x)h(y), h(ε)= ε ∗ → ∗ Σ ∆ h : 2 ∗ 2 ∗ h(L)= x L h(x) → ∈ 0 ab, 1 ba, 2 ε → → → 00212 ababba → 0n21n n 0 (ab)n(ba)n n 0 { | ≥ } → { | ≥ } Thm. h(K L)= h(K) h(L) ∪ ∪ h(K L)= h(K) h(L) · · h(K∗)= h(K)∗ REG closed under morphisms Theorem 3.3.1 III 15 substitution bb a a p q p q a a a+b(aa)*ab b b b b b ab p q b ba a a+ba(aa)*b r s r b(aa)*b bb+ba(aa)*ab a aa 1 p q 1 0 0 0 b(aa)*b → 1 a+b(aa)*ab → K = x 0, 1 # x is even { ∈{ }∗ | 1 } s(K)= x a, b #ax, # x are even { ∈{ }∗ | b } III 16 inverse morphism h : Σ ∆ , K ∆ → ∗ ⊆ ∗ h 1(K)= x Σ h(x) K − { ∈ ∗ | ∈ } Thm. REG closed under inverse morphism a h(a) δ′(p, a)= δ(p, h(a)) h : 0 ab, 1 ba → → h 1( bb, aba )= 0011 − { }∗ { }∗ a 1 b 1 b 0 b a 0 Theorem 3.3.9 III 17 shuffle shuff(K, L)= K L shuffle abb aca = aabbca, aabcba, aabcab, aacabb, aacbab, aacbba, abbaca, { ababca, abacba, abacab, acabba, acabab, acaabb } x ε = ε x = x { } ax by = a(x by) b(ax y) ∪ K L = x K,y L x y ∈ ∈ Thm. K, L regular, then K L regular. but where is that stated? Ex. 3.3.8 III 18 shuffle abbba acac abacbacba ∋ K L using morphisms, intersection copies of alphabet Σ, Σ = a a Σ , Σ = a a Σ 1 { 1 | ∈ } 2 { 2 | ∈ } h : Σ Σ Σ a a a ε 1 1 ∪ 2 → ∗ 1 → 2 → h : Σ Σ Σ a ε a a 2 1 ∪ 2 → ∗ 1 → 2 → g : Σ Σ Σ a a a a 1 ∪ 2 → ∗ 1 → 2 → h h abbba 1 a b a c b a c b a 2 acac ← 1 1 2 2 1 2 2 1 1 → K g L ∈ ↓ ∈ abacbacba 1 1 K L = g( h− (K) h− (L) ) 1 ∩ 2 Ex. 3.3.8 3.4 Advanced closure properties of regular languages III 19 exotic: halve, sqrt 1L = x Σ xy L for y with y = x . 2 { ∈ ∗ | ∈ | | | |} 1 Thm. L regular, then 2L regular guess middle state, simulate halves in parallel Q = q Q Q Q middle, 1st, 2nd ′ { 0′ } ∪ × × δ (q ,ε)= [q, q , q] q Q ε-move ′ 0′ { 0 | ∈ } δ ([q, p, r], a)= [q,δ(p, a),δ(r, b)] b Σ ′ { | ∈ } F = [q,q,p] q Q, p F ′ { | ∈ ∈ } √ L = x Σ xx L . { ∈ ∗ | ∈ } Theorem 3.4.1 III 20 cutting cut L = x xy L for y with y = f( x ) . f { | ∈ | | | | } 1 f(n)= n 2L f(n) = 2n log L p.76 f(n)= n2 which f ? see: transition matrix (Ch. 3.8) III 21 cyclic closure cyc(L)= x x x x L . { 1 2 | 2 1 ∈ } Thm. If L is regular, then so is cyc(L) guess middle, simulate halves in opposite order Q = q Q Q 0, 1 ′ { 0′ } ∪ × ×{ } middle, state, phase δ (q ,ε)= [q,q, 0] q Q ε-move ′ 0′ { | ∈ } δ ([q,p,i], a)= [q,δ(p, a),i] ′ { } δ ([q, q , 0],ε)= [q, q , 1] q Q ′ f { 0 | f ∈ } F = [q,q, 1] q Q ′ { | ∈ } Theorem 3.4.3 ⊲ In informal notation, (1) Note that the construction introduces x y ε-moves.