Tehnishe Universität Münhen Winter term 29/ I7 Prof. J. Esprz / J. Křetínský / M. Luttenerger. Ferur 2 Solution Automt nd Forml Lnguges Homework 2 Due 5..29. Exerise 2. Let A e the following finite utomton: strt, () Trnsform the utomton A into n equivlent regulr expression, then trnsform this expression into n NFA (with ε-trnsitions), remove the ε-trnsitions, determinize the utomton nd then minimize it using the lgorithms from the leture. Chek tht the resulting utomton is isomorphi to the originl one. () Use JFLAP (http://www.jflp.org/) to perform the sme trnsformtions. Is there ny differene? () Let us denote Σ = {, }. Then L(A) = Σ \ Σ Σ. Prove tht A is miniml y proving tht no equivlene reltion on Σ of index t most 2 n stisfy x y w(xw L(A) yw L(A)) (nd thus onluding y Nerode theorem); omputing the index of L(A) (nd if it is 3 then onluding y Myhill-Nerode theorem); performing the Bisim lgorithm for minimiztion (nd heking the result is isomorphi to the originl utomton). Exerise 2.2 For n N let msf(n) e the lnguge of ll words over {, } whih represent n w.r.t. to the most signifint it first representtion where n ritrry numer of leding zeros is llowed. For exmple: msf(3) = L( ) nd msf() = L( ). Similrly, let lsf(n) denote the lnguge of ll lest signifint it first representtions of n with n ritrry numer of following zeros, e.g.: lsf(6) = L( ) nd lsf() = L( ). () Construt nd ompre the miniml DFAs representing ll even nturl numers n N w.r.t. the unry enoding (i.e., n n ), the msf enoding, nd the lsf enoding. () Consider the following FA A over the lphet {,,, }: strt
W.r.t. the msf enoding, we my interpret ny word w {,,, } s pir of nturl numers (X(w), Y (w)) N N. Exmple : (Underlined letters orrespond to Y (w).) w = () k () k ( k, k ) (3, ) = (X(w), Y (w)) Find onstnts, Z suh tht X(w) + Y (w) = for ll w L(A). () Construt the miniml DFA representing the lnguge {w {, } msf (w) is divisile y 3}. Solution: () Unry enoding: MSBF enoding: strt strt LSBF enoding:, strt, () We lel the sttes s follows: strt 2 We show y indution on the length of word w Σ tht for δ(, w) = q we hve 3Y (w) X(w) = q. Oviously, this will then imply tht 3Y (w) X(w) = for ll w L(A). Let l denote the length of word w (w.r.t. the lphet {,,, }). l = : We hve w = ε nd oth δ(, ε) = nd X(w) = = Y (w). l l + : We my write w s u with, {, }. Note tht we then hve X(w) = 2X(u) + nd Y (w) = 2Y (w) +. Assume tht δ(, w) =: q is defined, otherwise there is nothing to show. Then lso δ(, u) =: q is defined. By indution hypothesis we hve 3Y (u) X(u) = q. Assume q = q = : Then =, = hs to hold, i.e., X(w) = 2X(u) nd Y (w) = 2Y (u). Hene, 3Y (w) X(w) = 3 2Y (u) 2X(u) = 2(3Y (u) X(u)) = 2 q = 2 = = q.
Assume q = q =. Then =, =, nd X(w) = 2X(u) + nd Y (w) = 2Y (u) + susequently follow, leding to: 3Y (w) X(w) = 3 (2Y (u) + ) (2X(u) + ) = 2(3Y (u) X(u)) + 2 = 2 q + 2 = 2 ( ) + 2 = = q. Similrly, the remining ses follow. One n even show tht A epts extly those words w with 3Y (w) X(w) =. For this, let w = u e word suh tht δ(, u) is defined, ut δ(, w) is undefined, i.e., is the rejeting stte. Assume δ(, u) =. Then either = or =. We only onsider the se =, s the se = is quite similr. Then y our preeding result we hve 3Y (u) X(u) =, whih leds to 3Y (w) X(w) = 3(2Y (u) + ) 2X(u) = 3. Assume we dd letter xy to w. In order to lulte 3Y (wxy) X(wxy) we doule the vlue 3Y (w) X(w) nd then dd numer from {,, 2, 3}. Hene, 5 = 2(3Y (w) X(w)) 3Y (wxy) X(wxy) 2(3Y (w) X(w)) + 3 = 9, i.e., no mtter how we extend w y some word u {,,, }, we never will e le to otin 3Y (wu) X(wu). Similrly, one shows for the other ses of δ(, u) tht ll words leding to the rejeting stte nnot stisfy the liner eqution 3y x =. () The ide is tht the stte rehed fter reding the word u orresponds to the reminder of the numer represented y u when dividing y 3. We therefore tke s sttes {,, 2} with the initil stte nd define This yields the utomton: δ(q, ) = 2q + (mod 3). strt 2 Oviously, this utomton hs to e miniml s two different sttes enode two different reminder lsses. Note tht we lso otin this utomton from the one of () y forgetting (projeting) the y-omponent. Exerise 2.3 In the leture you hve seen the definition of the Myhill-Nerode reltion L for given lnguge L Σ : For two words x, y Σ we write x L y iff xv L yv L holds for ll v Σ. () Determine the equivlene lsses of L w.r.t. the following lnguges over Σ = {, }: L := L(( + ) ), L 2 := L(() ), L 3 := {w {, } the numer of ourrenes of nd in w is the sme }. L 4 := { n n n n }. () In the definition of L we ompre two given words y ppending ll possile words. Insted of ppending, we my lso prepend. Consider therefore the inry reltion L on Σ defined y For two words x, y Σ we write x L y iff ux L uy L holds for ll u Σ. Determine the equivlene lsses of L nd L2. Show tht L is regulr iff L hs only finitely mny equivlene lsses. Is the numer of equivlene lsses of L equl to the one of L? () Finlly, we my ompre two words x, y lso y ppending nd prepending ritrry words, i.e., define the reltion L s follows:
For two words x, y Σ we write x L y iff uxv L uzv L holds for ll u, v Σ. For x Σ let [x] L denote the equivlene lss of x w.r.t. L, i.e., [x] L = {t Σ x L y}. We write Σ / L for the set of equivlene lsses. How does L relte to L, resp. L? Determine the equivlene lsses of L2. Show tht the following multiplition on Σ / L is well-defined, ssoitive nd hs [ε] L s its neutrl element: Remrk : Σ / L is lled the syntti monoid of L. [w] L [w ] L := [ww ] L. Solution: () Reminder : For L Σ, the reltion L on Σ ws defined y x L y iff z Σ : xz L yz L. Let A = (Q, Σ, δ, q I, F ) e DFA. Set P (q) = {x Σ δ(q I, x) = q} for q Q. Oviously, for x, y P (q) we hve for ny word v Σ tht δ(q initil, xv) = δ(δ(q initil, x), v) = δ(q, v) = δ(δ(q initil, y), v) = δ(q initil, yv). s the utomton is deterministi, i.e., x, y P (q) x L y. Hene, the prtition {P (q) q Q} is refinement of Σ / L. So, if A is lso miniml, then we even hve x, y P (q) x L y. Hene, for lulting the equvilene lsses of regulr lnguge L it suffies to onstrut miniml DFA for L nd otin from it the lnguges P (q). L : q strt q q 3, q 2 P (q ) = L(( + ) ), P (q ) = L(( + ) ), P (q 2 ) = L(( + ) ) nd P (q 3 ) = L(( + ) ( + )). L 2 : q strt q q 2 P (q ) = L(() ), P (q ) = L(() )) nd P (q 2 ) = L(() ( + )). L 3 :,
q q 2 strt q q 3 q 4 It s left to the reder to determine the equivlene lsses from the DFA. L 4 : Although L 4 is ontext-sensitive, ut neither ontext-free nor regulr, the sme ide s for the preeding lnguges n e used, leit one hs to onsider n utomton with infinite numer of sttes (the rejeting stte isn t shown here): strt One esily heks tht ny two sttes re inequivlent. We otin the equivlene lsses: { k } for k, { k l } for k > l, { k+l k+l l l } for k, nd the omplement of the union of these. () For w Σ let w R e its reverse, i.e., the word we otin when reding w from right to left, e.g., () R =. For L Σ we then set L R := {w R w L}. It is well-known tht L is regulr if nd only if L R is regulr (exerise!). Consider the definition of L now: x L y iff u Σ ux L uy L iff u Σ (ux) R L R (uy) R L R iff u Σ x R u R L R y R u R L R iff v Σ x R v L R y R v L R iff v Σ x R v L R y R v L R iff x R L R y R. The ruil point here is tht u R is ny possile word s we onsider ll u Σ whih llows us to reple u R nd u y v. This mens tht we n otin the equivlene lsses of L from those of L R y simply reversing the memers of the equivlene lsses, nd we lredy know how to otin the equivlene lsses of L R (see ()). In oth ses, L nd L 2, L R i = L i, so we hve lredy otined the sought equivlene lsses in ().
It lso immeditely follows tht L is finite iff L is regulr, s L = L R nd we know tht (i) L is regulr iff L R is regulr, nd (ii) L R is regulr iff L R is finite. Finlly, we show tht in generl L nd L do not need to hve the sme numer of lsses: Let L Σ onsist of those words whose third letter is n. It is esy to see tht miniml DFA for L onsists of 4 + sttes; four sttes re required to ount how mny letters hve lredy een red, while the fifth stte is the rejeting stte. On the other hnd, L R onsists of ll words whose third lst letter is n. A orresponding miniml DFA hs to rememer the lst seen within window of three letters, leding to the equivlene lsses [ε], [], [], [], [], [], [], []: strt ε () Oviously, x L y implies oth x L y nd x L y. But in generl, L hs more equivlene lsses thn L or L. Consider for exmple L : We hve oth ε L nd ε L, ut ε L s ε L, ut () L. (See lso exerise 3.2.) In the se of L 2 one esily heks x L2 y iff x L2 y It remins to show tht the defined multiplition on Σ / L is independent of the representtive tken from the equivlene lss. Choose x, y, x, y Σ s.t. x L x nd y L y. We hve to show tht xy L x y : x L x implies xy L x y. (Set v = yv in the definition with v Σ ). y L y implies x y L x y. (Set u = u x in the definition with u Σ.) As L is equivlene reltion, it is trnsitive, nd we otin xy L x y. Exerise 2.4 Let Σ e n lphet. The set S Σ of str-free expression over Σ is indutively defined: S := Σ {ε, } S k+ := {(φ + ψ), (φ ψ), φ, (φ ψ) φ, ψ S k } S k S Σ := k N Sk. The lnguge L(ρ) represented y str-free expression ρ S Σ is defined s expeted: if ρ = L(φ) L(ψ) if ρ = (φ + ψ) L(ρ) := {ρ} if ρ Σ {ε} L(φ) L(ψ) if ρ = (φ ψ) Σ \ L(φ) if ρ = φ L(φ) L(ψ) if ρ = (φ ψ). To void prentheses, we ssume tht ontention hs the highest priority, followed y intersetion, then ddition. Some exmples: L( ) = Σ \ L( ) = Σ, L( ( + )) = {}. () Show tht for every str-free expression φ S Σ it holds tht L(φ) is regulr lnguges over Σ. () Give str-free expression for the regulr lnguge L(() ) for Σ = {, }. Remrk : There is no str-free expression for the lnguge L(() )!
Solution: () We lim tht Note tht L( ) = Σ = L(( + ) ). So we my write: L( ( + ) )! = L(()() ). L( + ) = L(( + ) ) \ L(( + ) ( + )( + ) ). This follows from strightforwrd indution on the term struture using tht regulr lnguges re losed under union, intersetion nd omplement. L(( + ) ) \ L(( + ) ( + )( + ) ) L(()() ): Consider w = () k for some k. Clerly, w L(( + ) ). Further, neither nor pper s suwords in w, so w L(Σ ( + )Σ ). L(( + ) ) \ L(( + ) ( + )( + ) ) L(()() ): Choose some w L(( + ) ) \ L(( + ) ( + )( + ) ). (Note tht this lnguge is not empty s it ontins the word.) Oviously, w ε. One now shows y indution on the length of w, tht the letters nd hve to lternte in w nd tht w hs to e of even length (s it strts with n, ut ends with ). So, w L(()() ). It follows tht L(() ) = L(ε + ( + ) ).