Download as pdf
Download as pdf
You are on page 1of 29
Normal Forms jor CFG ai G= (wt, Ps) . Productions in & satisty certain reshichons Art, AEN, ce (vuT)* Two of them c Chomsky Abrmal form (CNe) L— Greibback Normal form (GNF) Chomsky Normal form (Restrictions on the lengtho? RUS and nature of symbols in RUS of production ). A CEG G is in CHE, if every preducton is of the form Avo or ASC ond SE isin G Ht EELS) When £ €1(4) we assume that $ doesnot appear on re RHS. of ony production Emramples se ABle, Ara, Bob + For o CFG in CAF, the porse tree has the Jollowima Property a Every rode has at most two descendants, -cither Hoo intemal vertices os a single leay Reduction to (NF Enample + $4 Apclac, Axa, Gov, Ce © SPABC , is not inthe required Equivalent crG Replace them by S29 AE, E> Be Sr AE, E>RC, 59 DC SAE, E> B¢ pea, Axa, Bee « $4 al is nok inthe requised fom cee Reploce them oy Spe, Da Theerem (Reduction to CPN) For every CFG , there ib an equivalent grammar Go in CNP Prop Stept: Elimination oF null productions and unit productions 4 encept jor 52£, if E€LLG) and S doesnt appear on R-H.5- of ony productions Let G= (wT, PS) ve the sesulking CPG Step 2: Elimination of termmals on R-H> We define G,= (vit Fs"), where Pand 6’ ove constructed as yellows: D AN productions of the Jorm A> a or A*6¢ one included inp’. All variables in V ave included in V’ #) Comsjdet A> %%_ -- Xy With some terminal in RS. Ty x; is a terminal , say ai, add new variable Co te Vv and Co; > aj in P Tn production A+ %%,--. Xn) every terminal on the RHS. is teploced by the corres ponding new voriable and the variables on the RS are tetained. The resulting production is added to P Thus we get G+ (vet, #5") Steph: Restricting the numbes of variables on R-H-5. For an production in P the R¥-S. consists of either a single terminal lov £,if 5-22) oF two oF more variables. Define G+ (v",7, P”, S ) 05 Jotlows: i. AN productions in P' ave added 40 PB Hoey ave in the Tequited form . All variables in V' ave added to V" ® Consider ASA Ar.-An when n%, AC ev We intvoduce new productions A+A,Gy> C AzCay--~ Cora @ Ans An ond new variables Cros, 07° Cnn These ave added to P” ond V" sespechively. Then Gy (vst, 9") iethe required ene. Example Reduce ‘the following grammar G to ONE. G 1% SAAD, A+ ab] bAG, Bob, Dod Sols: reps: Step2: No null productions o7 unit productions Bb, D3d ave included in Pp’ S27 aAS gives vise to $9 GAD, Cgod A> o® gives vise to A> CB, A> bAB gives tise te A> CLAS, Gb G's (vines), vie fs, Ae.d, Cas C3 Pe $$ 5 CoAb, A» C,8/C,Am, Ob, bd, Cara, Cyeobs Step 3 i. A> CoB, G2 vb, D>d, Cara, CL—>b, ave included in Py he 59% Co AD is replaced by $4 Cot, CAD A> LAB Is seplaced by As ee,, 62 >AB Ga = ( £50, 0.8, core Cert, fared}, Ps, §) where Pee f $> Cots, As CoB] Cue, , C9 AD, Co DAB, B+ b&b, bed, Casa, > b} SP le my (CNG Ged te equivelent > G. Step 4: Claim: L (4): LLG.) Te complete the proof we heve to show that Llg): bla)+ bls) To prove U4) & b(41) Let well4). Ty A» %%--- Xm te used in the derivation of w, the same effect con be achieved by woing we comespording productions in F* ond the productions inthe new variables. Henwe, A &» Hy Xp eee Xwe Thus, bo) eb tan) To prove tla) ¢£ Ll4) Let w ella) To show we L (4), it 1 enough to prove A pei Rev, A 3 —— We prove it by Induction onthe number of step in P S ‘Pe Adw oy Bases ; 5 Caen As w isin P ‘ By construction of P',w iso single termined. 50 Aswin Pte. Awe Induckion step: Let us assume or derivations in at most K steps. ‘ tet A ow 4, We can split this derivation as « => W.-W Fw Ap Ailes An oy « St Ay SD wy . i. either in V, oF Now each Ai is i. o new variable , Sey Cay * % when AreV, then A, > wr 35 @ desivakon in at , wost k steps, 0 by induction hypothesis . * Ai Que when Ai = Cai, the production Cay > ay is je applied to get pi S$ wy % “The production A+ AvAz s+. An in P's induced ley @ produchon A+%,%,-- Xm in 7 avhere. Xie ay if AieV Ker Ace Ca So, A > AKe - S x Kn Sy boptwg-. We te A dw a Thus @) is tre forall derivatons Leg) LLG) To prove L4,) = LCG.) The eqject of applying A> ArAr-~ Am ina derivation jor we Ll4,) can be achieved by applying the productions A® AVC, GS Ares, - + Curia > Ama Am Hence it 19 easy tosay thet L(g.) ¢ La) To prove Llbs) ¢ l6,), we can prove an auailiory aesult A dw ilpnev’, ADw (2 G, 42 (2) com ve proved by induction on the number of steps iW A Dw % Applying G)it 5, we get Lla,) ¢ bla). Enomple: Find @ grammar in ONE equivalent to 57 aAvB, Ar ahla, 85 bb)b Solt: > No unit production, no null preductons + eliminate terminals on R-H-S Let G,: (Ww, fobs, ?,,5) where V, ond PR ave constructed as jollows: i. Kea, Bb ove added +o P, » 97% aA, Arak, G+ bb ayield> S> CoAC,&, A> Cah, 2 CyB, Cao, Cyab which ore added to Pr Vie [S,A, 0, c0,Co$ » Restrict the number of variables on Ret-d. R consists of S> CoACy®, A> Cad, © Com, Comm Cheb, Ata, tov Let 63-(\s, farbd, fe, 5) where , and Vs ore const ucted ad: i $9 CoACEB is teplaced by S>Cal, >A, C,> Sob Which ave added to P,. i Remaining productions in P, ave added to fe Nye 48, A, RCo, Cy, Or, 023 Example: And o grammar in CAF equivalent to the qrmmar oe es] T2557] Pla fs cand he only voriable ) S0)2: + No unit preducHon® , vo null productions + Eliminate terminals on R-H-S- Let G,2[w, TP 5), where Pi,V, ore constructed a> Follows: | 8% b, $94 are added +o P, ii, So% ~S induced S3AS, A> ~ | wohichare added +o P, fi $5 [s>5 s] S> BSc sp, induces G+, c5 >, Bs] which are added to P, + Restrict tne number of variables on R-H-d Let G,2 (Va, Ts Per $) where P, ond Vo ove constructed as . - consists of o>plq|As, AM ~, BAL, c+ 9,05] 4 B5C5D is seplaced by S> BC, C,-> Sea, Co Cog, C43 SD which are added to Py Np © $9,A,0,C,Dd, Cr, Ce, es3 Go in in CANE omd is equivalent te the given qramm ar Grei bach Normal Form (Qn) Useful iw some preet> and constructons eg. cea qoverated by pushdown automata is in ane) Dejinition + A cha qe (VT.P.5) 39 in GNF IP every production is of the Form Asan, where aéT and Kev" (& moy be £) and $5 € isin G if € € LUG) When €€L(4), we assume that S doesnot appear on the Rs. of any production - 2.9. S» aABle, A> bC, BS, CHC isin GNF Lewma 1} Let G- (WP, 5) bea CFG, Let A+ a, Ba, be an A- production in P and &+ B,|Prl-~|Pr be the set of all B- productions. Let G,=lv.T, A, $) be obtained from G by deleting the production A> a, 82, yrom Pond odding the product on A> ap, «| apits | -- [4 Brae Ther, L(al= LUG) Froo}: To prove Ll4) £2(4,) Let wert) Ty we epply A >a, Be, In the derivation Joe weElla), then we have to apply B> Bi jor some i ata later step. Also note thet A+ A Bax, is the only production in Gel na The efPect of applying A>% Be, ond eldminating 6 iw grammar G is the same as applying A> Ki Bins Jer some 2 in G, Hence we LLG,) To prove La) ¢Ll4) Instead of applying A> lyBiety ina derivakion of G, we can apply A> %, Ba, and BB in G to get A 3 Ay By ty 6 Geass vy well) and A + a, Bir, is used for the derivative of w, then by Teplacing the single AS KB A, by two steps A> aga, ond B+ 8B; in the derivative of w, we obtain we Ll) Hence LLb,) ¢ LLG) Lemma 2 bee Gu 647, 4) be w CEG. Lol the ack oF A-productions be Ar Ax| Acs] --- LAr) Bi] Brl--- [Bs Let Z be a new variable. bet G,- (vu te} 7, Pe 5), whese eC is defined as follows: i. the set of A- productions in f, ove Aw | Pel--- [Bs ba pel poe] [Pee Wl. The sek of r- productions in P ase. Z-> a, [oy] «-- lay zo yz] oz] -- Joy2 8. The productions qor-the other variables ave as in Q. Then Gis a CFG and equi valent to G ie. L(g)= tla) Poot Tm @ leftwost derivation, o sequence of productions of the Jorm A> Aaj must event end with a production Am Pi The sequence of replacements in § Ag Aa, Aa, a, z 2 A Acptin yes ay, ZB ip Heyy ss a con be teplaced in G, by A= 8)2 > B) 4,2 5 Aig ay 4 8; ea B3 tp a B Aip Atp, Z a Bs Ap ip, --- m2 : Ps Aipaip., --- Aisa, The reverse tvansjormation can be also made. Thus L(G) = Ll4,) A A A Ak rs A “ ip . 7 “ip oe % Example: Apply LemmaZ te the Jprlowsing A- productivity in @ CFG G. A> abp| bdo} A> ABlAL io i _ | gol": G> WTP) > Geli 7, 9,5), vie vufe} P: “4. Asa 0d |edelc A- produckons A> & lf) Bs A> abbz |b Dbz | cz p> palpez) pz H.z> wld 2- productions 22 bzlb2 25 ala, ZaKz laze Theorem (Greibach Alormal form or GNF) Every CEL L without can be generated by @ CFG Jer which each preduction is of the form A> aa, where A is o terminal and & is a (possi lly empty) Shing of variables. Proo}s (Construction on COG im Gil) Steps: Eliminate null productions and then construct a grammar G in enf generating | We sename the variables aF Ay Az --) An with o:A, Let Gs (fAnAsy- And, Tf Av) Step2: (Modify the productions sothal & APs AT is @ production, then pri) Starting vith and proceeding yo we do this as gellovs* ye) Assume productions have been modified 50 that jer hier ZK, Ai > Ayf is 0 production only Fj >) We now modify the. Ay productions (Apply lemme }) + Ty Ay AGL is @ production usith jek, then we generate @ new set of production® by substituting jor Aj the Rus. of each A, - productions according +o Lemme l. te. we temove Ar A,f and ada productions Ay > et Fes all As~ productions A, > B as \ek, APPR satis yies *%? Repeating the process K4 Hummes ot most, we obtain productions of the orm Ay > Ail, Lyk Step 2: (Apply lemma 2) + The production with I=K ave then replaced according t+ lemma 2 , introducing a new variable Z fe. we remove each Ay > Axl, and productions Ze, 2 > (zx and jor each Ay, where § doesnot start with Ay, we add production Ayo pz . By repeating the above process jor each original varvialle, we have only productions of the jorm: t% AL AY, jrt We Ri aaf , aeT * eZ > 6, Fe (We faye zed) Any An- production is of the jprm An>a where 2ET as Anis the Wighest numbered variable Steph. ( Modify A-productions to the jomm Ai rat yor ts 2,06 nt wring lemma 4.) « An productions are of the Jer An of + Any productions are of the porno! An» > at! ov Ang Bey’ Eliminate production Ana Anf by using lemma lL. The vesulting produstions ove in the required jorm - . Repeat the constuction by considering Aw» Anes, . a Step 5? (red $y Z- productions using lemma 4) + Zr productions ave of the Jorm Zi-al or Zi Ant Jor some K- Remark : Tt is not necessary +o convert all the productions fo the jorm vequired jor CNP in the 1% step. We may allow production s of the jomm « AFA where aeT, wev*™ 5 AK where KEV" with Jal 7D Remark A CFG in GNE generates @ CFL without £ Enample: Cowerk the grammar 57 AB, A? Bs\e, 8 sala Into GNF. Sold: step: No mull productions» cné dename variable: Air S, Aare A, Ase @ productions ave. Ai-> AAs, Ar—> AsAy \v, Aso Aids la Step 2: 1 Ay productions A, Ar As ie in sequired jpn iis Ay productions A, AsA,\& ove im the required Jorm ih Aga isin required form Apply Lemma l to Ags AsAr teplace Ag > AiAa by the Jpllowing, productions Ag AAs Ag as A, A2As is an Ac productions Apply lemma L again +o Da > AsAsAr Renulting productions ove Ag> AsAr Asan |bAsAn Thus Ag- productions are Ag > a| ASA As Ay [BAS Step: Apply Lemma2 to As Ash: Ashe introduce @ new Variable Zs the resulting productions are: Aa al bASA |aza|bAs A222 Za > ArAsAr) AsAsAg Zs (aso ple | P23] Zs, Z37> AilX2s) Step ys |. Ag- preductions ave Ag > al bAsAs)azs| bAsAc Zs a —— w Age productions are Ar > AsA,\> + We retain A, +b + We replace A, > AsA, using lemma 1. The vesulking productions ave. A, 2 aA, |bAs ArAs lazad, |b AsAa ts hy The set of all modified Az ~ productions is [aa > b]oA, | eAsAs A, | azsAs | BAS AD Zar Th. Ay productions are A, >? AAs Apply. lemma l to Ar? AaAs te qe Ay > bAw|aA,As| AAs AAs JazsAAs | bAsAa2s AAs Sep S$ The Zs- productions ave Za> A, As 22 AAs Ar Zs Apply Lewmal +o modify 2y- productions The resulting Z- preductions are Za > bAsAsA:) aA, AsAsAs | DASAa AAs Ash | AZsArASAsAa |bASALZ3 AAs Ad Emomple: Construct a CF in GNE equivelent do the CtG S>AAla, A> S$\b Self: Step: No mull productions, the CFG isin ONE Rename the variables: Ars 5, Ape A Se, the productions are: A,» A, A, la, Ag? ArAlb Step2: 1 Ay productions ove im the sequired tom. They ove Ay Ar Az |a 2. Ay —->b is inthe required form. Apply lemma t fo Ag > Ar As As A, > AsA,|a ove Ay- productions, we teplace Ag > ALA, by the JPllowsi ng productions : A, > ALA, A, aA, Thus Az- productions ove A, > b] A AAs ors Step 3: Apply Lemma to A, -7 A2A,A: + Tutreduce 0 new variable 2 + AL AAA, 1s xeploced by Ap 262; ]oAr22 a ALA | ALA, 2 Step 4: | Ay- produckons ave A, > b]aA,| bz, |aAiz2| —@ Ai- productions ate AL ArAla We vetain A, >a We replace A,—> ArAd using Lemma 1 and get the Jpollowi ng productions A, bA, | aaa] b25 As |aAs2sAn The set of all modified Aj- productions are [> -> alba, |aAA,| bz,A, [04,242] — 9) Step 5 Modify Zg- productions using Lemma J Zy productions Z, 7 AsAr|AsArZ ave replaced by the followin Z, vA, [aA As] bz, A, | aA, 2, Ay producti on 2 baz, |aAMizs| bz, Arze | aA, ArZy_ Heme the equivalent grammar is G's (tay as, 23, tabs, @, Ar) where P, consists of Ay- productions, A>- productions ond Z,- productions given by 0,0, @ tespectively Rishdown Aviomata (Ppa) tequley expression a» FA pea) content-free qrammay «—> PHA (non: deterministic device) * Deterministic version accepts only a subset of al) CFls Enowple: Le \orte |n>f is not a regular Leon be shown using Pamping Lemma), but isa CFL as the CF4 5% abv lab generates Lb + A EA cannot accept Le for [nor] as it has to remember vumber of o's inthe string and soon infinite wumber ef states + Wis difficulty con ve avoided by adding an ounilliary memory im the jorm of a stack a F\fusw we ab in the string ave added to $ 2 (fuse a) stack 5 When b 35 encountered inthe input shing an a is temoved from S LPoP o) Thus matching of the numbers of o's and of b's id accompli shed PDA is essentially a FA with control of both an input tape and a stack. Definition (Pea) A pushdown automata MM is a system (82,1, 45, 2, F) where 1. GO ie @ dite set of states 4.2 is om alphabet , called the input alphabet %. [is an alphabet, called the stack alphabet - Lo in & is the initial state -2Zo wf ito particular stack symbol called the. Start symbol: FSO is the set of final states 4. B is a mapping from Qx(Lufej)xl a Puite subset oF Oxtt no + a boa £ [Tall 3 Le talk Pushdown store LPPS) + lower case letters near the front of alphabel Ly input symbol + lower case letters near the end of alphabet Lrctrings of input symbels . Capital letters stack 5 wmbe) Greek letters —y string of stack symbbols Moves b(tazd= Flb.G), Ure t)-.- [per Godt where q ond bi, tetem ove states afZ, 2isa stack symbol and Gq enm*, letem . Inter pretation of §(4,0,z) * PDA is olela cats. input symbel a and z is the top Symbo} on the stack. + Com For any, enter state Pi, replace symbol 2 by (, , ond advance the input head one symbel * Convention - leftmost syrnloe) of (wi be placed highest on the stack and the Tightmost Symbol lowest on the stack zy te WP fs ty --. zy then 20 + Interpretation of $14, €,2)+ [Cboti)--- (pmted ~ PDA in state ¢ , independent of the input Sy mbo) being scamned and with the top symbol on the Stack, Can enter stete b: and teplace Zz by ft fer any —In this case input head is not advanced. Enample: Let M+ (8, 8,1,8, 40,25, F) where. GO: ft. aay t,o. fod, re ja, 26] fF: £453 ond 5 is given by SL 4., 9,25) = $040, 0,209} 514, bade fla, £3 5anae)s {4,009 8 (%,,8,20): fla, 6 64, boa)= $4.94 + PDA cannot take transition when PbS is empty. In this case the PDA halts. + The behaviour of PRA is non-deterministic ad the Hransition given by any element of 5l¢, a2) a, 2.]aZ— b, ale & aloa & ee Tnstantaneous Desetiption (1b) Let M+ (8,£,1,6,40, 2, &) bea PbA An instantaneous desctiption (1b) is @duple (4, w. 1) where q isa state, w isa string oP input Symbols and {isa string of stack symbols. Move elation (1.0m, 24) Fe (p. wpa) if 5(4, 0,2) contains (pp) (a may be £ oF on input symbol) ch oe + if we 82% On , Ae Zye-. Zm, Pet te-- Ye [3x | = Pa Ea An illustration of the move telalion Relation ee [Reflenive and transitive closure of zr) «IT Hao I qr each Ib 1 © T ta To ond T by K imply 7 Kk Note: T E-k if ID 1 can become K after enactly t steps Note: tq» ta, a subscript Mis dropped ? PhAM is understood Accepted Lonquages + fora PDA Mz (8,2,1, 6 4, Ze, F) we define LIM) the longuage accepted by the qnal state ad i» (4%, 10120) ee lp £7) fev some b we and fT In if { + We define NIH), the language accepted boy empty stock (mull stack) to be 5 aw | UYe, 020) = Lp) gor seme P in af + When acceptance Is by nul) stack, the set of five! states is \elevant, and in Ws case, we usually let the set of Pinal states be the empty set, 1:¢) 2 a a) re las, € p) FP por every yes” (asay, 2) FH (4254,P) “tt (4, aya) —— (Eos er) then jor every per (4, %, ep) H— lqe tp) + Converse is not tre Enample: The following PDA accepts j ww8 | w in tony* f Me ( f,4,5, ford, {R.%43, 5,4,, RB, +) Ri: Slt.0 R= § la, ORF &: & yu Re fla, aert fo: & [t,o Be Fla, 08), la, €9$ hur 8 (44,0,6)2 {A 0495 Rs: & [a1 B)= flu, 6893 Re: 8 (4nn G) = £ la 647, las, €)} Ry: & (4,,0,0)+ 414, 6} Rs: & (444 a) = $l, Bes Caner) tae) Ry: & (44,8, Re fae, 294 a + R.- Re allow 40 store the input on the stack initial (4, genes, Re) (4,,00100,) halt _ , OR) l cue (44,1100, R)->( 2yo1120,2) halk (4%, 00, 86R) L (4%, too, Gea8R) 42, 00, BER)-»(% » 0, (4, 00, G4 OBR) (12, 80 (% eee) L (a,,€, 2) (4,,0, 864 8eR) (42, €,4986n) (42, €,¢) 4 (4, £, 6044 BBA) Wale accept Example: Construct @ PDA M accepting the set of of strings over fae} with equal number of o's and b's 5012: Let M: [ #23, faves, $Ze.ab}, § 4,2, +) where & 3s defined by the following aules ° (4,0, 2) = £ (4,024 5 (4,% 20) §$ (4, b209} $ (4,0,a) 2 §t4,a074 5 (4, vw) = $4,003 new incomin: ser ee lyme! 5 (4, % wd (9, ¢)} (b is evased in PDS) Sla,ba)e $a, 2} [ais erased in Pos) Slaez)> fla, oF (4,0, 2) HY ([9,¢,2) F— (2, ee) if ao has equa) number of 0's amd bos Hence w € A(m) Enomple di Ms { 1468, te,b1, $203, 5, a5, 2:, +) where 5 (40,a,20): $40, 4} , 8(4,b, 20)= $l 4%, 2020)} (4, aab, Ze%e%e%e) F- (40, ab, zoz020) F (4%, bs zoz0) (4, €, 22 Zz) But (4, aab, 2) t (4%, ab, €) Thu: + (ag, aab, 2e2Zez») H— (40, €, Ze220) but (4, nab, 202022) we (to, £, 20 20) bt ( Fo, abe, Zot) a € Example 2+ Me [45% dy5, farbie}, Save} , 5. te 20, $453) is a PDA, where 6 is defined as: 5(40,0,26) + fl%, a2}, Stee, 20) = § (4, 20% 54, a,0)= f (40,0004 $l, ale § (40) ba)} Siete Or ae ie GUA) © oo las ibis) = ities Ub)s 8 (4, cad: Ela, a)§ $ (40, eb): {lb 5 [4,0 2)+ f(e,200$ $ (tare): Blt) 8 (4,,£, 2)= $l 4, 2093 > fave] M accepts L= fwew|we fae} 4 oy final state. tee LUD: Lb + (42, vaceb,ze) tT (4%, acab, b20) t (te, cab, alozo) (4, , ab, abe) & [4,, b, bze) & [w, € 2) & (a, €, 20) te. (o, vacab,ze) — (4%, €,20) Proceeding Ina similoy way | we can show that (40, wew®,2,) [ 44, 20) ¥ we farb3* nee Le Savew® lwe favs’$ ¢ vim) Reverse inclusion is also true- © (4, abebb, 22) F- (40, bebb ,a20) t— (4, cb, azo’) E (4, bb, baz.) — (4, b, a2) * PDA nalts when it is in ID (4, b, ¢2) as Sla,be) 2 > + AS $l 4062022 ¢, the PDA connot make ony trom sition iP it stants with an IDoP the form (4, cw, 20)

You might also like