Informally describe the Nondeterministic PDA that generates:
$$\{x\#y\ \mid x,y\in\{a,b\}^{*}\text{and}\space x\ne y\}$$
My initial plan was to use nondeterminism to go through each character before and after the # and try to match them, and if they do not match, then accept. So I would check the first char against the first char after #, etc. However I can't get this idea to work since I can't seem to both record the character position after the # as well as the character I need to match against before the # with the single stack.
Thanks for any help.
Consider the following languages: $$\newcommand{\A}{\mathtt{a}} \newcommand{\B}{\mathtt{b}} \newcommand{\P}{\mathtt{\#}}\begin{gather} L_\text{long} = \{ x \P y : x , y \in \{ \A , \B \}^* , | x | > | y | \};\\ L_\text{short} = \{ x \P y : x , y \in \{ \A , \B \}^* , | x | < | y | \};\\ L_\text{diff} = \{ x \P y : x , y \in \{ \A , \B \}^* , | x | = | y |, ( \exists k ) ( x_k \neq y_k ) \}. \end{gather}$$ Note that your language $L$ is clearly the union of these three languages, and so a nondeterministic PDA for $L$ can first nondeterministically choose which of these three languages the string belongs to, and then check that the string actually belongs to that language. (Nondeterministic) PDAs for $L_\text{long}$ and $L_\text{short}$ are relatively easy to construct, the real difficulty is with $L_\text{diff}$.
I don't claim that $L_\text{diff}$ is context-free (I actually don't think it is), but there is a context-free language which includes $L_\text{diff}$ as a sub-language, and is itself a sub-language of $L$: let $L^\prime_{\text{diff}}$ consist of all strings $w \in \{ \A , \B , \P \}^*$ such that
It should be clear that $L_\text{diff}$ is a sub-language of $L_\text{diff}^\prime$, and every string in $L_\text{diff}^\prime$ belongs to $L$.
Suppose that $x = x_1 \cdots x_n$ and $y = y_1 \cdots y_n$ are such that $x \neq y$. This means that there is an $k \leq n$ such that $x_k \neq y_k$: for the moment let us suppose $x_k = \A$ and $y_k = \B$. Then we may rewrite our string as $$x y = x_1 \cdots x_{k-1} \;\A\; x_{k+1} \cdots x_n \; y_1 \cdots y_{k-1} \;\B\; y_{k+1} \cdots y_n$$ Note that the substring $x_{k+1} \cdots x_n \; y_1 \cdots y_{k-1}$ has length $(n-k) + (k - 1 ) = n - 1$ and so let us write it as $$z_1 \cdots z_{k-1} z_k \cdots z_{n-1}$$ Then $$\begin{align} xy &= x_1 \cdots x_{k-1} \;\A\; x_{k+1} \cdots x_n \; y_1 \cdots y_{k-1} \;\B\; y_{k+1} \cdots y_n \\ &= \overbrace{x_1 \cdots x_{k-1}}^{\text{length } k-1}\; \A\;\overbrace{z_1 \cdots z_{k-1}}^{\text{length } k-1} \; \overbrace{z_k \cdots z_{n-1}}^{\text{length }n-k} \;\B\; \overbrace{y_{k+1} \cdots y_n}^{\text{length }n-k} \end{align}$$ So the string $xy$ can be seen as the concatenation of two odd length strings $u , w$ which have different middle symbols. Once this is observed, it is relatively easy to construct a nondeterministic PDA for this language. (First non-deterministically decide whether the first substring has a $\A$ as its middle symbol and the second a $\B$, or vice versa, as you read the string first pop a symbol onto the stack until you non-deterministically guess the middle symbol of the first substring, and then pop those symbols off; once the stake is empty again pop symbols back on and non-deterministically guess where the middle symbol of the second string is.)
To obtain a nondeterministic PDA for $L_\text{diff}^\prime$ also ensure that you find one (and only one) $\P$ in the string before accepting (but reading a $\P$ does not affect the stack in any way).