How would I find the Context Free Grammar for the complement of L = {a^n | n>= 0}? The alphabet is {a}.

682 Views Asked by At

I am being asked to complement a language similar to $L = \{a^n\mid n \ge 0\}$. Then construct a context free grammar for that. As I understand, the complement of this is $L' = \{a^n\mid n \lt 0\}$. The part I am hung up on is the concept of $a^n$ with a negative $n$. If $a^3 = a\times a\times a$ and so on, how could one think of writing a a negative number of times? Does this concept even make sense? I also wonder if I am taking the complement incorrectly.

1

There are 1 best solutions below

0
On

CFG for $\mathcal L=\{a^n|n \geq 0\}$:

Let's say thet $S$ is the start so:

$S\to aA|\varepsilon\\ A\to a|aA|\varepsilon$

Now from this CFG you can generate every word from your language e.g the word $z=aaa$

So we can derivate this wod:

$S\to aA\to A\to aaA \to aaaA \to \varepsilon$ and you can do the same for all $n$