Sets and Set Operations
A set is just a bag of distinct things where order doesn't matter. Combining sets with union, intersection and complement is the same thing as combining statements with "or," "and" and "not," so everything you learned in logic carries straight over.
What the symbols mean
- Union
Everything in A or B (or both).
- Intersection
Everything in both A and B.
- Difference
Everything in A but not in B.
- Complement
Everything in the universe that is not in A.
- Power set
The set of all subsets of A.
Explanation
A set is simply a collection of things, where all you care about is what's in it and what isn't. It's good for describing groups precisely: "the even numbers," "users who watch dramas," "search results matching both keywords." The symbols look foreign, but each is a one-word idea: (everything in or ), (only what's in both), (in but not ), (everything outside ) and (the collection of all possible sub-collections of ). That's the whole toolkit, and you'll find you already know it from logic.
Sets are written with braces, , or by a rule, . Order and repetition don't matter, since a set only records membership: . The cardinality is the number of elements, and is the empty set.
means every element of is in . The power set collects all subsets. Why is its size ? Building a subset means walking through the elements of and deciding, for each one, "in or out." That's two choices per element, so .
Now think back to the logic unit. The operations match it exactly: means , means , and complement is "not." So any law of logic becomes a law about sets for free. De Morgan's laws, for instance, turn into : being outside " or " means being outside and outside .
A common mistake. It's tempting to treat and as the same thing, since both look "empty." They aren't: has no elements, while has one element (which happens to be the empty set). That's also why the empty set counts as one of the subsets in the power set.
The Cartesian product is the set of ordered pairs , and , since each of the first entries pairs with each of the second entries.
See it
Worked examples
Let and . Find , , and .
- 1
Everything in either set gives , and the overlap is .
Practice
Type your answer and check it. Solve them all to complete the lesson.
How many subsets does have?
If and , what is ?
and . What is ?
Which set operation matches the logical "and"?
A streaming service surveyed 200 users: 120 watch dramas, 90 watch comedies and 50 watch both. How many watch neither?
Set identities mirror logic. Which set equals ?
The hardest one here. Get it, and you've got this lesson.
How many subsets of contain at least one even number?
Where it's used
Database queries combine result sets with exactly these operations (SQL's UNION, INTERSECT and EXCEPT), and so do search filters.