;
for (t=k-s,ss=s,tt=w-ss;tt<=t;ss--,tt++) {
addto(subtotal,binom(w,ss));
if (ss==p) nonbeads++; /* see below */
}
}
@ Nonbeads $[r_0,\ldots,r_m]$ are of four kinds: (a)~$r_p=x_{k+1}$,
$r_j=1$ for $jp$; (b)~$[0,x_n,1]$;
(c)~$[r_0,\ldots,r_m]=[0,\ldots,0]$, within Type~A;
(d)~$[r_0,\ldots,r_m]=[1,\ldots,1]$, within Type~D.
Here we look for (a) and (b).
@=
p=n+1; /* |n+1| is ``infinity'' */
if (ww==m-2) {
if (m==2 && perm[s+1]==n)
p=(perm[s+2]<=k? 1: 0);
else if (w==m) {
for (p=1;;p++) if (perm[s+p]>k) break;
if (perm[s+p]!=k+1) p=n+1;
}
}
@ Each constant type is a symmetric function. I need to contribute
$m-1\choose r$ to the subtotal for each possible value of
$r=r_1+\cdots+r_{m-1}$. But I want to contribute exactly once for
every such~$r$; equal values of $r$ can arise from different values of~$s$.
So there are tables |addedA|, |addedB|, |addedC|, |addedD|, to remember
when a particular $r$ has been contributed already to the counts of
each type.
@=
for (j=0;j=
{
for (t=k-s,ss=s,tt=w-ss;tt<=t;ss--,tt++) if (ss>=0 && tt>=0) {
if (perm[s+m]<=k) { /* true constant at right */
if (!addedA[ss])
addedA[ss]=1,addto(subtotal,binom(m-1,ss));
if (ss>0 && !addedB[ss-1])
addedB[ss-1]=1,addto(subtotal,binom(m-1,ss-1));
}@+else if (!addedB[ss])
addedB[ss]=1,addto(subtotal,binom(m-1,ss));
if (ss>0 && perm[s]<=k) { /* true constant at left */
if (perm[s+m]<=k) { /* and also at right */
if (!addedC[ss-1])
addedC[ss-1]=1,addto(subtotal,binom(m-1,ss-1));
if (ss>1 && !addedD[ss-2])
addedD[ss-2]=1,addto(subtotal,binom(m-1,ss-2));
}@+else if (!addedD[ss-1])
addedD[ss-1]=1,addto(subtotal,binom(m-1,ss-1));
}
}
}
@ @=
if (addedA[0]) nonbeads++; /* all 0s */
if (addedD[m-1]) nonbeads++; /* all 1s */
@*Index.