1

Language is defined as:

$L = \{a \space | \space a ∈ \{0,1\}^*\ ∧ \space len(a) \text{ is a prime number}\}$

How to prove that this language is not context-free? By far I was trying to prove it using the Pumping lemma, but struggled to find a suitable string on which to perform the proof.

  • 1
    @ThomasAndrews I edited a language definition. a is a string that consists of 0s and 1s and its length is a prime number. –  Nov 23 '23 at 21:19
  • Does this answer your question? Technically it's slightly different but the size of the alphabet really isn't important here. – Izaak van Dongen Nov 24 '23 at 00:14

2 Answers2

1

Clearly $1^p$ belongs to $L$ for any prime $p$. If $L$ were regular, then, by the pumping lemma, for large enough prime $p$, you can write $1^p$ as $xyz$, where $y$ is non-empty and any string of the form $xy^mz$ belongs to $L$. Choose a large enough prime $p$, and let $a$, $b$ and $c$ be the lengths of the corresponding $x$, $y$ and $z$ respectively. Then the length of $xy^mz$ is $a + mb + c$, which must be prime if $xy^mz \in L$. But as $b \neq 0$, the numbers $a + mb + c$ cannot all be prime, so $L$ cannot be regular.

Rob Arthan
  • 51,538
  • 4
  • 53
  • 105
  • I'm trying to prove that L is not context-free, not regular. I guess pumping lemma for context-free languages would be similar to the one you wrote above, can you clarify it? –  Nov 23 '23 at 22:03
  • Sorry, I misread your question. I think the same idea works to show that $L$ is not context free. I will update the answer when I have time. – Rob Arthan Nov 23 '23 at 22:13
0

If $L$ is context-free, then by the pumping lemma for CFLs, there is a pumping length $k$ such that each string of length longer than $k$ can be somehow subdivided into $uvwxy$, with $vx$ nonempty (among other conditions), such that $uv^nwx^ny$ is in the language for each $n\geq 0$. (Without loss of generality, we may choose a pumping length greater than 1 so as to avoid edge cases in what follows.)

Let $p$ be any prime greater than $k$. Then $a^p$ belongs to the language, and we should be able to subdivide it as above. Let us put $\ell=|vx|\geq 1$. Then the pumped string $uv^nwx^ny$ is equal to $a^{p+(n-1)\ell}$. But that means if we pump $n=p+1$ times, we get the string $a^{p(\ell+1)}$, which is not in the language because $p(\ell+1)$ is composite.

Hence $L$ is not context-free, because it fails the conditions of the pumping lemma for CFLs.

user326210
  • 19,274