Cartesian product [0077]
- February 23, 2026
Definition Cartesian product [0078]
- February 23, 2026
If A and B are sets, the (Cartesian) product of A and B, written A \times B, is the set of all possible ordered pairs of elements from A and B. That is, A \times B = \{ (a, b) \mid a \in A, b \in B \}.
Example [0079]
- February 23, 2026
Let A = \{1, 2, 3\} and B = \{ \triangle , \square \}. Then A \times B = \{(1,\triangle ), (1,\square ), (2,\triangle ), (2,\square ), (3,\triangle ), (3,\square )\}. We can think of this in terms of filling out a 2D grid where the rows are labeled with elements from A and the columns with elements from B:
\begin {array}{ccc} & \triangle & \square \\ 1 & (1,\triangle ) & (1, \square ) \\ 2 & (2,\triangle ) & (2, \square ) \\ 3 & (3,\triangle ) & (3, \square ) \\ \end {array}Each cell in the grid corresponds to one possible combination of an element from A with an element from B.
From this we can also see that for finite sets, the cardinality of a Cartesian product is the product of the cardinalities: |A \times B| = |A| \times |B|.
Cartesian product in Disco [007A]
- February 23, 2026
We can use the >< operator in Disco for Cartesian product:
Disco> {1,2,3} >< {T, F}
{(1, F), (1, T), (2, F), (2, T), (3, F), (3, T)}Cartesian product of types [007X]
- February 26, 2026
In Disco, we can take the Cartesian product of types as well. For example, if we take the Cartesian product of a set of natural numbers and a set of Booleans, the type of the resulting elements is ℕ × Bool:
Disco> {1,2,3} >< {T,F}
{(1, F), (1, T), (2, F), (2, T), (3, F), (3, T)}
Disco> :type {1,2,3} >< {T,F}
{1, 2, 3} >< {T, F} : Set(ℕ × Bool)In this example, ℕ × Bool is the type of the elements, which look like pairs such as (1, F). In general, the type A × B (also written A >< B or A * B) has values that look like ordered pairs (a,b).