Set theory is the branch of math that studies collections of distinct objects and how they combine. This calculator handles the core operations — union, intersection, difference, symmetric difference, and Cartesian product — that show up everywhere from introductory math courses to database queries.

How the Set Theory Calculator works

The calculator parses Set A and Set B from your comma-separated input, trims whitespace, and removes duplicates while preserving the order elements first appear. Every operation — union, intersection, difference, symmetric difference, and Cartesian product — is computed directly from those two element lists using standard set-builder definitions, and cardinalities (set sizes) are derived by counting the resulting elements.

Because elements are compared as exact text matches, 2 and 2.0 are treated as different elements unless you enter them identically in both sets. This mirrors how most math courses define set equality: two elements are the same only if they're written the same way.

Where set operations show up in practice

Set operations aren't just a math-class exercise. A SQL UNION or INTERSECT query does exactly what the Union and Intersection operations here do, but on rows of a table instead of numbers. Venn diagrams are a visual way to represent A ∪ B, A ∩ B, and A − B. In probability, the union and intersection of events follow the same inclusion-exclusion rule this calculator's Cardinality tab demonstrates: |A ∪ B| = |A| + |B| − |A ∩ B|.

Limits and edge cases

This calculator treats every input as a finite set of literal text tokens — it doesn't evaluate expressions, ranges, or infinite sets like "all even numbers." Cartesian products are capped at 200 displayed pairs for very large inputs (the total count is still shown accurately). If either Set A or Set B is empty, the calculator shows a partial-input prompt rather than a result, since every operation needs both sets to be meaningful.