Reputation: 1323
Let's say there is a grammar
There is a loop:
How to eliminate it when converting to CNF? I don't think it's fine to add a rule to grammar (as in unit elimination) X -> X, right, because it s basically another loop?
Upvotes: 1
Views: 1216
Reputation: 28312
If X -> Y
and Y -> X
, the nonterminal symbols are interchangeable and you can safely replace all instances of either of the two with the other of the two, eliminating one of the two completely. As you also pointed out, rules of the form X -> X
can be safely eliminated. So this grammar is equivalent to the one you give:
S -> PQT
R -> T
U -> aU | bX
P -> bQ
X -> SX | c
Q -> aRX
T -> U
And so is this one:
S -> PQT
R -> T
U -> aU | bY
P -> bQ
Y -> SY | c
Q -> aRY
T -> U
Upvotes: 1