Union and Intersection Calculator
Calculate union intersection instantly with our math tool. Shows detailed work, formulas used, and multiple solution methods.
Formula
|A U B| = |A| + |B| - |A n B|
The Inclusion-Exclusion Principle: the size of the union equals the sum of individual set sizes minus the size of the intersection. This avoids double-counting elements that appear in both sets.
Worked Examples
Example 1: Numeric Set Operations
Problem: Find the union, intersection, and differences of A = {1, 2, 3, 4, 5} and B = {3, 4, 5, 6, 7}.
Solution: A U B = {1, 2, 3, 4, 5, 6, 7} (all unique elements)\nA n B = {3, 4, 5} (common elements)\nA - B = {1, 2} (in A but not B)\nB - A = {6, 7} (in B but not A)\nSymmetric Difference = {1, 2, 6, 7}\nVerify: |A U B| = 7 = |A| + |B| - |A n B| = 5 + 5 - 3 = 7
Result: Union: 7 elements, Intersection: 3 elements, Jaccard Similarity: 3/7 = 0.4286
Example 2: Disjoint Sets Example
Problem: Find operations for A = {a, b, c} and B = {x, y, z}.
Solution: A U B = {a, b, c, x, y, z}\nA n B = {} (empty set - no common elements)\nA - B = {a, b, c} = A\nB - A = {x, y, z} = B\nSymmetric Difference = {a, b, c, x, y, z} = A U B\n|A U B| = 6 = 3 + 3 - 0
Result: Sets are disjoint. Union has 6 elements. Intersection is empty. Jaccard Similarity: 0.
Frequently Asked Questions
What is the union of two sets and how is it calculated?
The union of two sets A and B, written as A U B, is the set containing all elements that are in A, in B, or in both. No element is repeated in the result even if it appears in both sets. For example, if A = {1, 2, 3} and B = {2, 3, 4}, then A U B = {1, 2, 3, 4}. The union operation combines both sets while eliminating duplicates. This concept is fundamental in database queries (SQL UNION), probability theory (where P(A or B) relates to set union), and data analysis when merging datasets from different sources.
What is the intersection of two sets and what does it represent?
The intersection of two sets A and B, written as A n B or A and B, contains only the elements that appear in BOTH sets simultaneously. For example, if A = {1, 2, 3, 4} and B = {3, 4, 5, 6}, then A n B = {3, 4}. The intersection identifies the common elements shared between sets. In database terms, this corresponds to an INNER JOIN. In probability, the intersection relates to the probability of both events occurring. In everyday language, the intersection answers questions like which customers appear in both the online and in-store purchase lists.
What is a subset and how does it relate to union and intersection?
A set A is a subset of B (written A is a subset of B) if every element of A is also in B. When A is a subset of B, interesting simplifications occur: A n B = A (the intersection equals the smaller set) and A U B = B (the union equals the larger set). Every set is a subset of itself, and the empty set is a subset of every set. If A is a subset of B AND B is a subset of A, then A and B are equal sets. Testing subset relationships is essential in access control systems, data validation, and mathematical proofs. Understanding subset relationships helps predict the results of union and intersection operations.
How do Venn diagrams represent union and intersection visually?
Venn diagrams use overlapping circles to represent sets and their relationships visually. Each circle represents a set, and the overlapping region represents the intersection (elements in both sets). The union is represented by the entire area covered by both circles combined. The non-overlapping parts of each circle represent the set differences (A - B and B - A). The symmetric difference is the total shaded area excluding the overlap. Venn diagrams make abstract set operations intuitive and are particularly helpful for teaching probability, logic, and data analysis concepts. For three sets, the diagram shows seven distinct regions, each representing a unique combination of membership.
Is my data stored or sent to a server?
No. All calculations run entirely in your browser using JavaScript. No data you enter is ever transmitted to any server or stored anywhere. Your inputs remain completely private.
Can I share or bookmark my calculation?
You can bookmark the calculator page in your browser. Many calculators also display a shareable result summary you can copy. The page URL stays the same so returning to it will bring you back to the same tool.