Chomsky Normal Form
Context: FIT2014_MOC Β· the binary-tree normal form for a CFG β the enabling hypothesis for both CYK and the CFL pumping lemma Parent Framework: Context-Free Grammars (CFG)
Quick Revision
- π― Objective: rewrite any CFG so every rule is (live) or (dead) β every parse tree becomes binary, which is what makes tree-height arguments and table parsing work.
- π¦ Core Components: live production β exactly two nonterminals | dead production β exactly one terminal. Nothing else is permitted.
- β‘ Key Constraint: CNF generates the non-empty words only β is handled separately by the nullability algorithm.
π The theorem
Theorem. For any context-free language , the non-empty words in can be generated by a grammar in Chomsky Normal Form.
- Why it matters β two later results are stated for CNF grammars and inherit their generality from this theorem: the polynomial-time CYK Algorithm, and the Pumping Lemma for Context-Free Languages.
- β Name clash β Chomsky Normal Form (grammars) vs Conjunctive Normal Form (propositional logic). Same acronym, unrelated objects β the exam exploits this.
π How It Works β the five-step conversion
1. Eliminate -productions
For every rule : for every other rule with in the body, add all rules obtained by deleting some subset of the occurrences (keeping the original), then remove .
| old rule with in body | new rules |
|---|---|
| , | |
| , , , | |
| , (a new -rule β repeat the step) |
- Iterate to fixpoint β the step creates new -productions; stop only when none remain. Invariant achieved: no rule has an empty RHS.
- Housekeeping (optional, simplifying) β a nonterminal that now never appears on the left of any rule can never be replaced, so every rule containing it on the right is dead code and may be deleted.
2. Eliminate unit productions
For every rule (nonterminal to single nonterminal): for every rule with on the left, add the same rule with on the left (keeping the original), then remove .
| old rule with on left | new rules |
|---|---|
| , | |
| , (unless was already handled) | |
| , |
- Invariant achieved β every RHS is either a single terminal or at least two symbols.
3. Give each terminal its own nonterminal
For each terminal , create a fresh nonterminal and the rule . (Terminals β , .)
4. Purge terminals from the long rules
In every rule that does not just produce a single terminal, replace each terminal by its new nonterminal: becomes .
- Invariant achieved β every RHS is a single terminal or β₯2 nonterminals.
5. Break rules down to exactly two nonterminals
Chain fresh nonterminals until every long RHS is binary.
| old rule | new rules |
|---|---|
| , | |
| , , | |
| , , , |
- Invariant achieved (final) β every RHS is a single terminal or exactly two nonterminals. β
π Exam Execution Trace & Applied Exercises
Manual Execution Trace
No - or unit productions here, so steps 1β2 are skipped.
| Original | After steps 3 & 4 | After step 5 (CNF) |
|---|---|---|
| , | ||
| , | ||
| β | , | , |
- Read step 5 carefully β only the three-nonterminal rules changed; was already binary and passed through untouched.
Applied Exercise
Problem: convert to CNF.
Final Extracted Output: , , . (This grammar is the input to the CYK Algorithm trace.)
π³οΈ Nullability β the case CNF cannot cover
CNF covers , so decide by a separate marking algorithm on the original grammar. A nonterminal is nullable iff .
- For every rule , mark nullable.
- While there is a rule whose RHS is all nonterminals and all of them are marked: mark .
- If the start symbol is marked, Accept (); else Reject.
- Why it terminates β each pass marks at least one new nonterminal or none at all; there are finitely many, so it reaches a fixpoint.
- β Step 2βs precondition β the RHS must contain no terminals. One terminal anywhere on the RHS makes that rule unusable for nullability.
β οΈ Common Mistakes
- π‘ Chomsky β Conjunctive β Conjunctive Normal Form is -of--clauses in logic; Chomsky NF is a grammar shape. Both abbreviate βCNFβ in this unit.
- π‘ Deleting the original rule in steps 1β2 β you keep and add ; only the (resp. ) rule itself is removed.
- π‘ Stopping after one pass β both step 1 and step 2 can create the very thing they eliminate. Iterate to fixpoint.
- π‘ Claiming CNF generates β it generates . If , say so and run nullability separately.
- π‘ Leaving a mixed RHS β is not CNF; only (dead) and (live) qualify.
π§ Active Recall
What does the binary shape of CNF actually buy, and where is it used?
Answer
- Short answer: every parse tree becomes a binary tree, so β a bound linking word length to tree height, and hence to the number of nonterminals on a root-to-leaf path.
- Why: Two consumers β the CFL pumping lemma uses that bound to force a repeated nonterminal on a path once ; the CYK Algorithm uses binary rules so each substring need only be split into two parts, giving a polynomial-time table fill.
- Bonus: the same shape kills and unit rules, so no derivation step can ever shrink or merely rename β which is what makes those bounds tight.
Step 1 removes but must be repeated. Why can it not finish in one pass?
Answer
- Short answer: a rule whose RHS is exactly , i.e. , spawns β a brand new -production β so the process must loop until no -rule survives.
- Why: Nullability propagates upward β the same fact drives the nullability algorithm: emptiness climbs the grammar from -rules through all-nonterminal rules. Step 1 is that propagation, performed destructively.