AI Glossary / Data engineering and architecture / Intermediate

Chomsky normal form

Definition

Chomsky normal form is a restricted form of a context-free grammar in which rules expand one nonterminal into either two nonterminals or one terminal. The usual shapes are A → BC and A → a. Empty-string handling requires an explicit convention. This normal form supports systematic parsing algorithms and proofs about context-free languages.

What it means

A grammar describes which strings can be generated and how they can be structured. Nonterminals represent categories that can expand further, while terminals are the actual symbols of the resulting string.

Chomsky normal form standardizes the shape of the rules without restricting the non-empty strings that a context-free language can express. A suitable conversion can introduce helper symbols and replace longer or otherwise nonconforming rules.

The abbreviation CNF also means conjunctive normal form in logic. That is a different concept involving logical clauses, not grammar productions. Neither meaning is a database normal form such as BCNF, despite the shared phrase normal form.

How it works

A conversion handles rules that do not fit the required shapes. It eliminates or accounts for empty productions and unit productions, where one nonterminal expands directly to another. It also removes unusable material as appropriate to the conversion.

Terminals appearing alongside other symbols can be represented through helper nonterminals. Long right-hand sides are broken into binary steps using additional symbols. Each transformation must preserve the intended language, with the empty-string case stated separately.

The resulting binary structure is useful for the CKY, also called CYK, parsing approach. The parser builds information about short spans and combines two adjacent spans when a grammar rule allows it.

A converted grammar can contain artificial categories introduced only for computation. If users need trees in the original grammar's form, the system should retain a mapping back. Preserving accepted strings does not mean every displayed tree retains its original labels and shape.

Three practical examples

  • A language-processing course converts a small grammar to CNF before implementing a CKY parser.
  • A parser component normalizes grammar rules into binary combinations while retaining mappings to the original grammatical categories.
  • A formal-language proof uses restricted rule shapes to reason about derivations of non-empty strings.

Think of it this way

Think of rewriting assembly instructions so every step either produces one finished part or combines exactly two subassemblies. A larger assembly can still be built, but intermediate steps may need new names.

The analogy is limited because grammars describe formal derivations, not physical manufacturing. The helper categories do not necessarily represent meaningful linguistic units. They support uniform computation.

Worked example

Binarizing a three-part rule

Consider an invented grammar with S → ABC, A → red, B → fox and C → runs. Here red, fox and runs are terminal tokens, while S, A, B and C are nonterminals. The rule S → ABC is not in CNF because its right-hand side contains three nonterminals.

Introduce a fresh helper X and replace that rule with S → AX and X → BC. Keep A → red, B → fox and C → runs. Every rule now has one of the two permitted shapes.

A derivation can proceed S, then AX, then ABC, then the terminal sequence red fox runs. The helper has reorganized the derivation without adding a new terminal word or allowing a different terminal sequence in this toy grammar.

This example only demonstrates binarization. It begins without unit rules, mixed terminal-nonterminal rules or empty productions. A general conversion must handle those cases too; splitting long rules alone is not a complete CNF conversion procedure.

Illustrative case study

A fictional team builds a parser for a controlled command language. It converts its grammar to binary rules and presents the resulting parse trees directly to business reviewers. Reviewers are confused by labels such as X17 that have no meaning in their command vocabulary.

The team preserves a mapping from helper rules to original rules and converts the output trees into the agreed presentation form. It also checks accepted and rejected example commands before and after conversion, including the empty-input policy.

The internal grammar must suit the parser, while external trees remain understandable. A normal form need not suit user editing.

Common misconceptions and mistakes

  • Any rule with at most two symbols on the right is CNF. A → B is a unit rule, and A → aB mixes a terminal with a nonterminal; neither is one of the basic permitted shapes.
  • Conversion removes ambiguity. A language or grammar can still admit multiple parses; CNF does not choose the intended meaning.
  • Language equivalence means identical parse trees. Helper symbols and changed branching can alter tree representation even when accepted strings are preserved.

Business use

Chomsky normal form matters most when a project uses explicit grammar-based parsing or needs to understand the foundations of syntax analysis. It provides a uniform internal representation that can simplify algorithm design and validation.

For a business application, first decide whether a context-free grammar captures the required input structure. Then check the chosen parser's grammar restrictions and empty-string convention. Keep grammar conversion separate from semantic checks such as whether a referenced account exists or an operation is permitted.

In AI-assisted development, review generated grammar transformations with small counterexamples. Check that helper symbols are fresh, all rule shapes are valid and original terminal strings remain accepted as intended. Finite tests support implementation review but do not replace a general correctness argument for the conversion.

People also ask

Can every context-free grammar be converted?

Its non-empty language can be represented in CNF; preserving the empty string requires the chosen convention or separate handling.

Does CNF make a grammar unambiguous?

No. Restricted rule shapes do not by themselves resolve multiple valid parses.

Is it required by all parsers?

No. It is useful for algorithms such as basic CKY, while other parsing methods accept different grammar forms.

Check your understanding

Which rule fits the basic CNF shapes: A → BC, A → B or A → aB?

Answer: A → BC fits when B and C are nonterminals. The unit rule A → B and mixed rule A → aB do not. A → a would also fit when a is a terminal.

Related terms

  • Context-free grammar
  • Dynamic programming
  • Parse tree
  • Conjunctive normal form
  • nonterminal
  • terminal
  • production rule
  • CKY parsing
  • binarisation

Learn next

Read context-free grammars and CKY parsing. Convert one three-symbol production using a fresh helper, then trace the same terminal string through the original and converted grammars.

More in Data engineering and architecture

  • Centralized computing - Centralized computing is an arrangement in which a main system or centrally managed computing environment performs a substantial share of processing and...
  • Certain answer - A certain answer is a query result that holds in every admissible interpretation or completion of an incomplete database.
  • Chaining (vector processing) - Chaining in vector processing lets a dependent vector operation begin using individual results from an earlier operation before the entire earlier vector is...
  • Chow - Liu tree - A Chow - Liu tree is a tree-structured probability model that approximates a joint distribution using relationships between pairs of variables.
  • Chunked transfer encoding - Chunked transfer encoding is an HTTP/1.1 message-framing mechanism that sends a message body as a sequence of length-prefixed chunks.
  • CICD or CI/CD - CI/CD means continuous integration combined with continuous delivery or continuous deployment.

Sources

Jurafsky and Martin, Constituency Parsing: https://www.web.stanford.edu/~jurafsky/slp3/old_oct19/13.pdf. Primary textbook explanation of CNF conversion and CKY.

Old Dominion University, Properties of Context-Free Languages: https://www.cs.odu.edu/~zeil/cs390/s25-live/Public/cfreeLang/index.html. Primary teaching treatment of conversion and the non-empty-language qualification.

MIT OpenCourseWare, Advanced Natural Language Processing lecture 2: https://ocw.mit.edu/courses/6-864-advanced-natural-language-processing-fall-2005/87a7c15d21927542083d3a46a16868ef_lec2.pdf. Primary grammar-form definition. The toy grammar and command-parser case are original illustrations.

Previous: Chomsky-adjunction Next: Chordal

  • Home
  • Daily AI Updates
  • Blog
  • AIFBL Academy
  • AI Glossary
  • Products and Tools
  • Store
  • Free CFO AI Prompt Pack
  • About Shihan Sheriff
  • Privacy Policy
  • Terms of Use
  • Refund Policy
  • Cookie Policy
  • Earnings Disclaimer