Functions & Relations
Sets are just collections. A relation is a set of "if–then" rules connecting two sets. A function is a relation where each input gets exactly one output. This unit is the language for everything else in the course.
1. Cartesian Product
The Cartesian product of two sets A and B is every possible ordered pair you can build by taking one thing from A and one thing from B.
Let A = {1, 2, 3} and B = {a, b}. Pick from A first, then from B. Write A outside, B inside:
- Order matters. (1, a) and (a, 1) are different pairs. So |A × B| = |B × A| = |A| · |B|, but the sets are not the same unless A = B.
- "Outside × inside." Say it out loud: "|A| outside, |B| inside, answer = multiply."
2. Relations and the Four Special Types
A binary relation from A to B is any subset of A × B. It is simply a list of arrows.
The four special relations you must recognise instantly
| Relation | Definition | Easy way to remember |
|---|---|---|
| Identity | R = {(a,a) : a ∈ A} — every element relates to itself and nothing else | Diagonal lines only |
| Universal | R = A × B — every single possible pair is in R | The whole grid, fully filled |
| Void (empty) | R = ∅ — no pairs at all | An empty grid |
| Binary | Any relation that links exactly two sets A and B (i.e. any subset of A × B) | "Bi" = 2 boxes. It's the umbrella term |
I U V B — Identity (straight lines), Universal (all lines), Void (zero lines), Binary (the family that contains all the others).
3. Reflexive, Symmetric, Transitive
These three words describe properties a relation may or may not have. A relation on a single set A (A to itself) can be checked by looking at the arrows.
symmetric ⇔ ∀a, b ∈ A : (a, b) ∈ R ⇒ (b, a) ∈ R
transitive ⇔ ∀a, b, c ∈ A : (a, b) ∈ R ∧ (b, c) ∈ R ⇒ (a, c) ∈ R
antisymmetric ⇔ ∀a ≠ b : (a, b) ∈ R ⇒ (b, a) ∉ R
- "Reflexive" rhymes with "reflect" — you see yourself. "Symmetric" = "symmetry" — a mirror. "Transitive" = "transit" — you pass through b to get from a to c.
- Loop test for reflexive: count the elements in A. Count the loops in the diagram. Equal numbers? Reflexive. (Faster than checking one by one.)
- Antisymmetric is the opposite of symmetric but weaker: it only forbids a two-way pair. "≤" is antisymmetric; "<" is not symmetric and not antisymmetric.
- Fewer pairs = easier to check. If a relation has 3 or fewer pairs, just write them out. If it has more, look for a pattern.
4. Equivalence Relation & Equivalence Classes
When a relation is an equivalence relation, the set A splits up neatly into groups of elements that are "related to each other". These groups are called equivalence classes, written A/a ("A over a").
Classes are disjoint (no element in two classes) and their union is A (nothing left out). If you draw classes that overlap, your relation was not transitive.
5. Functions: The Special Relation
Types of functions
| Type | What it means | Condition |
|---|---|---|
| One-one / Injective | Different inputs give different outputs | f(x₁)=f(x₂) ⇒ x₁=x₂ |
| Onto / Surjective | Every output is used at least once | Range = codomain |
| Bijective | One-one and onto | Has an inverse function |
| Constant | All outputs equal one fixed value | f(x)=c for all x |
| Identity | Returns the input unchanged | f(x)=x |
Draw a vertical line anywhere on the graph.
- Line hits the curve once everywhere → injective (one-one). This is the "vertical line test".
- Line misses some part of the range → not onto.
- Line hits some values twice → not one-one.
For a finite set: if |A| = |B|, then one-one automatically means onto (bijective). One of the two conditions is free — saves you marks.
6. Functions for Computer Science
Floor and Ceiling
⌈x⌉ = ceiling(x) = smallest integer ≥ x (round up)
Floor = down to the floor. Ceiling = up to the ceiling. The symbols are arrows: ⌊ ⌋ open at the top (stuff can go up = round up), ⌈ ⌉ open at the bottom (stuff falls down = round down). Draw them as a "cup" and a "hat".
For negatives, always test with a small example: ⌊−1.5⌋ = −2 (not −1!) and ⌈−1.5⌉ = −1.
⌊−0.2⌋ = −1 ⌈−0.2⌉ = 0 ⌊−4⌋ = −4
The general trick for negatives: the floor is always ≤ x, the ceiling is always ≥ x. Check your answer against that.
Boolean Function
A Boolean function works on inputs that are only 0 (False) or 1 (True) — the same values used in logic and in every computer's binary arithmetic.
AND needs both (multiplication, so one zero kills it). OR needs one (addition, so one is enough). XOR needs a difference — output 1 exactly when the inputs are different.
Exponential Function
All exponentials pass through (0, 1) because a⁰ = 1. So:
- a > 1 → rises to the right (explosive) → 2ˣ, 3ˣ, eˣ, 10ˣ
- 0 < a < 1 → falls to the right (decays) → ½ˣ, 0.9ˣ
- a = 1 → flat line y = 1 (never used, it is linear not exponential)
Two facts worth memorising: a⁰ = 1, a⁻ⁿ = 1/aⁿ, and the domain/range of aˣ is all real x, and y > 0 always (it never touches 0).
Piecewise Function
A function built from several small formulas, each used on a different part of the input. Like a traffic light: different colour for different times.
{ x², if 0 ≤ x < 3
{ x − 1, if x ≥ 3 }
- Forgetting the open circle at a boundary where the value is excluded.
- Using ≤ in two branches at the same point — only one branch may own a boundary value.
7. Recursion
A recursive definition describes something in terms of a smaller version of itself. It always has two parts: a base case (where it stops) and a recursive step.
Factorial
Method 1 (unwrap):
= 120
Method 2 (unwinding back up):
2! = 2·1 = 2
3! = 3·2 = 6
4! = 4·6 = 24
5! = 5·24 = 120
Fibonacci
Fₙ = Fₙ₋₁ + Fₙ₋₂ for n ≥ 2
= (F₅ + F₄) + F₅
= ((F₄ + F₃) + F₄) + F₅
= (((F₃ + F₂) + F₃) + F₄) + F₅
= (((F₂ + F₁) + F₂) + F₃) + F₄ + F₅
= (((F₁ + F₀) + F₁) + F₂) + F₃ + F₄ + F₅
= ((1 + 0) + 1) + 1 + 2 + 3 + 5 = 13
For any recursion question: write the base case, then write the "smaller" version in a column beside each step until you hit the base case, then compute the column back up. Marks are awarded for the base case even if you make an arithmetic slip.
Note the growth: Fibonacci roughly triples every 2 steps (F ≈ 1.618ⁿ) while factorial is far worse (n! ≈ (n/e)ⁿ). That is why real programs use loops, not naive recursion — but for your exam, recursion is the required method.
8. Solution of a Homogeneous Recurrence
A homogeneous linear recurrence is an equation that only mentions the sequence itself — no extra "forcing" term like 3ⁿ or 5.
The standard method: try an answer of the form aₙ = rⁿ, substitute, solve for r, and use those roots to build the answer.
rⁿ = c₁rⁿ⁻¹ + c₂rⁿ⁻² ÷ divide by rⁿ⁻²: r² = c₁r + c₂
| If the roots are… | General solution | Shape |
|---|---|---|
| Two distinct roots r₁, r₂ | aₙ = A·r₁ⁿ + B·r₂ⁿ | Sum of two exponentials |
| One repeated root r (twice) | aₙ = (A + Bn)·rⁿ | One exponential times a straight line |
| Complex roots r = ρe±iθ | aₙ = ρⁿ(A cos nθ + B sin nθ) | Oscillates, amplitude grows/shrinks by ρⁿ |
Step 1 · characteristic equation. Try aₙ = rⁿ:
Step 2 · factorise.
Two distinct roots, so use the first row: aₙ = A·1ⁿ + B·2ⁿ.
Step 3 · use the initial values to find A and B.
n = 1: a₁ = A + 2B = 4
→ subtract: B = 3, so A = 1 − 3 = −2
Step 4 · write the answer.
- Always check your final answer in the original recurrence. Put your closed form back in and see if a₂, a₃ match. 30 seconds, saves a whole answer.
- Factorial is a homogeneous recurrence in disguise: n! = 1·(n−1)!. Roots: the characteristic equation is r = 1 — a single repeated root, but the exact answer n! is not of the exponential form, so use the definition instead. If a question asks for the "solution of the homogeneous relation" for factorial, they mean the recurrence form.
- Fibonacci is homogeneous too: Fₙ = Fₙ₋₁ + Fₙ₋₂ gives r² = r + 1, roots (1±√5)/2, and the Binet formula. In the exam they usually just want the recursive answer.
- Write the constants as A, B, C… in the order the roots are listed. Mixing up A and B is the most common arithmetic slip.
Self-check
Open to see the answers
1. A = {1,2,3,4}, B = {x, y}. List A × B and give |A × B|.
|A × B| = 4 × 2 = 8 — 4 rows of 2.
2. Is the relation R = {(1,1),(1,2),(2,1)} on A = {1,2} reflexive, symmetric, transitive? Is it an equivalence relation?
Symmetric? (1,2) present and (2,1) present → Yes.
Transitive? (1,1) and (1,2) are in R, so (1,2) must be in R ✓; (1,2) and (2,1) in R so (1,1) ✓; (2,1) and (1,1) in R so (2,1) ✓ → Yes.
Equivalence relation? Needs all three. Reflexive fails → No.
3. Find ⌊−2.5⌋, ⌈−2.5⌉, ⌊7.999⌋.
⌈−2.5⌉ = −2 (smallest integer ≥ −2.5)
⌊7.999⌋ = 7