18.37 Tuples

Module: sage.combinat.tuple

Tuples

Module-level Functions

Tuples( S, k)

Returns the combinatorial class 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.

       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']]

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

UnorderedTuples( S, k)

Returns the combinatorial class 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.

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']]

Class: Tuples_sk

class Tuples_sk
Tuples_sk( self, S, k)

TESTS:

sage: T = Tuples([1,2,3],2)
sage: T == loads(dumps(T))
True

Functions: count,$ \,$ iterator

count( self)

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

iterator( self)

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']]

Special Functions: __init__,$ \,$ __repr__

__repr__( self)

TESTS:

sage: repr(Tuples([1,2,3],2))
'Tuples of [1, 2, 3] of length 2'

Class: UnorderedTuples_sk

class UnorderedTuples_sk
UnorderedTuples_sk( self, S, k)

TESTS:

sage: T = Tuples([1,2,3],2)
sage: T == loads(dumps(T))
True

Functions: count,$ \,$ list

count( self)

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

list( self)

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']]

Special Functions: __init__,$ \,$ __repr__

__repr__( self)

TESTS:

sage: repr(UnorderedTuples([1,2,3],2))
'Unordered tuples of [1, 2, 3] of length 2'

See About this document... for information on suggesting changes.