Skip to content

ZigzagCompositions ​

The alternating compositions of nn: a1<a2>a3<…a_1 < a_2 > a_3 < … or a1>a2<a3>…a_1 > a_2 < a_3 > …, either starting direction.

ZigzagCompositions(n)the alternating compositions of nn: a1<a2>a3<…a_1 < a_2 > a_3 < … or a1>a2<a3>…a_1 > a_2 < a_3 > …, either starting direction
Typed signatures
TypePackageApplies
(integer<0..>) -> indexed_collection<composition>combinatoricsalways

Domain: Collections

Details
  • Count is A025047.

Definition

Epsil, as the implementation runs it.

count(_n)

_tables[_n * (3 * _n + 1) + 3 * _n + 1]

unrank(_n, _r)

Drop(Fold(
           Function(Apply((pw_m: integer) => Apply((pw_c: integer) => Apply((pw_r: integer) => pw_u if pw_m == 0 else Apply(
                                                                                                                             (pw_chosen: list<integer>) => Join([
                                                                                                                                                                  pw_m - pw_chosen[2],
                                                                                                                                                                  _n + pw_chosen[2] -
                                                                                                                                                                  1 if pw_c < _n else _n - pw_chosen[2] if pw_c >= _n &&
                                                                                                                                                                                                          pw_c <
                                                                                                                                                                                                          2 * _n else (_n + pw_chosen[2] -
                                                                                                                                                                                                                 1 if pw_chosen[2] >
                                                                                                                                                                                                                     (_n - pw_c if pw_c < _n else pw_c - _n +
                                                                                                                                                                                                                                                  1 if pw_c >= _n &&
                                                                                                                                                                                                                                                      pw_c <
                                                                                                                                                                                                                                                      2 * _n else pw_c -
                                                                                                                                                                                                                                                            2 * _n +
                                                                                                                                                                                                                                                            1 if pw_c >=
                                                                                                                                                                                                                                                                2 * _n &&
                                                                                                                                                                                                                                                                pw_c <
                                                                                                                                                                                                                                                                3 * _n else 0) else _n - pw_chosen[2]) if pw_c >=
                                                                                                                                                                                                                                                 2 * _n &&
                                                                                                                                                                                                                                                 pw_c <
                                                                                                                                                                                                                                                 3 * _n else 2 * _n +
                                                                                                                                                                                                                                                       pw_chosen[2] -
                                                                                                                                                                                                                                                       1,
                                                                                                                                                                  pw_chosen[1],
                                                                                                                                                                ], Drop(pw_u, 3), [pw_chosen[2]]),
                                                                                                                             Fold(
                                                                                                                                   Function(pw_pick if pw_pick[2] != 0 else Apply(
                                                                                                                                                                                   (pw_k: integer) => [pw_pick[1], pw_p] if pw_pick[1] < pw_k else [pw_pick[1] - pw_k, 0],
                                                                                                                                                                                   _tables[(pw_m - pw_p) *
                                                                                                                                                                                           (3 * _n +
                                                                                                                                                                                            1) +
                                                                                                                                                                                           (_n + pw_p -
                                                                                                                                                                                            1 if pw_c < _n else _n - pw_p if pw_c >= _n &&
                                                                                                                                                                                                                            pw_c <
                                                                                                                                                                                                                            2 * _n else (_n + pw_p -
                                                                                                                                                                                                                                   1 if pw_p >
                                                                                                                                                                                                                                       (_n - pw_c if pw_c < _n else pw_c - _n +
                                                                                                                                                                                                                                                                    1 if pw_c >= _n &&
                                                                                                                                                                                                                                                                        pw_c <
                                                                                                                                                                                                                                                                        2 * _n else pw_c -
                                                                                                                                                                                                                                                                              2 * _n +
                                                                                                                                                                                                                                                                              1 if pw_c >=
                                                                                                                                                                                                                                                                                  2 * _n &&
                                                                                                                                                                                                                                                                                  pw_c <
                                                                                                                                                                                                                                                                                  3 * _n else 0) else _n - pw_p) if pw_c >=
                                                                                                                                                                                                                                                           2 * _n &&
                                                                                                                                                                                                                                                           pw_c <
                                                                                                                                                                                                                                                           3 * _n else 2 * _n +
                                                                                                                                                                                                                                                                 pw_p -
                                                                                                                                                                                                                                                                 1) +
                                                                                                                                                                                           1],
                                                                                                                                                                                 ) if (pw_p >
                                                                                                                                                                                      (_n - pw_c if pw_c < _n else pw_c - _n +
                                                                                                                                                                                                                   1 if pw_c >= _n &&
                                                                                                                                                                                                                       pw_c <
                                                                                                                                                                                                                       2 * _n else pw_c -
                                                                                                                                                                                                                             2 * _n +
                                                                                                                                                                                                                             1 if pw_c >=
                                                                                                                                                                                                                                 2 * _n &&
                                                                                                                                                                                                                                 pw_c <
                                                                                                                                                                                                                                 3 * _n else 0) if pw_c < _n else pw_p <
                                                                                                                                                                                                         (_n - pw_c if pw_c < _n else pw_c - _n +
                                                                                                                                                                                                                                      1 if pw_c >= _n &&
                                                                                                                                                                                                                                          pw_c <
                                                                                                                                                                                                                                          2 * _n else pw_c -
                                                                                                                                                                                                                                                2 * _n +
                                                                                                                                                                                                                                                1 if pw_c >=
                                                                                                                                                                                                                                                    2 * _n &&
                                                                                                                                                                                                                                                    pw_c <
                                                                                                                                                                                                                                                    3 * _n else 0) if pw_c >= _n &&
                                                                                                                                                                                                             pw_c <
                                                                                                                                                                                                             2 * _n else pw_p !=
                                                                                                                                                                                                                   (_n - pw_c if pw_c < _n else pw_c - _n +
                                                                                                                                                                                                                                                1 if pw_c >= _n &&
                                                                                                                                                                                                                                                    pw_c <
                                                                                                                                                                                                                                                    2 * _n else pw_c -
                                                                                                                                                                                                                                                          2 * _n +
                                                                                                                                                                                                                                                          1 if pw_c >=
                                                                                                                                                                                                                                                              2 * _n &&
                                                                                                                                                                                                                                                              pw_c <
                                                                                                                                                                                                                                                              3 * _n else 0) if pw_c >=
                                                                                                                                                                                                                       2 * _n &&
                                                                                                                                                                                                                       pw_c <
                                                                                                                                                                                                                       3 * _n else True) else pw_pick, pw_pick, pw_p),
                                                                                                                                   [pw_r, 0],
                                                                                                                                   Range(1, pw_m, 1),
                                                                                                                                 ),
                                                                                                                           ), pw_u[3]), pw_u[2]), pw_u[1]), pw_u, pw_i),
           [_n, 3 * _n, _r],
           Range(1, _n, 1),
         ), 3)

rank(_n, _x)

Fold(
      Function(Apply((pw_r: integer) => Apply((pw_m: integer) => Apply((pw_c: integer) => [
                                                                                            pw_r +
                                                                                            Fold(Function(pw_s +
                                                                                                          (_tables[(pw_m - pw_q) *
                                                                                                                   (3 * _n +
                                                                                                                    1) +
                                                                                                                   (_n + pw_q -
                                                                                                                    1 if pw_c < _n else _n - pw_q if pw_c >= _n &&
                                                                                                                                                    pw_c <
                                                                                                                                                    2 * _n else (_n + pw_q -
                                                                                                                                                           1 if pw_q >
                                                                                                                                                               (_n - pw_c if pw_c < _n else pw_c - _n +
                                                                                                                                                                                            1 if pw_c >= _n &&
                                                                                                                                                                                                pw_c <
                                                                                                                                                                                                2 * _n else pw_c -
                                                                                                                                                                                                      2 * _n +
                                                                                                                                                                                                      1 if pw_c >=
                                                                                                                                                                                                          2 * _n &&
                                                                                                                                                                                                          pw_c <
                                                                                                                                                                                                          3 * _n else 0) else _n - pw_q) if pw_c >=
                                                                                                                                                                                   2 * _n &&
                                                                                                                                                                                   pw_c <
                                                                                                                                                                                   3 * _n else 2 * _n +
                                                                                                                                                                                         pw_q -
                                                                                                                                                                                         1) +
                                                                                                                   1] if (pw_q >
                                                                                                                         (_n - pw_c if pw_c < _n else pw_c - _n +
                                                                                                                                                      1 if pw_c >= _n &&
                                                                                                                                                          pw_c <
                                                                                                                                                          2 * _n else pw_c -
                                                                                                                                                                2 * _n +
                                                                                                                                                                1 if pw_c >=
                                                                                                                                                                    2 * _n &&
                                                                                                                                                                    pw_c <
                                                                                                                                                                    3 * _n else 0) if pw_c < _n else pw_q <
                                                                                                                                            (_n - pw_c if pw_c < _n else pw_c - _n +
                                                                                                                                                                         1 if pw_c >= _n &&
                                                                                                                                                                             pw_c <
                                                                                                                                                                             2 * _n else pw_c -
                                                                                                                                                                                   2 * _n +
                                                                                                                                                                                   1 if pw_c >=
                                                                                                                                                                                       2 * _n &&
                                                                                                                                                                                       pw_c <
                                                                                                                                                                                       3 * _n else 0) if pw_c >= _n &&
                                                                                                                                                pw_c <
                                                                                                                                                2 * _n else pw_q !=
                                                                                                                                                      (_n - pw_c if pw_c < _n else pw_c - _n +
                                                                                                                                                                                   1 if pw_c >= _n &&
                                                                                                                                                                                       pw_c <
                                                                                                                                                                                       2 * _n else pw_c -
                                                                                                                                                                                             2 * _n +
                                                                                                                                                                                             1 if pw_c >=
                                                                                                                                                                                                 2 * _n &&
                                                                                                                                                                                                 pw_c <
                                                                                                                                                                                                 3 * _n else 0) if pw_c >=
                                                                                                                                                          2 * _n &&
                                                                                                                                                          pw_c <
                                                                                                                                                          3 * _n else True) else 0), pw_s, pw_q), 0, Range(1, pw_x - 1, 1)),
                                                                                            pw_m - pw_x,
                                                                                            _n + pw_x -
                                                                                            1 if pw_c < _n else _n - pw_x if pw_c >= _n &&
                                                                                                                            pw_c <
                                                                                                                            2 * _n else (_n + pw_x -
                                                                                                                                   1 if pw_x >
                                                                                                                                       (_n - pw_c if pw_c < _n else pw_c - _n +
                                                                                                                                                                    1 if pw_c >= _n &&
                                                                                                                                                                        pw_c <
                                                                                                                                                                        2 * _n else pw_c -
                                                                                                                                                                              2 * _n +
                                                                                                                                                                              1 if pw_c >=
                                                                                                                                                                                  2 * _n &&
                                                                                                                                                                                  pw_c <
                                                                                                                                                                                  3 * _n else 0) else _n - pw_x) if pw_c >=
                                                                                                                                                           2 * _n &&
                                                                                                                                                           pw_c <
                                                                                                                                                           3 * _n else 2 * _n +
                                                                                                                                                                 pw_x -
                                                                                                                                                                 1,
                                                                                          ], pw_a[3]), pw_a[2]), pw_a[1]), pw_a, pw_x),
      [0, _n, 3 * _n],
      _x,
    )[1]

valid(_n, _x)

Apply(
       (pw_end: list<integer>) => pw_end[1] == 1 && pw_end[2] == 0 && 1 != 0,
       Fold(
             Function(Apply((pw_f: integer) => Apply((pw_m: integer) => Apply((pw_c: integer) => [
                                                                                                   1,
                                                                                                   pw_m - pw_y,
                                                                                                   _n + pw_y -
                                                                                                   1 if pw_c < _n else _n - pw_y if pw_c >= _n &&
                                                                                                                                   pw_c <
                                                                                                                                   2 * _n else (_n + pw_y -
                                                                                                                                          1 if pw_y >
                                                                                                                                              (_n - pw_c if pw_c < _n else pw_c - _n +
                                                                                                                                                                           1 if pw_c >= _n &&
                                                                                                                                                                               pw_c <
                                                                                                                                                                               2 * _n else pw_c -
                                                                                                                                                                                     2 * _n +
                                                                                                                                                                                     1 if pw_c >=
                                                                                                                                                                                         2 * _n &&
                                                                                                                                                                                         pw_c <
                                                                                                                                                                                         3 * _n else 0) else _n - pw_y) if pw_c >=
                                                                                                                                                                  2 * _n &&
                                                                                                                                                                  pw_c <
                                                                                                                                                                  3 * _n else 2 * _n +
                                                                                                                                                                        pw_y -
                                                                                                                                                                        1,
                                                                                                 ] if pw_f == 1 &&
                                                                                                     pw_y >= 1 &&
                                                                                                     pw_y <= pw_m &&
                                                                                                     (pw_y >
                                                                                                      (_n - pw_c if pw_c < _n else pw_c - _n +
                                                                                                                                   1 if pw_c >= _n &&
                                                                                                                                       pw_c <
                                                                                                                                       2 * _n else pw_c -
                                                                                                                                             2 * _n +
                                                                                                                                             1 if pw_c >=
                                                                                                                                                 2 * _n &&
                                                                                                                                                 pw_c <
                                                                                                                                                 3 * _n else 0) if pw_c < _n else pw_y <
                                                                                                                         (_n - pw_c if pw_c < _n else pw_c - _n +
                                                                                                                                                      1 if pw_c >= _n &&
                                                                                                                                                          pw_c <
                                                                                                                                                          2 * _n else pw_c -
                                                                                                                                                                2 * _n +
                                                                                                                                                                1 if pw_c >=
                                                                                                                                                                    2 * _n &&
                                                                                                                                                                    pw_c <
                                                                                                                                                                    3 * _n else 0) if pw_c >= _n &&
                                                                                                                             pw_c <
                                                                                                                             2 * _n else pw_y !=
                                                                                                                                   (_n - pw_c if pw_c < _n else pw_c - _n +
                                                                                                                                                                1 if pw_c >= _n &&
                                                                                                                                                                    pw_c <
                                                                                                                                                                    2 * _n else pw_c -
                                                                                                                                                                          2 * _n +
                                                                                                                                                                          1 if pw_c >=
                                                                                                                                                                              2 * _n &&
                                                                                                                                                                              pw_c <
                                                                                                                                                                              3 * _n else 0) if pw_c >=
                                                                                                                                       2 * _n &&
                                                                                                                                       pw_c <
                                                                                                                                       3 * _n else True) else [0, 0, 0], pw_v[3]), pw_v[2]), pw_v[1]), pw_v, pw_y),
             [1, _n, 3 * _n],
             _x,
           ),
     )

tables(_n)

Fold(
      Function(Join(
                     pw_t,
                     Fold(Function(ReplaceAt(
                                              pw_row,
                                              pw_c + 1,
                                              (0 if pw_c == 0 else pw_row[pw_c -
                                                                          1 + 1] +
                                                                   (pw_t[(pw_s -
                                                                          (_n -
                                                                           pw_c + 1)) * (3 *
                                                                               _n +
                                                                               1) +
                                                                         (_n + _n -
                                                                               pw_c +
                                                                               1 -
                                                                          1) + 1] if _n -
                                                                              pw_c +
                                                                              1 <=
                                                                              pw_s else 0)) if pw_c <
                                                                        _n else (0 if pw_c == _n else pw_row[pw_c - 1 +
                                                                                                           1] +
                                                                                                    (pw_t[(pw_s -
                                                                                                           ((_n - pw_c if pw_c < _n else pw_c - _n +
                                                                                                                                         1 if pw_c >= _n &&
                                                                                                                                             pw_c <
                                                                                                                                             2 * _n else pw_c -
                                                                                                                                                   2 * _n +
                                                                                                                                                   1 if pw_c >=
                                                                                                                                                       2 * _n &&
                                                                                                                                                       pw_c <
                                                                                                                                                       3 * _n else 0) -
                                                                                                            1)) *
                                                                                                          (3 * _n +
                                                                                                           1) +
                                                                                                          (_n -
                                                                                                           ((_n - pw_c if pw_c < _n else pw_c - _n +
                                                                                                                                         1 if pw_c >= _n &&
                                                                                                                                             pw_c <
                                                                                                                                             2 * _n else pw_c -
                                                                                                                                                   2 * _n +
                                                                                                                                                   1 if pw_c >=
                                                                                                                                                       2 * _n &&
                                                                                                                                                       pw_c <
                                                                                                                                                       3 * _n else 0) -
                                                                                                            1)) +
                                                                                                          1] if (_n - pw_c if pw_c < _n else pw_c - _n +
                                                                                                                                            1 if pw_c >= _n &&
                                                                                                                                                pw_c <
                                                                                                                                                2 * _n else pw_c -
                                                                                                                                                      2 * _n +
                                                                                                                                                      1 if pw_c >=
                                                                                                                                                          2 * _n &&
                                                                                                                                                          pw_c <
                                                                                                                                                          3 * _n else 0) -
                                                                                                               1 <=
                                                                                                               pw_s else 0)) if pw_c >= _n &&
                                                                                                         pw_c <
                                                                                                         2 * _n else pw_row[_n -
                                                                                                                      (_n - pw_c if pw_c < _n else pw_c - _n +
                                                                                                                                                   1 if pw_c >= _n &&
                                                                                                                                                       pw_c <
                                                                                                                                                       2 * _n else pw_c -
                                                                                                                                                             2 * _n +
                                                                                                                                                             1 if pw_c >=
                                                                                                                                                                 2 * _n &&
                                                                                                                                                                 pw_c <
                                                                                                                                                                 3 * _n else 0) +
                                                                                                                      1] +
                                                                                                               pw_row[_n +
                                                                                                                      (_n - pw_c if pw_c < _n else pw_c - _n +
                                                                                                                                                   1 if pw_c >= _n &&
                                                                                                                                                       pw_c <
                                                                                                                                                       2 * _n else pw_c -
                                                                                                                                                             2 * _n +
                                                                                                                                                             1 if pw_c >=
                                                                                                                                                                 2 * _n &&
                                                                                                                                                                 pw_c <
                                                                                                                                                                 3 * _n else 0) -
                                                                                                                      1 +
                                                                                                                      1] if pw_c >=
                                                                                                                   2 * _n &&
                                                                                                                   pw_c <
                                                                                                                   3 * _n else Fold(Function(zz_a +
                                                                                                                                       pw_t[(pw_s - zz_q) *
                                                                                                                                            (3 * _n +
                                                                                                                                             1) +
                                                                                                                                            (2 * _n +
                                                                                                                                             zz_q -
                                                                                                                                             1) +
                                                                                                                                            1], zz_a, zz_q), 0, Range(1, pw_s, 1)),
                                            ), pw_row, pw_c), Map(
                                                                  Function(
                                                                            0,
                                                                            pw_z,
                                                                          ),
                                                                  Range(0, 3 *
                                                                           _n + 1 -
                                                                           1, 1),
                                                                ), Range(0, 3 *
                                                                           _n + 1 -
                                                                           1, 1)),
                   ), pw_t, pw_s),
      Fold(
            Function(ReplaceAt(pw_row, pw_c + 1, 1), pw_row, pw_c),
            Map(Function(0, pw_z), Range(0, 3 * _n + 1 - 1, 1)),
            Range(0, 3 * _n + 1 - 1, 1),
          ),
      Range(1, _n + 1 - 1, 1),
    )

Statistics

On IntegerComposition, called as CombinatorialStat(x, "Name").

Maps

Into and out of IntegerComposition, called as CombinatorialMap(x, "Name"). Properties are the laws we state and what FindStat records.

From IntegerComposition

  • CodeWordIntegerComposition → BinaryWordInjectionGraded mapMp00094The word that writes each part i as a one followed by i - 1 zeros.
  • ComplementIntegerComposition → IntegerCompositioninvolutionBijectionGraded mapInvolutionMp00039The composition cut exactly where this one is not: its cut set complemented.
  • CompositionBouncePathIntegerComposition → DyckPathInjectionGraded mapMp00231The Dyck path that bounces off the diagonal once for each part: a run of that many ups, then as many downs.
  • CutWordIntegerComposition → BinaryWordinverseA composition of n as the binary word of length n - 1 marking where it is cut.
  • CyclicShiftIntegerComposition → IntegerCompositioninverseBijectionGraded mapMp00173Rotate the parts one place to the left: the first part moves to the end.
  • DeltaMorphismIntegerComposition → IntegerCompositionSurjectionMp00133The lengths of the maximal runs of equal parts, left to right.
  • FoataInversionsToMajorIntegerComposition → IntegerCompositionbijectioninverseBijectionGraded mapMp00315The inverse of Foata's bijection on compositions: peel off the last part, rotate the blocks of the rest back.
  • FoataMajorToInversionsIntegerComposition → IntegerCompositionbijectioninverseBijectionGraded mapMp00314Foata's bijection on the word of parts: each part is put on the end of the image so far, which is cut into blocks, and every block is rotated one place right.
  • InverseCyclicShiftIntegerComposition → IntegerCompositioninverseBijectionGraded mapMp00172Rotate the parts one place to the right: the last part moves to the front.
  • ReverseIntegerComposition → IntegerCompositioninvolutionBijectionGraded mapInvolutionMp00038The parts read backwards.
  • SortedPartitionIntegerComposition → IntegerPartitionsurjectionSurjectionGraded mapMp00040The partition a composition's parts form, sorted largest first.
  • TransposeCompositionIntegerComposition → IntegerCompositioninvolutionBijectionGraded mapInvolutionMp00041The conjugate composition: its ribbon shape transposed, the complement of the reverse.

To IntegerComposition

  • BlockSizeCompositionSetPartition → IntegerCompositionsurjectionSurjectionGraded mapMp00128The block sizes of a set partition, its blocks taken in order of their least elements.
  • BlockSizeCompositionSetComposition → IntegerCompositionsurjectionSurjectionGraded mapMp00287The block sizes of a set composition, its blocks taken in order.
  • CodeCompositionBinaryWord → IntegerCompositionInjectionGraded mapMp00178The composition whose code is the word with a 1 put in front: each 1 opens a part, of 1 plus the zeros after it.
  • DescentCompositionPermutation → IntegerCompositionsurjectionSurjectionGraded mapMp00071The composition of n cut at the descent positions.
  • IntegerCompositionBinaryWord → IntegerCompositioninverseThe composition of m + 1 a binary word of length m cuts out.
  • PeakCompositionStandardTableau → IntegerCompositionGraded mapMp00294The composition cut at the peaks: entries i that are descents after an ascent.
  • RiseCompositionDyckPath → IntegerCompositionsurjectionSurjectionGraded mapMp00102The lengths of the maximal runs of up steps, left to right.
  • RunCompositionBinaryWord → IntegerCompositionsurjectionSurjectionGraded mapMp00097The lengths of the maximal runs of equal letters, left to right.
  • TouchCompositionDyckPath → IntegerCompositionsurjectionSurjectionGraded mapMp00100The semilengths of the primitive pieces between a path's returns to the diagonal.
  • ValleyCompositionStandardTableau → IntegerCompositionGraded mapMp00295The composition cut at the valleys: entries i that are ascents after a descent.
10 more in FindStat, not implemented here
  • Mp00054ParkingFunction → IntegerCompositionSurjectionGraded mapto inverse des composition
  • Mp00057ParkingFunction → IntegerCompositionSurjectionGraded mapto touch composition
  • Mp00152LabeledGraph → IntegerCompositionSurjectionGraded mapLaplacian multiplicities
  • Mp00180IntegerComposition → SkewPartitionInjectionGraded mapto ribbon
  • Mp00181SkewPartition → IntegerCompositionSurjectionGraded maprow lengths
  • Mp00184IntegerComposition → LabeledGraphInjectionGraded mapto threshold graph
  • Mp00207StandardTableau → IntegerCompositionSurjectionGraded maphorizontal strip sizes
  • Mp00248Permutation → IntegerCompositionGraded mapDEX composition
  • Mp00319ParkingFunction → IntegerCompositionInjectionto composition
  • Mp00324LabeledGraph → IntegerCompositionGraded mapchromatic difference sequence

Enumeration

Examples

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

Count(ZigzagCompositions(6))=12Count(ZigzagCompositions(6)) = 12

live ↗
InCount(ZigzagCompositions(6))\mathrm{Count}(\mathrm{ZigzagCompositions}(6))Out1212

The first element in enumeration order

live ↗
InZigzagCompositions(6)[1]\mathrm{ZigzagCompositions}(6)[1]OutIntegerComposition⁡([1,2,1,2]){\operatorname{IntegerComposition}}([1, 2, 1, 2])
About
Examples3
CrosswalkOEIS

See also: IntegerCompositions, AlternatingPermutations