0

Hello I would like to ask you this question.

I was supposed to compute (manually) a grammar in Greibach Normal Form, that generates the language

L = {ai bj ck | i + j = 2k and k >= 1}

I really have no idea. Can someone please help me?

Thanks in advance
Chriss

Grijesh Chauhan
  • 57,103
  • 20
  • 141
  • 208
user2799534
  • 183
  • 1
  • 1
  • 7

2 Answers2

1

Context Free Grammar CFG for your language La = {ai bj ck | i + j = 2k and k >= 1}.

Below is answer with language L = {ai bj ck | i + j = k and k >= 1}.

CFG:

S --> aAc | bBc |
A --> aAc | B   |  ^
B --> bBc | ^ 

What is GNF?

One important form of CFG is Greibach Normal Form GNF:

   A --> aα   
   Where α ∈ V* (any number of variables including zero)

Note: nul ^ can't be a symbol on RHS of any production accept start symbol S with constrict that if S --> ^ is a production in grammar then S can't be appear on RHS of any other production in grammar.

Any CFG can be written in GNF form.

How to convert CFG in GNF?

Note in CFG I written above have nul productions A --> ^ and B --> ^ and a Unit production A --> B. Unit productions and nul productions are not allowed in GNF form. Although other productions can easily written in GNF form by introduction in GNF productions in grammar e.g. S --> aAc can be rewrite as S --> aAC and C --> c.

So below I am rewriting equivalent CFG for language and removing nul and unit productions called simplified CFG.

Simplified CFG:

S --> aAc | bBc | ac | bc
A --> aAc | bBc 
B --> bBc | bc

Now this grammar can easily converted into GNF form by introducing new GNF production C --> c and replace c by C in other production rules.

GFN for language L:

S --> aAC | bBC | aC | bC
A --> aAC | bBC 
B --> bBC | bC
C --> c

By mistake I written a wrong grammar I will update answer for language La

Edit

La = {ai bj ck | i + j = 2k and k >= 1}.

CFG for La:

S --> aaAc | bbBc | abBc
A --> aaAc | B    | abBc |  ^
B --> bbBc | ^ 

Simplified CFG:

S --> aaAc | bbBc | abBc | aac | bbc | abc 
A --> aaAc | bbBc | abBc | aac | abc
B --> bbBc | bbc 

GFN for language La:

Add three new production rules: X --> a, Y --> b and Z --> c.

Change programmer and replace terminal by variables:

S --> aXAZ | bYBZ | aYBZ | aAZ | bYZ | aYZ  
A --> aXAZ | bYBZ | aYBZ | aXZ | aYZ
B --> bYBZ | bYZ
X --> a
Y --> b
Z --> c
Taryn
  • 242,637
  • 56
  • 362
  • 405
Grijesh Chauhan
  • 57,103
  • 20
  • 141
  • 208
  • Many thanks, but actually the resulting grammar doesn't produce the language. i.e. S->bC-> bc is not contained in the given language. And there are words that belongs to the language that I can't produce, like "abc" – user2799534 Sep 21 '13 at 14:01
  • @user2799534 ok check updated answer, let me know if there is any mistake. – Grijesh Chauhan Sep 22 '13 at 05:46
1

About Below answer CFG of La = {ai bj ck | i + j = k and k >= 1} is wrong

Your Simplified CFG:

S --> aAc | bBc | ac | bc . A --> aAc | bBc . B --> bBc | bc .

Because the above language L = {ai bj ck | i + j = k and k >= 1} produce the language aabccc but your Simplified CFG not produce it .

Right CFG is

Simplified CFG

S --> aAc | bBc | ac | bc A --> aAc | bBc | bc | ac B --> bBc | bc

Correct it, Second language has the same problem.

Thanks!

Sohaib Aslam
  • 1,245
  • 17
  • 27