MotzkinNumbers
The Motzkin numbers as a lazy indexed collection.
Wikipedia
Motzkin numberMathWorldMotzkinNumberWikidataQ2915234DLMF26.6.E2OEISA001006SymPymotzkin.find_first_n_motzkinsMotzkinNumbersThe number of Motzkin paths of length , an infinite indexed collection.Details
- A lazy indexed collection: , and unranks term via , bigint throughout -- .
- OEIS A001006, starting exactly at its offset-0 term: .
- Membership goes through Element: is true, is false.
Definition
Epsil, as the implementation runs it.
count()
PositiveInfinityunrank(_r)
Fold(Function(sm_a + Binomial(_r, 2sm_k) * (Binomial(2sm_k, sm_k) -
(0 if 2sm_k < sm_k + 1 else Binomial(
2sm_k,
sm_k + 1,
))), sm_a, sm_k), 0, Range(
0,
(_r - _r %
2) /
2,
1,
))rank(_x)
Apply(
(sq_at: integer) => (0 if _x == Fold(
Function(sm_a + Binomial(0, 2sm_k) *
(Binomial(
2sm_k,
sm_k,
) -
(0 if 2sm_k < sm_k +
1 else Binomial(2sm_k, sm_k + 1))), sm_a, sm_k),
0,
Range(0, (0 - 0 % 2) / 2, 1),
) else sq_at) if Fold(
Function(sm_a +
Binomial(sq_at, 2sm_k) *
(Binomial(2sm_k, sm_k) -
(0 if 2sm_k <
sm_k + 1 else Binomial(2sm_k, sm_k + 1))), sm_a, sm_k),
0,
Range(
0,
(sq_at -
sq_at %
2) / 2,
1,
),
) == _x else -1,
Fold(
Function(sq_at + 2 ^ sq_b if Fold(
Function(
sm_a + Binomial(sq_at +
2 ^
sq_b, 2sm_k) *
(Binomial(
2sm_k,
sm_k,
) -
(0 if 2sm_k <
sm_k + 1 else Binomial(2sm_k, sm_k + 1))),
sm_a,
sm_k,
),
0,
Range(
0,
(sq_at + 2 ^ sq_b - (sq_at +
2 ^
sq_b) %
2) / 2,
1,
),
) <= _x else sq_at, sq_at, sq_b),
0,
Range(Floor(Log(Floor(Log(_x, 2)) + 2, 2)) + 1, 0, -1),
),
) if True else -1valid(_x)
Apply(
(sq_at: integer) => Fold(
Function(sm_a + Binomial(sq_at, 2sm_k) * (Binomial(2sm_k, sm_k) -
(0 if 2sm_k <
sm_k + 1 else Binomial(2sm_k, sm_k + 1))), sm_a, sm_k),
0,
Range(0, (sq_at - sq_at % 2) / 2, 1),
) == _x,
Fold(
Function(sq_at + 2 ^ sq_b if Fold(
Function(
sm_a + Binomial(sq_at +
2 ^
sq_b, 2sm_k) *
(Binomial(
2sm_k,
sm_k,
) -
(0 if 2sm_k <
sm_k + 1 else Binomial(2sm_k, sm_k + 1))),
sm_a,
sm_k,
),
0,
Range(
0,
(sq_at + 2 ^ sq_b - (sq_at +
2 ^
sq_b) %
2) / 2,
1,
),
) <= _x else sq_at, sq_at, sq_b),
0,
Range(Floor(Log(Floor(Log(_x, 2)) + 2, 2)) + 1, 0, -1),
),
) if True && _x >= 1 else FalseEnumeration
Examples
1 more kept as data, checked against the oracles See also: Count, At, Element, CatalanNumbers