Cartesian Products
Tuples, ordered pairs, and pairing sets
Tuple
A tuple is a finite, ordered collection of elements. An n-tuple is a tuple of n elements. 2-tuples are also called pairs. 3-tuples are also called triples.
Key point: Order matters in tuples, unlike sets.
Ordered Pair
An ordered pair (a, b) is a pair of objects where the order matters. Two ordered pairs are equal if and only if their corresponding components are equal:
(a, b) = (c, d) if and only if a = c and b = d.
In particular, (a, b) ≠ (b, a) unless a = b.
Cartesian Product
The Cartesian product of sets A and B, written A × B, is the set of all ordered pairs (x, y) where x ∈ A and y ∈ B.
A × B = {(x, y) | x ∈ A and y ∈ B}
A × B is the set of all possible ways that an element x of A can be paired with an element y of B.
A × B = { (x, y) | x ∈ A ∧ y ∈ B }
|A × B| = |A| · |B|
The Cartesian product is not commutative. In general, A × B ≠ B × A. The pairs are ordered, so switching the components produces a different set.
Subset Preservation in Cartesian Products
Empty Set and Cartesian Product
Cartesian Product Distributes over Intersection
(A × B) ∩ (A × C) = A × (B ∩ C)
Some books define A × B × C as ((A × B) × C). Others define it as the set of 3-tuples (a, b, c). Either way, they represent the same information, and there is a natural one-to-one correspondence between ((a, b), c) and (a, b, c). Just be aware of which convention your course uses.
Section Quiz
Test your understanding with 6 questions
Relations
Subsets of Cartesian products that connect elements
Convention: throughout this module, ℕ = {0, 1, 2, ...} (the natural numbers include 0).
Relation
A relation from a set A to a set B is a subset R ⊆ A × B.
If R is a relation from A to B and (x, y) ∈ R, then x is said to be "related to y" by R.
(a) (1, 3)
(b) (3, 1)
(c) (2, 4)
(d) (−3, −5)
Domain of a Relation
The domain of a relation R from A to B is the set of all "first elements" of the pairs in R:
{x ∈ A | there exists y ∈ B such that (x, y) ∈ R}
Range of a Relation
The range of a relation R from A to B is the set of all "second elements" of the pairs in R:
{y ∈ B | there exists x ∈ A such that (x, y) ∈ R}
A relation is not the same thing as a function. A relation has no restriction on how many outputs a single input can have, and not every input needs to have an output. Functions add two extra rules, which we cover in the next section.
Section Quiz
Test your understanding with 6 questions
Functions — Core Definition
Two rules, arrow diagrams, and what counts
Function
A function f from a set A to a set B, written f : A → B, is a relation from A to B satisfying two rules:
Rule 1 — Every input has an output:
For every x ∈ A, there exists y ∈ B such that (x, y) ∈ f.
Rule 2 — Each input maps to exactly one output:
If (x, y) ∈ f and (x, z) ∈ f, then y = z.
In other words, f : A → B maps each and every element of A to exactly one element of B.
If (x, y) ∈ f, where input x ∈ A is mapped to output y ∈ B, then we write f(x) = y.
A function f : A → B is itself a set — specifically a subset of A × B. The pairs in f are points in the plot of f(x). This is why we can talk about function equality using set equality.
Arrow diagrams are a visual way to represent functions: - Left column = elements of A (the domain) - Right column = elements of B (the codomain) - Arrows = mappings from inputs to outputs For a valid function, every element in the left column must have exactly one arrow going out.
Is f = {(1, 1), (2, 4), (3, 9), (4, 16)} a function from A to B?
Is f = {(1, 1), (4, 16)} a function from A to B?
Is f = {(4, 16), (1, 16)} a function from A to B?
Is f = {(1, 1), (4, 16)} a function from A to B?
Is f = {(1, 16), (1, 1), (4, 16)} a function from A to B?
Common mistakes when checking if something is a function:
1. Forgetting to check EVERY input — if even one element of A has no output, it is not a function.
2. Thinking two inputs can't share the same output — they can! Only two outputs from the same input is a problem.
3. Thinking every element of B must be "used" — that is not required for a function (though it is required for a surjection, which we cover later).
Codomain
The codomain of a function f : A → B is the set B. It is the set of "possible outputs" — the set that the function is declared to map into.
Important: A function's range (actual outputs) need not equal its codomain (possible outputs). The range is always a subset of the codomain, but they may not be equal.
Function Equality Preserves Domain
In other words, equal functions must have the same domain.
Function Equality Does Not Require Equal Codomains
In other words, two functions can be equal (same set of pairs) even if they are declared with different codomains.
Two functions are equal if they have the same domain and give the same output for every input. The codomain is part of the declaration but not part of the set of pairs, so it does not affect equality.
In this course, we treat a function mainly by its domain and input→output rule (equivalently, its graph). That is why two functions can count as 'the same' if they agree on every input, even if a textbook lists different codomains.
Section Quiz
Test your understanding with 6 questions
Injections (One-to-One)
Distinct inputs always produce distinct outputs
Injection (One-to-One Function)
A function f : A → B is an injection (also called injective or one-to-one) if and only if:
((x, y) ∈ f and (z, y) ∈ f) implies x = z
Equivalently: f(a) = f(b) implies a = b.
In other words, an injection never maps two different inputs to the same output. Every output comes from at most one input.
Visual intuition: In an arrow diagram, no element in B has more than one arrow pointing to it. Each element of B receives at most one arrow.
∀a, b ∈ A: f(a) = f(b) → a = b
Is f = {(1, 1), (4, 16)} injective?
Is f = {(1, 16), (4, 16)} injective?
To prove a function is injective, you can use the contrapositive: a ≠ b implies f(a) ≠ f(b). Sometimes this direction is easier to work with. Both statements say the same thing.
Common mistake: thinking "injective" means every element of B is used. That is surjectivity, not injectivity. Injective is about inputs being distinguishable from their outputs. Elements of B that are not "hit" are perfectly fine for an injection.
Section Quiz
Test your understanding with 6 questions
Surjections (Onto)
Every element of the codomain is actually reached
Surjection (Onto Function)
A function f : A → B is a surjection (also called surjective or onto) if and only if:
For every y ∈ B, there exists x ∈ A such that (x, y) ∈ f.
In other words, a surjection maps every element of the codomain from at least one input. The range equals the codomain.
∀y ∈ B(∃x ∈ A((x, y) ∈ f))
Visual intuition: In an arrow diagram, every element in B has at least one arrow pointing to it. No element of B is "left out."
Is f = {(2, 4), (1, 4), (4, 9), (3, 9)} surjective?
Is f = {(2, 4), (1, 4), (4, 4), (3, 4)} surjective?
A function is surjective if and only if its range equals its codomain. Equivalently: range(f) = B.
Common mistake: confusing surjective with injective.
Injective = no two inputs share an output (look at B: at most one arrow into each element).
Surjective = every output is used (look at B: at least one arrow into each element).
A function can be one without the other, both, or neither.
Section Quiz
Test your understanding with 6 questions
Bijections
The perfect pairing: injective and surjective
Bijection
A function f : A → B is a bijection (also called bijective) if and only if it is both an injection and a surjection.
In other words, a bijection maps:
- Each and every input to exactly one unique output
- Each and every output from exactly one unique input
This creates a perfect one-to-one correspondence between A and B.
Is f = {(1, 1), (2, 4), (3, 9), (4, 16)} bijective?
Is f = {(1, 1), (2, 4), (3, 16), (4, 16)} bijective?
(a) f(x) = x²
(b) f(x) = 2x
(c) f(x) = x³ − x
(d) f(x) = x (the identity function)
Note on f(x) = 2x: Over ℝ → ℝ this is a bijection because for every real y, there is a real x = y/2. However, if we consider f : ℤ → ℤ instead, then f(x) = 2x is injective but not surjective (for example, 1 has no integer preimage under doubling). The choice of domain and codomain matters!
Section Quiz
Test your understanding with 6 questions
Real-World Interpretations
What injection and surjection mean in everyday terms
Let A = the set of teachers at a school, B = the set of offices in that school, and f : A → B maps each teacher to their assigned office.
(b) What does it mean if f is a surjection?
This is a great way to remember the difference:
Injection → "no sharing" (each office has at most 1 teacher)
Surjection → "no empties" (each office has at least 1 teacher)
Bijection → "no sharing and no empties" (each office has exactly 1 teacher)
Finding the right codomain or domain Sometimes a function is not bijective because the codomain or domain is "too big." By restricting the codomain or domain, we can turn a non-bijection into a bijection.
This is a common exam technique: if a function fails to be bijective, the question may ask you to adjust the domain or codomain to make it work. The key is to:
1. Identify whether the problem is with injectivity (domain too big) or surjectivity (codomain too big).
2. Restrict the appropriate set to match the function's actual behavior.
Section Quiz
Test your understanding with 6 questions
Inverse Functions
Reversing the arrows — but only for bijections
Inverse Function
The inverse of a bijection f : A → B, written f⁻¹ : B → A, is a bijection such that:
(x, y) ∈ f if and only if (y, x) ∈ f⁻¹
An inverse function maps outputs back to their original inputs. If f sends x to y, then f⁻¹ sends y back to x.
Key requirement: Only bijections have inverse functions.
If f is not a bijection, then f⁻¹ is not a function.
- If f is not injective: some output y came from two different inputs. Then f⁻¹(y) would need to produce two values, violating Rule 2.
- If f is not surjective: some element y ∈ B was never reached. Then f⁻¹(y) has no value, violating Rule 1.
Common mistake: writing f⁻¹ for a function that is not a bijection. Always check that f is both injective and surjective before claiming f⁻¹ exists as a function.
Also note: f⁻¹ is NOT the same as 1/f(x). The notation f⁻¹ means the inverse function, not the reciprocal.
Section Quiz
Test your understanding with 6 questions
Function Composition
Chaining functions together: apply g first, then f
Composition of Functions
The composition of functions f : B → C and g : A → B, written f ∘ g : A → C, is a function such that:
(x, z) ∈ (f ∘ g) ⇔ ∃y [ (x, y) ∈ g ∧ (y, z) ∈ f ].
Meaning: first g sends x to some y, then f sends that y to z.
In other words: (f ∘ g)(x) = f(g(x))
A composition uses the outputs from one function as the inputs to another.
(f ∘ g)(x) = f(g(x))
Important notes about composition:
1. The order matters: f ∘ g means "apply g first, then f." Read it right-to-left.
2. f ∘ g is only defined when the range of g is compatible with the domain of f. Specifically, g maps into B, and f takes inputs from B.
3. f ∘ g may exist even when g ∘ f does not.
Common mistake: reading f ∘ g as "f then g." It is the opposite! f ∘ g means g first, then f. The function closest to x in f(g(x)) is applied first.
Composition Preserves Injectivity
Composition Preserves Surjectivity
Composition Preserves Bijectivity
The bijectivity theorem follows directly from the other two: if both components are injective (so the composition is injective) and both are surjective (so the composition is surjective), then the composition is bijective.
The result (f ∘ g)⁻¹ = g⁻¹ ∘ f⁻¹ is sometimes called the "socks and shoes" rule. To undo putting on socks then shoes, you take off shoes first, then socks. The order reverses!
Section Quiz
Test your understanding with 6 questions
Cardinality & Functions
Using bijections to compare set sizes — even infinite ones
Cardinality
A set A has cardinality |A| = n if it contains exactly n distinct elements.
(a) {1, 5, 8, 9}
(b) {red, blue, red, blue, blue}
Equal Cardinality
Two sets A and B have equal cardinality (|A| = |B|) if and only if there exists a bijection between A and B.
This definition works for both finite and infinite sets. For finite sets, it just means they have the same number of elements. For infinite sets, it gives us a way to compare "sizes" that goes beyond counting.
Injection and Cardinality
If you can match every element of A to a unique element of B (with possibly some elements of B left over), then A is no bigger than B.
Infinite Set
If there is an injection from ℕ into A, then A must be infinite. In other words, |ℕ| ≤ |A| guarantees that A is infinite.
In the standard foundations used in this course, the converse is also true, so we treat this as an 'if and only if.'
Intuitively, this means you can keep picking new elements from A forever without running out.
Countable Set
A set is countable if and only if there exists an injection from A to ℕ. In other words, |A| ≤ |ℕ|.
A countable set is one whose elements can be listed in a sequence (possibly infinite). You could "count off" the elements one by one.
Countably Infinite Set
A set A is countably infinite (|A| = ℵ₀) if and only if there exists a bijection between A and ℕ.
Countably infinite means "the same size as ℕ" — infinite, but not "more" infinite than the natural numbers.
Cantor-Schröder-Bernstein Theorem
In other words: |A| ≤ |B| and |B| ≤ |A| implies |A| = |B|.
This is a powerful tool for proving two sets have the same cardinality — you just need to find an injection in each direction, rather than constructing a bijection directly.
The Cantor-Schröder-Bernstein theorem is especially useful for infinite sets, where constructing an explicit bijection can be very difficult. Finding two injections (one in each direction) is often much easier.
ℤ⁻ is Countably Infinite
ℤ is Countably Infinite
Union of Countably Infinite Sets
ℚ is Countably Infinite
ℝ is Uncountably Infinite
This is proved by Cantor's famous diagonalization argument.
Summary of cardinality results:
Countably infinite (same size as ℕ): ℕ, ℤ⁻, ℤ, ℚ
Uncountably infinite (strictly bigger than ℕ): ℝ
The key idea: |ℕ| = |ℤ| = |ℚ| < |ℝ|.
It seems surprising that ℤ and ℚ are the "same size" as ℕ, but this is what the formal definition via bijections gives us.
Common mistake: assuming that because ℤ or ℚ "looks bigger" than ℕ, it must have a larger cardinality. Cardinality is about the existence of bijections, not about how the sets "look." As long as you can pair up all the elements one-to-one, the sets have the same cardinality.
Section Quiz
Test your understanding with 6 questions
Practice Problems
Mixed exam-style problems covering all topics
These problems cover all topics from the previous sections. Try each one on paper before checking the solution! Working through these will prepare you for exam-style questions.
(a) A × B
(b) |A × B|
(c) Is A × B = B × A?
(a) {(1, a), (2, b), (3, a)}
(b) {(1, a), (2, b)}
(c) {(1, a), (2, a), (3, b), (1, b)}
(a) Show f is a bijection.
(b) Find f⁻¹.
(a) (f ∘ g)(x)
(b) (g ∘ f)(x)
(c) Are f ∘ g and g ∘ f equal?
Hint: Start with the assumption that the composition gives equal outputs, and work inward: use f's injectivity first, then g's.
(a) |ℕ| = |ℤ|
(b) |ℕ| = |ℝ|
(c) |ℚ| = |ℕ|
(d) If |A| ≤ |B| and |B| ≤ |A|, then |A| = |B|.
(a) Is f injective?
(b) Is f surjective?
(c) What is the range of f?
(d) Does f⁻¹ exist?
(a) Why is f : ℝ → ℝ not a bijection?
(b) Find sets A and B such that f : A → B is a bijection.
Exam tips for functions:
1. Always state which rule is violated when something is not a function (Rule 1 or Rule 2).
2. To disprove a statement, one counterexample is enough.
3. To prove injectivity, start with "Assume f(a) = f(b)" and show a = b.
4. To prove surjectivity, start with "Let y ∈ B" and find an x ∈ A with f(x) = y.
5. For composition, always check domain/range compatibility before computing.
6. Remember: f⁻¹ only exists when f is a bijection.
7. Check the domain carefully — a formula might look problematic but be safe on the given domain (like (x² − 2)⁻¹ on ℤ).