Skip to content

ColoredPermutations ​

Permutations of {1,…,n}\{1, \dots, n\} with each position colored by one of kk colors — the wreath product Zk≀Sn\mathbb{Z}_k \wr S_n. Element is a [image,colors][\text{image}, \text{colors}] pair.

✓ checked against that system · ! checked, with disagreements (hover a chip)OEISA337997✓
ColoredPermutations(n, k)the kn⋅n!k^n \cdot n! colored permutations of {1,…,n}\{1, \dots, n\}
Typed signatures
TypePackageApplies
(integer<0..>, integer<0..>) -> indexed_collection<list<list<integer>>>combinatoricsalways

Domain: Collections

Definition

Epsil, as the implementation runs it.

count(_n, _k)

1 if _n == 0 else _k ^ _n * _n!

unrank(_n, _k, _r)

[
  Map(Function(Fold(
                     Function(v + 1 if v >= (_r % _n! - _r % _n! % (_n - i)!) /
                                            (_n - i)! % (_n - i + 1) + 1 else v, v, i),
                     (_r % _n! - _r % _n! % (_n - j)!) / (_n - j)! %
                     (_n - j + 1) + 1,
                     Range(j - 1, 1, -1),
                   ), j), Range(1, _n, 1)),
  Map(Function(((_r - _r % _n!) / _n! - (_r - _r % _n!) / _n! % _k ^ (_n - j)) /
               _k ^ (_n - j) % _k, j), Range(1, _n, 1)),
]

rank(_n, _k, _x)

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

valid(_n, _k, _x)

((Fold(Function(
                 (ReplaceAt(di_seen, _x[1][di_j], 1) if di_seen[_x[1][di_j]] ==
                                                        0 else ReplaceAt(
                                                                         di_seen,
                                                                         _n + 1,
                                                                         1,
                                                                       )) if 1 <=
                                                                            _x[1][di_j] &&
                                                                            _x[1][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, _n, 1))[_n +
                                                                               1] ==
  0 && Fold(
            Function(ok && 0 <= _x[2][j] && _x[2][j] <= _k - 1, ok, j),
            True,
            Range(1, _n, 1),
          ) if Length(_x[2]) == _n else False) if Length(_x[1]) == _n else False) if Length(_x) == 2 else False

Examples

Basic #

23⋅3!=482^3 \cdot 3! = 48

live ↗
InCount(ColoredPermutations(3,2))\mathrm{Count}(\mathrm{ColoredPermutations}(3, 2))Out4848

Each element is [image,colors][\text{image}, \text{colors}]

live ↗
InTake(ColoredPermutations(2,2),8)\mathrm{Take}(\mathrm{ColoredPermutations}(2, 2), 8)Out[[[1,2],[0,0]],[[2,1],[0,0]],[[1,2],[0,1]],[[2,1],[0,1]],[[1,2],[1,0]],[[2,1],[1,0]],[[1,2],[1,1]],[[2,1],[1,1]]]\bigl\lbrack\bigl\lbrack\bigl\lbrack1, 2\bigr\rbrack, \bigl\lbrack0, 0\bigr\rbrack\bigr\rbrack, \bigl\lbrack\bigl\lbrack2, 1\bigr\rbrack, \bigl\lbrack0, 0\bigr\rbrack\bigr\rbrack, \bigl\lbrack\bigl\lbrack1, 2\bigr\rbrack, \bigl\lbrack0, 1\bigr\rbrack\bigr\rbrack, \bigl\lbrack\bigl\lbrack2, 1\bigr\rbrack, \bigl\lbrack0, 1\bigr\rbrack\bigr\rbrack, \bigl\lbrack\bigl\lbrack1, 2\bigr\rbrack, \bigl\lbrack1, 0\bigr\rbrack\bigr\rbrack, \bigl\lbrack\bigl\lbrack2, 1\bigr\rbrack, \bigl\lbrack1, 0\bigr\rbrack\bigr\rbrack, \bigl\lbrack\bigl\lbrack1, 2\bigr\rbrack, \bigl\lbrack1, 1\bigr\rbrack\bigr\rbrack, \bigl\lbrack\bigl\lbrack2, 1\bigr\rbrack, \bigl\lbrack1, 1\bigr\rbrack\bigr\rbrack\bigr\rbrack
About
Examples2
CrosswalkOEIS

See also: SignedPermutations