×

Cartesian Products

Tuples, ordered pairs, and pairing sets

Definition

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.

Example
Give examples of tuples and explain why order matters.
Definition(a, b)

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.

DefinitionA × 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.

Formal definition of Cartesian product

A × B = { (x, y) | x ∈ A ∧ y ∈ B }

Cardinality of the Cartesian product

|A × B| = |A| · |B|

Warning

The Cartesian product is not commutative. In general, A × B ≠ B × A. The pairs are ordered, so switching the components produces a different set.

Example
Let A = {1, 2, 3} and B = {a, b}. Find A × B and B × A.
Theorem

Subset Preservation in Cartesian Products

Let A, B, C, and D be sets. If A ⊆ C and B ⊆ D, then A × B ⊆ C × D.
Theorem

Empty Set and Cartesian Product

Let A be a set. Then ∅ × A = ∅.
Theorem

Cartesian Product Distributes over Intersection

Let A, B, and C be sets. Then:

(A × B) ∩ (A × C) = A × (B ∩ C)
Warning

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

R

Relations

Subsets of Cartesian products that connect elements

💡Tip

Convention: throughout this module, ℕ = {0, 1, 2, ...} (the natural numbers include 0).

DefinitionR ⊆ A × B

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.

Example
Let R be the relation {(x, y) ∈ ℕ × ℕ | y = 2x + 1}. Determine which of the following are in R:
(a) (1, 3)
(b) (3, 1)
(c) (2, 4)
(d) (−3, −5)
Definitiondom(R)

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}

Definitionrange(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}

Example
For R = {(x, y) ∈ ℕ × ℕ | y = 2x + 1}, find the domain and range.
Note

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

f

Functions — Core Definition

Two rules, arrow diagrams, and what counts

Definitionf : A → B

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.

Note

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.

Example
Example 1: Let A = {2, 1, 4, 3} and B = {1, 9, 16, 4}.
Is f = {(1, 1), (2, 4), (3, 9), (4, 16)} a function from A to B?
Example
Example 2: Let A = {1, 4} and B = {1, 9, 16, 4}.
Is f = {(1, 1), (4, 16)} a function from A to B?
Example
Example 3: Let A = {1, 4} and B = {1, 9, 16, 4}.
Is f = {(4, 16), (1, 16)} a function from A to B?
Example
Example 4: Let A = {2, 1, 4, 3} and B = {1, 9, 16, 4}.
Is f = {(1, 1), (4, 16)} a function from A to B?
Example
Example 5: Let A = {1, 4} and B = {1, 9, 16, 4}.
Is f = {(1, 16), (1, 1), (4, 16)} a function from A to B?
Warning

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).

Example
Let f : ℕ → ℕ be defined by f(x) = 2x + 1. Express f as a set of ordered pairs and list a few points.
DefinitionB in f : A → B

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.

Example
Let f : ℕ → ℕ be f(x) = 2x + 1. What are the codomain and range?
Theorem

Function Equality Preserves Domain

Let f : A → B and g : C → D be functions. If f = g, then A = C.

In other words, equal functions must have the same domain.
Theorem

Function Equality Does Not Require Equal Codomains

There exist functions f : A → B and g : C → D where f = g but B ≠ D.

In other words, two functions can be equal (same set of pairs) even if they are declared with different codomains.
💡Tip

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.

Warning

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

Definitionf(a) = f(b) → a = b

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.

Formal definition of injection

∀a, b ∈ A: f(a) = f(b) → a = b

Example
Let A = {1, 4} and B = {1, 9, 16, 4}.
Is f = {(1, 1), (4, 16)} injective?
Example
Let A = {1, 4} and B = {1, 9, 16, 4}.
Is f = {(1, 16), (4, 16)} injective?
💡Tip

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.

Warning

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

Definition∀y ∈ B, ∃x ∈ A: f(x) = y

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.

Formal definition of surjection

∀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."

Example
Let A = {2, 1, 4, 3} and B = {9, 4}.
Is f = {(2, 4), (1, 4), (4, 9), (3, 9)} surjective?
Example
Let A = {2, 1, 4, 3} and B = {9, 4}.
Is f = {(2, 4), (1, 4), (4, 4), (3, 4)} surjective?
Note

A function is surjective if and only if its range equals its codomain. Equivalently: range(f) = B.

Warning

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

Definition

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.

Example
Let A = {2, 1, 4, 3} and B = {1, 9, 16, 4}.
Is f = {(1, 1), (2, 4), (3, 9), (4, 16)} bijective?
Example
Let A = {2, 1, 4, 3} and B = {1, 9, 16, 4}.
Is f = {(1, 1), (2, 4), (3, 16), (4, 16)} bijective?
Example
Classify each function f : ℝ → ℝ as injective, surjective, both (bijective), or neither.

(a) f(x) = x²
(b) f(x) = 2x
(c) f(x) = x³ − x
(d) f(x) = x (the identity function)
Note

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.

Example
(a) What does it mean if f is an injection?

(b) What does it mean if f is a surjection?
💡Tip

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.

Note

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

f⁻¹

Inverse Functions

Reversing the arrows — but only for bijections

Definitionf⁻¹

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.

Warning

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.

Example
f : ℝ → ℝ given by f(x) = x + 4. Find f⁻¹.
Example
f : ℝ → ℝ given by f(x) = x². Does f⁻¹ exist?
Warning

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

Definitionf ∘ g

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.

Composition formula

(f ∘ g)(x) = f(g(x))

Warning

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.

Example
Let g : ℝ → ℝ given by g(x) = x − 2, and f : [0, ∞) → ℝ given by f(x) = √x. Find f ∘ g and g ∘ f.
Warning

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.

Theorem

Composition Preserves Injectivity

If f : B → C and g : A → B are both injections, then f ∘ g : A → C is also an injection.
Theorem

Composition Preserves Surjectivity

If f : B → C and g : A → B are both surjections, then f ∘ g : A → C is also a surjection.
Theorem

Composition Preserves Bijectivity

If f : B → C and g : A → B are both bijections, then f ∘ g : A → C is also a bijection.
💡Tip

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.

💡Tip

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

Definition|A|

Cardinality

A set A has cardinality |A| = n if it contains exactly n distinct elements.

Example
Find the cardinality of each set:
(a) {1, 5, 8, 9}
(b) {red, blue, red, blue, blue}
Definition

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.

Theorem

Injection and Cardinality

There exists an injection from A to B if and only if |A| ≤ |B|.

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.
Definition

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.

Definition

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.

Definition|A| = ℵ₀

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.

Theorem

Cantor-Schröder-Bernstein Theorem

If there exists an injection f : A → B and an injection g : B → A, then there exists a bijection h : A → B.

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.
Note

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.

Theorem

ℤ⁻ is Countably Infinite

The set of negative integers ℤ⁻ = {−1, −2, −3, ...} is countably infinite. A bijection from ℕ to ℤ⁻ is given by f(n) = −(n + 1).
Theorem

ℤ is Countably Infinite

The set of all integers ℤ = {..., −2, −1, 0, 1, 2, ...} is countably infinite. Even though ℤ "extends in both directions," it has the same cardinality as ℕ.
Theorem

Union of Countably Infinite Sets

If A and B are countably infinite, then A ∪ B is countably infinite.
Theorem

ℚ is Countably Infinite

The set of rational numbers ℚ is countably infinite. Despite the fact that between any two rationals there are infinitely many more rationals, ℚ is still "only" countably infinite — the same size as ℕ.
Theorem

ℝ is Uncountably Infinite

The set of real numbers ℝ is uncountably infinite. There is no bijection between ℕ and ℝ. The real numbers are "more infinite" than the natural numbers.

This is proved by Cantor's famous diagonalization argument.
💡Tip

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.

Warning

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.

Example
Practice 1 (Cartesian Products): Let A = {1, 2} and B = {a, b, c}. Find:
(a) A × B
(b) |A × B|
(c) Is A × B = B × A?
Example
Practice 2 (Relations): Let A = {1, 2, 3} and B = {2, 4, 6}. Define R = {(x, y) ∈ A × B | y = 2x}. Find R, its domain, and its range.
Example
Practice 3 (Function Check): Let A = {1, 2, 3} and B = {a, b}. For each relation, determine if it is a function from A to B.

(a) {(1, a), (2, b), (3, a)}
(b) {(1, a), (2, b)}
(c) {(1, a), (2, a), (3, b), (1, b)}
Example
Practice 4 (Classification): Let f : {1, 2, 3} → {a, b, c, d} be defined by f(1) = a, f(2) = b, f(3) = c. Is f injective? Is f surjective? Is f bijective?
Example
Practice 5 (Inverse): Let f : ℝ → ℝ be defined by f(x) = 3x − 2.
(a) Show f is a bijection.
(b) Find f⁻¹.
Example
Practice 6 (Composition): Let f : ℝ → ℝ be f(x) = x + 1 and g : ℝ → ℝ be g(x) = 2x. Find:
(a) (f ∘ g)(x)
(b) (g ∘ f)(x)
(c) Are f ∘ g and g ∘ f equal?
Example
Practice 7 (Proof): Let f : B → C and g : A → B both be injections. Prove that f ∘ g : A → C is an injection.

Hint: Start with the assumption that the composition gives equal outputs, and work inward: use f's injectivity first, then g's.

Example
Practice 8 (Cardinality): True or false? Justify your answer.

(a) |ℕ| = |ℤ|
(b) |ℕ| = |ℝ|
(c) |ℚ| = |ℕ|
(d) If |A| ≤ |B| and |B| ≤ |A|, then |A| = |B|.
Example
Practice 9 (Mixed): Let f : ℤ → ℤ be defined by f(n) = 2n + 1.
(a) Is f injective?
(b) Is f surjective?
(c) What is the range of f?
(d) Does f⁻¹ exist?
Example
Practice 10 (Domain/Codomain): Consider f(x) = x².
(a) Why is f : ℝ → ℝ not a bijection?
(b) Find sets A and B such that f : A → B is a bijection.
💡Tip

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 ℤ).

📝

Ready for the exam?

20 questions + written proofs · 45 minutes

Go to Exam