# Cartesian products¶

AUTHORS:

• Nicolas Thiery (2010-03): initial version
class sage.sets.cartesian_product.CartesianProduct(sets, category, flatten=False)

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

_cartesian_product_of_elements(elements)

Return the cartesian product of the given elements.

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

INPUT:

• elements – a tuple (or iterable) 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)

class Element

EXAMPLES:

sage: from sage.structure.element_wrapper import DummyParent
sage: a = ElementWrapper(DummyParent("A parent"), 1)


TESTS:

sage: TestSuite(a).run(skip = "_test_category")

sage: a = ElementWrapper(1, DummyParent("A parent"))
doctest:...: DeprecationWarning: the first argument must be a parent
See http://trac.sagemath.org/14519 for details.


Note

ElementWrapper is not intended to be used directly, hence the failing category test.

cartesian_projection(i)

Return the projection of self on the $$i$$-th factor of the cartesian product, as per Sets.CartesianProducts.ElementMethods.cartesian_projection().

INPUTS:

• i – the index of a factor of the cartesian product

EXAMPLES:

sage: C = Sets().CartesianProducts().example(); C
The cartesian product of (Set of prime numbers (basic implementation), An example of an infinite enumerated set: the non negative integers, An example of a finite enumerated set: {1,2,3})
sage: x = C.an_element(); x
(47, 42, 1)
sage: x.cartesian_projection(1)
42

sage: x.summand_projection(1)
doctest:...: DeprecationWarning: summand_projection is deprecated. Please use cartesian_projection instead.
See http://trac.sagemath.org/10963 for details.
42

CartesianProduct.an_element()

EXAMPLES:

sage: C = Sets().CartesianProducts().example(); C
The cartesian product of (Set of prime numbers (basic implementation),
An example of an infinite enumerated set: the non negative integers,
An example of a finite enumerated set: {1,2,3})
sage: C.an_element()
(47, 42, 1)

CartesianProduct.cartesian_factors()

Return the cartesian factors of self.

EXAMPLES:

sage: cartesian_product([QQ, ZZ, ZZ]).cartesian_factors()
(Rational Field, Integer Ring, Integer Ring)

CartesianProduct.cartesian_projection(i)

Return the natural projection onto the $$i$$-th cartesian factor of self as per Sets.CartesianProducts.ParentMethods.cartesian_projection().

INPUT:

• i – the index of a cartesian factor of self

EXAMPLES:

sage: C = Sets().CartesianProducts().example(); C
The cartesian product of (Set of prime numbers (basic implementation), An example of an infinite enumerated set: the non negative integers, An example of a finite enumerated set: {1,2,3})
sage: x = C.an_element(); x
(47, 42, 1)
sage: pi = C.cartesian_projection(1)
sage: pi(x)
42

CartesianProduct.summand_projection(*args, **kwds)

Deprecated: Use cartesian_projection() instead. See trac ticket #10963 for details.

#### Previous topic

Wrapper for Graphics Files

Families