Solutions Cambridge Problems
Solutions Cambridge Problems
Solutions Cambridge Problems
Surjective. Absolute value function to the naturals |−|: Z ↠ N; natural log function
ln: R+0 ↠ R; first projection function from the Cartesian product of two (nonempty) sets
π1 : A × B ↠ A.
Not surjective. Integer squaring function on the naturals: (−)2 : N → N (only returns perfect
squares); constant function c b : A → B with value b ∈ B (always outputs b if B is not the
singleton set); successor function (−) + 1: N → N (0 is not the successor of any number).
2. Give two examples of functions that are injective, and two examples of functions that are not.
Not injective. Integer squaring function: (−)2 : Z → Z (since x 2 = (−x)2 ); quotient function
q(a) = [a] E : A → A/E for an equivalence relation E (related elements map to the same
equivalence class); sin(x): [0, 2π] → [−1, 1] since sin(0) = sin(2π) = 0.
Every injection (from a non-empty domain) has a retraction which “undoes” its effect. If
i : A ↣ B is an injection, every b in B is mapped to by at most a ∈ A; thus, a retraction can
be defined as (
a if ∃a ∈ A. i(a) = b
r(b) =
a0 otherwise
where a0 is any element of A. This is total, since every b is either mapped to the source a
for which i(a) = b, or to the fixed a0 . It is also functional, since there may only be at most
one a for which i(a) = b. By construction, r ◦ i = idA, so the two form a section-retraction
pair.
The implication holds in the other direction as well: every section s : A → B (with a retraction
r : B → A) is an injection. To see this, consider a, a′ ∈ A and assume s(a) = s(a′ ). But since
r ◦ s = idA, we have that r(s(a)) = r(s(a′ )) implies a = a′ , so s must be an injection.
2. Show that f : A → B is a surjection if and only if for all sets C and functions g, h: B → C ,
g ◦ f = h ◦ f implies g = h.
D I S C R E T E M AT H E M AT I C S E X E R C I S E S 8 – S O L U T I O N S W I T H C O M M E N TA R Y
(⇒) Let f : A ↠ B be a surjection: for all b ∈ B there exists an a ∈ A such that f (a) = b.
Furthermore, let g, h: B → C be functions and assume ⃝ 1 g ◦ f = h ◦ f . We need to show
that g = h, that is, for all b ∈ B , g(b) = h(b). But by assumption any b ∈ B is equal to
f (a) for some a ∈ A, so the condition is equivalent to g( f (a)) = h( f (a)), which is just ⃝
1 .
(⇐) We show the contrapositive: if f : A ↠ B is not surjective, then there exists a C and
functions g, h: B → C such that g ◦ f = h ◦ f but g ̸= h. If f is not surjective, there exists
a b0 ∈ B such that for all a ∈ A, f (a) ̸= b0 . We can therefore choose two functions g and h
such that they match on the range of f , but differ on b0 . For example, take C to be B with
a new distinguished element ⋆ added: C = B ∪ { ⋆ }. Let g : B → B ∪ { ⋆ } be the inclusion
g(b) = b, and let h(b0 ) = ⋆ and h(b) = b for all b ̸= b0 . Then, g ◦ f = h ◦ f , since g and h
defined to be equal for all elements in the range of f , but they differ on the element b0
not “covered” by f , hence g ̸= h.
12. On images
12.1. Basic exercises
1. Let R2 = { (m, n) | m = n2 }: N → Z be the integer square-root relation. What is the direct
image of N under R2 ? And what is the inverse image of N?
D I S C R E T E M AT H E M AT I C S E X E R C I S E S 8 – S O L U T I O N S W I T H C O M M E N TA R Y
This may well be called a “trick question”, since the answer could hardly be more coun-
terintuitive – then again, it follows directly from the definition of inverse relation images so
there is not much to argue about! R2 relates every integer (on the right) with its square (on
the left), a natural number: R2 = { (0, 0), (1, −1), (1, 1), (4, 2), (4, −2), (9, −3), (9, 3), . . . }.
The direct image of the natural numbers is therefore Z itself, since the square of every
integer is in N. It may seem intuitively obvious that the inverse image of N ⊆ Z the square
root relation would be the set of square numbers, but this is distinctly not the case. Recall
the definition of inverse relational images:
←
−
R (Y ⊆ B) ≜ { a ∈ A | ∀b ∈ B. a R b ⇒ b ∈ Y }
You may rightly ask: why do we define inverse images in such a way? The answer is simply
−
→
that this is the most natural way to define it as a dual of the direct image R (X ) ≜ { b ∈
B | ∃x ∈ X . x R b }. Indeed, if we slightly rephrase the condition ∃x ∈ X . x R b to separate
existence and membership of X , and compare it to the inverse image definition, we get:
−
→
R (X ) ≜ { b ∈ B | ∃x ∈ A. x R b ∧ x ∈ X }
←
−
R (Y ) ≜ { a ∈ A | ∀ y ∈ B. a R y ⇒ y ∈ Y }
As is often the case with mathematics, symmetry and simplicity takes precedence over
intuition, and trying to define the inverse image to yield the “expected” results would
needlessly complicate the definition. In fact, what we intuitively expect the inverse image
of N under R2 to be (the set of perfect squares) is nothing more than the direct image of N
op
under the opposite relation R2 .
D I S C R E T E M AT H E M AT I C S E X E R C I S E S 8 – S O L U T I O N S W I T H C O M M E N TA R Y
←
− −
→
b) R (Y ) = a ∈ A R ({ a }) ⊆ Y for all Y ⊆ B .
Let f : A → B be an injective function and let X be a subset of A. We show that the direct
∼ −
→
=
image of X under f is isomorphic to X by constructing a bijection h: X −→ f (X ). Define
h as
−
→
h(x ∈ X ) = f (x) ∈ f (X )
−
→
By construction, h is a function from X to f (X ) because every output of f for an input in
X ends up in the direct image. We show that h is surjective and injective. Take any element
−
→
y ∈ f (X ); by definition, there must exist an element x ∈ X such that f (x) = h(x) = y ,
which is the condition for surjectivity of h. Now, take x 1 , x 2 ∈ X and assume that h(x 1 ) =
h(x 2 ). Then, f (x 1 ) = f (x 2 ), but f is injective, so x 1 = x 2 – proving that h is injective too.
−→
As a direct corollary, the range of an injection is isomorphic to the domain: f (A) ∼ = A.
This is a situation where proving injectivity and surjectivity is more convenient than
−
→
trying to precisely formulate an inverse function that maps y ∈ f (X ) to “the element in X
that got uniquely mapped to y ” and using this to calculate the inverse laws.
−
→
2. Prove that for a surjective function f : A ↠ B , the direct image function f : P (A) → P (B) is
surjective.
D I S C R E T E M AT H E M AT I C S E X E R C I S E S 8 – S O L U T I O N S W I T H C O M M E N TA R Y
but the last set is precisely Y since f is surjective and therefore the comprehension
condition holds for all b ∈ Y . As a direct corollary, the range of a surjection is equal to the
−
→ −
→
= f (A) = B .
codomain: f (A) = B . A bijection is both an injection and a surjection, so A ∼
3. Show that any function f : A → B can be decomposed into an injection and a surjection: that
is, there exists a set X , a surjection s : A ↠ X and an injection i : X ↣ B such that f = i ◦ s.
5. Show that, by the inverse image, every map A → B induces a Boolean algebra map P (B) → P (A).
That is, for every function f : A → B , its inverse image preserves set operations:
←
−
• f (;) = ;
←
−
a ∈ f (;) ⇔ f (a) ∈ ; ⇔ false ⇔ a ∈ ;
←
−
• f (B) = A
←
−
a ∈ f (B) ⇔ f a ∈ B ⇔ true ⇔ a ∈ A
←
− ←
− ←
−
• f (X ∪ Y ) = f (X ) ∪ f (Y )
←
−
a ∈ f (X ∪ Y ) ⇔ f (a) ∈ (X ∪ Y ) ⇔ f (a) ∈ X ∨ f (a) ∈ Y
←
− ←
− ←
− ←
−
⇔ a ∈ f (X ) ∨ a ∈ f (X ) ⇔ a ∈ f (X ) ∪ f (Y )
←
− ←
− ←
−
• f (X ∩ Y ) = f (X ) ∩ f (Y )
←
−
a ∈ f (X ∩ Y ) ⇔ f (a) ∈ (X ∩ Y ) ⇔ f (a) ∈ X ∧ f (a) ∈ Y
←
− ←
− ←
− ←
−
⇔ a ∈ f (X ) ∧ a ∈ f (X ) ⇔ a ∈ f (X ) ∩ f (Y )
←
− ←− c
• f (X c ) = f (X )
←− ←− ←− c
a ∈ f (X c ) ⇔ f (a) ∈ X c ⇔ ¬( f (a) ∈ X ) ⇔ ¬(a ∈ f (X )) ⇔ a ∈ f (X )
13. On countability
13.1. Basic exercises
1. Prove that every finite set is countable.
it is an enumeration.
2. Demonstrate that N, Z, Q are countable sets.
Q is enumerable using the traversal of the coordinate plane demonstrated on Slide 398.
To show that µ is a surjection, we let a be an arbitrary element of A and show that there
is an i ∈ N such that µ(i) = a. Consider the set { k ∈ N | µ(k) < a } of numbers which
get mapped to an element below a in A, and let N be the size of this set (which, by the
Pigeonhole Principle, must be at most a). Now, AN is the subset of A obtained by removing
its N least elements, and by construction, its least element is a. But if a = min(AN ), then it
is equal to µ(N + 1) by the definition of µ, so we indeed have the natural number i = N + 1
such that µ(i) = a.
This encodes an element x ∈ A by the position of its first occurrence in the enumeration
given by s. We can see that i is injective as s acts as its retraction: for any x ∈ S ,
s(i(x)) = s(n) where n is the smallest natural number such that s(n) = x so clearly
s(i(x)) = s(n) = x and s ◦ i = idA, as required.
= ∼
(c) ⇒ (a) Let i : A ↣ N be an injection. We need to construct a bijection A −→ N, or
equivalently, show that A and N are isomorphic. By §12.2.1, the direct image of the
−
→
domain under the injection i (i.e. the range of i ) is isomorphic to the domain: i (A) ∼
= A.
−→
By assumption, A is infinite, so i (A) ⊆ N is infinite as well. But then it is an infinite
subset of the natural numbers, and by §13.2.1, it is isomorphic to N. Hence we have
−
→ ∼
= i (A) ∼
=
the chain A ∼ = N, establishing the bijection N −→ A.
If you look at other resources on countability, you will face several competing, but equi-
valent (but sometimes not quite equivalent) definitions which make translating between
various statements and proofs a bit of a chore – especially since the same terms are used
by different authors for different purposes. This course uses enumerable for sets which
have a surjection N ↠ A, and countable for sets which are enumerable or empty (since
one can’t have a function into the empty set so this needs to be handled as a special case).
Other literature (e.g. Wikipedia) calls sets which are isomorphic to N countably infinite,
and sets which are either finite or countably infinite are called countable. The countability
condition can be equivalently stated as the set being isomorphic to some subset of the
natural numbers, i.e. coming with an injection A ↣ N. Yet other terms used for the above
notions are at most countable, enumerable, denumerable, equinumerous, listable, etc.
As this exercise shows, the bijection/surjection/injection notions are equivalent when the
set A is infinite, and appropriate connections can be made when the sets are empty or
finite. This gives us two equivalent ways of showing that a set is enumerable: either by
constructing an enumeration N ↠ A, or by defining an encoding function A ↣ N that maps
every element of A to a unique natural number. This is related to a concept called Gödel
encoding which will be covered in more detail in the IB Computation Theory course.
3. Prove that:
If either is empty, the Cartesian product will be empty too and therefore countable.
In the general case, assume they are enumerable and there are injections f : A ↣ N
and g : B ↣ N that uniquely encode the elements of the sets. We define a function
p : A × B → N as follows:
p(a, b) = 2 f (a) · 3 g(a)
If both sets are empty, their disjoint union will be empty and therefore countable.
If either is empty, the disjoint union will be isomorphic to the other set, which is
countable by assumption. In the general case, assume A and B are enumerable and
come with injections f : A ↣ N and g : B ↣ N. We define the function u: A ⊎ B → N
as follows:
u(0, a) = 2 f (a) u(1, b) = 3 g(b)
All the results follow from Proposition 154: an enumerable indexed disjoint union of
enumerable sets is enumerable. An enumeration-style proof is presented in the notes, but
U
an encoding-style argument is straightforward too: we can encode elements of i∈I Ai as
where c : I ↣ N is the encoding of the index set, and ci : Ai ↣ N is an encoding for every
element of the indexed family.
A∗ =
U
n∈N A
n
is the set of finite sequences on A. If A is empty, the only finite sequence
with elements from A is the empty sequence, so { () } is finite and countable. In the general
case, we know that N is enumerable, and An is the iterated binary Cartesian product of
enumerable sets and hence is an enumerable set for every n ∈ N (quick inline induction
proof: A0 = ; is countable; Ak+1 = Ak × A is the Cartesian product of countable Ak by IH,
and countable A by assumption). By the above proposition, the N-indexed disjoint union
of countable sets is countable.
Pfin (A) = { S ⊆ A | S is finite } is the set of finite subsets of A. If A is empty, Pfin (A) = { ; }
which is finite so countable. Otherwise, the set A has an encoding c : A ↣ N which imposes
an ordering on the elements on A based on the ordering of their code: for a, b ∈ A, a ⊑ b
if c(a) ≤ c(b). This ordering restricts to every subset of A, so in particular, finite subsets of
A can be mapped to finite sequences of elements of A according to the ordering ⊑. Then,
the set of finite subsets of A is isomorphic to the set of finite sequences on A, which is
countable for a countable A.
PFunfin (A, B) = S∈Pfin (A) S ⇒ B is the set of partial functions with a finite domain of
U
definition from A to B . If A or B are empty, the totally undefined function is the only
element of the set so it is countable. Otherwise, the disjoint union is indexed by Pfin (A)
which is enumerable by the result above. The function space S ⇒ B has a finite domain
S , so a single function f : S → B can be captured as a finite sequence of elements of B
as ( f (s1 ), f (s2 ), f (s3 ), . . . , f (sn )) where n = #S and si is the {i th } element of S in some
#S
ordering (which is always possible to define for a finite S ). Thus, S ⇒ B ∼ = B which is
countable for any countable B . By Proposition 154, the set PFunfin (A, B) is a countable
indexed disjoint union of countable sets and is therefore itself countable.