HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

PDA for { xy : |x| = |y|, x ≠ y} from its grammar, and intuition behind it

Submitted by: @import:stackexchange-cs··
0
Viewed 0 times
pdaitsgrammarforbehindandfromintuition

Problem

I know the grammar for the language $\{ xy : |x| = |y|, x ≠ y \}$ if $\Sigma=\{a,b\}$:

$$
\begin{align*}
&S→AB∣BA \\
&A→a∣aAa∣aAb∣bAa∣bAb \\
&B→b∣aBa∣aBb∣bBa∣bBb
\end{align*}
$$

I know this is a grammar, but I need a PDA for this language, and intuition how $\{xy: |x|=|y|,x \neq y\}$ is a CFL while $\{xy: |x|=|y|,x=y\}$ is a CSL but not a CFL. How is this possible?

Solution

You are asking two questions: how to construct a PDA for the language, and why this language is context-free while the same language with the condition $x \neq y$ replaced by the condition $x = y$, is not. I will only answer the second, since for the first question there are known algorithms.

The reason that your language is context-free is that we can rewrite it as follows:
$$
\{ \Sigma^i a \Sigma^i \Sigma^j b \Sigma^j : i,j \neq 0 \} \cup
\{ \Sigma^i b \Sigma^i \Sigma^j a \Sigma^j : i,j \neq 0 \}.
$$
This gives a different description of the language as the union of concatenations of context-free languages. A similar trick just doesn't work for the language $\{ xy : x=y \}$.

Here is a different example. Consider the following two collections of natural numbers (without zero):

  • $A = \{ x \cdot y : x \neq y \}$.



  • $B = \{ x \cdot y : x = y \}$.



The set $A$ consists of all natural numbers other than $1$, whereas the set $B$ consists of all squares. Even though we defined them in a similar way, the set $A$ has a much simpler description, while $B$ doesn't.

Context

StackExchange Computer Science Q#66807, answer score: 5

Revisions (0)

No revisions yet.