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.

πŸ“ 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 bodynew 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 leftnew 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 rulenew 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.

OriginalAfter steps 3 & 4After 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 .

  1. For every rule , mark nullable.
  2. While there is a rule whose RHS is all nonterminals and all of them are marked: mark .
  3. 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