Finishing converting to Chomsky Normal Form from a CFG?

  • MHB
  • Thread starter Lolligirl
  • Start date
  • Tags
    Form Normal
In summary, the person is working on a question and is having trouble with something. They are worried about losing a word in their language. They might try to fix it by keeping the meaning of S the same.
  • #1
Lolligirl
23
0
Hello everyone! Here is a question I am working on:

Consider the context-free grammar G = ( { S, B, E }, { 0, 1, i, e, s }, R, S ), where R is:

S --> iBSE | s
B --> 0 | 1
E --> lambda | eS

Convert this to Chomsky Normal Form, showing all steps.


Alrighty, so I removed the lambda and got:

S0 --> S
S --> iBS | iBSE | s
B --> 0 | 1
E --> eS

And now I'm trying to remove the unit/chain rules and the rest, and this is what I have so far:

S0 --> X
X --> YS
S --> BS
S --> BSE
S --> s
B --> 0
B --> 1
E --> ZS
Y --> i
Z --> e

But I know S0 --> X and S --> BSE are not valid. From here I am a bit unsure: How can I fix this? Can I do this?

S0 --> YS
S --> BS
S --> BT
S --> s
B --> 0
B --> 1
E --> ZS
T --> SE
Y --> i
Z --> e

Thank you for any help! :)
 
Last edited:
Technology news on Phys.org
  • #2
Hi Lolligirl!

Are you still busy with this problem? (Wondering)

Lolligirl said:
S --> iBSE | s
B --> 0 | 1
E --> lambda | eS

Convert this to Chomsky Normal Form, showing all steps.

Alrighty, so I removed the lambda and got:
S0 --> S
S --> iBS | iBSE | s
B --> 0 | 1
E --> eS

And now I'm trying to remove the unit/chain rules and the rest, and this is what I have so far:
S0 --> X
X --> YS
S --> BS
S --> BSE
S --> s

Hmm... it looks like you have recycled S to mean something else now... (Worried)
But hold on!
The language in the previous step contained $S_0 \to S \to s$.
But your new language only contains the equivalent $S_0 \to X \to YS \to is$.
You have lost a word from your language! :eek:
 
  • #3
Oh! Could I fix it by doing this?

S0 --> YS | s
S --> BS | BT
B --> 0 | 1
T --> SE
E --> ZS
Y --> i
Z --> eOr maybe I'm nuts. :eek:
 
  • #4
Lolligirl said:
Oh! Could I fix it by doing this?

S0 --> YS | s
S --> BS | BT
B --> 0 | 1
T --> SE
E --> ZS
Y --> i
Z --> eOr maybe I'm nuts. :eek:

That would take care of the missing word 's'... but I do not think the reduction of the rules is right.

You started from:
S0 --> S
S --> iBS | iBSE | s

With your reduction, you no longer have the rule S-->s that could be applied recursively. Now it can only be applied once a the beginning. :eek:I think this will go better if you keep the meaning of S the same as it was.
Your might do for instance:
S0 --> S
S --> YU | YV | s
U --> BS
V --> BT
Y --> i
(Wasntme)
 
  • #5


I would like to commend you on your progress in converting the given context-free grammar to Chomsky Normal Form. It is a complex and time-consuming task, but your approach seems to be on the right track.

To address your question about the validity of the rules S0 --> X and S --> BSE, I would suggest looking at the rules carefully to see if they follow the format of Chomsky Normal Form. In this form, all rules must have a single non-terminal symbol on the left-hand side and either two non-terminal symbols or a terminal symbol on the right-hand side.

In the case of S0 --> X, the left-hand side contains a single non-terminal symbol, which is good. However, the right-hand side contains a non-terminal symbol followed by a terminal symbol, which is not allowed in Chomsky Normal Form. To fix this, you can introduce a new non-terminal symbol, say V, and rewrite the rule as S0 --> V. Then, you can add a new rule V --> X to maintain the same meaning as the original rule.

Similarly, for the rule S --> BSE, the right-hand side has three non-terminal symbols, which is not allowed in Chomsky Normal Form. To fix this, you can introduce another new non-terminal symbol, say U, and rewrite the rule as S --> BU. Then, you can add a new rule U --> SE to maintain the same meaning as the original rule.

Overall, your approach to removing unit/chain rules and the rest seems to be correct. Just make sure to carefully check the format of the rules in Chomsky Normal Form and make necessary changes as suggested above. Keep up the good work!
 

Related to Finishing converting to Chomsky Normal Form from a CFG?

1. What is Chomsky Normal Form (CNF)?

Chomsky Normal Form is a standardized form used to represent context-free grammars (CFGs). It is named after linguist Noam Chomsky and consists of rules that are either in the form of A → BC or A → a, where A, B, and C are non-terminal symbols and a is a terminal symbol.

2. Why do we need to convert CFGs to CNF?

Converting CFGs to CNF makes them easier to analyze and manipulate. It also allows for more efficient parsing algorithms to be used. Additionally, many theoretical results and algorithms for CFGs are only applicable to CNF grammars.

3. What is the process for converting a CFG to CNF?

The process involves three main steps: 1) eliminating ε-rules, 2) eliminating unit rules, and 3) converting remaining rules to the form A → BC. This may also involve adding new non-terminal symbols and rules. The resulting grammar should have no ε-rules or unit rules, and all rules should be in the form A → BC or A → a.

4. Are there any limitations to converting CFGs to CNF?

Yes, not all CFGs can be converted to CNF. For example, if the CFG generates the empty language or if it generates strings with only one terminal symbol, it cannot be converted. Additionally, the size of the resulting grammar may potentially grow exponentially.

5. How do I know if my CFG is already in CNF?

A CFG is in CNF if all its rules are in the form A → BC or A → a, where A, B, and C are non-terminal symbols and a is a terminal symbol. It should also have no ε-rules or unit rules. If your CFG meets these criteria, it is already in CNF.

Similar threads

  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
29
Views
5K
Replies
3
Views
2K
  • Advanced Physics Homework Help
Replies
9
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
  • Atomic and Condensed Matter
Replies
4
Views
2K
Replies
1
Views
1K
Replies
1
Views
1K
Replies
1
Views
1K
Back
Top