GATE / CS ARCHIVE

SIMILAR QUESTIONS / THEORY OF COMPUTATION

Classify prime-length unary languages

2 questions solved the same way, newest first. Back to Theory of Computation

How these are solved

Use eventual periodicity/pumping to rule out unary prime lengths; unary CFLs are regular. The later question also requires decidability, so these are not exact repeats.

1 mark · MCQ
Report issue

Unary prime-length language

Context-Free Grammars & Languages

Question 9, GATE 2008: Which statement holds for {a^p | p is prime}?

(A) Not accepted by a Turing machine
(B) Regular but not context-free
(C) Context-free but not regular
(D) Neither regular nor context-free, but accepted by a Turing machine
Tap to enlarge
Your answer
Answer & solution

Answer: D (no official key was published)

1. Primality of the input length is decidable, so a Turing machine accepts the language. It is not regular: if a pumping length is p, choose prime q>p; a pumpable nonempty segment has length d≤p, and pumping it q+1 times changes length to q+qd=q(1+d), composite.
2. Every unary context-free language is regular (its length set is ultimately periodic/semilinear), so this language is not context-free either. Therefore D.

Original paper, page 3

Descriptive
Report issue

Unary prime-length language is not regular

Regular Expressions & Languages

Question 16(ii), GATE 1992: True or false? L={0ⁿ : n is prime} is not regular. Prove your answer.
Question 16(ii), GATE 1992: True or false? L={0ⁿ : n is prime} is not regular. Prove your answer.
Tap to enlarge
Answer & solution

Answer: True. Pump a prime-length q word with i=q+1 to obtain composite length q(1+|y|). (no official key was published)

True. Suppose for contradiction that L is regular, and let p≥1 be its pumping length. There is a prime q≥p, because primes are unbounded. Choose w=0q∈L. For any pumping-lemma decomposition w=xyz with |xy|≤p and |y|≥1, let d=|y|, so 1≤d≤p.

The pumping lemma requires xyi z∈L for every integer i≥0. Choose i=q+1. This word has length
|xz|+(q+1)|y| = (q−d)+(q+1)d = q+qd = q(1+d).
Both factors exceed one: q is prime and therefore q≥2, while d≥1 gives 1+d≥2. The length is composite. Consequently xyq+1z∉L, contradicting the pumping lemma.

The contradiction holds for every valid decomposition, because the same choice i=q+1 works for every positive d. We therefore refute the existence of a pumping length, and L is nonregular. Choosing an arbitrary fixed pump such as i=2 would not suffice: q+d might itself be prime for some decompositions. The deliberately selected exponent makes the resulting length a multiple of q larger than q.

Original paper, page 9