Skip to main content

CNF: S→AB, A→aAA|ε, B→bBB|ε

Short answer

Remove ε-productions: S→AB|A|B|ε, A→aAA|aA|a, B→bBB|bB|b. Remove unit productions: S→AB|aAA|aA|a|bBB|bB|b|ε. Introduce Xa→a, Xb→b, C→AA, D→BB. CNF: S→AB|XaC|XaA|a|XbD|XbB|b|ε, A→XaC|XaA|a, B→XbD|XbB|b, C→AA, D→BB, Xa→a, Xb→b.

Convert the given context free grammar (CFG) into an equivalent CNF: S → AB; A → aAA | ε; B → bBB | ε (ε is the empty symbol).

Grammar: S → AB; A → aAA | ε; B → bBB | ε.

Step 1: Start symbol

S does not appear on any right-hand side, so no new start symbol is needed.

Step 2: Remove ε-productions

Nullable: A, B, and S (S → AB). Generate all variants:

  • S → AB gives AB | A | B (we drop the all-ε variant; ε stays only for S).
  • A → aAA gives aAA | aA | a.
  • B → bBB gives bBB | bB | b.
S → AB | A | B | ε
A → aAA | aA | a
B → bBB | bB | b

S → ε remains because ε ∈ L(G) and S is the start symbol not occurring on a right side.

Step 3: Remove unit productions

S → A and S → B are units. Replace by the rules of A and B:

S → AB | aAA | aA | a | bBB | bB | b | ε
A → aAA | aA | a
B → bBB | bB | b

Step 4: Convert to CNF

Terminals inside longer rules: Xa → a, Xb → b. Break long rules: C → AA, D → BB.

S  → AB | XaC | XaA | a | XbD | XbB | b | ε
A  → XaC | XaA | a
B  → XbD | XbB | b
C  → AA
D  → BB
Xa → a
Xb → b

All rules have the form X → YZ or X → a (S → ε allowed for the start). This is the required CNF.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Theory of Computation chapter 3 questions →