Professional Documents
Culture Documents
By:
Video.edhole.com
Normal Forms
Chomsky Normal Form
Griebach Normal Form
cs466(Prasad)
Video.edhole.com
L8Norm
S SS |
S SS | a
S aS | a
Shorter derivations
cs466(Prasad)
Video.edhole.com
L8Norm
Elimination of -rules
Reduces the length of the derivation
S aBS |
B bB |
S aS | aBS |
B bB | b
L( B ) b *
L( S ) (ab*) *
L( B ) b
L( S ) ( ab*) *
S 7 aaa
S 4 aaa
cs466(Prasad)
Video.edhole.com
L8Norm
G (V , , P, S )
G' (V {S ' }, , P {S ' S}, S ' )
L ( G ) L (G ' )
cs466(Prasad)
Video.edhole.com
L8Norm
B bB |
B bB | b |
B bB | b
cs466(Prasad)
Video.edhole.com
L8Norm
Example
S' S |
S AB
S AB | A | B
B bB |
B bB | b
A aA |
A aA | a
S' S
S AB | A | B
B bB | | b
A aA | | a
cs466(Prasad)
Video.edhole.com
a *b*
a b a b
L8Norm
S AC
C cC |
A aA | C
B AbC
{C} {A, C} {S , A, C}
Bottom-up flow of information
cs466(Prasad)
Video.edhole.com
L8Norm
L8Norm
Proof of correctness
Soundness
If A e NULL(final) then A=>* .
Induction on the number of iterations of the loop.
Completeness
If A=>* then A e NULL(final).
Induction on the minimal derivation of the null
string from a non-terminal.
Termination
Bounded by the number of non-terminals.
cs466(Prasad)
Video.edhole.com
L8Norm
10
A aA | a | B
B bB | b | C
Cc
A aA | a | bB | b | c
B bB | b | c
Cc
Top-down flow of information
cs466(Prasad)
Video.edhole.com
L8Norm
11
Construction of Chain(A)
Chain(A) := {A};
PREV := f;
repeat
NEW := Chain(A) - PREV;
PREV := Chain(A);
foreach B e NEW do
if there is a rule B->C
then Chain(A) := Chain(A) U {C}
until Chain(A) = PREV;
cs466(Prasad)
Video.edhole.com
L8Norm
12
Examples
S AB | A | B
A aA | a | B
S AB | aA | a | b
A aA | a | b
Bb
Bb
S aA | b | A
S aA | b | Sa | bB
A Sa | B
A Sa | bB | aA | b
B bB | S
B bB | aA | b | Sa
cs466(Prasad)
Video.edhole.com
L8Norm
13
S *G uXv where X V
u,v (V ) *
X *G
where *
cs466(Prasad)
Video.edhole.com
L8Norm
14
L8Norm
15
Examples
S AB |
A aA | a
C cC | c
S
A aA | a
terminal string;
C unreachable.
S BD
B BD | B
Empty set of
productions
D DB | D
Non-termination
cs466(Prasad)
Video.edhole.com
L8Norm
16
L8Norm
17
Construction
Obtain an equivalent grammar that does not
contain -rules, chain rules, and useless
variables.
Apply following conversion on rules of the
form:
A bBcC
A PQ
Q BR
Pb
R WC
W c
cs466(Prasad)
Video.edhole.com
L8Norm
18
Significance of CNF
Length of derivation of a string of length n
in CNF = (2n-1)
(Cf. Number of nodes of a strictly binary tree with n-leaves)
cs466(Prasad)
Video.edhole.com
L8Norm
19
L( A) ba *
A bZ | b
Z aZ | a
cs466(Prasad)
Video.edhole.com
L( A) ba *
L( Z ) a
L8Norm
20
cs466(Prasad)
Video.edhole.com
L8Norm
21
A Bb | a
B Aa | b
(Cf. Gaussian
Elimination)
A Bb | a
B ( Bb | a )a | b
A Bb | a
A Bb | a
B Bba | aa | b
cs466(Prasad)
Video.edhole.com
B (aa | b) Z | (aa | b)
Z baZ | ba
L8Norm
22
L8Norm
23
y
3
2y z 1
z -x
2z 6
x
y
z -2
y 1
- z -1
z -( y 3) 2 z 6
z 1 - 3 2z 6
cs466(Prasad)
Video.edhole.com
L8Norm
x4
24
A BC
| bCB | a
B CA | b
R ACBR | ACB
C AB | a
Introducing terminals
as first element on RHS
A B C
A BC
B CA | b
C BCB | a
C CAC B | bC B | a
C bCBR | aR | bCB | a
B bcBRA | aRA
| bCBA | aA | b
A bcBRAC | aRAC
| bCBAC | aAC | bC
R (bCBRAC | ... | bC )(CBR | CB )
cs466(Prasad)
Video.edhole.com
L8Norm
25
L8Norm
26