To convert a context-free grammar to Chomsky normal form, first add a fresh start symbol. Remove epsilon productions, retaining the exceptional start production only when the empty word is to remain in the language; then remove unit productions and symbols that cannot participate in a terminal derivation. Replace each terminal occurring in a right-hand side of length at least two by a new nonterminal that produces that terminal. Finally split every right-hand side of length greater than two into binary productions using fresh nonterminals.
Past exam of the mathematics course of the University of Cambridge 2018 ii Paper 3 4G b Solution Created 2026-09-24 Updated 2026-10-03
The standard conversion of a context-free grammar to Chomsky normal form proceeds as follows:
Add a fresh start symbol with .
Find the nullable nonterminals, add the variants obtained by omitting nullable occurrences, and remove all epsilon productions. Omit as well because the requested language excludes .
Remove every unit production by copying the non-unit productions reachable from to .
Remove nonterminals that are unreachable from or cannot derive a terminal word.
In every right-hand side of length at least two, replace a terminal by a fresh nonterminal with .
Replace each right-hand side of length greater than two by a chain of binary productions using fresh nonterminals.
Find the nullable nonterminals, add the variants obtained by omitting nullable occurrences, and remove all epsilon productions. Omit as well because the requested language excludes .
Remove every unit production by copying the non-unit productions reachable from to .
Remove nonterminals that are unreachable from or cannot derive a terminal word.
In every right-hand side of length at least two, replace a terminal by a fresh nonterminal with .
Replace each right-hand side of length greater than two by a chain of binary productions using fresh nonterminals.
Each remaining production is of the required binary or terminal form, and these transformations preserve every nonempty generated word. Thus .
Past exam of the mathematics course of the University of Cambridge 2019 ii Paper 3 4H c Solution Created 2026-09-24 Updated 2026-10-03
Introduce nonterminals for the terminals and one for the pair :Because the original start symbol occurs on a right-hand side, take a fresh start symbol . After eliminating the unit production , one grammar in Chomsky normal form isThe original grammar generates exactlyThe displayed grammar generates the same set: adds an on the left, adds one pair on the right, and terminates the derivation with . Since the original grammar does not generate ,
Past exam of the mathematics course of the University of Cambridge 2020 ii Paper 4 4F Solution Created 2026-09-24 Updated 2026-09-29
A context-free grammar is in Chomsky normal form when every production has the form or , where are nonterminals and is a terminal symbol; one may additionally allow the new start production when the language contains the empty string, provided never appears on a right-hand side.
The standard conversion proceeds as follows.
- Introduce a fresh start symbol and . This changes only when the old start symbol occurs on a right-hand side or when a protected start symbol is needed to preserve .
- Find all nullable nonterminals, add productions obtained by omitting nullable occurrences, and remove the original -productions except the permitted . This leaves unchanged.
- Eliminate each unit production by adding to the non-unit productions reachable through its transitive closure. This leaves unchanged.
- Delete non-generating symbols and then unreachable symbols. This is the only simplification stage that can shrink .
- In every right-hand side of length at least two, replace a terminal by a fresh nonterminal with . New nonterminals are needed exactly for terminals that occur in such mixed or long productions.
- Break every right-hand side of length at least three into binary productions, introducing fresh nonterminals for successive suffixes. New nonterminals are needed exactly when such long productions remain.
The terminal alphabet may be kept unchanged throughout, although unused terminals may be discarded by convention. Every stage preserves the generated language, with the explicit protection of at the start-symbol stage. For example,is already in Chomsky normal form and generates the infinite language , so its conversion may be the grammar itself.
Past exam of the mathematics course of the University of Cambridge 2022 ii Paper 4 4I Solution Created 2026-09-23 Updated 2026-09-25
A context-free grammar is in Chomsky normal form when every production has one of the formswhere are nonterminals and is a terminal. One may additionally allow when the empty word belongs to the language, usually with the restriction that the start symbol does not occur on a right-hand side.
In , the productions for giveConsequentlyIn , and generate and , while again givesSince , the two start productions generate exactlyThusEvery production of has the required binary-nonterminal or single-terminal form, so is the Chomsky-normal-form grammar for the nonempty part of .