Skip to content

LatticePaths ​

The monotone lattice paths from (0,0)(0,0) to (a,b)(a,b) using unit north/east steps, each written as a 0/10/1 step sequence (11 = north). Count (a+ba)\binom{a+b}{a}.

✓ checked against that system · ! checked, with disagreements (hover a chip)OEISA046899✓
LatticePaths(a, b)the monotone north/east lattice paths in an a×ba \times b grid
Typed signatures
TypePackageApplies
(integer<0..>, integer<0..>) -> indexed_collection<list<integer>>combinatoricsalways

Domain: Collections

Definition

Epsil, as the implementation runs it.

count(_a, _b)

Binomial(_a + _b, _a) if 0 <= _a && _a <= _a + _b else 0

unrank(_a, _b, _r)

Drop(Fold(Function(Apply(
                          (lu_o: integer) => Join([
                                                    lu_s[1] - lu_o,
                                                    lu_s[2] - 1,
                                                    1,
                                                  ], Drop(lu_s, 2)) if lu_s[1] >=
                                                                      lu_o else Join(
                                                                                  [lu_s[1], lu_s[2], 0],
                                                                                  Drop(lu_s, 2),
                                                                                ),
                          Binomial(lu_j - 1, lu_s[2]) if 0 <= lu_s[2] && lu_s[2] <=
                                                                         lu_j -
                                                                         1 else 0,
                        ), lu_s, lu_j), [_r, _a], Range(_a + _b, 1, -1)), 2)

rank(_a, _b, _x)

Fold(Function([
                lr_s[1] +
                ((Binomial(lr_s[3] - 1, lr_s[2] + 1) if 0 <= lr_s[2] + 1 && lr_s[2] +
                                                                            1 <=
                                                                            lr_s[3] -
                                                                            1 else 0) if lr_t == 1 else 0),
                lr_s[2] + (1 if lr_t == 1 else 0),
                lr_s[3] + 1,
              ], lr_s, lr_t), [0, 0, 1], _x)[1]

valid(_a, _b, _x)

Length(_x) == _a + _b && Fold(Function(
                                        ok_lv_t && 0 <= lv_t && lv_t <= 1,
                                        ok_lv_t,
                                        lv_t,
                                      ), True, _x) && Fold(Function(
                                                                    lv_c + lv_u,
                                                                    lv_c,
                                                                    lv_u,
                                                                  ), 0, _x) == _a

Examples

Basic #

(53)=10\binom{5}{3} = 10

live ↗
InCount(LatticePaths(3,2))\mathrm{Count}(\mathrm{LatticePaths}(3, 2))Out1010

11 = north

live ↗
InTake(LatticePaths(2,2),6)\mathrm{Take}(\mathrm{LatticePaths}(2, 2), 6)Out[[1,1,0,0],[1,0,1,0],[0,1,1,0],[1,0,0,1],[0,1,0,1],[0,0,1,1]]\bigl\lbrack\bigl\lbrack1, 1, 0, 0\bigr\rbrack, \bigl\lbrack1, 0, 1, 0\bigr\rbrack, \bigl\lbrack0, 1, 1, 0\bigr\rbrack, \bigl\lbrack1, 0, 0, 1\bigr\rbrack, \bigl\lbrack0, 1, 0, 1\bigr\rbrack, \bigl\lbrack0, 0, 1, 1\bigr\rbrack\bigr\rbrack
About
Examples2
CrosswalkOEIS

See also: PartitionsInBox