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
Set Operations
Inclusion-Exclusion Verification
Venn Diagram
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}) |
|---|---|---|---|
| Union | A ∪ B | Elements in A or B or both | {1, 2, 3, 4} |
| Intersection | A ∩ B | Elements in both A and B | {2, 3} |
| Difference | A − B | Elements in A but not B | {1} |
| Difference | B − A | Elements in B but not A | {4} |
| Symmetric Difference | A △ B | Elements in exactly one of A, B | {1, 4} |
| Complement of A | A' (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.