Proofs: Chomsky normal form conversion
These are the human proofs of Chomsky normal form conversion, at full length.
The Chomsky normal form conversion keeps the language and produces Chomsky normal form full
This proof shows: correctness.
Let with . Write for the grammars after START (L1), TERM (L2, L3), BIN (L4, L5), DEL (L6 to L8), UNIT (L9, L10) and USELESS (L11). For a grammar and a symbol let , with for a terminal . We use parse trees throughout: exactly when there is a parse tree of with root and yield . All new nonterminals are fresh, so they differ from each other and from every symbol of .
Invariant 0. is on no right side of any . It is fresh, L1 puts it only on a left side, TERM and BIN rewrite right sides of without adding , and DEL and UNIT only build right sides from parts of existing right sides.
Step 1 (START). , and for .
Proof. By Invariant 0, a parse tree of contains at most at the root. A tree with root is a tree of . A tree with root is above a tree of with root .
Step 2 (TERM). for every nonterminal of .
Proof. Let replace each new by . Every production of other than is with in . Given a tree of with root , delete every node and attach its leaf to its parent; the result is a tree of with the same root and yield. Conversely, in a tree of , replace at each node that uses a production with each terminal child by a node with the leaf ; the result is a tree of .
Step 3 (BIN). for every nonterminal of .
Proof. The new nonterminals made for one production are fresh for , so each has exactly one production, (or ), and appears on exactly one right side, that of (or of for ). In a tree of with an old root, every node labelled is therefore the right child of a node that uses , and below it the chain continues to . Contracting each such chain into one node with children gives a tree of with the same yield. Expanding each node that uses into the chain turns a tree of into a tree of .
After BIN every right side has length at most 2, and every right side of length 2 consists of two nonterminals, by TERM.
Step 4 (DEL). Let be the set of nullable nonterminals of . Then for every nonterminal of and every , . Moreover .
Proof. () Every production of other than is where comes from a production of by deleting symbols of , which derive in . So , and every derivation of that does not use is simulated in . A derivation of from does not use : if it never meets , by Invariant 0, and if the production yields only .
() By induction on the height of a tree of with root and yield . The root uses with , since gives the yield . Let be the yields of the children, and let , which is nonempty. For , derives , so it is a nonterminal in . For , is a terminal with , or a nonterminal with by induction. The production is in : if it is the original nonempty production, kept by L8; if and it was added by L7 because ; if , because . Using it at the root gives a tree of with yield .
Finally, exactly when L8 added , that is, when , that is, when : every other production of has a nonempty right side, so no other derivation can yield .
After DEL the productions are with nonterminals, , unit productions , and possibly . L7 adds only right sides of length 1, and L8 removes every other -production.
Step 5 (UNIT). For every nonterminal , .
Proof. () A production of comes from some with in , so . Replacing each step of a derivation of by these steps gives a derivation of .
() By induction on the number of nodes of a tree of with root and yield . Starting at the root, follow the nodes that use unit productions: , where is a unit production and the node uses a production that is not a unit production. Then , so is in by L10. The children of the node are terminals, or roots of subtrees with fewer nodes than whose yields are, by induction, derivable in . Putting at the root above these subtrees gives a tree of with yield .
is computed by a graph search over the unit productions, which terminates even when they form cycles. L10 copies only productions that are not unit productions, so has only , and . Since is on no right side, only for , so is not copied to any other nonterminal.
Step 6 (USELESS). .
Proof. has a subset of the productions of , which gives . Conversely, let be a tree of with root and yield . Every node of is the root of a subtree with a terminal yield, so is generating, and every production used in has a generating left side and generating right-side symbols; so it survives the first part of L11. Every node is reached from the root along edges of , which use these surviving productions, so its label is reachable from in the grammar after the first part, and the production survives the second part. So is a tree of .
Theorem. is in Chomsky normal form with start symbol , and .
Proof. The language: by Steps 1 to 3, ; by Step 4, ; by Steps 5 and 6, . The form: after Step 5 every production is with nonterminals , , or ; Step 6 only removes productions; and by Invariant 0, .