MODULE 03

Set Theory Calculator: Union, Intersection & Power Sets

Enter two sets, e.g. {1,2,3} and {2,3,4}. Universal set is optional.

What is Set Theory?

Set theory studies collections of distinct objects (sets) and the operations — union, intersection, difference, complement — that combine or compare them. It underlies nearly all of discrete mathematics.

How Does This Calculator Work?

Enter Set A and Set B using curly-brace notation like {1,2,3}, plus an optional universal set for complements. Click compute to instantly see union, intersection, difference, complement, subset check, and Cartesian product, each with element-by-element reasoning.

Common Formulas & Rules

  • Union (A ∪ B): every element that belongs to A, to B, or to both.
  • Intersection (A ∩ B): only the elements that belong to both A and B.
  • Difference (A - B): elements in A that are not in B.
  • Complement (Ā): elements of the universal set U that are not in A.
  • Subset (A ⊆ B): every element of A is also an element of B.
  • Cartesian Product (A × B): the set of all ordered pairs (a, b) with a in A and b in B.

Worked Example

Let A = {1,2,3,4} and B = {3,4,5,6}. Then A ∪ B = {1,2,3,4,5,6} (combine everything, no duplicates), A ∩ B = {3,4} (only what's shared), and A - B = {1,2} (what's in A but disappears once we remove B's elements). Notice |A × B| = |A| × |B| = 16, one pair for every combination of an A-element with a B-element.

Study guide: Set Theory

Written for students learning this topic for the first time. Last updated October 2026.

Overview

A set is a collection of distinct objects where order and repetition do not matter: {1, 2, 2, 3} is the same set as {3, 2, 1}. Sets are the common language of discrete mathematics. Relations, functions, probability events and database tables are all built from them.

Set theory also teaches precision. A complement means nothing until a universal set is fixed, and “element of” and “subset of” are different relationships that are easy to confuse.

Key ideas explained

The basic operations

Union A ∪ B collects everything in either set. Intersection A ∩ B keeps what is in both. Difference A − B keeps what is in A but not B. Symmetric difference A ⊕ B keeps what is in exactly one of them. The complement A′ is everything in the universal set U that is not in A, and A − B = A ∩ B′.

Subsets and the power set

A ⊆ B means every element of A is in B. The power set P(A) is the set of all subsets of A, including ∅ and A itself, and it has 2^|A| members.

Cartesian products

A × B is the set of ordered pairs (a, b) with a in A and b in B, so |A × B| = |A|·|B|. Order matters: (1, 2) ≠ (2, 1), and A × B is generally different from B × A.

Inclusion–exclusion

|A ∪ B| = |A| + |B| − |A ∩ B|, because adding the sizes counts the overlap twice. For three sets: |A ∪ B ∪ C| = |A| + |B| + |C| − |A ∩ B| − |A ∩ C| − |B ∩ C| + |A ∩ B ∩ C|.

Worked examples

All the basic operations on two sets

Problem. Let U = {1,…,8}, A = {1,2,3,4,5} and B = {4,5,6,7}. Find A ∪ B, A ∩ B, A − B, B − A, A ⊕ B and A′.

  1. Union: everything in either set gives {1,2,3,4,5,6,7}.
  2. Intersection: the shared elements are {4,5}.
  3. A − B = {1,2,3} and B − A = {6,7}.
  4. Symmetric difference: A − B together with B − A gives {1,2,3,6,7}.
  5. Complement of A in U is {6,7,8}.
  6. Check: |A ∪ B| = 5 + 4 − 2 = 7.

Answer. A ∪ B = {1,…,7}, A ∩ B = {4,5}, A − B = {1,2,3}, B − A = {6,7}, A ⊕ B = {1,2,3,6,7}, A′ = {6,7,8}.

Listing a power set

Problem. Find P({a, b, c}).

  1. The set has 3 elements, so expect 2³ = 8 subsets.
  2. By size: one empty set; three singletons; three pairs; one full set (1 + 3 + 3 + 1 = 8).

Answer. ∅, {a}, {b}, {c}, {a,b}, {a,c}, {b,c}, {a,b,c}.

Enter these same values in the calculator above and compare each step with the working shown here.

Common mistakes to avoid

  • Confusing ∈ with ⊆: 2 ∈ {1,2,3} and {2} ⊆ {1,2,3}, but {2} ∈ {1,2,3} is false.
  • Leaving ∅ or the set itself out of the power set.
  • Taking a complement without a universal set.
  • Counting duplicates: {1, 1, 2} has two elements, not three.
  • Assuming A × B = B × A.

Where this shows up in computer science

  • SQL's UNION, INTERSECT and EXCEPT operate on result sets, and a cross join is a Cartesian product.
  • In probability, events are subsets of a sample space, and P(A ∪ B) = P(A) + P(B) − P(A ∩ B) is inclusion–exclusion.
  • Programming: Python's set, permission flags and de-duplication all rely on set operations.

Test yourself

Try each question before opening the answer.

If |A| = 6, |B| = 4 and |A ∩ B| = 2, what is |A ∪ B|?

6 + 4 − 2 = 8.

How many subsets, and how many proper subsets, does a 7-element set have?

2⁷ = 128 subsets and 127 proper subsets (all except the set itself).

Is {∅} equal to ∅?

No. ∅ has no elements, while {∅} has exactly one element, namely the empty set.

Frequently asked questions

What's the difference between A - B and B - A?

A - B keeps elements that are in A but not in B. B - A keeps elements that are in B but not in A. These are generally different sets unless A and B are identical.

What's the difference between union and intersection?

Union (A ∪ B) combines every element from both sets, no duplicates. Intersection (A ∩ B) keeps only elements present in both sets simultaneously. Union is always at least as large as either individual set; intersection is never larger than the smaller set.

How many elements does a power set have?

The power set of a set with n elements has exactly 2ⁿ elements (subsets), including the empty set and the set itself.