---
title: "Cartesian Product Constructor and Functions"
canonical: "https://docs.magma-maths.org/v2.30-1/SetsSequencesMappings/TuplesCartesianProducts/creation.html"
source: "https://docs.magma-maths.org/v2.30-1/SetsSequencesMappings/TuplesCartesianProducts/creation.md"
part: "Sets, Sequences, and Mappings"
chapter: "Tuples and Cartesian Products"
breadcrumbs:
  - {"title": "Magma Handbook", "source": "https://docs.magma-maths.org/v2.30-1/index.md"}
  - {"title": "Sets, Sequences, and Mappings", "source": "https://docs.magma-maths.org/v2.30-1/SetsSequencesMappings/index-sets-sequences-mappings.md"}
  - {"title": "Tuples and Cartesian Products", "source": "https://docs.magma-maths.org/v2.30-1/SetsSequencesMappings/TuplesCartesianProducts/index-tuples-cartesian-products.md"}
prev: {"title": "Introduction", "source": "https://docs.magma-maths.org/v2.30-1/SetsSequencesMappings/TuplesCartesianProducts/introduction.md"}
next: {"title": "Creating and Modifying Tuples", "source": "https://docs.magma-maths.org/v2.30-1/SetsSequencesMappings/TuplesCartesianProducts/tuple.md"}
intrinsics:
  - {"name": "car", "signature": "car< R₁, ..., Rₖ >: Str, ..., Str -> SetCart"}
  - {"name": "CartesianProduct", "signature": "CartesianProduct(R, S): Str, ..., Str -> SetCart"}
  - {"name": "CartesianProduct", "signature": "CartesianProduct(L): [Str] -> SetCart"}
  - {"name": "CartesianProduct", "signature": "CartesianProduct(L): <Str> -> SetCart"}
  - {"name": "CartesianPower", "signature": "CartesianPower(R, k): Str, RngIntElt -> SetCart"}
  - {"name": "Flat", "signature": "Flat(C): SetCart -> SetCart"}
  - {"name": "NumberOfComponents", "signature": "NumberOfComponents(C): SetCart -> RngIntElt"}
  - {"name": "Component", "signature": "Component(C, i): SetCart, RngIntElt -> Str"}
  - {"name": "C[i]", "signature": "C[i]: SetCart, RngIntElt -> Str"}
  - {"name": "Components", "signature": "Components(C): SetCart -> List"}
  - {"name": "#", "signature": "# C: SetCart -> RngIntElt"}
  - {"name": "Rep", "signature": "Rep(C): SetCart -> Elt"}
  - {"name": "Random", "signature": "Random(C): SetCart -> Elt"}
examples:
  - "ex-c2f16a"
---

# Cartesian Product Constructor and Functions

The special constructor `car< ... >` is used for the creation of cartesian products of structures.

<a id="constructor-constructor-car-str-str-setcart"></a>
## `car< R₁, ..., Rₖ >: Str, ..., Str -> SetCart`

Given a list of sets or algebraic structures $R_1, \ldots, R_k$, construct the cartesian product set $R_1 \times \cdots \times R_k$.

<a id="function-cartesianproduct-str-str"></a>
## `CartesianProduct(R, S): Str, ..., Str -> SetCart`

Given structures $R$ and $S$, construct the cartesian product set $R \times S$. This is the same as calling the `car` constructor with the two arguments $R$ and $S$.

<a id="function-cartesianproduct-str"></a>
## `CartesianProduct(L): [Str] -> SetCart`

<a id="function-cartesianproduct-str-2"></a>
## `CartesianProduct(L): <Str> -> SetCart`

Given a sequence or tuple $L$ of structures, construct the cartesian product of the elements of $L$.

<a id="function-cartesianpower-str-rngintelt"></a>
## `CartesianPower(R, k): Str, RngIntElt -> SetCart`

Given a structure $R$ and an integer $k$, construct the cartesian power set $R^{k}$.

<a id="function-tuple-flat1"></a>
## `Flat(C): SetCart -> SetCart`

Given a cartesian product $C$ of structures which may themselves be cartesian products, return the cartesian product of the base structures, considered in depth-first order (see [`Flat`](https://docs.magma-maths.org/v2.30-1/SetsSequencesMappings/TuplesCartesianProducts/tuple.md#function-tuple-flat2) for the element version).

<a id="function-numberofcomponents-setcart"></a>
## `NumberOfComponents(C): SetCart -> RngIntElt`

Given a cartesian product $C$, return the number of components of $C$.

<a id="function-component-setcart-rngintelt"></a>
## `Component(C, i): SetCart, RngIntElt -> Str`

<a id="literal-literal-c-i-setcart-rngintelt-str"></a>
## `C[i]: SetCart, RngIntElt -> Str`

The $i$-th component of $C$.

<a id="function-components-setcart"></a>
## `Components(C): SetCart -> List`

The list of components of a cartesian product.

<a id="operation-operation-setcart-rngintelt"></a>
## `# C: SetCart -> RngIntElt`

Given a cartesian product $C$, return the cardinality of $C$.

<a id="function-rep-setcart"></a>
## `Rep(C): SetCart -> Elt`

Given a cartesian product $C$, return a representative of $C$.

<a id="function-random-setcart"></a>
## `Random(C): SetCart -> Elt`

Given a cartesian product $C$, return a random element of $C$.

<a id="example-ex-c2f16a"></a>
## `Example: Cartesian Product of Q and Z (ex-c2f16a)`

We create the product of ${\mathbb{Q}}$ and ${\mathbb{Z}}$.

```magma
> C := car< RationalField(), Integers() >;
> C;
Cartesian Product<Rational Field, Ring of Integers>
```
