Find a course

Module 3: Sets, Functions and RelationsLesson 7 of 1215 min

Functions and Relations

Classify functions as injective, surjective or bijective, compose and invert them, and test relations for the properties that define equivalence relations.

Step 1 of 12Learn

Functions: one output per input

Every student at a university gets exactly one ID number. That assignment is a function: a rule f from a set A (the domain) to a set B (the codomain) that assigns exactly one element of B to each element of A. We write f: A → B and f(a) = b.

The range (or image) is the set of outputs actually used, which may be smaller than the codomain. If f: ℤ → ℤ is f(n) = 2n, the codomain is ℤ but the range is the even integers.

Something is not a function if some input has no output or more than one. "Each person maps to their phone number" fails if someone has two phones or none.

Three properties describe how a function uses its codomain:

  • Injective (one-to-one): different inputs always give different outputs. If f(a₁) = f(a₂), then a₁ = a₂. Student IDs are injective: no two students share one.
  • Surjective (onto): every element of the codomain is hit by some input. The range equals the codomain.
  • Bijective: both injective and surjective. Every element of B is matched with exactly one element of A, a perfect pairing.

Examples on ℤ → ℤ:

  • f(n) = n + 3 is bijective: you can always undo it with n − 3.
  • f(n) = 2n is injective but not surjective: 3 is never an output.
  • f(n) = n² is neither: f(2) = f(−2), and negative numbers are never outputs.

The same formula can change category with a different domain or codomain. n² from ℕ to ℕ is injective.

Step 2 of 12Practice · Sort into groups

Classify each function.

Tap an item, then tap its group (or drag it there).

Step 3 of 12Flashcards

Kinds of functions

Tap a card to flip it.

Step 4 of 12Learn

Composition, inverses and counting

Composition. If f: A → B and g: B → C, then g ∘ f: A → C is defined by (g ∘ f)(x) = g(f(x)): apply f first, then g. With f(x) = x + 1 and g(x) = 2x, (g ∘ f)(3) = g(4) = 8, but (f ∘ g)(3) = f(6) = 7. Like matrix multiplication, composition is not commutative.

Inverses. A function f: A → B has an inverse f⁻¹: B → A, undoing it, exactly when f is a bijection. If f isn't injective, some output came from two inputs and you can't decide which to return. If it isn't surjective, some element of B has nothing to return. For f(x) = 3x + 2 on ℝ, solving y = 3x + 2 gives f⁻¹(y) = (y − 2)/3.

Counting functions. For finite sets with |A| = m and |B| = n:

  • The number of functions from A to B is nᵐ: each of the m inputs independently picks one of n outputs.
  • An injection from A to B can exist only if m ≤ n.
  • A surjection can exist only if m ≥ n.
  • A bijection can exist only if m = n, and then there are n! of them.

Those size conditions explain an important idea: two finite sets have the same size exactly when there's a bijection between them. Counting is really building a bijection with {1, 2, …, n}. Mathematicians extended this definition to infinite sets and found the surprise that ℕ and ℤ have the same size, while ℝ is strictly larger.

Step 5 of 12Diagram

Composition (g ∘ f)(3): apply f first

Composition (g ∘ f)(3): apply f firstProcess diagram: x = 3 → f(x) = x + 1 → g(x) = 2x → (g ∘ f)(3) = 8.x = 3f(x) = x + 1g(x) = 2x(g ∘ f)(3) = 8

Tap a shape with to see more.

x = 3
f(x) = x + 1

f(3) = 4.

g(x) = 2x

g(4) = 8.

(g ∘ f)(3) = 8

In the other order, (f ∘ g)(3) = f(6) = 7. Composition is not commutative.

Step 6 of 12Practice · Work it out

How many functions are there from a set with 3 elements to a set with 5 elements?

Step 7 of 12Learn

Relations and their properties

A function is a special case of a more general idea. A relation R on a set A is any set of ordered pairs from A × A; we write a R b when (a, b) is in it. "Is less than," "divides," "is a friend of," "has the same birthday as" are all relations.

Relations are classified by four properties:

  • Reflexive: a R a for every a. ("Same birthday as" is reflexive; "less than" is not.)
  • Symmetric: if a R b then b R a. ("Is a sibling of" is symmetric; "divides" is not: 2 divides 4 but 4 doesn't divide 2.)
  • Antisymmetric: if a R b and b R a then a = b. ("≤" and "divides" on positive integers are antisymmetric.)
  • Transitive: if a R b and b R c then a R c. ("Less than" is transitive; "is a friend of" usually isn't.)

An equivalence relation is reflexive, symmetric and transitive. It captures "is the same as, in some respect." Every equivalence relation splits the set into disjoint equivalence classes, groups of elements that are all related to each other.

Example. On ℤ, let a R b mean "a − b is divisible by 3." It's reflexive (a − a = 0), symmetric (if 3 divides a − b, it divides b − a) and transitive (add the two differences). It splits ℤ into three classes: remainders 0, 1 and 2. This relation is the foundation of modular arithmetic in Module 5.

A relation that's reflexive, antisymmetric and transitive is a partial order, like ≤ on numbers, ⊆ on sets, or "must be done before" for tasks in a project schedule.

Step 8 of 12Practice · Diagram

Equivalence classes mod 3

An equivalence relation splits a set into non-overlapping classes. "Same remainder mod 3" gives three.

Which class does 14 belong to?

Tap the shape that answers the question, then press Check.

Equivalence classes mod 3Hierarchy diagram: All integers, [0]: …, −3, 0, 3, 6, …, [1]: …, −2, 1, 4, 7, …, [2]: …, −1, 2, 5, 8, ….All integers[0]: …, −3, 0, 3, 6, …[1]: …, −2, 1, 4, 7, …[2]: …, −1, 2, 5, 8, …
All integers
[0]: …, −3, 0, 3, 6, …
[1]: …, −2, 1, 4, 7, …
[2]: …, −1, 2, 5, 8, …

Step 9 of 12Practice · Select all that apply

On the set of all people, consider the relation "x is at least as tall as y." Which properties does it have? Select all that apply.

Select all that apply.

Step 10 of 12Compare

Equivalence relations vs. partial orders

AspectEquivalence relationPartial order
PropertiesReflexive, symmetric, transitiveReflexive, antisymmetric, transitive
Captures"Is the same as" in some respect"Comes before or equals"
StructureSplits the set into disjoint classesArranges elements in a hierarchy (some may be incomparable)
ExamplesSame remainder mod n; same birthday; similar triangles≤ on numbers; ⊆ on sets; divides on positive integers
In computingHashing groups keys into bucketsTask scheduling and dependency resolution

Step 11 of 12Practice · True or false

A function f: A → B has an inverse function only if f is both injective and surjective.

Step 12 of 12Practice · Choose one

The relation "a and b have the same remainder when divided by 5" on the integers has how many equivalence classes?