Set Operations Calculator
Perform union, intersection, difference, and complement operations on sets. Enter values for instant results with step-by-step formulas.
Reviewed for accuracy by Manoj Kumar, Mathematics Educator
Set Operations Calculator
Calculator
Adjust values & calculateEnter your values below. Every result is computed in your browser โ no data is sent to any server.
Formula: A U B, A intersect B, A - B, A delta B
Worked example โ |A U B| = 7, |A intersect B| = 3, |A-B| = 2, |B-A| = 2
Formula
A U B, A intersect B, A - B, A delta B
Union combines all elements from both sets. Intersection finds common elements. Difference A-B finds elements in A but not B. Symmetric difference finds elements in exactly one of the two sets. Complement finds elements in the universal set but not in the given set.
Worked Examples
Example 1: Basic Set Operations
Problem:Given A = {1, 2, 3, 4, 5} and B = {3, 4, 5, 6, 7}, find all basic set operations.
Solution:Union: A U B = {1, 2, 3, 4, 5, 6, 7} (7 elements) Intersection: A intersect B = {3, 4, 5} (3 elements) Difference A-B = {1, 2} (2 elements) Difference B-A = {6, 7} (2 elements) Symmetric difference = {1, 2, 6, 7} (4 elements) Jaccard similarity = 3/7 = 42.9%
Result:|A U B| = 7, |A intersect B| = 3, |A-B| = 2, |B-A| = 2
Example 2: Subset and Complement
Problem:Given U = {1,...,10}, A = {2, 4, 6, 8}, B = {1, 2, 3, 4}, find complements and check subset.
Solution:Complement of A = {1, 3, 5, 7, 9, 10} Complement of B = {5, 6, 7, 8, 9, 10} A is not a subset of B (6, 8 not in B) B is not a subset of A (1, 3 not in A) A intersect B = {2, 4} De Morgan: (A U B)' = A' intersect B' = {5, 7, 9, 10}
Result:Sets are overlapping but neither is a subset of the other. |A intersect B| = 2.
Frequently Asked Questions
What are set operations and why are they important in mathematics?
Set operations are fundamental mathematical procedures that combine or compare collections of distinct objects called sets. The primary operations include union (combining all elements from both sets), intersection (finding common elements), difference (elements in one set but not the other), and complement (elements in the universal set but not in the given set). Set theory, formalized by Georg Cantor in the late 19th century, provides the foundational language for virtually all of modern mathematics. Every mathematical structure, from numbers to functions to topological spaces, can be described in terms of sets and set operations. Understanding set operations is essential for logic, probability theory, database queries, and computer science.
What is the union of two sets and how is it computed?
The union of sets A and B, written A U B, is the set containing all elements that belong to A, to B, or to both. For example, if A = {1, 2, 3} and B = {3, 4, 5}, then A U B = {1, 2, 3, 4, 5}. Note that element 3 appears only once in the result because sets contain no duplicates. The union operation is commutative (A U B = B U A), associative ((A U B) U C = A U (B U C)), and has the empty set as its identity element (A U empty = A). The cardinality of the union follows the inclusion-exclusion principle: |A U B| = |A| + |B| - |A intersect B|. In databases, the union operation corresponds to the SQL UNION keyword that combines result sets.
What is the intersection of two sets?
The intersection of sets A and B, written A intersect B, is the set of all elements that belong to both A and B simultaneously. For example, if A = {1, 2, 3, 4} and B = {3, 4, 5, 6}, then A intersect B = {3, 4}. If two sets have no elements in common, their intersection is the empty set and the sets are called disjoint. Like union, intersection is commutative and associative. The intersection distributes over union: A intersect (B U C) = (A intersect B) U (A intersect C). In probability theory, the intersection of events corresponds to the AND operation, and P(A intersect B) = P(A) * P(B) for independent events. In databases, intersection corresponds to SQL INTERSECT or JOIN operations.
What is the difference between set difference and symmetric difference?
Set difference A - B (also written A \ B) contains all elements that are in A but not in B. For example, if A = {1, 2, 3, 4} and B = {3, 4, 5}, then A - B = {1, 2}. Note that set difference is not commutative: B - A = {5}, which is different. Symmetric difference A delta B contains elements that are in either A or B but not in both, equivalently (A - B) U (B - A) = (A U B) - (A intersect B). In our example, A delta B = {1, 2, 5}. Symmetric difference is commutative and associative, making it useful in coding theory and cryptography. In database terms, symmetric difference identifies records that exist in one table but not the other.
What is the complement of a set?
The complement of a set A, written A-prime or A-bar, is the set of all elements in the universal set U that are not in A. The universal set is the set of all elements under consideration in a given context. For example, if U = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} and A = {2, 4, 6, 8}, then the complement of A is {1, 3, 5, 7, 9, 10}. De Morgan laws connect complements with union and intersection: the complement of A U B equals the complement of A intersected with the complement of B, and vice versa. These laws are fundamental in logic (connecting AND, OR, and NOT), circuit design, and probability (complement rule: P(not A) = 1 - P(A)).
What is the Cartesian product of two sets?
The Cartesian product A x B is the set of all ordered pairs (a, b) where a is from A and b is from B. For example, if A = {1, 2} and B = {x, y, z}, then A x B = {(1,x), (1,y), (1,z), (2,x), (2,y), (2,z)}, containing 2 times 3 = 6 pairs. The Cartesian product is named after Rene Descartes, who introduced coordinate geometry by taking the product of the real number line with itself to create the coordinate plane R^2. Unlike union and intersection, the Cartesian product is not commutative: A x B and B x A contain different ordered pairs unless A = B. In databases, the Cartesian product corresponds to the CROSS JOIN operation that combines every row from one table with every row from another.
What is the power set and how large is it?
The power set of a set A, written P(A), is the set of all possible subsets of A, including the empty set and A itself. For example, if A = {1, 2, 3}, then P(A) = {empty, {1}, {2}, {3}, {1,2}, {1,3}, {2,3}, {1,2,3}}, containing 2^3 = 8 subsets. In general, if A has n elements, its power set has exactly 2^n elements. This exponential growth means power sets become extremely large very quickly: a set with 10 elements has 1,024 subsets, a set with 20 elements has over a million subsets, and a set with 30 elements has over a billion subsets. The power set is important in combinatorics, topology (where it defines discrete topologies), and measure theory (where sigma-algebras are subsets of the power set).
What are subset and superset relationships?
Set A is a subset of set B (written A is a subset of B) if every element of A is also an element of B. Equivalently, B is a superset of A. For example, {1, 2} is a subset of {1, 2, 3, 4}. Every set is a subset of itself, and the empty set is a subset of every set. A is a proper subset of B if A is a subset of B and A does not equal B (meaning B has at least one element not in A). The subset relation defines a partial order on sets, which can be visualized using Hasse diagrams. In the lattice of all subsets of a universal set, the empty set is the bottom element and the universal set is the top element. Testing subset relationships is essential in database security, access control, and type systems in programming languages.
How is set theory used in probability and statistics?
Set theory provides the mathematical foundation for probability theory. The sample space is the universal set of all possible outcomes, events are subsets of the sample space, and probability is a function that assigns a number between 0 and 1 to each event. Union of events corresponds to OR (probability of A or B), intersection corresponds to AND (probability of A and B), and complement corresponds to NOT (probability of not A). The inclusion-exclusion principle gives P(A U B) = P(A) + P(B) - P(A intersect B). Independent events satisfy P(A intersect B) = P(A) * P(B). Conditional probability P(A|B) = P(A intersect B) / P(B). Bayes theorem, which is central to modern statistics and machine learning, is derived entirely from these set-theoretic probability rules.
What is the Jaccard similarity index and how does it use set operations?
The Jaccard similarity index (also called Jaccard coefficient) measures the similarity between two sets as the ratio of the size of their intersection to the size of their union: J(A,B) = |A intersect B| / |A U B|. It ranges from 0 (completely disjoint sets) to 1 (identical sets). For example, if A = {1,2,3,4} and B = {3,4,5,6}, the intersection has 2 elements and the union has 6 elements, giving J = 2/6 = 0.333. The Jaccard index is widely used in data mining, information retrieval, and ecology. In document similarity, sets represent the words or n-grams in documents. In recommendation systems, sets represent the items liked by different users. MinHash algorithms enable efficient estimation of Jaccard similarity for very large sets.
References
Reviewed for accuracy by Manoj Kumar, Mathematics Educator ยท Editorial policy
Related Calculators
๐งฎData Set Analyzer
Calculate data set analyzer with inputs, formulas, and instant results.
๐งฎPower Set Calculator
Calculate power set with inputs, formulas, and instant results.
๐งฎSet Builder Calculator
Calculate set builder with inputs, formulas, and instant results.
๐งฎMatrix Operations Calculator
matrix operations calculator. Get instant, accurate results.
๐งฎBinary Calculator
binary calculator. Get instant, accurate results.
๐งฎHexadecimal Calculator
hexadecimal calculator. Get instant, accurate results.
๐งฎModular Arithmetic Calculator
Perform modular arithmetic operations including modular exponentiation and inverse.
๐งฎMean Median Mode Range Calculator
Calculate mean, median, mode, and range from a data set with step-by-step work.