Cartesian products

AUTHORS:

  • Nicolas Thiery (2010-03): initial version
sage.sets.cartesian_product.CartesianProduct

A class implementing a raw data structure for Cartesian products of sets (and elements thereof). See cartesian_product for how to construct full fledged Cartesian products.

EXAMPLES:

sage: G = cartesian_product([GF(5), Permutations(10)])
sage: G.cartesian_factors()
(Finite Field of size 5, Standard permutations of 10)
sage: G.cardinality()
18144000
sage: G.random_element()    # random
(1, [4, 7, 6, 5, 10, 1, 3, 2, 8, 9])
sage: G.category()
Join of Category of finite monoids
    and Category of Cartesian products of monoids
    and Category of Cartesian products of finite enumerated sets
CartesianProduct._cartesian_product_of_elements(elements)

Return the Cartesian product of the given elements.

This implements Sets.CartesianProducts.ParentMethods._cartesian_product_of_elements(). INPUT:

  • elements – an iterable (e.g. tuple, list) with one element of each Cartesian factor of self

Warning

This is meant as a fast low-level method. In particular, no coercion is attempted. When coercion or sanity checks are desirable, please use instead self(elements) or self._element_constructor_(elements).

EXAMPLES:

sage: S1 = Sets().example()
sage: S2 = InfiniteEnumeratedSets().example()
sage: C = cartesian_product([S2, S1, S2])
sage: C._cartesian_product_of_elements([S2.an_element(), S1.an_element(), S2.an_element()])
(42, 47, 42)