Decidability of Finiteness of a Context Free Grammer

6
Decidability of Finiteness of a CFG Muhammad Saqib (14-Arid-1193) Tamur Sultan (14-Arid-1194) Zeeshan Masood (14-Arid-1213)

Transcript of Decidability of Finiteness of a Context Free Grammer

Page 1: Decidability of Finiteness of a Context Free Grammer

Decidability of Finiteness of a CFG

Muhammad Saqib (14-Arid-1193)

Tamur Sultan (14-Arid-1194)

Zeeshan Masood (14-Arid-1213)

Page 2: Decidability of Finiteness of a Context Free Grammer

Requirements before Deciding the Finiteness of a CFGEliminate all useless terminals from the grammar and check whether the grammar generates any word of the language or not e.g. we have grammar.

S XYZ aX ZZY BBB bA XA

Step 1: Replace All Z’s with a and B with b.S XYX aaY bbA XA

Step 2: Replace All Y’s with bb and X’s with aa.S aabbA aaA

Step 3: Here we can replace production S with aabb but production A have never been used in generation of any word of the language so it is useless and we will eliminate it before deciding about finiteness of CFG S aabbA aaA

Page 3: Decidability of Finiteness of a Context Free Grammer

Deciding about the finiteness of CFGCheck Nonterminal either they are self embedded or not. If any Nonterminal found self embedded then the Language is infinite. To Perform the check will follow the following steps. We have modified Grammar as

S XYZ aX ZZY BBB b

Step 1: Let here we check whether X is self embedded or not. For this purpose first replace all X’s on left side of all production with letter Ж. S XYZ aЖ ZZY BBB b

Step 2: Paint all X’s blue. S XYZ aЖ ZZY BBB b

Step 3: Paint all left side terminals to blue as well corresponding to blue X’s on their right side and then to all terminals for which they are on right side and so on. S XYZ aЖ ZZY BBB b

Step 4: Check the color of letter Ж at the end if had become blue or not. Here for Nonterminal X the Ж is not blue so X is Not self embedded.

Step 5: Repeat the above four steps for Nonterminal Y and S. If any one of them found Self embedded then the language generated will be infinite otherwise language will finite.

Page 4: Decidability of Finiteness of a Context Free Grammer

Example 1Let we have CFGS Aba|bAZ|bA XB|bZaB bAAX aZa|bA|aaaZ ZAbA

First we eliminate all useless Nonterminal.Here Z is going to produce again Z so it is not producing any word of the language. So, it is useless. The new grammar will becomeS Aba|bA XBB bAAX bA|aaa

Now we check self embeddedness of Nonterminal. Here we start from X.

Step 1: Replace all X’s on left side with Ж.S Aba|bA XBB bAAЖ bA|aaa

Step 2: Paint all X’s blue on right side blue.S Aba|bA XBB bAAЖ bA|aaa

Step 3: Paint all Nonterminal on left side corresponding to X blue as wellS Aba|bA XBB bAAЖ bA|aaa

Here A has become blue so all Nonterminal which have A on their right side will also become blue.S Aba|bA XBB bAAЖ bA|aaa

Step 4: in step 3 we can see Ж has also become blue hence X is Self embedded and the language will be infinite.

Page 5: Decidability of Finiteness of a Context Free Grammer

Example 2Let we have CFGS XY|bbX YYY XY|SSHere Y XY so it is useless.Now Replace S’s with bb.S XYX YYY bbbbReplace Y’s by bbbbS XbbbbX bbbbbbbbReplace X by bbS bbbbbbbbbbbbSo, grammar generates words of the language.

Now we check self embeddedness of Nonterminal. Here we start from X.

Step 1: Replace all X’s on left side with Ж.S XY|bbЖ YYY SS

Step 2: Paint all X’s blue on right side blue.S XY|bbЖ YYY SS

Step 3: Paint all Nonterminal on left side corresponding to X blue as wellS XY|bbЖ YYY SS

Here Y has become blue so all Nonterminal which have Y on their right side will also become blue.S XY|bbЖ YYY SS

Step 4: in step 3 we can see Ж has also become blue hence X is Self embedded and the language will be infinite.

Page 6: Decidability of Finiteness of a Context Free Grammer

THANK YOU