# Three articles on "Chomsky Normal Form"

Source: Internet
Author: User
Chomsky Normal Form

In computer science, a formal grammar is in Chomsky Normal Form IFF all production rules 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.

Every grammar in Chomsky normal form is context-free, and conversely, every context-free grammar can be efficiently transformed into an equivalent one which is in Chomsky normal form.

With the exception of the optional rule S → ε (writable ded when the grammar may generate the empty string), all rules of a grammar in Chomsky normal form are expansive; thus, throughout the derivation of a string, each string of terminals and nonterminals is always either the same length or one element longer than the previous such string. the derivation of a string of length N is always exactly 2n-1 steps long. furthermore, since all rules deriving nonterminals transform one nonterminal to exactly two nonterminals, a parse tree based on a grammar in Chomsky normal form is a binary tree, and the height of this tree is limited to at most the length of the string.

Because of these properties, using proofs in the field of versions and Computability make use of the Chomsky normal form. these properties also yield various efficient algorithms based on grammars in Chomsky normal form; for example, the cyk between that decides whether a given string can be generated by a given grammar uses the Chomsky normal form.

The Chomsky normal form is named after Noam Chomsky, the US linguist who has Ted the Chomsky hierarchy.

Chomsky Normal Form
A Context Free Grammar is in Chomsky normal form if each production yields a terminal or two nonterminals. Any context free grammar can be converted to Chomsky normal form.

First remove all e productions. if X → e, then a production like y → axbxc spins off the productions y → ABC | axbc | abxc. perform similar substitutions for all nonterminals that lead to the empty string, then remove productions that yield E. if e is in the language, I. e. S → e, then this production must remain. this is the only nonstandard production in Chomsky normal form; all other productions must yield a terminal or two nonterminals.

Next, remove any productions X → X, as they are pointless. Given X → y, Let X derive everything that y derives, then remove the unit production X → y.

At this point the right side of each production has two or more symbols. Introduce new symbols to play out the right side. For instance, X → ayzbc might be replaced with the following.

X → q1q2
Q1 →
Q2 → yq3
Q3 → zq4
Q4 → q5q6
Q5 → B
Q6 → C

Do this operation ss the board and the resulting grammar is in Chomsky normal form.

Prove that a word of length N is derived in 2n-1 steps. Hint, each terminal implies one step.

Cyk Algorithm

The cocke-younger-kasami (cyk) algorithm (alternatively called cky) determines whether a string can be generated by a given context-free grammar and, if so, how it can be generated. this is known as parsing the string. the algorithm is an example of dynamic programming.

The standard version of cyk recognizes versions ages defined by context-free grammars written in Chomsky Normal Form (CNF ). since any context-free grammar can be converted to CNF without too much difficulty, cyk can be used to recognize any context-free language. it is also possible to extend the cyk algorithm to handle some context-free grammars which are not written in CNF; this may be done to improve performance, although at the cost of making the algorithm harder to understand.

The worst case asymptotic time complexity of cyk is ambiguous (N3), where N is the length of the parsed string. this makes it one of the most efficient (in those terms) algorithms for recognizing any context-free language. however, there are other algorithms that will perform better for certain subsets of the context-free versions.
Contents

* 1 The Algorithm
O 1.1 informally
O 1.2 algorithm Extension
* 2 references

The Algorithm

The cyk algorithm is a bottom up algorithm and is important theoretically, since it can be used to constructively prove that the membership problem for context-free versions is decidable.

The cyk Algorithm for the membership problem is as follows:

Let the input string consist of N letters, A1....
Let the grammar contain r terminal and nonterminal symbols R1... rr.
This grammar contains the subset RS which is the set of start symbols.
Let p [N, N, R] Be an array of booleans. Initialize all elements of P to false.
For each I = 1 to n
For each unit production RJ → AI, Set P [I, 1, J] = true.
For each I = 2 to n -- length of Span
For each j = 1 to n-I + 1 -- start of Span
For each k = 1 to I-1 -- partition of Span
For each production ra-> RB RC
If P [j, k, B] and P [J + K, I-K, C] then set p [J, I, a] = true
If any of P [1, n, x] is true (X is iterated over the set S, where S are all the indices for RS)
Then string is member of Language
Else string is not member of Language

Informally

In informal terms, this algorithm considers every possible substring of the string of letters and sets P [I, j, k] To be true if the substring of letters starting from I of length j can be generated from rk. once it has considered substrings of length 1, it goes on to substrings of length 2, and so on. for substrings of length 2 and greater, it considers every possible partition of the substring into two halves, and checks to see if there is some production p → q r such that Q matches the first half and r matches the second half. if so, it records P as matching the whole substring. once this process is completed, the sentence is recognized by the grammar if the substring containing the entire string is matched by the START symbol.
Cyk table s
VP

S
VP PP
S NP
Np v, VP det. n p det n
She eats a fish with a fork

Algorithm Extension

It is simple to extend the above algorithm to not only determine if a sentence is in a language, but to also construct a parse tree, by storing Parse Tree nodes as elements of the array, instead of booleans. since the grammars being recognized can be ambiguous, it is necessary to store a list of nodes (unless one wishes to only pick one possible parse tree ); the end result is then a forest of possible parse trees. an alternative formulation employs a second table B [N, N, R] of so-called backpointers.

It is also possible to extend the cyk algorithm to parse strings using weighted and stochastic context-free grammars. weights (probabilities) are then stored in the table P instead of booleans, so P [I, j, A] will contain the minimum weight (maximum probability) that the substring from I to J can be derived from. further extensions of the algorithm allow all parses of a string to be enumerated from lowest to highest weight (highest to lowest probability ).

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.