After 2 failed attempts, that were disproved by @Hendrik Jan (thank you), here is another one, that is not more successful. @Vor found an example of a deterministic CF language where
the same construction would apply, if correct. This allowed identifying an error in the anchoring of the yy string in the application of the lemma. The lemma itself does not seem at fault. This is clearly too simplistic a construction. See more details in the comments.
The language L={uxvy∣u,v,x,y∈{0,1}∗{ϵ} , ∣u∣=∣v∣ , u≠v , ∣x∣=∣y∣ , x≠y }L={uxvy∣u,v,x,y∈{0,1}∗{ϵ} , ∣u∣=∣v∣ , u≠v , ∣x∣=∣y∣ , x≠y } is not Context-Free.
It is helpful to keep in mind the characterization L={uv:|u|=|v|,d(u,v)≥2}L={uv:|u|=|v|,d(u,v)≥2} where d is the Hamming distance,
proposed by @sdcvvc. What one needs to think about are 2 selected positions in each half string such that the corresponding symbols differ.
Then you consider a string 10i10j10i10j such that i<ji<j and i+ji+j is even. It is clearly in the language L, by cutting uu and xx anywhere between the two 1's. We want to pump that string on the first part between the 1's, so that it will become 10j10j10j10j which is not supposed to be in the language.
We first try to use Ogden's lemma, which is like the pumping lemma, but applies to pp or more distinguished symbols that are marked on the string, pp being the pumping length for marked symbols (but the lemma can pump more because it can pump also unmarked symbols). The pumping marked-length pp depends only on the language. This attempt will fail, but the failure will be a hint.
We can then choose i=pi=p and we mark symbols on the first sequence of ii 0's.
We know that none of the two 1's will be in the pump, because it can pump out once (exponent 0) instead of pumping in. And pumping out the 1's would get us out of the language.
However, we could be pumping on both sides of the second 1 as fast or even faster on the right side, so that the second 1 would never get across the middle of the string. Also Ogden's lemma does not fix an upper limit to the size of what is being pumped, so that it is not possible to organize the pumping to get the rightmost 1 exactly across the middle of the string.
We use a modified version of the lemma, here called Nash's Lemma, which can handle these difficulties.
We first need a definition (it probably has another name in the literature, but I do not know which - help is welcome). A string uu is said to be an erasure of a string vv iff it is obtained from vv by erasing symbols in vv. We will note u≺vu≺v.
Nash's Lemma :
If LL is a context-free language, then there exists two numbers p>0p>0 and q>0q>0 such that for any string ww of length at least pp in LL, and every way of “marking” pp or more of the positions in ww, ww can be written as w=uxyzvw=uxyzv with string uu, xx, yy, zz, vv, such that
- xzxz has at least one marked position,
- xyzxyz has at most pp marked positions, and
- there are 3 strings ˆxx^, ˆyy^, ˆzz^ such that
- ˆx≺xx^≺x, ˆy≺yy^≺y, ˆz≺zz^≺z,
- 1≤∣ˆxˆz∣≤q1≤∣x^z^∣≤q, 1≤∣ˆy∣≤q1≤∣y^∣≤q, and
- uxjˆxiˆyˆzizjvuxjx^iy^z^izjv is in LL for every i≥0i≥0 and for every j≥0j≥0.
Proof: Similar to the proof of Ogden's lemma, but the subtrees corresponding to the strings yy and xzxz are pruned so that they do not contain any path with twice the same non-terminal (except for the roots of these two subtrees). This necessarily limits the size of the generated strings ˆxˆzx^z^ and ˆyy^ by a constant qq.
The strings xjxj and zjzj, for j≥0j≥0, corresponding to an unpruned version of the tree, are used mainly with j=1j=1 to simplify the accounting when the lemma is applied.
We modify the above proof attempt by marking the pp leftmost symbols
0, but they are followed by 2q2q symbols 0 to make sure that we pump
in the left part of the string, between the two 1's. That make a total of i=p+2qi=p+2q 0's between the 1's (actually i=p+qi=p+q would be sufficient, since the rightmost 1 cannot be in ˆzz^, which would allow to simply remove it).
What is left is to have chosen jj so that we can pump exactly the right number of 0's so that the two sequences are equal. But so far, the only constraint on jj is to be greater than ii. And we also know that the number of 0's that are pumped at each pumping is between 1 and q. So let hh be product of the first qq integers. We choose j=i+hj=i+h.
Hence, since the pumping increment dd - whatever it is - is in [1,q][1,q], it divides hh. Let kk be the quotient. If we pump exactly kk times, we get a string 10j10j10j10j which is not in the language. Hence L is not context-free.
.
I think that I shall never see
A string lovely as a tree.
For if it does not have a parse,
The string is naught but a farce