Home Â» Automata Chomsky’s Normal Form (CNF)

# Chomskyâ€™s Normal Form (CNF)

CNF stands for Chomsky normal form. A CFG(context free grammar) is in CNF(Chomsky normal form) if all production rules satisfy one of the following conditions:

• Start symbol generating Îµ. For example, A â†’ Îµ.
• A non-terminal generating two non-terminals. For example, S â†’ AB.
• A non-terminal generating a terminal. For example, S â†’ a.

### For example:

The production rules of Grammar G1 satisfy the rules specified for CNF, so the grammar G1 is in CNF. However, the production rule of Grammar G2 does not satisfy the rules specified for CNF as S â†’ aZ contains terminal followed by non-terminal. So the grammar G2 is not in CNF.

## Steps for converting CFG into CNF

Step 1: Eliminate start symbol from the RHS. If the start symbol T is at the right-hand side of any production, create a new production as:

Where S1 is the new start symbol.

Step 2: In the grammar, remove the null, unit and useless productions. You can refer to the Simplification of CFG.

Step 3: Eliminate terminals from the RHS of the production if they exist with other non-terminals or terminals. For example, production S â†’ aA can be decomposed as:

Step 4: Eliminate RHS with more than two non-terminals. For example, S â†’ ASB can be decomposed as:

### Example:

Convert the given CFG to CNF. Consider the given grammar G1:

Solution:

Step 1: We will create a new production S1 â†’ S, as the start symbol S appears on the RHS. The grammar will be:

Step 2: As grammar G1 contains A â†’ Îµ null production, its removal from the grammar yields:

Now, as grammar G1 contains Unit production S â†’ B, its removal yield:

Also remove the unit production S1 â†’ S, its removal from the grammar yields:

Step 3: In the production rule S0 â†’ aA | Aa, S â†’ aA | Aa, A â†’ aBB and B â†’ Aa, terminal a exists on RHS with non-terminals. So we will replace terminal a with X:

Step 4: In the production rule A â†’ XBB, RHS has more than two symbols, removing it from grammar yield:

Hence, for the given grammar, this is the required CNF.