Set Theory Calculator

Union · Intersection · Difference · Power Set · Venn Diagram

Enter two sets as comma-separated values. Instantly computes all set operations with a Venn diagram, power set, Cartesian product, and Inclusion-Exclusion verification.

Quick Examples

Comma-separated values

Comma-separated values

What Is Set Theory?

Set theory is a branch of mathematical logic that studies collections of objects, called sets. Developed formally by Georg Cantor in the late 19th century, it forms the foundation of virtually all modern mathematics — from arithmetic and algebra to topology, probability, and computer science. A set is an unordered collection of distinct elements; for example, A = {1, 2, 3} and B = {apple, banana, cherry} are both valid sets.

This calculator performs all fundamental set operations on two sets A and B simultaneously, displaying results along with a Venn diagram visualization, power set enumeration, and Cartesian product — making it useful for students, programmers, and mathematicians alike.

Core Set Operations

Operation Notation Definition Example (A={1,2,3}, B={2,3,4})
UnionA ∪ BElements in A or B or both{1, 2, 3, 4}
IntersectionA ∩ BElements in both A and B{2, 3}
DifferenceA − BElements in A but not B{1}
DifferenceB − AElements in B but not A{4}
Symmetric DifferenceA △ BElements in exactly one of A, B{1, 4}
Complement of AA' (rel. to universal)Elements in universal but not A{4} (when U = A∪B)

The Inclusion-Exclusion Principle

The Inclusion-Exclusion Principle is one of the most important counting formulas in combinatorics. It states that for any two finite sets:

|A ∪ B| = |A| + |B| − |A ∩ B|

The formula corrects for double-counting: when we add |A| and |B|, every element in A ∩ B is counted twice, so we subtract |A ∩ B| once to get the correct total. This principle extends to three or more sets and is a cornerstone of probability calculations, algorithm analysis, and database query optimization.

Power Set

The power set P(A) of a set A is the set of all subsets of A, including the empty set ∅ and A itself. If A has n elements, then P(A) has exactly 2ⁿ subsets. For example, if A = {x, y, z}, then P(A) = {∅, {x}, {y}, {z}, {x,y}, {x,z}, {y,z}, {x,y,z}} — eight subsets for n = 3.

Power sets grow exponentially and are foundational in Boolean algebra, computer science (bitmask DP), and formal language theory.

Cartesian Product

The Cartesian product A × B is the set of all ordered pairs (a, b) with a ∈ A and b ∈ B. The cardinality is |A × B| = |A| × |B|. In databases, this corresponds to a full JOIN (cross join) between two tables. In geometry, ℝ × ℝ = ℝ² (the 2D coordinate plane) is itself a Cartesian product. In programming, nested loops that iterate over two arrays produce every element of A × B.

Applications in Programming and Databases

  • SQL Queries: UNION, INTERSECT, and EXCEPT map directly to set union, intersection, and difference. CROSS JOIN produces the Cartesian product.
  • Data Deduplication: Set intersection finds duplicate records between two datasets; set difference identifies records unique to each.
  • Access Control: Permission sets use intersection (what a user can do vs. what a resource allows) and difference (revoked permissions).
  • Graph Theory: Vertex sets and edge sets are formally sets; graph operations like union and intersection of graphs use set arithmetic.
  • Probability Theory: Event spaces are sets; P(A ∪ B) = P(A) + P(B) − P(A ∩ B) directly uses Inclusion-Exclusion.
  • Compiler Design: FIRST and FOLLOW sets in LL(1) parsing, and symbol table lookups, rely on set operations.

Set Theory in Mathematics Education

Set theory is typically introduced in secondary school mathematics (classes 8–10) and revisited more formally in undergraduate discrete mathematics courses. Mastering set operations builds intuition for logic, proofs, functions, and relations — all of which underpin advanced mathematics and theoretical computer science.

The Venn diagram — invented by English logician John Venn in 1880 — remains one of the most effective visual tools for understanding set relationships. Each circle represents a set, and the overlapping region represents the intersection, making abstract relationships concrete and easy to reason about.

Frequently Asked Questions

What is the union of two sets?
The union A ∪ B contains every element that belongs to A, or B, or both. Duplicate elements are not repeated. For example, if A = {1, 2, 3} and B = {3, 4, 5}, then A ∪ B = {1, 2, 3, 4, 5}. The cardinality formula is |A ∪ B| = |A| + |B| − |A ∩ B|.
What is the intersection of two sets?
The intersection A ∩ B contains only the elements present in both A and B simultaneously. For A = {1, 2, 3} and B = {3, 4, 5}, A ∩ B = {3}. If no elements are shared, the intersection is the empty set ∅ and the sets are called disjoint.
What is the difference between A − B and B − A?
A − B (A minus B) contains elements in A but not in B. B − A contains elements in B but not in A. These are generally different: if A = {1,2,3} and B = {2,3,4}, then A − B = {1} and B − A = {4}. Set difference is not commutative.
What is the symmetric difference of two sets?
The symmetric difference A ∆ B contains elements in exactly one of A or B — not in both. It equals (A − B) ∪ (B − A). For A = {1,2,3} and B = {2,3,4}, A ∆ B = {1, 4}. In Boolean logic, this corresponds to XOR (exclusive OR).
What is the power set and how many subsets does a set have?
The power set P(A) is the set of all subsets of A, including ∅ and A itself. A set with n elements has exactly 2ⁿ subsets. For A = {1, 2}, P(A) = {∅, {1}, {2}, {1,2}} — four elements (2² = 4). This calculator shows P(A) when |A| ≤ 8 to avoid exponential blowup.
What is the Cartesian product A × B?
A × B is the set of all ordered pairs (a, b) where a ∈ A and b ∈ B. Its size is |A| × |B|. For A = {1,2} and B = {x,y}, A × B = {(1,x),(1,y),(2,x),(2,y)}. This calculator shows A × B when both sets have ≤ 4 elements each (max 16 pairs).
What is the Inclusion-Exclusion Principle?
The Inclusion-Exclusion Principle states |A ∪ B| = |A| + |B| − |A ∩ B|. It prevents double-counting elements in the intersection. For A = {1,2,3} and B = {2,3,4}: |A| = 3, |B| = 3, |A ∩ B| = 2, so |A ∪ B| = 3 + 3 − 2 = 4 = |{1,2,3,4}| ✓. This generalizes to any number of sets.