Skip to content

Tuples ​

The k-tuples over {1,…,n}\{1, \dots, n\}: all nkn^k ordered selections with repetition.

✓ checked against that system · ! checked, with disagreements (hover a chip)WikipediaTupleMathWorldn-TupleWikidataQ600590OEISA079901✓Wolfram LanguageTuples✓
Tuples(n, k)the nkn^k length-kk tuples
Tuples(list, k)the ∣list∣k\lvert list \rvert^k length-kk tuples of the list's own elements, as a ListList (up to a size cap)
Typed signatures
TypePackageApplies
((integer<0..>, integer<0..>) -> indexed_collection<list<integer>>) & ((list<any>, integer<0..>) -> list<list<any>>)combinatoricsalways

Domain: Combinatorial collections

Details
  • Count is nkn^k
  • Elements are ordered as mixed-radix (base nn) counting

Definition

Epsil, as the implementation runs it.

count(_n, _k)

1 if _k == 0 else _n ^ _k

unrank(_n, _k, _r)

Map(
     Function((_r - _r % _n ^ (_k - j)) / _n ^ (_k - j) % _n + 1, j),
     Range(1, _k, 1),
   )

rank(_n, _k, _x)

Fold(Function(acc * _n + (_x[j] - 1), acc, j), 0, Range(1, _k, 1))

valid(_n, _k, _x)

Length(_x) == _k && Fold(Function(
                                   ok_j && 1 <= _x[j] && _x[j] <= _n + 1 - 1,
                                   ok_j,
                                   j,
                                 ), True, Range(1, Length(_x), 1))

Examples

Basic #

232^3

live ↗
InCount(Tuples(2,3))\mathrm{Count}(\mathrm{Tuples}(2, 3))Out88
live ↗
InTuples(2,3)[1]\mathrm{Tuples}(2, 3)[1]Out[1,1,1]\bigl\lbrack1, 1, 1\bigr\rbrack
Applications #
live ↗
InThread(Rule(Tuples([1,0],3),IntegerDigits(30,2,8)))\mathrm{Thread}(\mathrm{Rule}(\mathrm{Tuples}(\bigl\lbrack1, 0\bigr\rbrack, 3), \mathrm{IntegerDigits}(30, 2, 8)))Out[Rule([1,1,1],0),Rule([1,1,0],0),Rule([1,0,1],0),Rule([1,0,0],1),Rule([0,1,1],1),Rule([0,1,0],1),Rule([0,0,1],1),Rule([0,0,0],0)]\bigl\lbrack\mathrm{Rule}(\bigl\lbrack1, 1, 1\bigr\rbrack, 0), \mathrm{Rule}(\bigl\lbrack1, 1, 0\bigr\rbrack, 0), \mathrm{Rule}(\bigl\lbrack1, 0, 1\bigr\rbrack, 0), \mathrm{Rule}(\bigl\lbrack1, 0, 0\bigr\rbrack, 1), \mathrm{Rule}(\bigl\lbrack0, 1, 1\bigr\rbrack, 1), \mathrm{Rule}(\bigl\lbrack0, 1, 0\bigr\rbrack, 1), \mathrm{Rule}(\bigl\lbrack0, 0, 1\bigr\rbrack, 1), \mathrm{Rule}(\bigl\lbrack0, 0, 0\bigr\rbrack, 0)\bigr\rbrack
About
Examples3
Checked againstWolfram Language 3 agree
CrosswalkWikipediaMathWorldWikidataOEISWolfram Language

See also: Subsets, Multisets