Sets, relations and functions
Sets, relations and functions are the vocabulary the rest of discrete mathematics is written in. Shade set expressions on a Venn diagram, then test relations for the properties that make them orders, equivalences or functions.
On this page
Sets
A set is a collection of distinct objects, its elements. Order and repetition don’t matter: , and are the same set. We write when is an element of , and describe sets either by listing elements or by a property, as in .
(A is a subset of B) means every element of is also in . Two sets are equal exactly when each is a subset of the other, and proving and separately is the standard way to show . The empty set has no elements and is a subset of every set.
Operations
| Operation | Notation | Elements | With A = {1, 2, 3, 4}, B = {3, 4, 5, 6} |
|---|---|---|---|
| Union | in A or B (or both) | {1, 2, 3, 4, 5, 6} | |
| Intersection | in both | {3, 4} | |
| Difference | in A but not B | {1, 2} | |
| Symmetric difference | in exactly one | {1, 2, 5, 6} | |
| Complement | in the universe U but not A | depends on U |
Each set operation is a logical connective in disguise: means , intersection is “and”, complement is “not”. So the laws of Boolean algebra carry over directly, including De Morgan’s laws:
The diagram below shades any expression you type. Check De Morgan by comparing (A ∪ B)ᶜ with Aᶜ ∩ Bᶜ, or the distributive law by comparing A ∩ (B ∪ C) with (A ∩ B) ∪ (A ∩ C).
Power sets and products
The power set is the set of all subsets of . Each element is either in a subset or not, two choices per element, so a set with elements has subsets. For , .
The Cartesian product is the set of ordered pairs with and . It has elements. Unlike sets, pairs are ordered: .
Relations
A relation from to is any subset . We write for . “Is less than”, “divides”, “is a prerequisite of” and “has the same birthday as” are all relations. A relation on a single set (a subset of ) can be drawn as a directed graph or written as a 0/1 matrix with a 1 in row , column when .
The five properties
| Property | Definition | In the matrix | Example |
|---|---|---|---|
| Reflexive | every | diagonal all 1 | , |
| Irreflexive | no | diagonal all 0 | |
| Symmetric | mirror image across the diagonal | “is a sibling of” | |
| Antisymmetric | no 1 has a mirrored 1 off the diagonal | , “divides” on positive integers | |
| Transitive | no shortcut is ever missing | , “is an ancestor of” |
Antisymmetric is not the opposite of symmetric. Equality is both; the relation on is neither.
Equivalence relations and partitions
A relation that is reflexive, symmetric and transitive is an equivalence relation. It says when two things are “the same for our purposes”: same remainder mod 5, same parity, same connected component of a graph. Every equivalence relation splits its set into disjoint equivalence classes, and every way of splitting a set into disjoint non-empty pieces comes from exactly one equivalence relation. Choose “same parity” in the checker: the classes are the odd and the even numbers.
Partial orders
A relation that is reflexive, antisymmetric and transitive is a partial order. “Partial” because two elements need not be comparable: under “divides”, neither 4 nor 6 divides the other. Partial orders are drawn as Hasse diagrams, which show only the covering steps and leave the reflexive loops and transitive shortcuts implied. They are everywhere in computer science: dependency graphs, version histories, type hierarchies, and the information orderings of domain theory.
Closures
The transitive closure of is the smallest transitive relation containing it: add whenever there is a chain of -steps from to . For the relation “has a direct flight to”, the transitive closure is “can be reached by flying”. Warshall’s algorithm computes it in time; the checker’s button uses it. Reflexive and symmetric closures are simpler: add the diagonal, or add every mirrored pair.
Functions
A function is a relation in which every is related to exactly one , written . is the domain and the codomain. The relation-checker preset passes the function test; “≤” fails it, since 1 is related to four elements.
| Kind | Meaning | Example on the integers |
|---|---|---|
| Injective (one-to-one) | different inputs give different outputs | |
| Surjective (onto) | every element of is hit | |
| Bijective | both: a perfect pairing, so has an inverse |
Bijections are how mathematics compares sizes. Two finite sets have the same number of elements exactly when there is a bijection between them, and the same definition extends to infinite sets. The even numbers and the natural numbers have the same size, because pairs them up; Cantor’s diagonal argument shows there is no bijection between and , so some infinities are bigger than others.
References
- K. H. Rosen, Discrete Mathematics and Its Applications, 8th ed., McGraw-Hill, 2019. Chapters 2 and 9.
- P. R. Halmos, Naive Set Theory, Van Nostrand, 1960.
- S. Warshall, “A theorem on Boolean matrices”, Journal of the ACM 9(1), 1962. doi:10.1145/321105.321107
- “Binary relation”, Wikipedia.