0

I need to find a context-free grammar for the above expression, $a^{m}b^{n}$ for the set $L = \left\{{a, b}\right\}$, but I am having difficulty accounting for the condition $m \neq n$.

This is what I have so far, but it clearly doesn't satisfy the above condition:

$\begin{align} &S \rightarrow aAb &\\ &S \rightarrow a &\\ &S \rightarrow b &\\ &A \rightarrow aA &\\ &A \rightarrow bA &\\ &A \rightarrow \lambda \\ \end{align}$

I have spent about an hour on this, and haven't found a solution. Any ideas?

xskxzr
  • 7,613
  • 5
  • 24
  • 47
dtg
  • 101

1 Answers1

0

Hint: Start with a CFG for the language $\{ a^{n+t} b^n : n \geq 0, t \geq 1 \}$.

Yuval Filmus
  • 280,205
  • 27
  • 317
  • 514