Tuples( set, k )
NrTuples( set, k )
Tuples returns the set of all ordered tuples of length k of the set
NrTuples returns the number of all ordered tuples of length k of the
An ordered tuple of length k of set is an ordered selection with repetition and is represented by a list of length k containing elements of set. There are |set|^k such ordered tuples.
Note that the fact that
Tuples returns a set implies that the last
index runs fastest. That means the first tuple contains the smallest
element from set k times, the second tuple contains the smallest
element of set at all positions except at the last positions, where it
contains the second smallest element from set and so on.
gap> Tuples( [1,2,3], 2 ); [ [ 1, 1 ], [ 1, 2 ], [ 1, 3 ], [ 2, 1 ], [ 2, 2 ], [ 2, 3 ], [ 3, 1 ], [ 3, 2 ], [ 3, 3 ] ] gap> NrTuples( [1..10], 5 ); 100000
Tuples(set,k) can also be viewed as the k-fold cartesian product
of set (see Cartesian).
Combinations (see Combinations) computes unordered
selections without repetitions,
Arrangements (see Arrangements)
computes ordered selections without repetitions, and finally the function
UnorderedTuples (see UnorderedTuples) computes unordered selections
Previous Up Top Next