Relations and Functions
What You’ll Learn
Section titled “What You’ll Learn”In this lesson you’ll learn what a relation is, the properties that classify relations (reflexive, symmetric, antisymmetric, transitive), what makes an equivalence relation and a partial order, and how functions are classified as injective, surjective, or bijective.
The Concept
Section titled “The Concept”Relations
Section titled “Relations”A relation from set to set is any subset of the Cartesian product . A relation on is a subset of .
That’s a very loose definition, and deliberately so. A relation is just a set of ordered pairs. If we write and say ” is related to .”
Examples of relations on the integers: “is less than,” “is equal to,” “divides,” “has the same remainder mod 5 as.” Examples elsewhere: “is a friend of,” “is a prerequisite for,” “is a subset of.”
You can picture a relation on as a directed graph where vertices are elements of and an arrow goes from to whenever . That picture makes the properties below easy to see.
The four key properties
Section titled “The four key properties”Let be a relation on a set .
- Reflexive - every element relates to itself: . “Equals” is reflexive. “Is less than” is not, since is false. In the digraph picture, every vertex has a self-loop.
- Symmetric - the relation always works both ways: . “Is a sibling of” is symmetric. “Is the parent of” is not. In the digraph, every arrow has a matching reverse arrow.
- Antisymmetric - it never works both ways for distinct elements: . “Less than or equal to” qualifies, since and force .
- Transitive - chains collapse: . “Is less than” is transitive, and so is “divides” (we proved that in the direct proof lesson). “Is a friend of” usually is not.
One warning on the third one: antisymmetric is not the negation of symmetric. A relation can be both (equality) or neither.
Drawn as arrows, each property becomes a shape you can check at a glance:
Equivalence relations
Section titled “Equivalence relations”A relation that is reflexive, symmetric, and transitive is an equivalence relation.
Equivalence relations formalize the idea of “the same in some respect.” Equality is the strictest example, but there are many looser ones:
- “Has the same birthday as” on a set of people.
- “Is congruent mod ” on the integers.
- “Has the same length as” on a set of strings.
The big structural result: an equivalence relation on partitions into disjoint equivalence classes. The class of , written , is everything related to . Every element belongs to exactly one class, and the classes cover completely.
That’s a two-way street. Every equivalence relation gives you a partition, and every partition gives you an equivalence relation. They are the same idea in two languages.
Congruence mod 3 on the integers, for example, splits into exactly three classes:
Three classes, no overlap, covering everything.
Partial orders
Section titled “Partial orders”A relation that is reflexive, antisymmetric, and transitive is a partial order.
Partial orders formalize “comes before” or “is at most.” Examples: on numbers, on sets, “divides” on positive integers, and task dependency in a project.
The word partial matters. Some pairs may be incomparable. Under , the sets and are incomparable, since neither contains the other. If every pair is comparable, the order is total (or linear), which is what on the reals gives you.
Task scheduling is the practical case: some tasks must come before others, and unrelated tasks can happen in either order. A topological sort produces a valid total ordering consistent with the partial order, which is exactly what a build system computes.
Functions
Section titled “Functions”A function is a relation where every element of is paired with exactly one element of .
is the domain, is the codomain, and the range (or image) is the set of values actually produced. The range is a subset of the codomain, possibly a proper one.
So a function is a special relation with two extra rules: nothing in the domain is left out, and nothing in the domain maps to two places.
Injective, surjective, bijective
Section titled “Injective, surjective, bijective”- Injective (one-to-one) - distinct inputs give distinct outputs, so . Nothing in gets hit twice.
- Surjective (onto) - every element of the codomain is hit: there is some with . The range equals the codomain, so nothing in is missed.
- Bijective - both injective and surjective. A perfect pairing, every element of matched to exactly one element of and vice versa.
Only bijections have inverse functions. If isn’t injective the inverse would be ambiguous; if it isn’t surjective the inverse would be undefined somewhere.
Cardinality connections
Section titled “Cardinality connections”For finite sets, these give you counting facts immediately:
- An injection requires .
- A surjection requires .
- A bijection requires .
The first one is the pigeonhole principle stated in function language: if , no injection exists, so two inputs must collide.
Bijections are also how mathematicians compare infinite sets. Two sets have the same cardinality if a bijection exists between them, which leads to the strange and true fact that there are exactly as many even integers as integers, since is a bijection.
Worked Examples
Section titled “Worked Examples”Example 1: Classify a relation.
Let on be . Which properties does it have?
Solution.
- Reflexive? Need . All present. Yes.
- Symmetric? is present and so is . The self-loops are their own reverses. Yes.
- Antisymmetric? and both present but . No.
- Transitive? Check the chains. and give , present. and give , present. Yes.
Reflexive, symmetric, transitive, so this is an equivalence relation. Its classes are and .
Example 2: “Divides” on positive integers.
Classify the relation .
Solution.
- Reflexive? since . Yes.
- Symmetric? but . No.
- Antisymmetric? If and with both positive, then . Yes.
- Transitive? Proved earlier: and give . Yes.
Reflexive, antisymmetric, transitive, so divides is a partial order on the positive integers. It’s partial and not total, because 4 and 6 are incomparable: neither divides the other.
Example 3: Congruence mod .
Show that "" is an equivalence relation on .
Solution. Recall means .
Reflexive: and . Yes.
Symmetric: If then , so , and . Yes.
Transitive: If and , then
so . Yes.
All three hold, so it’s an equivalence relation, and it partitions into the 5 classes . ∎
Example 4: Classify functions.
For each function, decide whether it’s injective, surjective, or bijective.
(a) , (b) , (c) , (d) ,
Solution.
(a) Bijective. Injective: forces . Surjective: for any , take . The inverse is .
(b) Neither. Not injective, since . Not surjective, since no real squares to .
(c) Injective, not surjective. forces . But 3 is never an output, since outputs are all even. Interesting note: this is an injection from to that isn’t a bijection, which can only happen with infinite sets.
(d) Surjective, not injective. Every non-negative real is a square, so it’s onto. But , so not one-to-one. Changing the codomain changed the classification without changing the formula, which is why the codomain is part of the function’s definition.
Example 5: Counting functions.
Let and .
(a) How many functions ? (b) How many injective functions ? (c) How many bijective functions ?
Solution.
(a) Each of the 3 elements independently picks one of 5 targets:
(b) Injective means no reuse, so it’s an ordered selection:
(c) A bijection requires . Since , there are 0.
Example 6: Partial order and topological sort.
Tasks with dependencies: before , before , before , before .
Find a valid execution order.
Solution. Repeatedly take any task with no unmet dependencies.
- and have none. Take , then .
- now has both dependencies met. Take .
- and are both free. Take , then .
Order: .
Another valid order: . The partial order allows multiple total orderings, precisely because and are incomparable, and so are and .
Real-World Applications
Section titled “Real-World Applications”Relational databases are named for relations in exactly this sense. A table is a relation, a row is a tuple, and a foreign key encodes a relation between two tables. Query optimizers reason about transitivity to infer constraints you never wrote down.
Equivalence relations power deduplication and caching. “Same content hash” is an equivalence relation, and grouping files by their class is how backup systems avoid storing the same photo forty times. Unicode normalization, case-insensitive comparison, and canonical URL forms all define equivalence classes and pick one representative from each.
Partial orders drive build systems and package managers. make, npm, cargo, and CI pipelines all take a dependency graph, verify it’s acyclic, and topologically sort it. When a package manager reports a circular dependency, it failed to find a topological sort, which is a direct consequence of the antisymmetry requirement being violated.
Injective functions are the requirement behind primary keys and unique constraints. A database index is useful precisely because the mapping from key to row is injective. Hash functions try to be injective and fail by the pigeonhole principle, which is why collision handling exists.
Bijections are the mathematical content of encoding and encryption. Base64, character encodings, and every cipher must be bijective, because a non-injective encoding cannot be decoded and a non-surjective one wastes representable space.
Version control, access control hierarchies, taxonomies, and course prerequisite systems all model partial orders.
Retrying will remove your ✅ checkmark until you pass again.