DEV Community

aanya0298
aanya0298

Posted on

What is the use of the Chomsky normal form?

Generally in the context of programming, we implement the use of the Chomsky Normal Form for creating the string objects rather than the context free grammar.

This is because the set of rules applied by the Chomsky Normal Form makes it easier for the system to understand the structure and thus it stores the data accordingly in the program.

These rules are predefined and they cannot be altered under any circumstances while we are making a conversion from the context free grammar (CFG) to the Chomsky Normal Form (CNF)

This is one of the main uses of the Chomsky Normal Form as you will see further in the blog.

Along with that, we have also discussed the conversion rules and the conversion process to give you a better understanding of the grammar.

What is the Chomsky Normal Form?

The Chomsky Normal Form which is also commonly referred with the abbreviation CNF, is the formal theory for the context free form of grammar.

You can understand the Chomsky Normal Form as a string of characters that has the following production rules:

A -> BC

A -> a

S -> é

In the context of the above mentioned rules, the letters A, B and C are basically nonterminal symbols.

Whereas, the letter a is essentially a terminal symbol. On the other hand, the letter S resembles a starting symbol and finally, the letter é is written for an empty string.

With that said, it is important to note that the Chomsky Normal Form is a context free form of grammar.

This essentially means that it can be mathematically changed into the number one where the size of the letters cannot be any longer than the exact square of the initial grammar's size.

With all the mathematical derivations that we have discussed so far, you might be wondering where the Chomsky Normal Form of grammar is basically used?

The next section of the blog will clear some of your doubts related to this question.

Where is the Chomsky Normal Form used?

The Chomsky Normal Form of context free grammar essentially allows the users to determine whether they can generate a string using a grammar.

This process has to be conducted by keeping in mind the rules of context free grammar. If you are interested in dynamic programming, then this algorithm would work the best under all conditions.

Henceforth, the conversion of a Context Free Grammar (CFG) into the Chomsky Normal Form is one of the ultimate uses of this polynomial time algorithm.

The main idea behind this is to make sure that the content rules of the grammar satisfies that CNF model.

There are several steps involved in making the conversion from Context Free Grammar (CFG) to Chomsky Normal Form (CNF), check them out as follows.

Steps to convert the Context Free Grammar to Chomsky Normal Form

Before you take a look into the steps, keep in mind that it is important to learn dynamic programming in order to make this conversion.

The Chomsky Normal Form works best with the principles of dynamic programming. Hence, learning about DP is absolutely required.

With that said, here are the steps for converting the Context Free Grammar (CFG) to Chomsky Normal Form (CNF):

Step 1: You will have to start with eliminating the starting symbol with the RHS. If you find that the beginning symbol is T from the right hand portion of the production, then you will have to form an entirely new production such as follows:

S1 -> S

Step 2: The next process involves removing the NULL, and the unit and all the useless forms of production . This method is essentially known as simplification of CFG.

Step 3: Afterwards, the next step involves eliminating the terminals of the right hand side of the production while considering the other terminals and non-terminals. For instance, you can decompose the productions S -> aA into S -> RA and the R into a

Step 4: This is the final step that involves a few more steps in order to complete the process of conversion.

For this step you are required to finally eliminate the right hand side with two or more forms of non terminals.

You can use the following derivations as examples:

S -> RS

R -> AS

Now, the process further involves a few more steps to be completed in order to form an entirely new production for the grammar 1 form. This is quite similar to the conversion process used in the Greibach Normal Form i.e GNF.

Here are the steps to convert this to an entirely new grammar production:

You will have to begin with creating an entirely new production such as S1 -> S. Here also the beginning symbol i.e S will appear on the right hand side

You will find that the grammar 1 i.e G1 involves an A that represents a NULL production. This form needs to be removed altogether from the grammar

Next up, you will also have to remove the production of unit from S1 -> S

In the third step for production, the terminals are required to be on the left hand side while the non-terminals can be placed on the right hand position

Also, keep in mind to remove the positions that consists of two or more symbols from the right hand position of the grammar

Finally, the grammar that you will be left with after performing all the required changes will be referred to as the Chomsky Normal Form

You might have observed that the CNF model or the Chomsky Normal Form uses the least amount of symbols for representing the grammar for the strings.

Keep this in mind while you are creating the conversion and you will be able to achieve the required result.

Final Thoughts

The Chomsky Normal Form and the Greibach Normal Form have quite similar rules for the grammar which is why, if you are acquainted with either of the models, you will be able to complete the conversion easily within a program.

If you still have a few doubts, you can refer to the step by step guide provided in this blog for converting the Context Free Grammar to the Chomsky Normal Form.

Top comments (0)