Cartesian Product Calculator

Enter the elements of set A and set B, separated by commas.

How it is calculated

Type the elements of each set separated by commas. The tool trims spaces around each element, ignores empty entries (so a doubled comma is harmless) and treats every element as plain text. Because a set has no repeats, identical entries are merged first, and the comparison is case-sensitive, so a and A stay separate. It then pairs each element of A with each element of B, in order, writing every pair as (a, b). The number of pairs is |A| × |B|, the size of A multiplied by the size of B, counted after merging, and the tool also prints both sizes. If either set ends up empty there is no result. Order matters: (a, b) and (b, a) are different pairs, so A × B and B × A hold the same pairs written the other way round.

Worked example

Set A is the colours red, green, blue (3 elements) and set B is the sizes S, M (2 elements). Each colour is paired with each size, colour first: (red, S), (red, M), (green, S), (green, M), (blue, S), (blue, M). The count is 3 × 2 = 6 pairs. This is the same list a shop would need for every colour and size combination of one product, and swapping the sets would give pairs with the size first instead.

Try this example →

Common mistakes

  • Separating elements with spaces or semicolons instead of commas. red green blue is read as a single element, giving 1 × |B| pairs.
  • Repeating an element and expecting it to count twice. a,a,b is merged to the two elements a and b, so |A| = 2, not 3.
  • Expecting a and A to be merged. They are compared exactly, so both stay and the pair count grows.
  • Entering elements that contain commas, such as Smith, John. The comma splits them into two separate elements.
  • Treating the result as unordered pairs. A × B lists (a, b) with a from A first; (b, a) belongs to B × A.

About this calculator

The Cartesian product of two sets A and B, written A × B, is the set of every possible ordered pair (a, b) where a comes from A and b comes from B — if A has m elements and B has n elements, the product has exactly m×n pairs. This calculator takes two comma-separated lists, generates every ordered pair between them, and reports the total pair count.

The concept is foundational across discrete mathematics, combinatorics and computer science: it's how a plane's coordinate grid (ℝ × ℝ) is formally defined, how programmers reason about nested loops that iterate over two collections, and — perhaps most practically — the mathematical basis of the SQL CROSS JOIN, where a database engine pairs every row of one table with every row of another. Students meet it early in set theory courses as the building block for relations and functions, since any relation between two sets is technically defined as a subset of their Cartesian product.

Was this helpful?

You can pick up to 3 reactions.

Comments (1)

  • Editorial team

    The pair count multiplies, which is the quick way to size a test plan before you list anything. Four browsers against six screen sizes is 24 combinations, and adding a third dimension later would multiply again. Order matters here, so (a, b) and (b, a) are different pairs. Duplicate entries are merged first. What are you combining: menu options, test cases, or something else?

Popular calculators

All Calculators