MathsDiscrete Math

Set Theory
calculator.

Find the union, intersection, difference and complement of two or three sets.

How it's worked out

A set is a list of distinct elements. Order does not matter, and each element is listed once however often you type it. You can enter numbers, letters or words, with spaces or commas between them, and braces are optional. The number of elements in a set is its cardinality, written |A||A| or n(A)n(A).

Each operation is a rule for which elements make the cut. The union holds elements in the first set, the second set, or both. The intersection holds elements in both. The difference A−BA - B keeps the elements of A that are not in B. The symmetric difference keeps elements in one set but not both. The complement A′A' is everything in the universal set U that is not in A.

A△B\displaystyle A \mathbin{\triangle} B=(A−B)∪(B−A)\displaystyle {}= (A - B) \cup (B - A)
A′\displaystyle A'=U−A\displaystyle {}= U - A

Adding the sizes of two sets counts the shared elements twice, so inclusion-exclusion takes the overlap off once. With three sets, the elements in all three are taken off three times by the pairwise overlaps, so they are added back once.

|A∪B|\displaystyle |A \cup B|=|A|+|B|−|A∩B|\displaystyle {}= |A| + |B| - |A \cap B|
|A∪B∪C|\displaystyle |A \cup B \cup C|=|A|\displaystyle {}= |A|+|B|\displaystyle {}+ |B|+|C|\displaystyle {}+ |C|−|A∩B|\displaystyle {}- |A \cap B|−|A∩C|\displaystyle {}- |A \cap C|−|B∩C|\displaystyle {}- |B \cap C|+|A∩B∩C|\displaystyle {}+ |A \cap B \cap C|

A set with n elements has 2n2^n subsets, because each element is either in a subset or out of it. The set {x, y, z} has 8. The Cartesian product A×BA \times B is every ordered pair with its first entry from A and its second from B, so it has |A|×|B||A| \times |B| pairs.

Worked examples

Priya sorts the numbers 1 to 10 for a probability task

Priya takes U as the whole numbers 1 to 10, A as the even numbers and B as the multiples of 3. The intersection is A∩B=6A \cap B = {6}, the multiples of 6. The union has 7 elements: {2, 3, 4, 6, 8, 9, 10}.

The two differences are not the same. A−B=2,4,8,10A - B = {2, 4, 8, 10}, the evens that are not multiples of 3, while B−A=3,9B - A = {3, 9}. The complement of A is {1, 3, 5, 7, 9}, the odd numbers, which only works because U stops at 10.

For her task, each number is one outcome. The chance of "even and a multiple of 3" is 1 out of 10, and the chance of "even or a multiple of 3" is 7 out of 10.

Open this example in the tool

Jon counts the people in three school clubs

The book club is {Ana, Ben, Cara, Dev, Eli, Fay}, the chess club is {Ben, Cara, Gus, Hal} and the choir is {Cara, Dev, Hal, Ivy}. Adding the three lists gives 6 + 4 + 4 names, but some people belong to more than one club.

|A∪B∪C|\displaystyle |A \cup B \cup C|=6+4+4−2−2−2+1\displaystyle {}= 6 + 4 + 4 - 2 - 2 - 2 + 1=9\displaystyle {}= 9

So 9 different people belong to at least one club. Only Cara is in all three, Ana, Eli and Fay are in the book club alone, and Hal is in chess and choir but not the book club. Leaving U blank makes U the union, so nobody falls outside all three circles.

Open this example in the tool

A café owner reads a tea and coffee survey

Of 40 customers asked, 25 drink tea, 20 drink coffee and 10 drink both. There are no names here, only counts, so the survey counter does the work. Tea or coffee covers 25 + 20 − 10 = 35 people, which leaves 5 who drink neither.

The regions read 15 tea only, 10 coffee only and 10 both. Run it the other way, with 5 in neither and the overlap blank, and the overlap comes back as 10. OpenStax works a party survey the same way in its section on two sets.

Open this example in the tool

Reading your result

The answer depends on U only for complements. Union, intersection and both differences use A, B and C alone. Change U from 1 to 10 into 1 to 12 in the first example and A′A' grows from 5 to 7 elements, while A∩BA \cap B stays {6}.

The region counts and the operation counts are different things. A region holds the elements in exactly one combination of sets, such as A and B but not C. An operation can cover several regions: A∪BA \cup B is A only, B only and the overlap together. The shaded regions show which ones each operation takes.

A proper subset is strictly smaller. When every element of A is in B and B has at least one more, A is a proper subset of B. When the two lists match, the tool reports A = B instead. Two sets with no element in common are disjoint, and then the size of the union is just the two sizes added.

Elements are matched as text. Typing 2 in one set and 2.0 in another gives two different elements, and Ana differs from ana. Use the same spelling in every set.

Common mistakes

  • Treating A − B as B − A. With A = {1, 2, 3} and B = {3, 4}, A−B=1,2A - B = {1, 2} but B−A=4B - A = {4}. Only the symmetric difference is the same both ways.
  • Adding the sizes for a union. In a survey, the people who said yes to both are in both counts. Take the overlap off once, or the total comes out too high.
  • Forgetting the people in no set. A survey total includes everyone asked. The ones outside every circle belong in the box for U, not nowhere.
  • Skipping U before a complement. "Not even" means the odd numbers only when U is the whole numbers you are working with. Write U down first.

Questions people ask

No. A minus B keeps only the part of A that is outside B, so it changes when you swap the sets. The symmetric difference keeps the parts of both sets that are outside the overlap, so it is the same in either order and is empty only when the two sets are equal.

Sources