5

I have to generate a grammar for the language $L = \{ w \in \{ a, b\}^* \mid |w| \in 2\mathbb{N}, w \neq w^R\}$ and give the type of the language.

I've generated the grammar

$\qquad \begin{align} S &\to aSa \mid bSb \mid aAb \mid bAa \\ A &\to abA \mid baA \mid aaA \mid bbA \mid \varepsilon \end{align}$

This grammar is a context free grammar. I now can say that $L$ is a context free language. But how can I say for sure that this language isn't regular ?

Raphael
  • 73,212
  • 30
  • 182
  • 400

3 Answers3

4

Regular languages are closed under complement and intersection. The complement of $L$, intersected with the regular $\{w : |w| \equiv 0 \pmod{2}\}$ is the language of even palindromes. If you must, you can easily show that it is not regular using pumping lemma.

Karolis Juodelė
  • 3,697
  • 16
  • 18
1

Your grammar is almost correct except for the fact that you cannot derive any word. Thus, it produces the empty language. However, as I said, the idea to produce a "difference" and then switch to another nonterminal is correct.

To prove that a language (no matter which one) is not regular, you can use the pumping lemma or, if you need it a little simpler, a proof by contradiction using a pumping argument.

Note, however, that the pumping lemma cannot be used to prove the converse.

Dan
  • 341
  • 3
  • 8
-2

Language categories are sets, and the context-free language set contains the regular language set. In other words, every regular language is context-free. It's useful to know that context-free contains LR, which contains LL, which contains regular.

Your language is regular because its definition conforms to the regular definition (strings that can be formed over an alphabet by applying the operations of concatenation, union, and closure).

There's an algorithm for converting a regular definition into a grammar. I believe that the algorithm would produce the following grammar for your language:

S -> aS
S -> bS
S -> ε

I'm not quite sure that the grammar you posted corresponds to the regular language definition. It's better to stick to proven stuff.

Apalala
  • 101
  • 1