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.

This calculator compares literal text tokens after trimming whitespace. The strings 2 and 2.0 remain distinct here, although both denote the same number in ordinary numerical equality. Choose one consistent representation for literal set elements.

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

An empty set is a valid mathematical operand. Use the explicit empty-set control in the workspace; a blank field without that control means missing input. The empty set united with B gives B, its intersection with B is empty, and it is a subset of every set.