Chomsky Normal Form
Muhammad Zeeshan khan
Raheel Khan
Introduction
 A useful form for dealing with context free grammars
is the Chomsky normal form. This is a particular form
of writing a CFG which is useful for understanding
CFGs and for proving things about them. It also makes
the parse
 tree for derivations using this form of the CFG a
binary tree.
Introduction
A special form of grammars
A grammar where every production is either of the form
A BC or A C→ →
(where A, B, C are arbitrary variables And can arbitrary
symbol).
Example:
S AS | a→
A SA | b→
(If language contains ", then we allow S ! "where S is start
symbol, and forbid S on RHS.)
General Grammars
 Production Rules
 Of the form A B→
 A is a string of terminals and variables
 B is a string of terminals and variables
 To apply a rule, replace any occurrence of A
 with the string
Chomsky Normal Form
Said to be Context free grammar.
..If a CFG has only productions of the form non-
terminal A string of two non-terminals Or non-terminal
A one terminal then the CFG is said to be in Chomsky
Normal Form (CNF).
..Increment of terminal
Why is importamt
The key advantage is that in Chomsky Normal Form, every
derivation of a string of n letters has exactly 2n − 1
steps.
Thus: one can determine if a string is in the language by
exhaustive search of all derivations.
Uses
 Simplicity of proofs
There are plenty of proofs around context-free grammars, including
reducibility and equivalence to automata. Those are the simpler the
more restricted the set of grammars you have to deal with is.
Therefore, normal forms can be helpful there.
 Enables parsing
While PDAs can be used to parse words with any grammar, this is
often inconvenient. Normal forms can give us more structure to work
with, resulting in easier parsing algorithms.
As a concrete example, the CYK algorithm uses Chomsky normal form.
Greibach normal form, on the other hand, enables recursive-descent
parsing; even though backtracking may be necessary, space
complexity is linear.
Proof ldea
 Any context-free language is generated by a context-
free grammar in Chomsky
PROOF IDEA
 We can convert any grammar G into Chomsky normal
form.
 The conversion has several stages wherein rules that
violate the conditions are replaced with equivalent ones
that are satisfactory.
Simple explanation
 If we can put a CFG into CNF, then we
 can calculate the “depth” of the longest
 branch of a parse tree for the derivation
 of a string.
A (parse tree)
B C
 a
Steps for CNF
 1. Remove λ- Productions
 2. Remove Unit Productions
 3. Remove Useless Symbols
Remove ε - Productions
Example : take A CFG
 S → ASB
 A → aAS | a |e
 B → SbS | A | bb
Next we need to eliminate the " rules. Eliminating A → e
yields
 S → ASB |SB
 A → aAS | a |aS
 B → SbS | A | bb | e
Remove Unit Productions
 Now we have a new " rule., B → ε. Lets remove it
 S → ASB |SB |S|AS
 A → aAS | a |aS
 B → SbS | A | bb
Next we need to remove all unit rules. Lets begin by
removing B→ A
 S → ASB |SB |S|AS
 A → aAS | a |aS
 B → SbS | aAS | a |aS | bb
now Where A is useless for the grammer..
. Remove Useless Symbols
Example: Let G be
S AB | a; A b→ →
 S and A are generating, B is not. If we eliminate
 B we have to eliminate because its non-generating
symbol so the grammar is
 S a; A b→ →
Thank You
Kingsoft Office
Make Presentation much more fun

Chomsky by zeeshan khan and Raheel Khan

  • 1.
    Chomsky Normal Form MuhammadZeeshan khan Raheel Khan
  • 2.
    Introduction  A usefulform for dealing with context free grammars is the Chomsky normal form. This is a particular form of writing a CFG which is useful for understanding CFGs and for proving things about them. It also makes the parse  tree for derivations using this form of the CFG a binary tree.
  • 3.
    Introduction A special formof grammars A grammar where every production is either of the form A BC or A C→ → (where A, B, C are arbitrary variables And can arbitrary symbol). Example: S AS | a→ A SA | b→ (If language contains ", then we allow S ! "where S is start symbol, and forbid S on RHS.)
  • 4.
    General Grammars  ProductionRules  Of the form A B→  A is a string of terminals and variables  B is a string of terminals and variables  To apply a rule, replace any occurrence of A  with the string
  • 5.
    Chomsky Normal Form Saidto be Context free grammar. ..If a CFG has only productions of the form non- terminal A string of two non-terminals Or non-terminal A one terminal then the CFG is said to be in Chomsky Normal Form (CNF). ..Increment of terminal
  • 6.
    Why is importamt Thekey advantage is that in Chomsky Normal Form, every derivation of a string of n letters has exactly 2n − 1 steps. Thus: one can determine if a string is in the language by exhaustive search of all derivations.
  • 7.
    Uses  Simplicity ofproofs There are plenty of proofs around context-free grammars, including reducibility and equivalence to automata. Those are the simpler the more restricted the set of grammars you have to deal with is. Therefore, normal forms can be helpful there.  Enables parsing While PDAs can be used to parse words with any grammar, this is often inconvenient. Normal forms can give us more structure to work with, resulting in easier parsing algorithms. As a concrete example, the CYK algorithm uses Chomsky normal form. Greibach normal form, on the other hand, enables recursive-descent parsing; even though backtracking may be necessary, space complexity is linear.
  • 8.
    Proof ldea  Anycontext-free language is generated by a context- free grammar in Chomsky PROOF IDEA  We can convert any grammar G into Chomsky normal form.  The conversion has several stages wherein rules that violate the conditions are replaced with equivalent ones that are satisfactory.
  • 9.
    Simple explanation  Ifwe can put a CFG into CNF, then we  can calculate the “depth” of the longest  branch of a parse tree for the derivation  of a string. A (parse tree) B C  a
  • 10.
    Steps for CNF 1. Remove λ- Productions  2. Remove Unit Productions  3. Remove Useless Symbols
  • 11.
    Remove ε -Productions Example : take A CFG  S → ASB  A → aAS | a |e  B → SbS | A | bb Next we need to eliminate the " rules. Eliminating A → e yields  S → ASB |SB  A → aAS | a |aS  B → SbS | A | bb | e
  • 12.
    Remove Unit Productions Now we have a new " rule., B → ε. Lets remove it  S → ASB |SB |S|AS  A → aAS | a |aS  B → SbS | A | bb Next we need to remove all unit rules. Lets begin by removing B→ A  S → ASB |SB |S|AS  A → aAS | a |aS  B → SbS | aAS | a |aS | bb now Where A is useless for the grammer..
  • 13.
    . Remove UselessSymbols Example: Let G be S AB | a; A b→ →  S and A are generating, B is not. If we eliminate  B we have to eliminate because its non-generating symbol so the grammar is  S a; A b→ →
  • 14.
    Thank You Kingsoft Office MakePresentation much more fun