Past exam of the mathematics course of the University of Cambridge 2018 ii Paper 3 4G a Solution Created 2026-09-24 Updated 2026-10-03
A context-free grammar is in Chomsky normal form when every production rule has one of the formswhere are nonterminal symbols and is a terminal symbol. If the language contains the empty word, one may additionally permit , with the start symbol absent from all right-hand sides.
Past exam of the mathematics course of the University of Cambridge 2019 ii Paper 3 4H a Solution Created 2026-09-24 Updated 2026-10-03
A context-free grammar is in Chomsky normal form when every production is of one of the formswhere are nonterminal symbols and is a terminal symbol. Under this strict convention there is no epsilon production, so such a grammar cannot generate the empty word. Conversion of an arbitrary grammar therefore givesIf , the two languages are equal. An alternative extended convention permits the exceptional start production ; under that convention conversion preserves the whole language.
Past exam of the mathematics course of the University of Cambridge 2020 ii Paper 3 4F i Solution Created 2026-09-24 Updated 2026-09-29
A context-free grammar is a quadruple consisting of a finite set of nonterminal symbols, a disjoint finite alphabet of terminal symbols, a start symbol , and a finite set of productions with and . A sentence is a terminal word over an alphabet with , and the generated formal language is .
The first language is context-free. For example, the productionsgenerate exactly : each recursive production adds two s to the left and two s to the right.
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.