Let's rank the totally balanced binary string 11011001110000, in decimal 13936. First we draw a corresponding mountain range, moving from the left (the most significant end) to the right (the least significant end) in binary string, letting 1 stand for the upward slope /, and 0 stand for the downward slope \.
Then we draw the mountain range over the triangle obtained from the EIS-sequence A009766, formatted as a triangular array, with one additional diagonal of zeroes appended at its left side. We start from the right-hand end of the range, setting the last downward slope to stretch from the first zero at the top to the next zero below it.11011001110000 /\ /\ / \ /\/ \/ \ / \
| 0 | 1 | ||||||||||||||||||||||||
| 0 | 1 | 1 | |||||||||||||||||||||||
| 0 | 1 | 2 | 2 | ||||||||||||||||||||||
| 0 | 1 | 3 | 5 | 5 | |||||||||||||||||||||
| 0 | ---- | ---1 | ---- | ---4 | ---- | ---9 | 14 | 14 | |||||||||||||||||
| 0 | 1 | 5 | 14 | 28 | 42 | 42 | |||||||||||||||||||
| 0 | 1 | 6 | 20 | ---- | --48 | ---- | --90 | 132 | 132 | ||||||||||||||||
| 0 | 1 | 7 | 27 | 75 | 165 | ---- | -297 | ---- | -429 | 429 | |||||||||||||||
| 0 | 1 | 8 | 35 | 110 | 275 | 572 | 1001 | 1430 | 1430 | ||||||||||||||||
| 0 | 1 | 9 | 44 | 154 | 429 | 1001 | 2002 | 3432 | 4862 | 4862 |
CatTriangleDirect := (r,m) -> `if`((m < 0),0,((r-m+1)*(r+m)!)/(r! * m! * (r+1)));
CatTriangle := proc(r,m) option remember;
if(m < 0) then RETURN(0); fi;
if(r < 0) then RETURN(0); fi;
if(m > r) then RETURN(0); fi;
if(0 = m) then RETURN(1); fi;
RETURN(CatTriangle(r,m-1) + CatTriangle(r-1,m));
end;
CatalanRank2 := proc(n,aa) local y,r,lo,a;
a := aa;
r := 0;
y := -1;
lo := 0;
while (a > 0)
do
if(0 = (a mod 2))
then
r := r+1;
lo := lo + CatTriangle(r,y);
else
y := y+1;
fi;
a := floor(a/2);
od;
RETURN((binomial(2*n,n)/(n+1))-(lo+1));
end;
CatalanUnrank2 := proc(n,rr) local t,y,lo,r,a,m;
r := (binomial(2*n,n)/(n+1))-(rr+1);
a := 0;
lo := 0;
t := n;
y := n-1;
while(t > 0)
do
m := CatTriangle(t,y);
if(r < (lo+m))
then
y := y-1;
a := 2*a + 1;
else
lo := lo+m;
t := t-1;
a := 2*a;
fi;
od;
RETURN(a);
end;
convert(2762, binary); 101011001010 /\ /\/\/ \/\/\
| 0 | 1 | ||||||||||||||||||||||||
| * | |||||||||||||||||||||||||
| 0 | ---- | ----1 | 1 | ||||||||||||||||||||||
| * | |||||||||||||||||||||||||
| 0 | 1 | ---- | ---2 | 2 | |||||||||||||||||||||
| * | |||||||||||||||||||||||||
| 0 | 1 | 3 | 5 | 5 | |||||||||||||||||||||
| * | |||||||||||||||||||||||||
| 0 | 1 | 4 | ---- | ---9 | ---- | --14 | 14 | ||||||||||||||||||
| * | |||||||||||||||||||||||||
| 0 | 1 | 5 | 14 | 28 | ---- | --42 | 42 | ||||||||||||||||||
| * | |||||||||||||||||||||||||
| 0 | 1 | 6 | 20 | 48 | 90 | ---- | -132 | 132 | |||||||||||||||||
| 0 | 1 | 7 | 27 | 75 | 165 | 297 | 429 | 429 | |||||||||||||||||
| 0 | 1 | 8 | 35 | 110 | 275 | 572 | 1001 | 1430 | 1430 | ||||||||||||||||
| 0 | 1 | 9 | 44 | 154 | 429 | 1001 | 2002 | 3432 | 4862 | 4862 |
Let's draw the above range another time on top of the triangle, this time starting from the top 1, at (0,0). Note, that because each term in the
triangle is obtained by summing its two neighbours, one at its left side, and one at its NE-corner
(everything outside the triangle is zeroes),
the each term gives precisely the number of different paths that start from the top (0,0)-cell,
stay inside the triangle, and end to that node, using only those two steps, NE->SW and W->E.
Furthermore, this one is a palindromic mountain range. Any palindromic range of length 12,
consists of a sequence of 6 steps, that end somewhere on the shallow diagonal marked here with bold
numbers, 1, 5, 9, 5, and which steps are then reflected as a mirror-image, on the other side of that "axis".
Because we know that terms on such shallow diagonals sum to the central binomial coefficients C(n,[n/2])
(see [1]),
i.e. the EIS-sequence A001405,
we see that they enumerate the number of such palindromic mountain ranges,
A061855,
and the corresponding "half-paths",
A061854.
It's now also easy to see why the squares of the terms on shallow diagonals sum to Catalan numbers
themselves A000108.
(But can you see why the row sums of the triangle, like 1+3+5+5 = 14, 1+4+9+14+14 = 42, etc. also sum to
Catalan numbers?)
| 1 | |||||||||||||||||||||||||
| * | |||||||||||||||||||||||||
| 1 | ---- | ---1 | |||||||||||||||||||||||
| * | |||||||||||||||||||||||||
| 1 | 2 | ---- | ---2 | ||||||||||||||||||||||
| * | |||||||||||||||||||||||||
| 1 | 3 | 5 | 5 | ||||||||||||||||||||||
| * | |||||||||||||||||||||||||
| 1 | 4 | 9 | ---- | --14 | ---- | --14 | |||||||||||||||||||
| * | |||||||||||||||||||||||||
| 1 | 5 | 14 | 28 | 42 | ---- | --42 | |||||||||||||||||||
| * | |||||||||||||||||||||||||
| 1 | 6 | 20 | 48 | 90 | 132 | ---- | -132 | ||||||||||||||||||
| 1 | 7 | 27 | 75 | 165 | 297 | 429 | 429 | ||||||||||||||||||
| 1 | 8 | 35 | 110 | 275 | 572 | 1001 | 1430 | 1430 | |||||||||||||||||
| 1 | 9 | 44 | 154 | 429 | 1001 | 2002 | 3432 | 4862 | 4862 |
Note that on the page 24 of the Frank's thesis, the while loop condition of the unranking algorithm is erroneously given as m > 0, while it should be m >= 0, i.e. we stop only when m goes negative.
Frank also mentioned in his mail that
These ranking and unranking schemes seem to get periodically re-discovered. It's quite possible that I'm not the originator either. Certainly Knott, Trojanowski, Rotem, Zaks and others were also ranking and generating various Catalan sequences in the late 70's.