# Prove not context free

How can we prove that:

$$L = \{ w_1\#w_2 \mid w_1 \in w_2;\; |w_2| > |w_1|;\; w_1 , w_2 \in \{0, 1\}^*\}$$

is not context-free?

The language defines $w_1$ as a sub-string of $w_2$, and they are separated by a $\#$. This is easy with the CFG pumping-lemma for a slightly different language with $|w_2| \ge |w_1|$ by using the special case of $|w_2| = |w_1|$ (i.e. $w_1 = w_2$).

But here, $w_1$ is a proper sub-string of $w_2$ so I can't do the same. I fail to push the string out since we can always pump, for example the first symbol of $w_2$.

• Some questions can't be shown to be non-context-free by the Pumping lemma; I recommend you check out our reference questions for more methods. – Raphael Apr 25 '14 at 12:39
• The $|w_2| \ge |w_1|$ is easy, $|w_2| > |w_1|$ is hard. So this site should not have any pumping-lemma applications in the future just because of that duplicate question? – perreal Apr 25 '14 at 12:46
• Okay, now I understand the question; thanks for clarifying. It probably is still a duplicate (I'd imagine Ogden's lemma might work, but I did not try it out) and you don't really display your attempt (cf here). You do note why the Pumping lemma fails, though, so I'm giving you the benefit of the doubt and reopen. – Raphael Apr 25 '14 at 12:56
• Thanks, are you aware of any theorems saying the pumped string should contain all distinct symbols in a sub-string with some sufficient length? – perreal Apr 25 '14 at 13:05
• @perreal There is no such theorem since it's not true. Consider for example the language $a^*$. – Yuval Filmus Apr 25 '14 at 13:58

For large enough $p$, consider the word $w = 0^{p+1}1^{p+1}\#0^{p+1}1^{p+2} \in L$. Mark the part $1^{p+1}\#0^{p+1}$. According to Ogden's lemma, we can write $w = uxyzv$ such that $xyz$ contains at least $1$ and at most $p$ marked symbols, and $ux^iyz^iv \in L$ for all $i \geq 0$. The pumped part $xyz$ cannot lie all to the right of $\#$ since then pumping it down would result in a word not in the language (here we crucially use the fact that only the $0^{p+1}$ part to the right of $\#$ is marked). It also cannot lie all to the left of $\#$ since then pumping it up would result in a word not in the language. It follows that the part of $xyz$ to the right of $\#$ is of the form $0^k$, and the part of $xyz$ to the left of $\#$ is of the form $1^\ell$ (otherwise, there would be more than $p$ marked symbols). However, pumping up, the resulting word is not in the language. This contradiction shows that $L$ is not context-free.
• Can we not use the same logic to prove $0^n1^n$ is not CFG by marking 0's? Sorry if this sounds dumb. – perreal Apr 25 '14 at 16:19
• I think what goes wrong with $0^n1^n$ is, we have to show for all possible markings to show non-cfl. I also think since you are just showing a single possible marking in the proof it is not complete. So perhaps this language obeys the lemma's. – perreal Apr 27 '14 at 7:27
• @perreal Ogden's lemma states that there exists $p$ such that for every word in $L$ and every possible marking with at least $p$ marks, there is a way to break the word in a certain way and pump it in a certain way. We get to chose the marks. Otherwise Ogden's lemma doesn't give us anything beyond the usual pumping lemma. – Yuval Filmus Apr 27 '14 at 16:21