8

Is the language

$$L = \{a,b\}^* \setminus \{(a^nb^n)^n\mid n \geq1 \}$$

context-free? I believe that the answer is that it is not a CFL, but I can't prove it by Ogden's lemma or Pumping lemma.

Raphael
  • 72,336
  • 29
  • 179
  • 389

1 Answers1

8

Hint:

Yes

Solution:

$$\{(a^n b^n)^n \mid n \geq 1 \} = \{a^{n_1} b^{n_2} \dots a^{n_{2k-1}} b^{n_{2k}}\}: k \geq 1 \land n_1 = k \land \forall i. n_i = n_{i+1} \}$$

and therefore the complement is

$$\{a,b\}^{\ast} \setminus \{(a^n b^n)^n \mid n \geq 1 \} = \{a^{n_1} b^{n_2} \dots a^{n_{2k-1}} b^{n_{2k}}: n_1 \neq k \lor \exists i. n_i \neq n_{i+1}\}$$

which is context-free as you can easily write a nondeterministic PDA.

Raphael
  • 72,336
  • 29
  • 179
  • 389
sdcvvc
  • 3,491
  • 18
  • 28
  • 2
    Ooohhh! *facepalm* Maybe you want to add the central design trick; it might not be obvious for the novice. – Raphael Jul 05 '12 at 09:42
  • I don't understand, I thought that the complement of a CFL wasn't CFL in general. Thank you – Andrés Felipe Téllez Crespo Jul 11 '12 at 21:55
  • ${(a^n b^n)^n}$ is not context-free, but its complement is. – sdcvvc Jul 11 '12 at 22:09
  • @AndrésFelipeTéllezCrespo: The complement of a CFL is not always CFL (so no closure property) but nobody says that there is no CFL whose complement is CFL. In particular, all the complements of all regular languages are context-free (because they are even regular). – Raphael Jul 23 '12 at 07:19
  • 1
    Languages similar to $L$ -- a finite disjunction of suitable conditions -- can be solved by using nondeterminism: guess the violated condition and verify that it is violated (ignore the rest). – Raphael Jul 23 '12 at 07:21