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,455
  • 5
  • 23
  • 46
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
  • 276,994
  • 27
  • 311
  • 503
  • Does this really count as an answer? – Pål GD Mar 08 '13 at 19:15
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. – Pål GD Mar 08 '13 at 19:16
  • I understand what you are saying, and I did try to find a grammar for this, but I run into the same problem -- how to ensure that $m$ and $n$ are not the same number. With my above grammar, any number of $a$s or $b$s is valid, and $a$s and $b$s can have the same degree, which is obviously wrong. – dtg Mar 08 '13 at 19:24
  • @PålGD This looks like a homework question to me, so my (personal) policy is to only give hints. If you disagree, you can always downvote. – Yuval Filmus Mar 08 '13 at 19:51
  • @Dylan The trick is to take $m = n+t$ where $t \geq 1$. This ensures that $n \neq m$. – Yuval Filmus Mar 08 '13 at 19:52
  • I see what I was doing wrong... I wasn't taking account of the original definition in that all $a$ characters appear before $b$ characters. I think I have it now, thank you for your help. – dtg Mar 08 '13 at 21:57