TITLE: Permutations containing a given subsequence
QUESTION [6 upvotes]: Let $f(n)$ denote the number of $4n$-long strings formed from $2n$ a's and $2n$ b's, such that the string contains, as a (possibly non-consecutive) subsequence, a pattern containing $n$ a's and $n$ b's.  (Note that $f(n)$ doesn't depend on the pattern, so two possible patterns would be
$$\overbrace{\strut a\cdots a}^{n\textrm{ times}}\, \overbrace{\strut b\cdots b}^{n\textrm{ times}}\quad\textrm{ or }\quad \overbrace{abab\cdots ab}^{n \textrm{ pairs}}.)$$
In the notation of this post, this number is $\left[\begin{array}{c}2n,2n\\n,n\end{array}\right]$.
By using the first pattern, and summing over the number of b's which occur before the $n$-th a, we find that
$$(*)\quad f(n)= \sum_{r=0}^n \binom{n+r-1}{r}\binom{3n-r}{n}.$$
The resulting sequence is $$1, 5, 53, 662, 8885, 124130, 1778966, 25947612, 383358645, \ldots$$
which appears in OEIS as A036910, where we find a nice closed form for the $n$-th term:
$$(**)\quad\frac12\left(\binom{4n}{2n}+\binom{2n}{n}^2\right).$$
The WZ-pair machinery should prove that $(*)$ and $(**)$ are equal, so that's not a concern.  My question: is there a straightforward combinatorial argument which gives the count $(**)$ directly (i.e., not as the result of evaluating a sum)?
The closed form suggests the cycle index formula for an involution, but I'm not seeing an answer along those lines.

REPLY [2 votes]: Addendum. The calculation in the other answer is  not quite rigorous in that the infinite series  that appears does  not converge in a  neighborhood of zero for $z.$ This can be fixed by using a different Iverson bracket.

Suppose as before that we are trying to evaluate
$$S = \sum_{r=0}^n {r+n-1\choose n-1} {3n-r\choose n}$$
which is
$$S_2-S_1  = 
\sum_{r=0}^{2n} {r+n-1\choose n-1} {3n-r\choose n}
- \sum_{r=n+1}^{2n} {r+n-1\choose n-1} {3n-r\choose n}.$$

Start by evaluating $S_2.$
Put
$${3n-r\choose n}
=  \frac{1}{2\pi i}
\int_{|w|=\epsilon} 
\frac{1}{w^{2n-r+1}} \frac{1}{(1-w)^{n+1}} \; dw.$$
and use the following Iverson bracket 
$$[[0\le r \le 2n]]
= \frac{1}{2\pi i}
\int_{|z|=\epsilon} \frac{z^{r}}{z^{2n+1}}\frac{1}{1-z} \; dz.$$
This second integral controls the range  so that we may extend the sum
to infinity to get
$$\frac{1}{2\pi i}
\int_{|w|=\epsilon} \frac{1}{w^{2n+1}} \frac{1}{(1-w)^{n+1}}
\frac{1}{2\pi i}
\int_{|z|=\epsilon} \frac{1}{z^{2n+1}} \frac{1}{1-z}
\sum_{r=0}^\infty {r+n-1\choose n-1}
z^r w^r \; dz \; dw.$$
This simplifies to
$$\frac{1}{2\pi i}
\int_{|w|=\epsilon} \frac{1}{w^{2n+1}} \frac{1}{(1-w)^{n+1}}
\frac{1}{2\pi i}
\int_{|z|=\epsilon} \frac{1}{z^{2n+1}} \frac{1}{1-z}
\frac{1}{(1-wz)^n}
\; dz \; dw.$$
We evaluate the inner integral using the fact that the residues at the
three poles sum  to zero. The residue at $z=0$ is  the sum $S_2$ which
we are trying to compute. The residue at $z=1$ yields
$$-\frac{1}{2\pi i}
\int_{|w|=\epsilon} \frac{1}{w^{2n+1}} \frac{1}{(1-w)^{2n+1}} \; dw
= -{2n+2n\choose 2n} = -{4n\choose 2n}.$$
For the residue at $z=1/w$ re-write the integral as follows:
$$\frac{(-1)^n}{2\pi i}
\int_{|w|=\epsilon} \frac{1}{w^{3n+1}} \frac{1}{(1-w)^{n+1}}
\frac{1}{2\pi i}
\int_{|z|=\epsilon} \frac{1}{z^{2n+1}} \frac{1}{1-z}
\frac{1}{(z-1/w)^n}
\; dz \; dw.$$
We require a derivative which we compute using Leibniz' rule:
$$\frac{1}{(n-1)!} 
\left(\frac{1}{z^{2n+1}} \frac{1}{1-z}\right)^{(n-1)}
\\ = \frac{1}{(n-1)!} \sum_{q=0}^{n-1} {n-1\choose q}
(-1)^q \frac{(2n+q)!}{(2n)! \times z^{2n+1+q}}
\frac{(n-1-q)!}{(1-z)^{1+n-1-q}}
\\ = \sum_{q=0}^{n-1} {2n+q\choose 2n}
(-1)^q \frac{1}{z^{2n+1+q}}
\frac{1}{(1-z)^{n-q}}.$$
Evaluate at $z=1/w$ to get
$$\sum_{q=0}^{n-1} {2n+q\choose 2n}
(-1)^q w^{2n+1+q}
\frac{w^{n-q}}{(w-1)^{n-q}}.$$
Substitute this back into the integral in $w$ to obtain
$$\sum_{q=0}^{n-1} {2n+q\choose 2n}
(-1)^q
\frac{(-1)^n}{2\pi i}
\int_{|w|=\epsilon} \frac{1}{w^{3n+1}} \frac{1}{(1-w)^{n+1}}
\frac{w^{3n+1}}{(w-1)^{n-q}} \; dw 
\\ = \sum_{q=0}^{n-1} {2n+q\choose 2n}
\frac{1}{2\pi i}
\int_{|w|=\epsilon} \frac{1}{(1-w)^{2n-q+1}} \; dw
= 0.$$
We have shown that
$$S_2 = {4n\choose 2n}.$$
Continuing with $S_1$ we see that
$$S_1 = \sum_{r=0}^{n-1}
{r+2n\choose n-1} {2n-1-r\choose n}
= \sum_{r=0}^{n-1}
{r+2n\choose n-1} {2n-1-r\choose n-1-r}.$$
For this sum no Iverson bracket is needed as the second binomial
coefficient controls the range via the following integral:
$${2n-1-r\choose n-1-r}
= \frac{1}{2\pi i}
\int_{|w|=\epsilon} \frac{(1+w)^{2n-1-r}}{w^{n-r}} \; dw.$$
Furthermore introduce
$${r+2n\choose n-1} 
= \frac{1}{2\pi i}
\int_{|z|=\epsilon} \frac{(1+z)^{r+2n}}{z^n} \; dz.$$
This gives the integral
$$\frac{1}{2\pi i}
\int_{|w|=\epsilon} \frac{(1+w)^{2n-1}}{w^{n}}
\frac{1}{2\pi i}
\int_{|z|=\epsilon} \frac{(1+z)^{2n}}{z^n}
\sum_{r\ge 0} \frac{w^r (1+z)^r}{(1+w)^r}
\; dz \; dw
\\ = \frac{1}{2\pi i}
\int_{|w|=\epsilon} \frac{(1+w)^{2n-1}}{w^{n}}
\frac{1}{2\pi i}
\int_{|z|=\epsilon} \frac{(1+z)^{2n}}{z^n}
\frac{1}{1-w(1+z)/(1+w)}
\; dz \; dw
\\ = \frac{1}{2\pi i}
\int_{|w|=\epsilon} \frac{(1+w)^{2n}}{w^{n}}
\frac{1}{2\pi i}
\int_{|z|=\epsilon} \frac{(1+z)^{2n}}{z^n}
\frac{1}{1+w-w(1+z)}
\; dz \; dw
\\ = \frac{1}{2\pi i}
\int_{|w|=\epsilon} \frac{(1+w)^{2n}}{w^{n}}
\frac{1}{2\pi i}
\int_{|z|=\epsilon} \frac{(1+z)^{2n}}{z^n}
\frac{1}{1-wz}
\; dz \; dw.$$
Extracting the inner residue we obtain
$$\sum_{q=0}^{n-1} {2n\choose n-1-q} w^q$$
which yields
$$\sum_{q=0}^{n-1} {2n\choose n-1-q} 
\frac{1}{2\pi i}
\int_{|w|=\epsilon} \frac{(1+w)^{2n}}{w^{n-q}} \; dw
\\= \sum_{q=0}^{n-1} {2n\choose n-1-q} {2n\choose n-1-q}.$$
This is
$$\sum_{q=0}^{n-1} {2n\choose q}^2$$
which may be evaluated by inspection as in the other answer, and collecting the contributions from $S_2$ and $S_1$ we once more obtain
$$\frac{1}{2}
\left({4n\choose 2n} + {2n\choose n}^2\right).$$
Remark. To be fully rigorous we must also show that the residue at
infinity of
$$\frac{1}{2\pi i}
\int_{|z|=\epsilon} \frac{1}{z^{2n+1}} \frac{1}{1-z}
\frac{1}{(1-wz)^n} \; dz$$
is zero. Recall the formula for the residue at infinity
$$\mathrm{Res}_{z=\infty} h(z)
= \mathrm{Res}_{z=0} 
\left[-\frac{1}{z^2} h\left(\frac{1}{z}\right)\right]$$
which in this case yields
$$-\mathrm{Res}_{z=0} 
\frac{1}{z^2} z^{2n+1} \frac{1}{1-1/z} \frac{1}{(1-w/z)^n}
\\ = -\mathrm{Res}_{z=0} 
z^{2n} \frac{1}{z-1} \frac{1}{(1-w/z)^n}
\\ = -\mathrm{Res}_{z=0} 
z^{3n} \frac{1}{z-1} \frac{1}{(z-w)^n}$$
which is zero by inspection.