- 2072 Kartik
Grammar for aⁿbⁿcⁿ, n ≥ 1
Short answer
The language is not context-free; use a context-sensitive grammar. S → aSBC | aBC, CB → BC, aB → ab, bB → bb, bC → bc, cC → cc.
Construct a grammar to accept the language L = {aⁿbⁿcⁿ : n ≥ 1}.
L = { aⁿbⁿcⁿ : n ≥ 1 } is not context free, so an unrestricted (context sensitive) grammar is needed. Here every production has |left side| ≤ |right side|.
Grammar
G = ({S, B, C}, {a, b, c}, P, S) with productions
1. S → aSBC
2. S → aBC
3. CB → BC
4. aB → ab
5. bB → bb
6. bC → bc
7. cC → cc
Idea. Rules 1 and 2 generate n a's followed by n copies of B and C mixed together: aⁿ (BC)ⁿ. Rule 3 sorts them so that all B's come before all C's. Rules 4 to 7 convert the variables into terminals from left to right, and only in the correct order, so the result is always aⁿbⁿcⁿ.
Derivation of aabbcc (n = 2)
S ⇒ aSBC (1)
⇒ aaBCBC (2)
⇒ aaBBCC (3: CB → BC)
⇒ aabBCC (4: aB → ab)
⇒ aabbCC (5: bB → bb)
⇒ aabbcC (6: bC → bc)
⇒ aabbcc (7: cC → cc)
Why only aⁿbⁿcⁿ is generated
The first B can become b only when it follows an a (rule 4), each later B only after a b (rule 5), and C can become c only after b or c (rules 6 and 7). If a C is turned into c while a B still stands to its right, that B is stuck after a c (there is no rule cB → …), so the derivation can never reach a terminal string. Hence the variables must be sorted into B…BC…C before the conversion finishes. The numbers of a's, B's and C's are always equal, since rules 1 and 2 create them together.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- CFG for aᵐbⁿ with m ≥ n · Theory of Computation, chapter 3 · asked 2×
- CFG for aⁿb^(2n); parse tree · Theory of Computation, chapter 3 · asked 2×
- TM accepting wwᴿ; process 101101 · Theory of Computation, chapter 4
- Every RE has NFA; ε-NFA for bb(a∪b)*ab · Theory of Computation, chapter 2
- PDA for a^n b^(n+m) c^m · Theory of Computation, chapter 3
- Language of grammar; grammar for strings not ending in ab · Discrete Structure, chapter 2
- Construct FSA accepting reverse language · Discrete Structure, chapter 2
- NFA and DFA from grammar σ→bσ|aC · Discrete Structure, chapter 2 · asked 4×
- NFA and DFA from grammar σ→aA|bB · Discrete Structure, chapter 2 · asked 2×