Skip to content

Arrangements ​

Ordered selections of kk distinct elements from {1,…,n}\{1, …, n\} — the kk-permutations of nn.

Arrangements(n, k)Ordered selections of kk distinct elements from {1,…,n}\{1, …, n\} — the kk-permutations of nn
Typed signatures
TypePackageApplies
(integer<0..>, integer<0..>) -> indexed_collection<arrangement>combinatoricsalways

Domain: Collections

Details
  • Count is the falling factorial nk‾=n!/(n−k)!n^{\underline{k}} = n!/(n-k)!.
  • Each element is a length-kk one-line word with distinct entries from {1,…,n}\{1, …, n\}.

Definition

Epsil, as the implementation runs it.

count(_n, _k)

Fold(Function(product * f, product, f), 1, Range(_n - _k + 1, _n, 1)) if _k <=
                                                                         _n else 0

unrank(_n, _k, _r)

Map(Function(Fold(
                   Function(v + 1 if v >= (_r - _r % Fold(
                                                           Function(
                                                                     product * f,
                                                                     product,
                                                                     f,
                                                                   ),
                                                           1,
                                                           Range(
                                                                  _n - i - (_k -
                                                                            i) +
                                                                  1,
                                                                  _n - i,
                                                                  1,
                                                                ),
                                                         )) / Fold(
                                                                   Function(
                                                                             product *
                                                                             f,
                                                                             product,
                                                                             f,
                                                                           ),
                                                                   1,
                                                                   Range(
                                                                          _n - i -
                                                                          (_k -
                                                                           i) + 1,
                                                                          _n - i,
                                                                          1,
                                                                        ),
                                                                 ) % (_n - i + 1) +
                                          1 else v, v, i),
                   (_r - _r % Fold(
                                    Function(product * f, product, f),
                                    1,
                                    Range(_n - j - (_k - j) + 1, _n - j, 1),
                                  )) / Fold(
                                            Function(product * f, product, f),
                                            1,
                                            Range(
                                                   _n - j - (_k - j) + 1,
                                                   _n - j,
                                                   1,
                                                 ),
                                          ) % (_n - j + 1) + 1,
                   Range(j - 1, 1, -1),
                 ), j), Range(1, _k, 1))

rank(_n, _k, _x)

Fold(
      Function(
                r * (_n - j + 1) + (_x[j] - 1 - Fold(
                                                      Function(c +
                                                               (1 if _x[i] <
                                                                     _x[j] else 0), c, i),
                                                      0,
                                                      Range(1, j - 1, 1),
                                                    )),
                r,
                j,
              ),
      0,
      Range(1, _k, 1),
    )

valid(_n, _k, _x)

Fold(Function(
               (ReplaceAt(di_seen, _x[di_j], 1) if di_seen[_x[di_j]] == 0 else ReplaceAt(
                                                                                          di_seen,
                                                                                          _n + 1,
                                                                                          1,
                                                                                        )) if 1 <= _x[di_j] &&
                                                                                             _x[di_j] <= _n else ReplaceAt(di_seen, _n + 1, 1),
               di_seen,
               di_j,
             ), Map(Function(0, di_z), Range(1, _n + 1, 1)), Range(1, _k, 1))[_n +
                                                                             1] ==
0 if Length(_x) == _k else False

Enumeration

Examples

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

Count(Arrangements(4,2))=12Count(Arrangements(4, 2)) = 12

live ↗
InCount(Arrangements(4,2))\mathrm{Count}(\mathrm{Arrangements}(4, 2))Out1212

The first element in enumeration order

live ↗
InArrangements(4,2)[1]\mathrm{Arrangements}(4, 2)[1]OutArrangement⁡([1,2]){\operatorname{Arrangement}}([1, 2])
About
Examples3
CrosswalkOEIS ×2Wolfram LanguageSageMathSymPymathlib4

See also: SymmetricGroup, Subsets, Binomial