1

$L = \{$$a^mb^nc^pd^q \mid m+p = n+q,$$\text{ where } m, n, p, q \geqslant0\}$

If, for instance, we try to construct a PDA for a similar language
$L2 = \{$$a^mb^nc^pd^q \mid m=p $ $\text{and}$ $ n=q,$$\text{ where } m, n, p, q \geqslant0\}$, it is clearly not possible to come up with one.

Then, why is $L$ context-free?

entechnic
  • 143
  • 6
Infinity
  • 133
  • 2
  • 3
  • 10

1 Answers1

4

We can keep the number $m-n+p-q$ on the stack of the PDA, and in the end check whether the result is zero. More precisely, we have the absolute value on stack, and the sign of the number in the state of the automaton.

We can also construct a context-free grammar, with a little case analysis. (The cases are equivalent to the question whether the pushdown-counter will drop below zero, or not.) Here was a recent similar question: Context free grammar for $1^n0^m1^k0^p$ where $n+k=m+p$.

The situation for $L2$ is quite different. There one would need to keep track two number differences $m-p$ and $m-q$ at the same time. This cannot be done by a PDA, so that is (at least intuitively) the reason the languages are different.

Hendrik Jan
  • 30,578
  • 1
  • 51
  • 105