Cartesian Product Calculator

Enter two or more finite sets to calculate their Cartesian product. The tool reports the exact cardinality and lists every ordered tuple when the product contains no more than 100,000 tuples. Duplicate elements are removed, and all processing stays in your browser.

Enter your sets

Separate elements with commas, semicolons, or line breaks. Optional outer braces are accepted. Blank input or ∅ represents the empty set.

Private by design: your sets and generated tuples stay on this device. Inputs are not uploaded, saved, or added to the page URL.

Cartesian product

The example product is calculated below.

Advertisement

Cartesian product definition and formula

Two sets

A × B = {(a, b) | a ∈ A and b ∈ B}

Each ordered pair chooses its first coordinate from A and its second coordinate from B.

Two-set cardinality

|A × B| = |A| · |B|

For every element of A, there is one pair with each element of B.

More than two sets

A₁ × ··· × Aₙ = {(a₁, …, aₙ) | aᵢ ∈ Aᵢ}

Each n-tuple contains exactly one coordinate from every factor set.

n-set cardinality

|A₁ × ··· × Aₙ| = ∏ᵢ₌₁ⁿ |Aᵢ|

Multiply all factor cardinalities. If any factor is empty, the product is empty.

Tuple order is significant. For example, (1, x) is not the same ordered pair as (x, 1). Consequently, A × B and B × A generally contain different ordered pairs even though their cardinalities are equal.

Cartesian product examples

Two finite sets

{1, 2} × {x, y}

= {(1, x), (1, y), (2, x), (2, y)}

There are 2 · 2 = 4 ordered pairs.

Three finite sets

{a, b} × {1, 2} × {T, F}

This product has 2 · 2 · 2 = 8 ordered triples, from (a, 1, T) through (b, 2, F).

Empty factor

A × ∅ × C = ∅

No tuple can contain a coordinate chosen from ∅, so the product has zero elements regardless of A and C.

Method, ordering, and limits

The calculator first trims every label, normalizes Unicode text, and removes duplicates within each set. It then multiplies the unique-element counts using exact integers. For generated output, it enumerates tuples in nested-loop order: the last set changes fastest, followed by the next-to-last set. Input order controls display order only; the elements of a mathematical set are unordered.

You may enter two to eight sets, with up to 1,000 unique elements and 20,000 characters per set. Individual element labels are limited to 80 characters. Tuple generation, copy, and download are available for products of up to 100,000 tuples; larger products still receive an exact cardinality without allocating an impractically large list. Commas, semicolons, and line breaks act as separators and therefore cannot be part of one element label.

Input values are treated as text labels. Thus 1 and 1.0 are distinct, as are A and a. If you need coordinates with embedded commas, use an unambiguous replacement label before calculating.

Cartesian product calculator FAQ

What is a Cartesian product?

The Cartesian product A × B contains every ordered pair (a, b) whose first coordinate is in A and whose second coordinate is in B. With more factors, the results are ordered tuples.

How many elements are in a Cartesian product?

Multiply the cardinalities of the factor sets. For example, sets with 3, 4, and 2 elements produce 3 · 4 · 2 = 24 ordered triples.

Does order matter in a Cartesian product?

Yes. Coordinates have fixed positions, so (a, b) generally differs from (b, a). Swapping the factor sets also swaps the coordinate roles.

Is the Cartesian product commutative?

Not as a set of ordered tuples: A × B generally does not equal B × A. Their cardinalities are equal for finite sets because multiplication is commutative.

What if one of the sets is empty?

The complete product is ∅ and its cardinality is zero. A tuple cannot be formed unless one element can be selected from every factor set.

Can I use more than two sets?

Yes. Add up to eight sets. The calculator returns ordered triples for three sets, ordered quadruples for four sets, and n-tuples in general.

Are duplicate elements counted more than once?

No. A set contains unique elements, so duplicate labels are removed within each input. The field summary shows how many duplicates were removed.

Why was the product counted but not generated?

Listing every tuple can become enormous. The calculator reports the exact cardinality for any valid input but generates at most 100,000 tuples to protect browser responsiveness.

Does the calculator store my sets?

No. Parsing, cardinality calculation, tuple generation, copying, and CSV creation happen locally in your browser.

Explore more tools