# Tuples#

class sage.combinat.tuple.Tuples(S, k)[source]#

Return the enumerated set of ordered tuples of S of length k.

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.

EXAMPLES:

sage: S = [1,2]
sage: Tuples(S,3).list()
[(1, 1, 1), (2, 1, 1), (1, 2, 1), (2, 2, 1), (1, 1, 2),
(2, 1, 2), (1, 2, 2), (2, 2, 2)]
sage: mset = ["s","t","e","i","n"]
sage: Tuples(mset,2).list()
[('s', 's'), ('t', 's'), ('e', 's'), ('i', 's'), ('n', 's'),
('s', 't'), ('t', 't'), ('e', 't'), ('i', 't'), ('n', 't'),
('s', 'e'), ('t', 'e'), ('e', 'e'), ('i', 'e'), ('n', 'e'),
('s', 'i'), ('t', 'i'), ('e', 'i'), ('i', 'i'), ('n', 'i'),
('s', 'n'), ('t', 'n'), ('e', 'n'), ('i', 'n'), ('n', 'n')]

>>> from sage.all import *
>>> S = [Integer(1),Integer(2)]
>>> Tuples(S,Integer(3)).list()
[(1, 1, 1), (2, 1, 1), (1, 2, 1), (2, 2, 1), (1, 1, 2),
(2, 1, 2), (1, 2, 2), (2, 2, 2)]
>>> mset = ["s","t","e","i","n"]
>>> Tuples(mset,Integer(2)).list()
[('s', 's'), ('t', 's'), ('e', 's'), ('i', 's'), ('n', 's'),
('s', 't'), ('t', 't'), ('e', 't'), ('i', 't'), ('n', 't'),
('s', 'e'), ('t', 'e'), ('e', 'e'), ('i', 'e'), ('n', 'e'),
('s', 'i'), ('t', 'i'), ('e', 'i'), ('i', 'i'), ('n', 'i'),
('s', 'n'), ('t', 'n'), ('e', 'n'), ('i', 'n'), ('n', 'n')]

sage: K.<a> = GF(4, 'a')                                                        # needs sage.rings.finite_rings
sage: mset = sorted((x for x in K if x != 0), key=str)                          # needs sage.rings.finite_rings
sage: Tuples(mset, 2).list()                                                    # needs sage.rings.finite_rings
[(1, 1),     (a, 1),     (a + 1, 1),
(1, a),     (a, a),     (a + 1, a),
(1, a + 1), (a, a + 1), (a + 1, a + 1)]

>>> from sage.all import *
>>> K = GF(Integer(4), 'a', names=('a',)); (a,) = K._first_ngens(1)# needs sage.rings.finite_rings
>>> mset = sorted((x for x in K if x != Integer(0)), key=str)                          # needs sage.rings.finite_rings
>>> Tuples(mset, Integer(2)).list()                                                    # needs sage.rings.finite_rings
[(1, 1),     (a, 1),     (a + 1, 1),
(1, a),     (a, a),     (a + 1, a),
(1, a + 1), (a, a + 1), (a + 1, a + 1)]

cardinality()[source]#

EXAMPLES:

sage: S = [1,2,3,4,5]
sage: Tuples(S,2).cardinality()
25
sage: S = [1,1,2,3,4,5]
sage: Tuples(S,2).cardinality()
25

>>> from sage.all import *
>>> S = [Integer(1),Integer(2),Integer(3),Integer(4),Integer(5)]
>>> Tuples(S,Integer(2)).cardinality()
25
>>> S = [Integer(1),Integer(1),Integer(2),Integer(3),Integer(4),Integer(5)]
>>> Tuples(S,Integer(2)).cardinality()
25

sage.combinat.tuple.Tuples_sk[source]#

alias of Tuples

class sage.combinat.tuple.UnorderedTuples(S, k)[source]#

Return the enumerated set of unordered tuples of S of length k.

An unordered tuple of length k of set is a unordered selection with repetitions of set and is represented by a sorted list of length k containing elements from set.

EXAMPLES:

sage: S = [1,2]
sage: UnorderedTuples(S,3).list()
[(1, 1, 1), (1, 1, 2), (1, 2, 2), (2, 2, 2)]
sage: UnorderedTuples(["a","b","c"],2).list()
[('a', 'a'), ('a', 'b'), ('a', 'c'), ('b', 'b'), ('b', 'c'),
('c', 'c')]

>>> from sage.all import *
>>> S = [Integer(1),Integer(2)]
>>> UnorderedTuples(S,Integer(3)).list()
[(1, 1, 1), (1, 1, 2), (1, 2, 2), (2, 2, 2)]
>>> UnorderedTuples(["a","b","c"],Integer(2)).list()
[('a', 'a'), ('a', 'b'), ('a', 'c'), ('b', 'b'), ('b', 'c'),
('c', 'c')]

cardinality()[source]#

EXAMPLES:

sage: S = [1,2,3,4,5]
sage: UnorderedTuples(S,2).cardinality()
15

>>> from sage.all import *
>>> S = [Integer(1),Integer(2),Integer(3),Integer(4),Integer(5)]
>>> UnorderedTuples(S,Integer(2)).cardinality()
15

sage.combinat.tuple.UnorderedTuples_sk[source]#

alias of UnorderedTuples