Skip to content

MotzkinNumbers ​

The Motzkin numbers 1,1,2,4,9,21,…1, 1, 2, 4, 9, 21, … as a lazy indexed collection.

WikipediaMotzkin numberMathWorldMotzkinNumberWikidataQ2915234DLMF26.6.E2OEISA001006SymPymotzkin.find_first_n_motzkins
MotzkinNumbersThe number of Motzkin paths of length nn, an infinite indexed collection.

Domain: Collections

Details
  • A lazy indexed collection: Count(MotzkinNumbers)=+∞Count(MotzkinNumbers) = +\infty, and At(MotzkinNumbers,k)At(MotzkinNumbers, k) unranks term k−1k-1 via M(n)=((2n+1)M(n−1)+3(n−1)M(n−2))/(n+2)M(n) = \left((2n+1)M(n-1) + 3(n-1)M(n-2)\right)/(n+2), bigint throughout -- At(MotzkinNumbers,1)=M0=1At(MotzkinNumbers, 1) = M_0 = 1.
  • OEIS A001006, starting exactly at its offset-0 term: 1,1,2,4,9,21,51,…1, 1, 2, 4, 9, 21, 51, ….
  • Membership goes through Element: Element(9,MotzkinNumbers)Element(9, MotzkinNumbers) is true, Element(6,MotzkinNumbers)Element(6, MotzkinNumbers) is false.

Definition

Epsil, as the implementation runs it.

count()

PositiveInfinity

unrank(_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 -1

valid(_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 False

Enumeration

Examples

1 more kept as data, checked against the oracles
About
Examples1
CrosswalkWikipediaMathWorldWikidataDLMFOEISSymPy

See also: Count, At, Element, CatalanNumbers