Chomsky normal form

From formulasearchengine
Revision as of 00:21, 4 February 2014 by en>AnomieBOT (Dating maintenance tags: {{Disambiguation needed}})
Jump to navigation Jump to search

In formal language theory, a context-free grammar is said to be in Chomsky normal form (named for Noam Chomsky) if all of its production rulesTemplate:Disambiguation needed are of the form:

A→BC or
A→α or
S→ε,

where A, B and C are nonterminal symbols, α is a terminal symbol (a symbol that represents a constant value), S is the start symbol, and ε is the empty string. Also, neither B nor C may be the start symbol, and the third production rule can only appear if ε is in L(G), namely, the language produced by the context-free grammar G.

Every grammar in Chomsky normal form is context-free, and conversely, every context-free grammar can be transformed into an equivalent one which is in Chomsky normal form. Several algorithms for performing such a transformation are known. Transformations are described in most textbooks on automata theory, such as Hopcroft and Ullman, 1979.[1] As pointed out by Lange and Leiß,[2] the drawback of these transformations is that they can lead to an undesirable bloat in grammar size. The size of a grammar is the sum of the sizes of its production rules, where the size of a rule is one plus the length of its right-hand side. Using |G| to denote the size of the original grammar G, the size blow-up in the worst case may range from |G|2 to 22|G|, depending on the transformation algorithm used.

Alternative definition

Another way to define the Chomsky normal form (e.g., Hopcroft and Ullman 1978,and Hopcroft et al. 2006) is:

A formal grammar is in Chomsky reduced form if all of its production rules are of the form:

A→BC or
A→α,

where A, B and C are nonterminal symbols, and α is a terminal symbol. When using this definition, B or C may be the start symbol. Only those context-free grammars which do not generate the empty string can be transformed into Chomsky reduced form.

Converting a grammar to Chomsky Normal Form

  1. Introduce S0
    Introduce a new start variable, S0 and a new rule S0→S where S is the previous start variable.
  2. Eliminate all ε rules
    ε rules are rules of the form A→ε, where A≠S0 and A∈V, where V is the CFG's variable alphabet.
    Remove every rule with ε on its right hand side (RHS). For each rule with A in its RHS, add a set of new rules consisting of the different possible combinations of A replaced or not replaced with ε. If a rule has A as a singleton on its RHS, add a new rule R=A→ε unless R has already been removed through this process. For example, examine the following grammar G:
    S→AbA∣B
    B→b∣c
    A→ε
    G has one ε rule. When the A→ε is removed, we get the following:
    S→AbA∣Ab∣bA∣b∣B
    B→b∣c
    Notice that we have to account for all possibilities of A→ε and so we actually end up adding 3 rules.
  3. Eliminate all unit rules
    A→B;A,B∈V
    After all the ε rules have been removed, you can begin removing unit rules, or rules whose RHS contains one variable and no terminals (which is inconsistent with CNF).
    To remove A→B
    ∀B→U, where U is a string of variables and terminals, add rule A→U unless this is a unit rule which has already been removed.
  4. Clean up the remaining rules that are not in Chomsky normal form.
    Replace A→u1u2…uk,k≥3,u1∈V∪Σ with A→u1A1,A1→u2A2,…,Ak−2→uk−1uk, where Ai are new variables.
    If ui∈Σ, replace ui in above rules with some new variable Vi and add rule Vi→ui.

See also

Footnotes

  1. ↑ * John E. Hopcroft, Rajeev Motwani, and Jeffrey D. Ullman. Introduction to Automata Theory, Languages, and Computation, 3rd Edition, Addison-Wesley, 2006. ISBN 0-321-45536-3 (see subsection 7.1.5, page 272.)
  2. ↑ Lange, Martin and Leiß, Hans. To CNF or not to CNF? An Efficient Yet Presentable Version of the CYK Algorithm. Informatica Didactica 8, 2009.

References

  • John E. Hopcroft and Jeffrey D. Ullman, Introduction to Automata Theory, Languages and Computation, Addison-Wesley Publishing, Reading Massachusetts, 1979. ISBN 0-201-02988-X. (See chapter 4.)
  • 20 year-old Real Estate Agent Rusty from Saint-Paul, has hobbies and interests which includes monopoly, property developers in singapore and poker. Will soon undertake a contiki trip that may include going to the Lower Valley of the Omo.

    My blog: http://www.primaboinca.com/view_profile.php?userid=5889534 (Pages 98–101 of section 2.1: context-free grammars. Page 156.)
  • 20 year-old Real Estate Agent Rusty from Saint-Paul, has hobbies and interests which includes monopoly, property developers in singapore and poker. Will soon undertake a contiki trip that may include going to the Lower Valley of the Omo.

    My blog: http://www.primaboinca.com/view_profile.php?userid=5889534 (Pages 237–240 of section 6.6: simplified forms and normal forms.)
  • 20 year-old Real Estate Agent Rusty from Saint-Paul, has hobbies and interests which includes monopoly, property developers in singapore and poker. Will soon undertake a contiki trip that may include going to the Lower Valley of the Omo.

    My blog: http://www.primaboinca.com/view_profile.php?userid=5889534 (Pages 103–106.)
  • Cole, Richard. Converting CFGs to CNF (Chomsky Normal Form), October 17, 2007. (pdf)
  • Sipser, Michael. Introduction to the Theory of Computation, 2nd edition.