Skip to content

RootedUnlabeledTrees ​

The rooted trees on nn unlabelled nodes, up to isomorphism, as a lazy indexed family.

RootedUnlabeledTrees(n)every rooted tree on nn nodes with unordered children, one per isomorphism class.
Typed signatures
TypePackageApplies
(integer<0..>) -> indexed_collection<rooted_unlabeled_tree>combinatoricsalways

Domain: Collections

Details
  • A lazy indexed collection; the count is A000081(n)A000081(n) — A000081(6)=20A000081(6) = 20 — with no elementary closed form, computed via the Euler transform over smaller rooted-tree counts (a multiset of subtrees hangs off the root).
  • Each element is the level sequence: node depths in canonical preorder, root first at depth 0. Canonical means a node's children are generated weight-descending, ties broken by ascending own rank — the order At unranks in, so isomorphic labellings collapse to one entry.
  • UnlabeledFreeTrees(n)UnlabeledFreeTrees(n) is the unrooted counterpart: a free tree canonically rooted at its centroid uses the same level-sequence encoding.

Definition

Epsil, as the implementation runs it.

count(_n)

0 if _n < 1 else _tables[(_n - 1) * Max(_n, 1) + (_n - 1) + 1]

unrank(_n, _r)

Take(Apply((tu_s_init: list<integer>) => Fold((tu_s: list<integer>, tu_i) => Apply(
                                                                                    (tu_s_next: list<integer>) => tu_s_next,
                                                                                    Apply((tu_d: integer) => Apply((tu_w: integer) => Apply((tu_r: integer) => Apply(
                                                                                                                                                                      (tu_kids: list<integer>) => Join(Take(tu_s, tu_i - 1), [tu_d], tu_kids, Drop(tu_s, tu_i + 2)),
                                                                                                                                                                      Drop(Apply((ts_s_init: list<integer>) => Fold((ts_s: list<integer>, ts_u) => Apply(
                                                                                                                                                                                                                                                          (ts_s_next: list<integer>) => ts_s_next,
                                                                                                                                                                                                                                                          Apply((ts_rem: integer) => Apply(
                                                                                                                                                                                                                                                                                            (ts_sc: list<integer>) => Apply((ts_kk: integer) => Apply((ts_ways: integer) => Apply(
                                                                                                                                                                                                                                                                                                                                                                                   (ts_digits: list<integer>) => Join(
                                                                                                                                                                                                                                                                                                                                                                                                                       [ts_rem -
                                                                                                                                                                                                                                                                                                                                                                                                                        ts_kk * ts_u, ts_sc[3] % ts_ways],
                                                                                                                                                                                                                                                                                                                                                                                                                       Drop(ts_s, 2),
                                                                                                                                                                                                                                                                                                                                                                                                                       Apply((ts_found_init: list<integer>) => Fold((ts_found: list<integer>, ts_j) => Apply((ts_found_next: list<integer>) => ts_found_next, Join(ts_found, [tu_d + 1, ts_u, ts_digits[ts_kk + 1 -
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        ts_j +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        2] -
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              (ts_j - 1)])), ts_found_init, Range(1, ts_kk, 1)), []),
                                                                                                                                                                                                                                                                                                                                                                                                                     ),
                                                                                                                                                                                                                                                                                                                                                                                   Apply(
                                                                                                                                                                                                                                                                                                                                                                                          (ts_dg_init: list<integer>) => Fold((ts_dg: list<integer>, ts_i) => Apply(
                                                                                                                                                                                                                                                                                                                                                                                                                                                                     (ts_dg_next: list<integer>) => ts_dg_next,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                     Apply((ts_left: integer) => Apply(
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        (ts_top: integer) => Join([ts_left -
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   (Binomial(ts_top, ts_i) if 0 <= ts_i &&
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              ts_i <= ts_top else 0), ts_top], Drop(ts_dg, 2), [ts_top]),
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Apply((ts_g_b_init: list<integer>) => Fold((ts_g_b: list<integer>, ts_g_h) => Apply(
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             (ts_g_b_next: list<integer>) => ts_g_b_next,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             Apply((ts_g_mid: integer) => [ts_g_mid, ts_g_b[2]] if (Binomial(ts_g_mid, ts_i) if 0 <= ts_i &&
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                ts_i <= ts_g_mid else 0) <=
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   ts_left else [ts_g_b[1], ts_g_mid - 1], (ts_g_b[1] + ts_g_b[2] + 1 -
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     (ts_g_b[1] + ts_g_b[2] + 1) %
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     2) /
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    2) if ts_g_b[1] < ts_g_b[2] else ts_g_b,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           ), ts_g_b_init, Range(1, 64, 1)), [ts_i - 1, ts_dg[2] - 1])[1],
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      ), ts_dg[1]),
                                                                                                                                                                                                                                                                                                                                                                                                                                                                   ), ts_dg_init, Range(ts_kk, 1, -1)),
                                                                                                                                                                                                                                                                                                                                                                                          [(ts_sc[3] -
                                                                                                                                                                                                                                                                                                                                                                                            ts_sc[3] % ts_ways) /
                                                                                                                                                                                                                                                                                                                                                                                           ts_ways, _tables[(ts_u - 1) *
                                                                                                                                                                                                                                                                                                                                                                                                     Max(_n, 1) +
                                                                                                                                                                                                                                                                                                                                                                                                     (ts_u - 1) +
                                                                                                                                                                                                                                                                                                                                                                                                     1] +
                                                                                                                                                                                                                                                                                                                                                                                             (ts_kk - 1)],
                                                                                                                                                                                                                                                                                                                                                                                        ),
                                                                                                                                                                                                                                                                                                                                                                                 ), Max(_tables[(ts_u - 1) *
                                                                                                                                                                                                                                                                                                                                                                                               Max(_n, 1) +
                                                                                                                                                                                                                                                                                                                                                                                               (ts_rem -
                                                                                                                                                                                                                                                                                                                                                                                                ts_kk * ts_u) +
                                                                                                                                                                                                                                                                                                                                                                                               1], 1)), ts_sc[2]),
                                                                                                                                                                                                                                                                                            Apply((ts_sc_init: list<integer>) => Fold(
                                                                                                                                                                                                                                                                                                                                       (ts_sc: list<integer>, ts_k) => Apply(
                                                                                                                                                                                                                                                                                                                                                                              (ts_sc_next: list<integer>) => ts_sc_next,
                                                                                                                                                                                                                                                                                                                                                                              ts_sc if ts_sc[1] == 1 else Apply(
                                                                                                                                                                                                                                                                                                                                                                                                                 (ts_blk: integer) => [1, ts_k, ts_sc[3]] if ts_sc[3] < ts_blk else [0, ts_k, ts_sc[3] - ts_blk],
                                                                                                                                                                                                                                                                                                                                                                                                                 Binomial(_tables[(ts_u - 1) *
                                                                                                                                                                                                                                                                                                                                                                                                                                  Max(_n, 1) +
                                                                                                                                                                                                                                                                                                                                                                                                                                  (ts_u - 1) +
                                                                                                                                                                                                                                                                                                                                                                                                                                  1] +
                                                                                                                                                                                                                                                                                                                                                                                                                          (ts_k - 1), ts_k) *
                                                                                                                                                                                                                                                                                                                                                                                                                 _tables[(ts_u - 1) *
                                                                                                                                                                                                                                                                                                                                                                                                                         Max(_n, 1) +
                                                                                                                                                                                                                                                                                                                                                                                                                         (ts_rem -
                                                                                                                                                                                                                                                                                                                                                                                                                          ts_k * ts_u) +
                                                                                                                                                                                                                                                                                                                                                                                                                         1],
                                                                                                                                                                                                                                                                                                                                                                                                               ),
                                                                                                                                                                                                                                                                                                                                                                            ),
                                                                                                                                                                                                                                                                                                                                       ts_sc_init,
                                                                                                                                                                                                                                                                                                                                       Range(0, (ts_rem -
                                                                                                                                                                                                                                                                                                                                                 ts_rem % ts_u) /
                                                                                                                                                                                                                                                                                                                                                ts_u, 1),
                                                                                                                                                                                                                                                                                                                                     ), [0, 0, ts_s[2]]),
                                                                                                                                                                                                                                                                                          ), ts_s[1]),
                                                                                                                                                                                                                                                        ), ts_s_init, Range(tu_w - 1, 1, -1)), [tu_w - 1, tu_r]), 2),
                                                                                                                                                                    ), tu_s[tu_i + 2]), tu_s[tu_i + 1]), tu_s[tu_i]),
                                                                                  ), tu_s_init, Range(1, _n, 1)), [0, _n, _r]), _n)

rank(_n, _x)

Apply((wk_xs: list<integer>) => Apply(
                                       (wk_w: list<integer>) => Apply(
                                                                       (wk_k: list<integer>) => Apply(
                                                                                                       (tf_pad: list<integer>) => Apply((tf_z_init: list<integer>) => Fold(
                                                                                                                                                                            (tf_z: list<integer>, tf_t) => Apply(
                                                                                                                                                                                                                  (tf_z_next: list<integer>) => tf_z_next,
                                                                                                                                                                                                                  Apply((tf_st: integer) => Apply(
                                                                                                                                                                                                                                                   (tf_w: integer) => Apply((tf_a: integer) => Apply((tf_ps: integer) => Apply((tf_base: integer) => Apply((tf_rem: integer) => Apply((tf_cw: integer) => Apply((tf_cnt: integer) => Apply((tf_ss: integer) => Apply((tf_pw: integer) => Apply((tf_pa: integer) => Apply((tf_bad: integer) => Apply((tf_risk: integer) => [
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            tf_base,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            tf_rem,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            tf_cw,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            tf_cnt + 1,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            tf_ss +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            Binomial(tf_a + tf_cnt, tf_cnt + 1),
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            tf_w,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            tf_a,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            tf_bad +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            (1 if tf_w > tf_pw ||
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  tf_w == tf_pw &&
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  tf_w < 40 &&
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  tf_a < tf_pa else 0),
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            tf_risk +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            ((0 if 0 ==
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   Fold(Function(tf_ix +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 Abs(wk_xs[tf_st + tf_iu] -
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     wk_xs[tf_st] -
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     (wk_xs[tf_ps + tf_iu] -
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      wk_xs[tf_ps])), tf_ix, tf_iu), 0, Range(0, tf_w - 1, 1)) else 1) if tf_w == tf_pw &&
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               40 <= tf_w else 0),
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            tf_st,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          ] if tf_w == tf_cw else Apply(
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        (tf_fin: integer) => [
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               tf_base + tf_fin,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               tf_rem -
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               tf_cw * tf_cnt if 0 < tf_cw else tf_rem,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               tf_w,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               1,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               tf_a,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               tf_w,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               tf_a,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               tf_bad +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               (1 if tf_w > tf_pw ||
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     tf_w == tf_pw &&
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     tf_w < 40 &&
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     tf_a < tf_pa else 0),
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               tf_risk +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               ((0 if 0 ==
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      Fold(Function(tf_ix +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    Abs(wk_xs[tf_st + tf_iu] -
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        wk_xs[tf_st] -
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        (wk_xs[tf_ps + tf_iu] -
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         wk_xs[tf_ps])), tf_ix, tf_iu), 0, Range(0, tf_w - 1, 1)) else 1) if tf_w == tf_pw &&
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  40 <= tf_w else 0),
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               tf_st,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             ],
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Fold(Function(tf_acc +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      Binomial(_tables[(tf_cw - 1) *
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       Max(_n, 1) +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       (tf_cw - 1) +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       1] +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               (tf_kk - 1), tf_kk) *
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      _tables[(tf_cw - 1) *
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              Max(_n, 1) +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              (tf_rem -
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               tf_kk * tf_cw) +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              1], tf_acc, tf_kk), 0, Range(0, tf_cnt - 1, 1)) +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        tf_ss *
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        _tables[(tf_cw - 1) *
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Max(_n, 1) +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                (tf_rem -
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 tf_cnt * tf_cw) +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                1] if 0 < tf_cw else 0,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      ), tf_z[9]), tf_z[8]), tf_z[7]), tf_z[6]), tf_z[5]), tf_z[4]), tf_z[3]), tf_z[2]), tf_z[1]), tf_z[10]), tf_pad[3tf_t]),
                                                                                                                                                                                                                                                   tf_pad[3tf_t - 1],
                                                                                                                                                                                                                                                 ), tf_pad[3tf_t - 2]),
                                                                                                                                                                                                                ),
                                                                                                                                                                            tf_z_init,
                                                                                                                                                                            Range(1, (Length(wk_k) -
                                                                                                                                                                                      Length(wk_k) % 3) /
                                                                                                                                                                                     3 +
                                                                                                                                                                                     1, 1),
                                                                                                                                                                          ), [0, _n - 1, 0, 0, 0, _n + 1, 0, 0, 0, 0]),
                                                                                                       Join(wk_k, [0, 0, 0]),
                                                                                                     )[1],
                                                                       Apply(
                                                                              (wk_h: list<integer>) => Drop(wk_h, 1),
                                                                              Apply(
                                                                                     (wk_acc_init: list<integer>) => Fold(
                                                                                                                           (wk_acc: list<integer>, wk_t) => Apply(
                                                                                                                                                                   (wk_acc_next: list<integer>) => wk_acc_next,
                                                                                                                                                                   Apply((wk_q: list<integer>) => Apply((wk_j: integer) => Join([wk_j +
                                                                                                                                                                                                                                 wk_w[wk_j + 2]], Drop(wk_q, 1), [wk_j, wk_w[wk_j + 2], wk_w[_n + wk_j + 2]]) if wk_j <= _n &&
                                                                                                                                                                                                                                                                                                   wk_xs[wk_j] ==
                                                                                                                                                                                                                                                                                                   wk_xs[1] + 1 else wk_q, wk_acc[1]), wk_acc),
                                                                                                                                                                 ),
                                                                                                                           wk_acc_init,
                                                                                                                           Range(1, _n - 1, 1),
                                                                                                                         ),
                                                                                     [1 + 1],
                                                                                   ),
                                                                            ),
                                                                     ),
                                       Apply(
                                              (wk_p_init: list<integer>) => Fold((wk_p: list<integer>, wk_i) => Apply(
                                                                                                                       (wk_p_next: list<integer>) => wk_p_next,
                                                                                                                       Apply(
                                                                                                                              (wk_hop: list<integer>) => Apply((wk_size: integer) => Apply(
                                                                                                                                                                                            (wk_z: list<integer>) => ReplaceAt(
                                                                                                                                                                                                                                ReplaceAt(ReplaceAt(ReplaceAt(wk_p, 1, wk_p[1] + wk_z[8]), 2, wk_p[2] + wk_z[9]), wk_i + 2, wk_size),
                                                                                                                                                                                                                                _n + wk_i + 2,
                                                                                                                                                                                                                                wk_z[1],
                                                                                                                                                                                                                              ),
                                                                                                                                                                                            Apply(
                                                                                                                                                                                                   (tw_pad: list<integer>) => Apply((tw_z_init: list<integer>) => Fold(
                                                                                                                                                                                                                                                                        (tw_z: list<integer>, tw_t) => Apply(
                                                                                                                                                                                                                                                                                                              (tw_z_next: list<integer>) => tw_z_next,
                                                                                                                                                                                                                                                                                                              Apply((tw_st: integer) => Apply(
                                                                                                                                                                                                                                                                                                                                               (tw_w: integer) => Apply((tw_a: integer) => Apply((tw_ps: integer) => Apply((tw_base: integer) => Apply((tw_rem: integer) => Apply((tw_cw: integer) => Apply((tw_cnt: integer) => Apply((tw_ss: integer) => Apply((tw_pw: integer) => Apply((tw_pa: integer) => Apply((tw_bad: integer) => Apply((tw_risk: integer) => [
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        tw_base,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        tw_rem,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        tw_cw,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        tw_cnt + 1,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        tw_ss +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Binomial(tw_a + tw_cnt, tw_cnt + 1),
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        tw_w,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        tw_a,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        tw_bad +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        (1 if tw_w > tw_pw ||
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              tw_w == tw_pw &&
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              tw_w < 40 &&
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              tw_a < tw_pa else 0),
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        tw_risk +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        ((0 if 0 ==
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               Fold(Function(tw_ix +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             Abs(wk_xs[tw_st + tw_iu] -
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 wk_xs[tw_st] -
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 (wk_xs[tw_ps + tw_iu] -
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  wk_xs[tw_ps])), tw_ix, tw_iu), 0, Range(0, tw_w - 1, 1)) else 1) if tw_w == tw_pw &&
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           40 <= tw_w else 0),
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        tw_st,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      ] if tw_w == tw_cw else Apply(
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    (tw_fin: integer) => [
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           tw_base + tw_fin,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           tw_rem -
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           tw_cw * tw_cnt if 0 < tw_cw else tw_rem,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           tw_w,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           1,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           tw_a,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           tw_w,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           tw_a,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           tw_bad +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           (1 if tw_w > tw_pw ||
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 tw_w == tw_pw &&
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 tw_w < 40 &&
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 tw_a < tw_pa else 0),
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           tw_risk +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           ((0 if 0 ==
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  Fold(Function(tw_ix +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Abs(wk_xs[tw_st + tw_iu] -
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    wk_xs[tw_st] -
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    (wk_xs[tw_ps + tw_iu] -
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     wk_xs[tw_ps])), tw_ix, tw_iu), 0, Range(0, tw_w - 1, 1)) else 1) if tw_w == tw_pw &&
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              40 <= tw_w else 0),
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           tw_st,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         ],
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    Fold(Function(tw_acc +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  Binomial(_tables[(tw_cw - 1) *
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   Max(_n, 1) +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   (tw_cw - 1) +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   1] +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           (tw_kk - 1), tw_kk) *
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  _tables[(tw_cw - 1) *
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          Max(_n, 1) +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          (tw_rem -
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           tw_kk * tw_cw) +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          1], tw_acc, tw_kk), 0, Range(0, tw_cnt - 1, 1)) +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    tw_ss *
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    _tables[(tw_cw - 1) *
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            Max(_n, 1) +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            (tw_rem -
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             tw_cnt * tw_cw) +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            1] if 0 < tw_cw else 0,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  ), tw_z[9]), tw_z[8]), tw_z[7]), tw_z[6]), tw_z[5]), tw_z[4]), tw_z[3]), tw_z[2]), tw_z[1]), tw_z[10]), tw_pad[3tw_t]),
                                                                                                                                                                                                                                                                                                                                               tw_pad[3tw_t - 1],
                                                                                                                                                                                                                                                                                                                                             ), tw_pad[3tw_t - 2]),
                                                                                                                                                                                                                                                                                                            ),
                                                                                                                                                                                                                                                                        tw_z_init,
                                                                                                                                                                                                                                                                        Range(1, (Length(Drop(wk_hop, 1)) -
                                                                                                                                                                                                                                                                                  Length(Drop(wk_hop, 1)) %
                                                                                                                                                                                                                                                                                  3) /
                                                                                                                                                                                                                                                                                 3 +
                                                                                                                                                                                                                                                                                 1, 1),
                                                                                                                                                                                                                                                                      ), [0, wk_size - 1, 0, 0, 0, _n + 1, 0, 0, 0, 0]),
                                                                                                                                                                                                   Join(Drop(wk_hop, 1), [0, 0, 0]),
                                                                                                                                                                                                 ),
                                                                                                                                                                                          ), wk_hop[1] - wk_i),
                                                                                                                              Apply((wk_acc_init: list<integer>) => Fold(
                                                                                                                                                                          (wk_acc: list<integer>, wk_t) => Apply(
                                                                                                                                                                                                                  (wk_acc_next: list<integer>) => wk_acc_next,
                                                                                                                                                                                                                  Apply((wk_q: list<integer>) => Apply((wk_j: integer) => Join([wk_j +
                                                                                                                                                                                                                                                                                wk_p[wk_j + 2]], Drop(wk_q, 1), [wk_j, wk_p[wk_j + 2], wk_p[_n + wk_j + 2]]) if wk_j <= _n &&
                                                                                                                                                                                                                                                                                                                                                  wk_xs[wk_j] ==
                                                                                                                                                                                                                                                                                                                                                  wk_xs[wk_i] + 1 else wk_q, wk_acc[1]), wk_acc),
                                                                                                                                                                                                                ),
                                                                                                                                                                          wk_acc_init,
                                                                                                                                                                          Range(1, _n - wk_i, 1),
                                                                                                                                                                        ), [wk_i + 1]),
                                                                                                                            ),
                                                                                                                     ), wk_p_init, Range(_n, 2, -1)),
                                              Join(
                                                    [0, 0],
                                                    Map(
                                                         Function(1, wk_z),
                                                         Range(1, _n, 1),
                                                       ),
                                                    Map(
                                                         Function(0, wk_z),
                                                         Range(1, _n, 1),
                                                       ),
                                                  ),
                                            ),
                                     ), Join(_x, [-1]))

valid(_n, _x)

(Apply((wk_xs: list<integer>) => Apply(
                                        (wk_w: list<integer>) => Apply(
                                                                        (wk_k: list<integer>) => Apply(
                                                                                                        (wk_z: list<integer>) => False if 0 <
                                                                                                                                          wk_w[1] + wk_z[8] else 0 if 0 <
                                                                                                                                                     wk_w[2] + wk_z[9] else True,
                                                                                                        Apply(
                                                                                                               (tf_pad: list<integer>) => Apply((tf_z_init: list<integer>) => Fold(
                                                                                                                                                                                    (tf_z: list<integer>, tf_t) => Apply(
                                                                                                                                                                                                                          (tf_z_next: list<integer>) => tf_z_next,
                                                                                                                                                                                                                          Apply((tf_st: integer) => Apply(
                                                                                                                                                                                                                                                           (tf_w: integer) => Apply((tf_a: integer) => Apply((tf_ps: integer) => Apply((tf_base: integer) => Apply((tf_rem: integer) => Apply((tf_cw: integer) => Apply((tf_cnt: integer) => Apply((tf_ss: integer) => Apply((tf_pw: integer) => Apply((tf_pa: integer) => Apply((tf_bad: integer) => Apply((tf_risk: integer) => [
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    tf_base,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    tf_rem,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    tf_cw,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    tf_cnt + 1,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    tf_ss +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    Binomial(tf_a + tf_cnt, tf_cnt + 1),
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    tf_w,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    tf_a,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    tf_bad +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    (1 if tf_w > tf_pw ||
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          tf_w == tf_pw &&
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          tf_w < 40 &&
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          tf_a < tf_pa else 0),
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    tf_risk +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    ((0 if 0 ==
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           Fold(Function(tf_ix +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         Abs(wk_xs[tf_st + tf_iu] -
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             wk_xs[tf_st] -
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             (wk_xs[tf_ps + tf_iu] -
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              wk_xs[tf_ps])), tf_ix, tf_iu), 0, Range(0, tf_w - 1, 1)) else 1) if tf_w == tf_pw &&
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       40 <= tf_w else 0),
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    tf_st,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  ] if tf_w == tf_cw else Apply(
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                (tf_fin: integer) => [
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       tf_base + tf_fin,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       tf_rem -
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       tf_cw * tf_cnt if 0 < tf_cw else tf_rem,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       tf_w,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       1,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       tf_a,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       tf_w,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       tf_a,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       tf_bad +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       (1 if tf_w > tf_pw ||
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             tf_w == tf_pw &&
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             tf_w < 40 &&
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             tf_a < tf_pa else 0),
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       tf_risk +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       ((0 if 0 ==
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              Fold(Function(tf_ix +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            Abs(wk_xs[tf_st + tf_iu] -
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                wk_xs[tf_st] -
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                (wk_xs[tf_ps + tf_iu] -
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 wk_xs[tf_ps])), tf_ix, tf_iu), 0, Range(0, tf_w - 1, 1)) else 1) if tf_w == tf_pw &&
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          40 <= tf_w else 0),
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       tf_st,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     ],
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Fold(Function(tf_acc +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              Binomial(_tables[(tf_cw - 1) *
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               Max(_n, 1) +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               (tf_cw - 1) +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               1] +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       (tf_kk - 1), tf_kk) *
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              _tables[(tf_cw - 1) *
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      Max(_n, 1) +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      (tf_rem -
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       tf_kk * tf_cw) +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      1], tf_acc, tf_kk), 0, Range(0, tf_cnt - 1, 1)) +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                tf_ss *
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                _tables[(tf_cw - 1) *
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Max(_n, 1) +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        (tf_rem -
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         tf_cnt * tf_cw) +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        1] if 0 < tf_cw else 0,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              ), tf_z[9]), tf_z[8]), tf_z[7]), tf_z[6]), tf_z[5]), tf_z[4]), tf_z[3]), tf_z[2]), tf_z[1]), tf_z[10]), tf_pad[3tf_t]),
                                                                                                                                                                                                                                                           tf_pad[3tf_t - 1],
                                                                                                                                                                                                                                                         ), tf_pad[3tf_t - 2]),
                                                                                                                                                                                                                        ),
                                                                                                                                                                                    tf_z_init,
                                                                                                                                                                                    Range(1, (Length(wk_k) -
                                                                                                                                                                                              Length(wk_k) % 3) /
                                                                                                                                                                                             3 +
                                                                                                                                                                                             1, 1),
                                                                                                                                                                                  ), [0, _n - 1, 0, 0, 0, _n + 1, 0, 0, 0, 0]),
                                                                                                               Join(wk_k, [0, 0, 0]),
                                                                                                             ),
                                                                                                      ),
                                                                        Apply(
                                                                               (wk_h: list<integer>) => Drop(wk_h, 1),
                                                                               Apply(
                                                                                      (wk_acc_init: list<integer>) => Fold(
                                                                                                                            (wk_acc: list<integer>, wk_t) => Apply(
                                                                                                                                                                    (wk_acc_next: list<integer>) => wk_acc_next,
                                                                                                                                                                    Apply((wk_q: list<integer>) => Apply((wk_j: integer) => Join([wk_j +
                                                                                                                                                                                                                                  wk_w[wk_j + 2]], Drop(wk_q, 1), [wk_j, wk_w[wk_j + 2], wk_w[_n + wk_j + 2]]) if wk_j <= _n &&
                                                                                                                                                                                                                                                                                                    wk_xs[wk_j] ==
                                                                                                                                                                                                                                                                                                    wk_xs[1] + 1 else wk_q, wk_acc[1]), wk_acc),
                                                                                                                                                                  ),
                                                                                                                            wk_acc_init,
                                                                                                                            Range(1, _n - 1, 1),
                                                                                                                          ),
                                                                                      [1 + 1],
                                                                                    ),
                                                                             ),
                                                                      ),
                                        Apply(
                                               (wk_p_init: list<integer>) => Fold((wk_p: list<integer>, wk_i) => Apply(
                                                                                                                        (wk_p_next: list<integer>) => wk_p_next,
                                                                                                                        Apply(
                                                                                                                               (wk_hop: list<integer>) => Apply((wk_size: integer) => Apply(
                                                                                                                                                                                             (wk_z: list<integer>) => ReplaceAt(
                                                                                                                                                                                                                                 ReplaceAt(ReplaceAt(ReplaceAt(wk_p, 1, wk_p[1] + wk_z[8]), 2, wk_p[2] + wk_z[9]), wk_i + 2, wk_size),
                                                                                                                                                                                                                                 _n + wk_i + 2,
                                                                                                                                                                                                                                 wk_z[1],
                                                                                                                                                                                                                               ),
                                                                                                                                                                                             Apply(
                                                                                                                                                                                                    (tw_pad: list<integer>) => Apply((tw_z_init: list<integer>) => Fold(
                                                                                                                                                                                                                                                                         (tw_z: list<integer>, tw_t) => Apply(
                                                                                                                                                                                                                                                                                                               (tw_z_next: list<integer>) => tw_z_next,
                                                                                                                                                                                                                                                                                                               Apply((tw_st: integer) => Apply(
                                                                                                                                                                                                                                                                                                                                                (tw_w: integer) => Apply((tw_a: integer) => Apply((tw_ps: integer) => Apply((tw_base: integer) => Apply((tw_rem: integer) => Apply((tw_cw: integer) => Apply((tw_cnt: integer) => Apply((tw_ss: integer) => Apply((tw_pw: integer) => Apply((tw_pa: integer) => Apply((tw_bad: integer) => Apply((tw_risk: integer) => [
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         tw_base,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         tw_rem,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         tw_cw,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         tw_cnt + 1,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         tw_ss +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         Binomial(tw_a + tw_cnt, tw_cnt + 1),
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         tw_w,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         tw_a,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         tw_bad +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         (1 if tw_w > tw_pw ||
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               tw_w == tw_pw &&
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               tw_w < 40 &&
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               tw_a < tw_pa else 0),
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         tw_risk +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         ((0 if 0 ==
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Fold(Function(tw_ix +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              Abs(wk_xs[tw_st + tw_iu] -
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  wk_xs[tw_st] -
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  (wk_xs[tw_ps + tw_iu] -
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   wk_xs[tw_ps])), tw_ix, tw_iu), 0, Range(0, tw_w - 1, 1)) else 1) if tw_w == tw_pw &&
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            40 <= tw_w else 0),
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         tw_st,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       ] if tw_w == tw_cw else Apply(
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     (tw_fin: integer) => [
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            tw_base + tw_fin,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            tw_rem -
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            tw_cw * tw_cnt if 0 < tw_cw else tw_rem,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            tw_w,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            1,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            tw_a,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            tw_w,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            tw_a,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            tw_bad +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            (1 if tw_w > tw_pw ||
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  tw_w == tw_pw &&
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  tw_w < 40 &&
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  tw_a < tw_pa else 0),
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            tw_risk +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            ((0 if 0 ==
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   Fold(Function(tw_ix +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 Abs(wk_xs[tw_st + tw_iu] -
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     wk_xs[tw_st] -
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     (wk_xs[tw_ps + tw_iu] -
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      wk_xs[tw_ps])), tw_ix, tw_iu), 0, Range(0, tw_w - 1, 1)) else 1) if tw_w == tw_pw &&
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               40 <= tw_w else 0),
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            tw_st,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          ],
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     Fold(Function(tw_acc +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   Binomial(_tables[(tw_cw - 1) *
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    Max(_n, 1) +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    (tw_cw - 1) +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    1] +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            (tw_kk - 1), tw_kk) *
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   _tables[(tw_cw - 1) *
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           Max(_n, 1) +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           (tw_rem -
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            tw_kk * tw_cw) +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           1], tw_acc, tw_kk), 0, Range(0, tw_cnt - 1, 1)) +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     tw_ss *
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     _tables[(tw_cw - 1) *
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             Max(_n, 1) +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             (tw_rem -
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              tw_cnt * tw_cw) +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             1] if 0 < tw_cw else 0,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   ), tw_z[9]), tw_z[8]), tw_z[7]), tw_z[6]), tw_z[5]), tw_z[4]), tw_z[3]), tw_z[2]), tw_z[1]), tw_z[10]), tw_pad[3tw_t]),
                                                                                                                                                                                                                                                                                                                                                tw_pad[3tw_t - 1],
                                                                                                                                                                                                                                                                                                                                              ), tw_pad[3tw_t - 2]),
                                                                                                                                                                                                                                                                                                             ),
                                                                                                                                                                                                                                                                         tw_z_init,
                                                                                                                                                                                                                                                                         Range(1, (Length(Drop(wk_hop, 1)) -
                                                                                                                                                                                                                                                                                   Length(Drop(wk_hop, 1)) %
                                                                                                                                                                                                                                                                                   3) /
                                                                                                                                                                                                                                                                                  3 +
                                                                                                                                                                                                                                                                                  1, 1),
                                                                                                                                                                                                                                                                       ), [0, wk_size - 1, 0, 0, 0, _n + 1, 0, 0, 0, 0]),
                                                                                                                                                                                                    Join(Drop(wk_hop, 1), [0, 0, 0]),
                                                                                                                                                                                                  ),
                                                                                                                                                                                           ), wk_hop[1] - wk_i),
                                                                                                                               Apply((wk_acc_init: list<integer>) => Fold(
                                                                                                                                                                           (wk_acc: list<integer>, wk_t) => Apply(
                                                                                                                                                                                                                   (wk_acc_next: list<integer>) => wk_acc_next,
                                                                                                                                                                                                                   Apply((wk_q: list<integer>) => Apply((wk_j: integer) => Join([wk_j +
                                                                                                                                                                                                                                                                                 wk_p[wk_j + 2]], Drop(wk_q, 1), [wk_j, wk_p[wk_j + 2], wk_p[_n + wk_j + 2]]) if wk_j <= _n &&
                                                                                                                                                                                                                                                                                                                                                   wk_xs[wk_j] ==
                                                                                                                                                                                                                                                                                                                                                   wk_xs[wk_i] + 1 else wk_q, wk_acc[1]), wk_acc),
                                                                                                                                                                                                                 ),
                                                                                                                                                                           wk_acc_init,
                                                                                                                                                                           Range(1, _n - wk_i, 1),
                                                                                                                                                                         ), [wk_i + 1]),
                                                                                                                             ),
                                                                                                                      ), wk_p_init, Range(_n, 2, -1)),
                                               Join(
                                                     [0, 0],
                                                     Map(
                                                          Function(1, wk_z),
                                                          Range(1, _n, 1),
                                                        ),
                                                     Map(
                                                          Function(0, wk_z),
                                                          Range(1, _n, 1),
                                                        ),
                                                   ),
                                             ),
                                      ), Join(_x, [-1])) if _x[1] == 0 && Fold(
                                                                               Function(ok_wk_v &&
                                                                                        1 <= _x[wk_v] &&
                                                                                        _x[wk_v] <=
                                                                                        _x[wk_v - 1] +
                                                                                        1, ok_wk_v, wk_v),
                                                                               True,
                                                                               Range(2, _n, 1),
                                                                             ) else False) if 1 <= _n &&
                                                                                             Length(_x) == _n else False

tables(_n)

Fold(Function(Join(
                    tr_t,
                    Fold(Function(ReplaceAt(
                                             tr_row,
                                             tr_c + 1,
                                             Apply((tr_a_init: integer) => Fold(
                                                                                 (tr_a: integer, tr_k) => Apply(
                                                                                                                 (tr_a_next: integer) => tr_a_next,
                                                                                                                 tr_a +
                                                                                                                 Binomial(tr_t[(tr_s - 1) *
                                                                                                                               Max(_n, 1) +
                                                                                                                               (tr_s - 1) +
                                                                                                                               1] +
                                                                                                                          (tr_k - 1), tr_k) *
                                                                                                                 tr_t[(tr_s - 1) *
                                                                                                                      Max(_n, 1) +
                                                                                                                      (tr_c -
                                                                                                                       tr_k * tr_s) +
                                                                                                                      1],
                                                                                                               ),
                                                                                 tr_a_init,
                                                                                 Range(0, (tr_c -
                                                                                           tr_c % tr_s) /
                                                                                          tr_s, 1),
                                                                               ), 0),
                                           ), tr_row, tr_c), Map(
                                                                 Function(
                                                                           0,
                                                                           tr_z,
                                                                         ),
                                                                 Range(
                                                                        0,
                                                                        Max(
                                                                             _n,
                                                                             1,
                                                                           ) - 1,
                                                                        1,
                                                                      ),
                                                               ), Range(
                                                                        0,
                                                                        Max(
                                                                             _n,
                                                                             1,
                                                                           ) - 1,
                                                                        1,
                                                                      )),
                  ), tr_t, tr_s), Fold(
                                       Function(ReplaceAt(
                                                           tr_row,
                                                           tr_c + 1,
                                                           1 if tr_c == 0 else 0,
                                                         ), tr_row, tr_c),
                                       Map(
                                            Function(0, tr_z),
                                            Range(0, Max(_n, 1) - 1, 1),
                                          ),
                                       Range(0, Max(_n, 1) - 1, 1),
                                     ), Range(1, Max(_n, 1) - 1, 1))

Enumeration

Examples

1 more kept as data, checked against the oracles
Basic #

Count(RootedUnlabeledTrees(6))=20Count(RootedUnlabeledTrees(6)) = 20, A000081

live ↗
InCount(RootedUnlabeledTrees(6))\mathrm{Count}(\mathrm{RootedUnlabeledTrees}(6))Out2020
About
Examples2
CrosswalkOEIS

See also: UnlabeledFreeTrees, Count, At