Mathematics for Computer Science 201-N11 • CEGEP, Montreal

Corrected exercises: injective, surjective and bijective functions (201-N11)

This is the corrected exercise set on functions between sets, injections, surjections and bijections, for Mathematics for Computer Science, 201-N11, the discrete mathematics course taken at CEGEP by students in computer science programs. Part A lays the foundations: what distinguishes a function from an arbitrary relation, the image, the inverse image of a subset and the fibres, the three natures read on an arrow diagram, the three standard write-ups for proving injectivity, proving surjectivity and disproving, then composition and what it really inherits. Part B moves up to exam level: the substitution cipher and its inverse, counting functions, injections, surjections and bijections between finite sets, a hash function examined as a function, and the enumeration of the integers by the natural numbers.

The thread of the set: injective, surjective and bijective are not properties of a formula, they are properties of the triple made of the rule, the domain and the codomain. The same rule x↦x2x \mapsto x^{2} takes all four possible natures depending on the two sets it is given, so the move repeated from one exercise to the next is always the same: look at the domain and the codomain before answering.

The second thread is the one that makes this chapter a computer science chapter: cardinality. An injection from AA to BB says ∣A∣≤∣B∣\lvert A \rvert \le \lvert B \rvert, a surjection says the opposite inequality, a bijection says equality, and that is how two sets are compared without counting either one. It is also what makes any injective hash function impossible, and what puts the natural numbers and the integers on an equal footing.

10 corrected exercises • 100 points • 150 minutes

This chapter is part of 201-N11, every chapter with its set and sheet Before you start Revision sheet: the traps and the method for this chapter

Self-checking set Type your answers and check them question by question: the page tells you right or wrong before you open the solution. With an account, every answer right on the first try earns points, and your right answers stay filled in when you come back.

Course recap

  • • A function f:A→Bf : A \to B is a relation that gives each element of AA ONE image and ONLY ONE. On an arrow diagram: exactly one arrow leaves each element on the left.
  • • INJECTIVE: each element of the codomain receives AT MOST one arrow. SURJECTIVE: AT LEAST one. BIJECTIVE: EXACTLY one.
  • • These three words never describe a formula alone, but the triple rule, domain, codomain. With R+=[0,∞)\mathbb{R}^{+}=[0,\infty), the nonnegative reals, x↦x2x \mapsto x^{2} is bijective from R+\mathbb{R}^{+} onto R+\mathbb{R}^{+} and none of the three from R\mathbb{R} to R\mathbb{R}.
  • • Proving injectivity: start from f(a)=f(b)f(a) = f(b) and arrive at a=ba = b. Proving surjectivity: take any yy and BUILD a preimage. Disproving: a single counterexample with numbers.
  • • f−1(Q)f^{-1}(Q), applied to a SUBSET of the codomain, always exists and returns the set of preimages. The inverse FUNCTION f−1f^{-1} exists only if ff is bijective.
  • • The nonempty fibres f−1({y})f^{-1}(\{y\}) form a partition of the domain: they are the classes of the relation having the same image.
  • • Composition: if g∘fg \circ f is injective, then ff is; if g∘fg \circ f is surjective, then gg is. Injectivity travels back to the input, surjectivity travels forward to the output.
  • • Inverse of a composition: (g∘f)−1=f−1∘g−1(g \circ f)^{-1} = f^{-1} \circ g^{-1}, the order is reversed.
  • • Between finite sets: ∣B∣∣A∣\lvert B \rvert^{\lvert A \rvert} functions, ∣B∣!(∣B∣−∣A∣)!\frac{\lvert B \rvert!}{(\lvert B \rvert - \lvert A \rvert)!} injections, ∣A∣!\lvert A \rvert! bijections when the cardinalities are equal.
  • • An injection gives ∣A∣≤∣B∣\lvert A \rvert \le \lvert B \rvert, a surjection gives ∣A∣≥∣B∣\lvert A \rvert \ge \lvert B \rvert, a bijection gives equality. For finite sets of the same cardinality, injective is equivalent to surjective; for infinite sets, it is not.

Part A: the basics (/50)

Exercise 1: Function or relation: what the word function requires

A relation from AA to BB is any subset of A×BA \times B. A FUNCTION f:A→Bf : A \to B is a relation that meets two conditions, and only two: every element of AA has an image (EXISTENCE), and it has only one (UNIQUENESS). The whole chapter rests on this starting point, because a relation that fails either condition does not even deserve the question of whether it is injective.

The figure shows four relations from A={1,2,3}A = \{1,2,3\} to B={a,b,c}B = \{a,b,c\}, drawn as arrow diagrams: one arrow from the domain to the codomain for each pair in the relation.

123AabcB(1)123AabcB(2)123AabcB(3)123AabcB(4)
  • a) Which of the four relations in the figure are functions from AA to BB? For each relation you reject, name the missing condition.
  • b) For relation (1), give f(1)f(1), f(2)f(2) and f(3)f(3), then the image f(A)f(A) and its cardinality.
  • c) Is relation (4) a function? Give its image and its cardinality.
  • d) Can a function from AA to BB have two elements of AA with the same image? Can it have two elements of BB with the same preimage?
  • e) Seen as a subset of A×BA \times B, exactly how many pairs does a function from AA to BB contain? Compare with the number of possible relations from AA to BB.

Type your answers, the page tells you right or wrong 0/12

a)
b)
c)
d)
e)
Show the solution

Answers

  • a) The functions are (1) and (4); (2) fails existence, (3) fails uniqueness
  • b) f(1)=af(1)=a, f(2)=bf(2)=b, f(3)=bf(3)=b, so f(A)={a,b}f(A)=\{a,b\}, of cardinality 2
  • c) Yes, the constant function with value cc; f(A)={c}f(A)=\{c\}, of cardinality 1
  • d) Yes for the same image, no for the same preimage: a function collapses, it never splits
  • e) Exactly 3 pairs, against 9 in A×BA \times B and 512 possible relations
a)

The functions are (1) and (4). Relation (2) fails EXISTENCE: no arrow leaves the element 2, so f(2)f(2) refers to nothing and the notation itself loses its meaning. Relation (3) fails UNIQUENESS: two arrows leave 1, towards aa and towards bb, so f(1)f(1) would refer to two objects at once. The test is read at a glance on an arrow diagram: there must be EXACTLY ONE arrow leaving EACH element on the left. Not zero, not two. Nothing at all is required on the codomain side, however: an element of BB may receive zero, one or ten arrows without leaving the world of functions. It is precisely this asymmetry between domain and codomain that will produce injectivity and surjectivity in the next exercises.

b)

f(1)=af(1) = a, f(2)=bf(2) = b, f(3)=bf(3) = b. The image is f(A)={a,b}f(A) = \{a, b\}, of cardinality 2. It is not written {a,b,b}\{a, b, b\}: a set does not count repetitions, and that is exactly why the cardinality of the image can be strictly smaller than that of the domain. Here ∣f(A)∣=2<3=∣A∣\lvert f(A) \rvert = 2 < 3 = \lvert A \rvert. The lost element is the visible sign that two arrows land in the same place.

c)

Yes, relation (4) is a function: each of the three elements of AA has exactly one arrow, and nothing forbids them from all ending at the same point. It is the constant function with value cc. Its image is f(A)={c}f(A) = \{c\}, of cardinality 1. The classic error is to reject it on the grounds that cc receives three arrows: that condition does not exist. It costs the whole question, when rereading the definition was enough.

d)

Two elements of AA can perfectly well have the same image, and relation (4) gives the extreme example. It is in fact exactly the defect that will be called non-injectivity. On the other hand, two elements of BB can never have the same preimage: that would mean an element of AA has two images, which uniqueness forbids. Remember the asymmetric wording: a function is allowed to COLLAPSE, it is not allowed to SPLIT.

e)

A function from AA to BB contains exactly ∣A∣=3\lvert A \rvert = 3 pairs, one per element of the domain, never one more or one less. The Cartesian product A×BA \times B, on the other hand, has 3×3=93 \times 3 = 9 pairs, and it has 29=5122^{9} = 512 subsets, so there are 512 relations from AA to BB. Functions are therefore a narrow minority among relations, 33=273^{3} = 27 out of 512, or about 5.3 percent. This count comes back in exercise 7, where it is used to count injections and bijections.

Tick the exercises you have done or want to review: a free account, no password, keeps your ticks and your right answers from one visit to the next, tells you which chapter to tackle next and lets you ask for the exercise you are missing. Create your space, an email is enough.

Exercise 2: Image and inverse image of a subset

Two notations look alike and say completely different things. f(P)f(P), for PP a subset of the domain, is the set of images of the elements of PP. f−1(Q)f^{-1}(Q), for QQ a subset of the codomain, is the set of PREIMAGES of the elements of QQ. The second one can be read and computed for any function, even the most collapsing one.

Take E={1,2,3,4,5,6}E = \{1,2,3,4,5,6\}, F={a,b,c,d}F = \{a,b,c,d\} and the function f:E→Ff : E \to F given by f(1)=af(1)=a, f(2)=cf(2)=c, f(3)=af(3)=a, f(4)=bf(4)=b, f(5)=cf(5)=c and f(6)=af(6)=a.

The figure below shows the situation.

E123456Fabcd
  • a) Give the image f(E)f(E) and its cardinality. Which element of FF is nobody's image?
  • b) Compute f(P)f(P) for P={1,3,4}P = \{1,3,4\}, then f(P′)f(P') for P′={2,5}P' = \{2,5\}. Each time, compare the cardinality of the subset with that of its image.
  • c) Compute f−1({a})f^{-1}(\{a\}), f−1({c})f^{-1}(\{c\}), f−1({d})f^{-1}(\{d\}) and f−1({a,b})f^{-1}(\{a,b\}).
  • d) Check that the four sets f−1({a})f^{-1}(\{a\}), f−1({b})f^{-1}(\{b\}), f−1({c})f^{-1}(\{c\}) and f−1({d})f^{-1}(\{d\}) have union EE and are pairwise disjoint. What do you recognize from the chapter on relations?
  • e) Does the notation f−1({a})f^{-1}(\{a\}) assume that ff has an inverse function?

Type your answers, the page tells you right or wrong 0/11

a)
b)
c)
d)
e)
Show the solution

Answers

  • a) f(E)={a,b,c}f(E)=\{a,b,c\}, of cardinality 3; dd is hit by nothing
  • b) f(P)={a,b}f(P)=\{a,b\} of cardinality 2 for ∣P∣=3\lvert P \rvert = 3; f(P′)={c}f(P')=\{c\} of cardinality 1 for ∣P′∣=2\lvert P' \rvert = 2
  • c) {1,3,6}\{1,3,6\}, {2,5}\{2,5\}, ∅\varnothing and {1,3,4,6}\{1,3,4,6\}
  • d) Union EE, pairwise disjoint subsets: the fibres form a partition, the classes of having the same image
  • e) No: f−1f^{-1} applied to a SUBSET is always defined, the inverse function only if ff is bijective
a)

f(E)={a,b,c}f(E) = \{a, b, c\}, of cardinality 3. The element dd has no preimage: no arrow reaches it, and we say it is not HIT. The image is therefore a proper subset of FF, and that is exactly what makes ff fail to be surjective, in the sense defined in exercise 3. The reflex to build: the image is not the codomain, it is the part of the codomain actually used, and the two coincide only in the surjective case.

b)

f(P)={f(1),f(3),f(4)}={a,a,b}={a,b}f(P) = \{f(1), f(3), f(4)\} = \{a, a, b\} = \{a, b\}, of cardinality 2 while ∣P∣=3\lvert P \rvert = 3. f(P′)={f(2),f(5)}={c}f(P') = \{f(2), f(5)\} = \{c\}, of cardinality 1 while ∣P′∣=2\lvert P' \rvert = 2. The general rule is ∣f(P)∣≤∣P∣\lvert f(P) \rvert \le \lvert P \rvert, with equality exactly when ff merges no two elements of PP. An image never grows: this is the first cardinality result of the chapter, and it is the source of the inequality ∣A∣≤∣B∣\lvert A \rvert \le \lvert B \rvert attached to an injection.

c)

f−1({a})={1,3,6}f^{-1}(\{a\}) = \{1, 3, 6\}, the three elements whose image is aa. f−1({c})={2,5}f^{-1}(\{c\}) = \{2, 5\}. f−1({d})=∅f^{-1}(\{d\}) = \varnothing: no preimage, and the empty set is a perfectly legitimate answer, not a failed computation. Finally f−1({a,b})={1,3,6}∪{4}={1,3,4,6}f^{-1}(\{a,b\}) = \{1,3,6\} \cup \{4\} = \{1,3,4,6\}. The classic trap is to answer with an ELEMENT when f−1f^{-1} returns a SET: f−1({b})f^{-1}(\{b\}) is {4}\{4\} and not 44, and the distinction is the one the chapter on sets already made between 33 and {3}\{3\}.

d)

The four sets are {1,3,6}\{1,3,6\}, {4}\{4\}, {2,5}\{2,5\} and ∅\varnothing. Their union is indeed {1,2,3,4,5,6}=E\{1,2,3,4,5,6\} = E, since every element has an image and therefore belongs to exactly one of these subsets, and the cardinalities add up to 3+1+2+0=63+1+2+0 = 6. They are pairwise disjoint, because an element cannot have two images. We therefore recover a PARTITION of EE, up to the empty parts: these are the classes of the equivalence relation having the same image, studied in the chapter on relations. Each set f−1({y})f^{-1}(\{y\}) is called a FIBRE of ff over yy, and the word is used as is in exercise 9 on hashing.

e)

No, and this is the most common misreading of the chapter. The notation f−1(Q)f^{-1}(Q), with a SET inside the parentheses, is defined for every function without exception: it denotes a subset of the domain, obtained by following the arrows backwards. The inverse FUNCTION f−1:F→Ef^{-1} : F \to E, on the other hand, exists only if ff is bijective, and our ff is nowhere near that, since dd has no preimage and aa has three. Two identical notations, two different objects: one takes a set and returns a set, the other would take an element and return an element. Confusing them leads to writing f−1(a)=1f^{-1}(a) = 1, which means nothing here and costs all the marks for the question.

Exercise 3: The same formula, four domains and four codomains

Injective, surjective and bijective are not properties of a formula. They are properties of the TRIPLE made of the rule, the domain and the codomain. Changing one of the two sets without touching the rule changes the answer, and the student who says that squaring is not injective without having looked at the domain has already lost the marks.

The definitions, to keep in front of you: ff is INJECTIVE when two distinct elements of the domain have distinct images, in other words when each element of the codomain receives AT MOST one arrow; it is SURJECTIVE when every element of the codomain has at least one preimage, in other words receives AT LEAST one; it is BIJECTIVE when it is both, so when each one receives EXACTLY one.

The figure shows four functions between finite sets, one per panel.

123AabcdB(1)1234AabcB(2)123AabcB(3)123AabcB(4)
  • a) For each of the four functions in the figure, say whether it is injective only, surjective only, bijective, or none of the three. Justify by the number of arrows received.
  • b) Consider the rule x↦x2x \mapsto x^{2}, where R+=[0,∞)\mathbb{R}^{+}=[0,\infty) denotes the nonnegative reals, zero included. Study the injectivity and the surjectivity of f:R→Rf : \mathbb{R} \to \mathbb{R}, then of f:R+→Rf : \mathbb{R}^{+} \to \mathbb{R}.
  • c) Same questions for f:R→R+f : \mathbb{R} \to \mathbb{R}^{+}, then for f:R+→R+f : \mathbb{R}^{+} \to \mathbb{R}^{+}.
  • d) Same questions for f:Z→Nf : \mathbb{Z} \to \mathbb{N}, n↦n2n \mapsto n^{2}.
  • e) Between questions b), c) and d), what was changed and what was left untouched? State the reading rule this forces on you.

Type your answers, the page tells you right or wrong 0/11

a)
b)
c)
d)
e)
Show the solution

Answers

  • a) (1) injective only, (2) surjective only, (3) bijective, (4) none of the three
  • b) R→R\mathbb{R} \to \mathbb{R}: none of the three; R+→R\mathbb{R}^{+} \to \mathbb{R}: injective only
  • c) R→R+\mathbb{R} \to \mathbb{R}^{+}: surjective only; R+→R+\mathbb{R}^{+} \to \mathbb{R}^{+}: bijective, with the square root as inverse
  • d) Z→N\mathbb{Z} \to \mathbb{N}: none of the three; the image is the set of perfect squares, only 6 values from 0 to 25
  • e) Only the domain and the codomain changed: look at the domain and the codomain before answering
a)

Panel (1): each element of BB receives at most one arrow, but dd receives none, so the function is INJECTIVE ONLY. Panel (2): all three elements of BB are hit, but aa receives two arrows, those from 1 and from 2, so SURJECTIVE ONLY. Panel (3): each element of BB receives exactly one arrow, so BIJECTIVE. Panel (4): aa receives two and bb none, so NONE OF THE THREE. Counting the arrows received is the only move to remember for a finite set: at most one gives injectivity, at least one surjectivity, exactly one bijectivity. The arrows LEAVING, on the other hand, are not counted: they have already been used to decide that the object is a function.

b)

From R\mathbb{R} to R\mathbb{R}: not injective, because f(−2)=f(2)=4f(-2) = f(2) = 4 with −2≠2-2 \ne 2, and a single counterexample is enough; not surjective either, because −1-1 has no preimage, the square of a real number never being negative. From R+\mathbb{R}^{+} to R\mathbb{R}: it becomes INJECTIVE, because if aa and bb are nonnegative and a2=b2a^{2} = b^{2} then a=ba = b, the candidate −b-b having been ruled out by the domain; it remains non-surjective, since the codomain has not moved and −1-1 is still not hit.

c)

From R\mathbb{R} to R+\mathbb{R}^{+}: it becomes SURJECTIVE, because every y≥0y \ge 0 has the preimage y\sqrt{y}, and even two as soon as y>0y > 0; it remains non-injective, since the domain has not moved and −2-2 and 22 still have the same image. From R+\mathbb{R}^{+} to R+\mathbb{R}^{+}: the two corrections add up, the function is BIJECTIVE, and its inverse is the square root. We have thus obtained all four possible natures with ONE SINGLE computation rule, without ever changing a sign.

d)

From Z\mathbb{Z} to N\mathbb{N}: neither one nor the other. Not injective, because (−3)2=32=9(-3)^{2} = 3^{2} = 9. Not surjective either, and that is the trap of the question: the codomain N\mathbb{N} looks tailor-made, since squares of integers are indeed natural numbers, but 2, 3, 5, 6 and 7 are the squares of no integer. Of the 26 integers from 0 to 25, only 6 are perfect squares and 20 are not. The image is the set of perfect squares, a very thin part of N\mathbb{N}. Remember that shrinking the codomain is not enough: it must be shrunk ALL THE WAY DOWN to the exact image.

e)

Only the domain and the codomain were changed. The rule x↦x2x \mapsto x^{2} did not move. The reading rule that follows is the thread of the whole set: LOOK AT THE DOMAIN AND THE CODOMAIN BEFORE ANSWERING. A question that asks whether squaring is injective without specifying the two sets is not a hard question, it is an ill-posed one. The precise mechanism is worth memorizing: shrinking the DOMAIN can only help injectivity and never makes a function surjective; shrinking the CODOMAIN can only help surjectivity and never changes injectivity.

Exercise 4: The three standard write-ups: prove, prove, disprove

Three questions, three write-ups that look nothing alike. Proving injectivity is a UNIVERSAL statement: start from f(a)=f(b)f(a) = f(b) and you must arrive at a=ba = b, for all pairs at once. Proving surjectivity is an EXISTENCE statement: take any yy in the codomain and BUILD a preimage. Disproving either one is a COUNTEREXAMPLE: a single one is enough, and it must be shown with its values.

The choice of write-up is not a matter of style. Writing an existence statement as if it were universal, or believing that you disprove something by saying it does not always work, are the two ways of losing all the marks on a theory question.

  • a) Prove that f:R→Rf : \mathbb{R} \to \mathbb{R}, f(x)=3x−7f(x) = 3x - 7, is injective, starting from f(a)=f(b)f(a) = f(b).
  • b) Prove that the same ff is surjective, by solving f(x)=yf(x) = y for an arbitrary yy. Check your preimage on y=5y = 5.
  • c) Disprove the injectivity of g:R→Rg : \mathbb{R} \to \mathbb{R}, g(x)=x2−4x+1g(x) = x^{2} - 4x + 1. Is a single counterexample enough, and why?
  • d) Let h:Z→Zh : \mathbb{Z} \to \mathbb{Z}, h(n)=2nh(n) = 2n. Is it injective? surjective? Answer the question again for h:Z→2Zh : \mathbb{Z} \to 2\mathbb{Z}, where 2Z2\mathbb{Z} denotes the set of even integers.
  • e) Sort the three write-ups: which one proves a universal statement, which one an existence statement, and which one settles for a single example?

Type your answers, the page tells you right or wrong 0/9

a)
b)
c)
d)
e)
Show the solution

Answers

  • a) 3a−7=3b−73a-7=3b-7 implies a=ba=b: ff is injective
  • b) x=y+73x = \frac{y+7}{3} works for every yy; for y=5y=5, x=4x=4 and f(4)=5f(4)=5
  • c) g(0)=g(4)=1g(0)=g(4)=1 with 0≠40 \ne 4; a single counterexample is enough, since it negates a universal statement
  • d) Z→Z\mathbb{Z} \to \mathbb{Z}: injective only; Z→2Z\mathbb{Z} \to 2\mathbb{Z}: bijective
  • e) Injectivity universal, surjectivity existential, disproof by a single example
a)

Let aa and bb be two real numbers such that f(a)=f(b)f(a) = f(b). Then 3a−7=3b−73a - 7 = 3b - 7, so 3a=3b3a = 3b by adding 7 to both sides, so a=ba = b by dividing by 3, which is legitimate since 3≠03 \ne 0. Two elements with the same image are therefore equal: ff is injective. The write-up begins with LET and ends with the requested conclusion, in a chain of implications, without a single numerical example. Checking three values proves nothing, it only tests, and that is worth zero on the question.

b)

Let yy be an arbitrary real number. We look for xx such that 3x−7=y3x - 7 = y, that is 3x=y+73x = y + 7, that is x=y+73x = \frac{y+7}{3}. This number is indeed real, whatever yy is, since division by 3 is always possible. Mandatory check: f(y+73)=3⋅y+73−7=y+7−7=yf\left(\frac{y+7}{3}\right) = 3 \cdot \frac{y+7}{3} - 7 = y + 7 - 7 = y. So every real number has a preimage and ff is surjective. For y=5y = 5: x=123=4x = \frac{12}{3} = 4, and f(4)=12−7=5f(4) = 12 - 7 = 5. The function is therefore bijective, which was predictable: a linear function with nonzero slope, from R\mathbb{R} to R\mathbb{R}, always is.

c)

g(0)=1g(0) = 1 and g(4)=16−16+1=1g(4) = 16 - 16 + 1 = 1. So g(0)=g(4)g(0) = g(4) with 0≠40 \ne 4: gg is not injective. A single counterexample is enough, because injectivity asserts something for ALL pairs, and the negation of a universal statement is the existence of ONE failing case. This pair is found without trial and error, by noticing that the quadratic has its vertex at x=2x = 2 and that two points symmetric about this axis have the same image; 00 and 44 are at distance 2 on either side. Writing only that the quadratic is not monotonic disproves nothing: you must produce the two values and their common image.

d)

From Z\mathbb{Z} to Z\mathbb{Z}: injective, because 2a=2b2a = 2b gives a=ba = b; not surjective, because 3 is odd and no integer nn satisfies 2n=32n = 3. From Z\mathbb{Z} to 2Z2\mathbb{Z}: the rule and the domain are unchanged, so injectivity still holds without proving anything again, and surjectivity becomes true since every even integer can be written 2k2k with kk an integer, this kk being the preimage we want. The function is therefore BIJECTIVE from Z\mathbb{Z} onto 2Z2\mathbb{Z}. It is the thread of exercise 3 applied once more, and this bijection comes back in exercise 10, where it says something surprising about infinite cardinalities.

e)

Injectivity is a UNIVERSAL statement: for all aa and bb, if f(a)=f(b)f(a) = f(b) then a=ba = b. Surjectivity is an EXISTENCE statement: for every yy, there EXISTS xx such that f(x)=yf(x) = y, and the write-up must produce this xx, not merely assert that it exists. Disproving is the only one of the three moves that settles for an example, and that is because it negates a universal statement. The table to remember fits in three lines: to ESTABLISH a universal statement you need a general proof; to DESTROY it one example is enough; to ESTABLISH an existence statement, on the contrary, one example is enough, here the preimage built in b).

Exercise 5: Composition and what it inherits

The composition g∘fg \circ f is read from right to left: apply ff, then gg. It goes from the domain of ff to the codomain of gg, and it is defined only if the codomain of ff is indeed the domain of gg.

The figure shows f:A→Bf : A \to B and g:B→Cg : B \to C with A={1,2,3}A = \{1,2,3\}, B={a,b,c,d}B = \{a,b,c,d\} and C={x,y,z}C = \{x,y,z\}. It is built to defuse the most stubborn idea of the chapter, namely that a composition inherits the defects of its two pieces.

123AabcdBxyzCfg
  • a) Give (g∘f)(1)(g \circ f)(1), (g∘f)(2)(g \circ f)(2) and (g∘f)(3)(g \circ f)(3), then say whether g∘fg \circ f is injective, surjective, bijective.
  • b) Is ff surjective? Is gg injective? What becomes of the idea that a composition inherits the defects of both functions?
  • c) Prove that if ff and gg are injective then g∘fg \circ f is, then that if ff and gg are surjective then g∘fg \circ f is.
  • d) Prove that if g∘fg \circ f is injective then ff is injective. Does the figure show that gg, for its part, may fail to be?
  • e) Prove that if g∘fg \circ f is surjective then gg is surjective. Does the figure show that ff, for its part, may fail to be?

Type your answers, the page tells you right or wrong 0/7

a)
b)
d)
e)
Show the solution

Answers

  • a) xx, yy and zz: g∘fg \circ f is bijective
  • b) ff not surjective, dd is missed; gg not injective, bb and dd go to yy; and yet the composition is bijective
  • c) Both implications are true: injectivity and surjectivity are passed on to the composition
  • d) g∘fg \circ f injective implies only ff injective; the figure shows gg not injective
  • e) g∘fg \circ f surjective implies only gg surjective; the figure shows ff not surjective
a)

f(1)=af(1) = a then g(a)=xg(a) = x, so (g∘f)(1)=x(g \circ f)(1) = x. Likewise (g∘f)(2)=g(b)=y(g \circ f)(2) = g(b) = y and (g∘f)(3)=g(c)=z(g \circ f)(3) = g(c) = z. The three images are distinct, so g∘fg \circ f is injective, and they exhaust C={x,y,z}C = \{x,y,z\}, so it is surjective: g∘fg \circ f is BIJECTIVE. The computation is always done in this order, following the arrows; writing (f∘g)(1)(f \circ g)(1) would make no sense here, since gg does not start from AA.

b)

ff is NOT surjective: dd receives no arrow from AA. gg is NOT injective: bb and dd have the same image yy. And yet the composition is bijective. The idea that a composition inherits defects is therefore false, and this figure is a complete counterexample: a function that does not hit everything, followed by a function that merges two elements, can give a bijection, because the merging done by gg involves precisely the element dd that ff never reached. What is passed on are the QUALITIES, and not even in both directions, as questions d) and e) show.

c)

INJECTIVITY. Let a1a_1 and a2a_2 be in AA with (g∘f)(a1)=(g∘f)(a2)(g \circ f)(a_1) = (g \circ f)(a_2), that is g(f(a1))=g(f(a2))g(f(a_1)) = g(f(a_2)). Since gg is injective, f(a1)=f(a2)f(a_1) = f(a_2). Since ff is injective, a1=a2a_1 = a_2. So g∘fg \circ f is injective. SURJECTIVITY. Let cc be in CC. Since gg is surjective, there exists bb in BB with g(b)=cg(b) = c. Since ff is surjective, there exists aa in AA with f(a)=bf(a) = b. Then (g∘f)(a)=g(b)=c(g \circ f)(a) = g(b) = c. So g∘fg \circ f is surjective. Notice the difference in movement: the injectivity proof UNWINDS, it starts from an equality and removes the functions one by one; the surjectivity proof BUILDS, it starts from the codomain and works its way back to the domain. Mixing the two movements produces a write-up that proves nothing.

d)

Suppose g∘fg \circ f is injective and let a1,a2a_1, a_2 satisfy f(a1)=f(a2)f(a_1) = f(a_2). Applying gg to both sides, g(f(a1))=g(f(a2))g(f(a_1)) = g(f(a_2)), so (g∘f)(a1)=(g∘f)(a2)(g \circ f)(a_1) = (g \circ f)(a_2), so a1=a2a_1 = a_2 by injectivity of the composition. So ff is injective. The figure does show that gg can fail: g∘fg \circ f is injective there and yet g(b)=g(d)=yg(b) = g(d) = y. The reason fits in one sentence: the composition only sees gg through its restriction to f(A)={a,b,c}f(A) = \{a,b,c\}, and dd is invisible to it. Remember the asymmetry: from an injective composition, only the FIRST function inherits.

e)

Suppose g∘fg \circ f is surjective and let cc be in CC. There exists aa in AA with g(f(a))=cg(f(a)) = c. Then the element b=f(a)b = f(a) of BB satisfies g(b)=cg(b) = c, so cc has a preimage under gg: gg is surjective. The figure confirms it and shows that ff, for its part, can fail: g∘fg \circ f is surjective there while ff misses dd. It is the mirror image of the previous asymmetry: from a surjective composition, only the SECOND function inherits. Both results sum up in one sentence, and that is the form to memorize: injectivity travels back to the input, surjectivity travels forward to the output.

Part B: problems and reasoning (/50)

Exercise 6: Problem: the bijection as a guarantee of decryption

A substitution cipher replaces each letter by another one, according to a fixed table. The question that settles everything is not how strong the scheme is, it is whether it can be decrypted: an encrypted message can be recovered only if the table is a BIJECTION from the alphabet onto itself.

We work on the reduced alphabet Σ={A,B,C,D,E}\Sigma = \{A,B,C,D,E\} and on the table cc given by the figure.

ABCDEplaintextABCDEciphertext
  • a) Check that cc is a bijection from Σ\Sigma onto Σ\Sigma. How many functions from Σ\Sigma to Σ\Sigma are there, and how many are bijections? What proportion is that?
  • b) Build c−1c^{-1}, letter by letter, then decrypt the message EDBCA.
  • c) Check c−1(c(B))=Bc^{-1}(c(B)) = B and c(c−1(B))=Bc(c^{-1}(B)) = B. Why are BOTH equalities required before speaking of an inverse function?
  • d) We compose with a second cipher dd, the shift by one position: d(A)=Bd(A)=B, d(B)=Cd(B)=C, d(C)=Dd(C)=D, d(D)=Ed(D)=E, d(E)=Ad(E)=A. Give the table of d∘cd \circ c, say whether it is a bijection, then express (d∘c)−1(d \circ c)^{-1} in terms of c−1c^{-1} and d−1d^{-1}.
  • e) An intern proposes e(A)=Ae(A)=A, e(B)=Ae(B)=A, e(C)=Ce(C)=C, e(D)=Ce(D)=C, e(E)=Ee(E)=E, explaining that this compresses the message. How many five-letter messages have AAAAA as their ciphertext? Is decryption possible?

Type your answers, the page tells you right or wrong 0/10

a)
b)
c)
d)
e)
Show the solution

Answers

  • a) cc is a bijection; 55=3,1255^{5}=3{,}125 functions, 5!=1205!=120 bijections, that is 3.843.84 percent
  • b) c−1:A→Cc^{-1} : A \to C, B→DB \to D, C→AC \to A, D→ED \to E, E→BE \to B; EDBCA decrypts to BEDAC
  • c) Both equalities equal BB; one expresses injectivity, the other surjectivity
  • d) d∘c:A→Dd \circ c : A \to D, B→AB \to A, C→BC \to B, D→CD \to C, E→EE \to E, bijective, and (d∘c)−1=c−1∘d−1(d \circ c)^{-1} = c^{-1} \circ d^{-1}
  • e) 25=322^{5} = 32 messages give AAAAA; decryption impossible, ee is not injective
a)

The table gives c(A)=Cc(A)=C, c(B)=Ec(B)=E, c(C)=Ac(C)=A, c(D)=Bc(D)=B, c(E)=Dc(E)=D. The five images are CC, EE, AA, BB and DD: they are pairwise distinct, so cc is injective, and they exhaust Σ\Sigma, so cc is surjective. It is a bijection. Since the domain and the codomain have the same finite cardinality here, one of the two checks would have been enough, a result proved in exercise 7. There are 55=3,1255^{5} = 3{,}125 functions from Σ\Sigma to Σ\Sigma, of which 5!=1205! = 120 are bijections, that is 3.843.84 percent. In other words, more than 96 functions out of 100 are useless as a cipher, so drawing a table at random is not good enough.

b)

Reverse each arrow. c(C)=Ac(C)=A gives c−1(A)=Cc^{-1}(A)=C; c(D)=Bc(D)=B gives c−1(B)=Dc^{-1}(B)=D; c(A)=Cc(A)=C gives c−1(C)=Ac^{-1}(C)=A; c(E)=Dc(E)=D gives c−1(D)=Ec^{-1}(D)=E; c(B)=Ec(B)=E gives c−1(E)=Bc^{-1}(E)=B. EDBCA is decrypted letter by letter: E→BE \to B, D→ED \to E, B→DB \to D, C→AC \to A, A→CA \to C, which gives BEDAC. Check in the other direction: cc applied to BEDAC does give back EE, DD, BB, CC, AA. The trap is to read the table in the wrong direction, which produces meaningless text without any visible computation error: checking by re-encrypting is therefore mandatory.

c)

c(B)=Ec(B) = E and c−1(E)=Bc^{-1}(E) = B: the first equality holds. c−1(B)=Dc^{-1}(B) = D and c(D)=Bc(D) = B: so does the second. Both are required because they do not say the same thing. The equality c−1∘c=idΣc^{-1} \circ c = \mathrm{id}_{\Sigma} says that you always get back the ORIGINAL message, which corresponds to the injectivity of cc; the equality c∘c−1=idΣc \circ c^{-1} = \mathrm{id}_{\Sigma} says that every possible encrypted letter does come from a plaintext letter, which corresponds to surjectivity. A function satisfying only one of the two has only a left inverse or a right inverse, never an inverse, and on an infinite set both situations really occur: the doubling map n↦2nn \mapsto 2n, taken from N\mathbb{N} to N\mathbb{N}, has the left inverse m↦⌊m/2⌋m \mapsto \lfloor m/2 \rfloor but no right inverse, since 11 has no preimage.

d)

Apply cc then dd: A→C→DA \to C \to D, B→E→AB \to E \to A, C→A→BC \to A \to B, D→B→CD \to B \to C, E→D→EE \to D \to E. The table of d∘cd \circ c is therefore A→DA \to D, B→AB \to A, C→BC \to B, D→CD \to C, E→EE \to E, and its five images are distinct: it is a bijection, as guaranteed by the result of exercise 5 on the composition of two bijections. Its inverse is (d∘c)−1=c−1∘d−1(d \circ c)^{-1} = c^{-1} \circ d^{-1}, and the order is reversed: to undo two chained operations, you first undo the LAST one performed. Writing d−1∘c−1d^{-1} \circ c^{-1} is the classic error, and it shows up immediately: in the general case where the three sets differ, that composition does not even start from the right set.

e)

The function ee is not injective: AA and BB have the same image AA, CC and DD have the same image CC. To obtain AAAAA, each of the five positions must contain a letter whose image is AA, so AA or BB: that makes 25=322^{5} = 32 different plaintext messages that give the same ciphertext. Decryption is therefore impossible, not for lack of cleverness but on principle: ee, not being injective, has no inverse, and a recipient who must choose among 32 messages has no way to decide. It is exactly the argument the chapter on proof techniques uses against the universal lossless compressor, and here it is the same property, read on the function rather than on a count.

ABCDEciphertextABCDEplaintext

Exercise 7: Counting functions, injections and bijections

Three tools from the course are used here and not proved again: the multiplication principle and the kk-permutations n!(n−k)!\frac{n!}{(n-k)!}, covered in the counting set of the same course, and the inclusion-exclusion principle, covered in the set on sets. They are used as they are to count functions between finite sets.

The goal is the second thread of the set: an injection from AA to BB forces ∣A∣≤∣B∣\lvert A \rvert \le \lvert B \rvert, a surjection forces ∣A∣≥∣B∣\lvert A \rvert \ge \lvert B \rvert, a bijection forces equality. That is how two sets are compared without counting either one.

  • a) ∣A∣=3\lvert A \rvert = 3 and ∣B∣=5\lvert B \rvert = 5. How many functions from AA to BB? How many injections? How many bijections?
  • b) ∣A∣=4\lvert A \rvert = 4 and ∣B∣=3\lvert B \rvert = 3. How many functions? How many injections, and why? How many surjections, by inclusion-exclusion?
  • c) ∣A∣=∣B∣=4\lvert A \rvert = \lvert B \rvert = 4. How many functions, how many bijections, and what proportion?
  • d) State the three cardinality inequalities attached to the existence of an injection, a surjection and a bijection between finite sets.
  • e) AA and BB are finite with the SAME cardinality. Prove that an injective function f:A→Bf : A \to B is automatically surjective. Does this result still hold if AA and BB are infinite?

Type your answers, the page tells you right or wrong 0/13

a)
b)
c)
d)
e)
Show the solution

Answers

  • a) 53=1255^{3}=125 functions, 5×4×3=605 \times 4 \times 3 = 60 injections, 0 bijections
  • b) 34=813^{4}=81 functions, 0 injections by the pigeonhole principle, 81−48+3=3681-48+3=36 surjections
  • c) 44=2564^{4}=256 functions, 4!=244!=24 bijections, that is 9.3759.375 percent
  • d) Injection: ∣A∣≤∣B∣\lvert A \rvert \le \lvert B \rvert; surjection: ∣A∣≥∣B∣\lvert A \rvert \ge \lvert B \rvert; bijection: equality
  • e) Yes for finite sets, since f(A)f(A) is a subset of BB with the same cardinality; false for infinite sets, as 2Z⊂Z2\mathbb{Z} \subset \mathbb{Z} shows
a)

FUNCTIONS: each element of AA chooses its image freely among the 5 elements of BB, independently of the others, so 53=1255^{3} = 125 by the multiplication principle. INJECTIONS: the images must be pairwise distinct, so the first element has 5 choices, the second 4, the third 3, that is 5×4×3=605 \times 4 \times 3 = 60. You recognize the kk-permutation count 5!2!=60\frac{5!}{2!} = 60 from the counting set: counting the injections from AA to BB is exactly counting the words of 3 distinct letters over an alphabet of 5. BIJECTIONS: none, that is 0, since a bijection would require 3=53 = 5. The general formula to remember: ∣B∣∣A∣\lvert B \rvert^{\lvert A \rvert} functions and ∣B∣!(∣B∣−∣A∣)!\frac{\lvert B \rvert!}{(\lvert B \rvert - \lvert A \rvert)!} injections.

b)

FUNCTIONS: 34=813^{4} = 81. INJECTIONS: none, that is 0. The reason takes one line with the pigeonhole principle: 4 objects are placed in 3 boxes, so at least two share a box, so at least two elements have the same image. SURJECTIONS: remove from the 81 functions those that miss at least one element of BB. Those that miss a given element number 24=162^{4} = 16, and there are 3 ways to choose the missed element; those that miss two given elements number 14=11^{4} = 1, with 3 choices of pair; none misses all three, since a function must have images. Inclusion-exclusion gives 81−3×16+3×1=81−48+3=3681 - 3 \times 16 + 3 \times 1 = 81 - 48 + 3 = 36 surjections. The classic error is to forget the correction term +3+3 and answer 33: the functions that miss two elements would then have been subtracted twice.

c)

FUNCTIONS: 44=2564^{4} = 256. BIJECTIONS: these are the permutations of 4 objects, that is 4!=244! = 24. The proportion is 24256=0.09375\frac{24}{256} = 0.09375, that is 9.3759.375 percent. The figure is worth remembering for its lesson: even between two sets of the same size, a function picked at random does not have one chance in ten of being a bijection, and the proportion collapses as the cardinality grows, n!nn\frac{n!}{n^{n}} tending to zero very quickly.

d)

If an injection from AA to BB exists, then ∣A∣≤∣B∣\lvert A \rvert \le \lvert B \rvert: the images are ∣A∣\lvert A \rvert distinct elements of BB. If a surjection from AA onto BB exists, then ∣A∣≥∣B∣\lvert A \rvert \ge \lvert B \rvert: the fibres are ∣B∣\lvert B \rvert nonempty, pairwise disjoint subsets of AA. If a bijection exists, then ∣A∣=∣B∣\lvert A \rvert = \lvert B \rvert, by the previous two. These three statements are the comparison tool of the chapter: ∣A∣=∣B∣\lvert A \rvert = \lvert B \rvert is proved by EXHIBITING a bijection, which requires counting neither AA nor BB.

e)

Let f:A→Bf : A \to B be injective, with ∣A∣=∣B∣=n\lvert A \rvert = \lvert B \rvert = n finite. Injectivity gives ∣f(A)∣=∣A∣=n\lvert f(A) \rvert = \lvert A \rvert = n, since no image is repeated. Now f(A)f(A) is a subset of BB, which has nn elements: a subset of a FINITE set that has as many elements as the set itself is the whole set. So f(A)=Bf(A) = B and ff is surjective. For infinite sets the result fails, and it is the second step that breaks: 2Z⊂Z2\mathbb{Z} \subset \mathbb{Z}, the two are in bijection as exercise 4 showed, and yet 2Z≠Z2\mathbb{Z} \ne \mathbb{Z}. A proper subset of an infinite set can have the same cardinality as the set, which is even the definition of an infinite set. Exercise 10 exploits this point.

Exercise 8: Five statements to correct

Each one is false, and each one is a sentence actually heard in class. Say why it is false, give the exact correction and, when possible, a counterexample with numbers.

  • 1) “Every function has an inverse.”
  • 2) “Injective means strictly increasing.”
  • 3) “You can change the codomain without changing the nature of the function.”
  • 4) “A bijection between two infinite sets is impossible.”
  • 5) “Surjective means that every element of the domain has an image.”

Type your answers, the page tells you right or wrong 0/7

1)
2)
3)
4)
5)
Show the solution

Answers

  • 1) FALSE: only a bijection has an inverse; f(x)=x2f(x)=x^{2} on R\mathbb{R} has none
  • 2) FALSE: strictly monotonic implies injective, never the converse; x↦1/xx \mapsto 1/x shows it
  • 3) FALSE: injectivity does not move, surjectivity does; x↦x2x \mapsto x^{2} becomes surjective from R\mathbb{R} to R+\mathbb{R}^{+}
  • 4) FALSE: n↦2nn \mapsto 2n from Z\mathbb{Z} onto 2Z2\mathbb{Z} is one; Cantor only says there is none from N\mathbb{N} onto R\mathbb{R}
  • 5) FALSE: that is the definition of a function; surjective is about the CODOMAIN and preimages
1)

FALSE. Only BIJECTIONS have an inverse function. The confusion comes from the notation: f−1(Q)f^{-1}(Q), applied to a subset of the codomain, exists for every function and denotes the set of preimages, whereas f−1(y)f^{-1}(y), applied to an element, makes sense only if ff is bijective. Counterexample: f:R→Rf : \mathbb{R} \to \mathbb{R}, f(x)=x2f(x) = x^{2} has no inverse, since f−1({4})={−2,2}f^{-1}(\{4\}) = \{-2, 2\} contains two elements and f−1({−1})=∅f^{-1}(\{-1\}) = \varnothing. The complete correction: a function has an inverse if and only if it is bijective, and exercise 6 showed that this is checked through BOTH compositions.

2)

FALSE, twice over. First, being increasing requires an ORDER on the domain and on the codomain: between two arbitrary finite sets, such as {1,2,3}\{1,2,3\} and {a,b,c}\{a,b,c\}, the sentence simply makes no sense, whereas injectivity does. Next, even on R\mathbb{R}, the statement is false: x↦1xx \mapsto \frac{1}{x} on R∖{0}\mathbb{R}\setminus\{0\} is injective and not increasing, since −1<1-1 < 1 gives 1−1=−1<1=11\frac{1}{-1} = -1 < 1 = \frac{1}{1}, which looks increasing, whereas 1<21 < 2 gives 11=1>0.5=12\frac{1}{1} = 1 > 0.5 = \frac{1}{2}. The correct implication goes in one direction only: strictly monotonic on an interval implies injective, never the converse.

3)

FALSE, and it is the thread of the whole set. Changing the codomain does not affect injectivity, but it changes surjectivity: x↦x2x \mapsto x^{2} from R\mathbb{R} to R\mathbb{R} is not surjective, while the same rule from R\mathbb{R} to R+\mathbb{R}^{+} is. The precise correction is worth memorizing: shrinking the CODOMAIN can only help surjectivity and never changes injectivity; shrinking the DOMAIN can only help injectivity and never makes a function surjective. A function is given only together with its two sets; without them, the question of its nature is not even asked.

4)

FALSE. Exercise 4 already gives one: n↦2nn \mapsto 2n is a bijection from Z\mathbb{Z} onto 2Z2\mathbb{Z}, two infinite sets. Exercise 10 gives another, between N\mathbb{N} and Z\mathbb{Z}. It is in fact through a bijection that equality of two infinite cardinalities is DEFINED, since counting is impossible. What is true, and probably the origin of the confusion, is a much subtler statement due to Cantor: there is no bijection from N\mathbb{N} onto R\mathbb{R}, so not all infinities have the same size. Two infinite sets can be in bijection, and sometimes they are not.

5)

FALSE: the sentence describes the definition of a FUNCTION, not surjectivity. Every element of the domain has an image: that is the existence condition of exercise 1, and every function satisfies it without exception. Surjectivity is about the CODOMAIN: every element of the codomain has at least one PREIMAGE. The counterexample is immediate: f:{1,2,3}→{a,b,c,d}f : \{1,2,3\} \to \{a,b,c,d\} with f(1)=af(1)=a, f(2)=bf(2)=b, f(3)=cf(3)=c is a function, so every element of the domain does have an image, and it is not surjective since dd has no preimage. Confusing the two sentences leads to answering that every function is surjective, which empties the word of its meaning.

Exercise 9: Problem: the hash function that collapses

A hash table stores keys in slots by means of a function hh that goes from the universe of keys to {0,1,…,m−1}\{0, 1, \dots, m-1\}. Everything this chapter says about functions can be read on this single object, and the reading explains a programming decision that many people apply without knowing why.

The figure shows six keys k1k_1 to k6k_6 and three slots numbered 0, 1 and 2.

k1k2k3k4k5k6keys012slots
  • a) Read the figure and give h−1({0})h^{-1}(\{0\}), h−1({1})h^{-1}(\{1\}) and h−1({2})h^{-1}(\{2\}). Check that these three fibres form a partition of the six keys.
  • b) Is hh surjective? injective? Which of the two properties do we ask of a good hash function, and which one is out of reach?
  • c) We now hash all words of 8 characters taken from an alphabet of 62 symbols, into 1,024 slots. Compute the cardinality of the universe of keys, compare it with 1,024 and conclude about injectivity.
  • d) Can a key be recovered from its slot number alone? Phrase the answer with the word inverse, and say what consequence this has on what a hash table must store.
  • e) We want instead a directory that assigns each employee a file number, and that makes it possible to find the employee from the number. What property is required of the function, and what constraint does that put on the two cardinalities?

Type your answers, the page tells you right or wrong 0/10

a)
b)
c)
d)
e)
Show the solution

Answers

  • a) {k1,k3,k6}\{k_1,k_3,k_6\}, {k4}\{k_4\} and {k2,k5}\{k_2,k_5\}; partition checked, 3+1+2=63+1+2=6, and 2 collisions in slot 0
  • b) Surjective only; we want surjectivity and balanced fibres, injectivity is out of reach
  • c) 628=218,340,105,584,89662^{8} = 218{,}340{,}105{,}584{,}896 against 1,024: no injection possible, about 2.13×10112.13 \times 10^{11} keys per slot
  • d) No: without injectivity, no inverse; only the fibre is recovered, hence the key must be stored in the slot
  • e) A bijection, so the two cardinalities are equal; a counter, not a hash
a)

The figure gives h(k1)=0h(k_1) = 0, h(k2)=2h(k_2) = 2, h(k3)=0h(k_3) = 0, h(k4)=1h(k_4) = 1, h(k5)=2h(k_5) = 2 and h(k6)=0h(k_6) = 0. So h−1({0})={k1,k3,k6}h^{-1}(\{0\}) = \{k_1, k_3, k_6\}, h−1({1})={k4}h^{-1}(\{1\}) = \{k_4\} and h−1({2})={k2,k5}h^{-1}(\{2\}) = \{k_2, k_5\}. The three subsets are nonempty, pairwise disjoint, and their union is the set of six keys: 3+1+2=63 + 1 + 2 = 6. It is indeed a partition, the partition into fibres introduced in exercise 2. Slot 0 holds three keys, so two collisions, since a collision is one more key in a slot that is already occupied.

b)

hh is SURJECTIVE: all three slots receive at least one key, none is empty. It is NOT injective, since k1k_1 and k3k_3 share slot 0. That is exactly what we ask of a good hash function, and even a little more: we want surjectivity, so as not to waste slots, and above all fibres of comparable sizes, so that the cost of a search stays bounded. Injectivity, on the other hand, is out of reach as soon as the universe of keys is larger than the number of slots, which is always the case in practice: question c).

c)

The universe of keys has 628=218,340,105,584,89662^{8} = 218{,}340{,}105{,}584{,}896 words, about 2.18×10142.18 \times 10^{14}. There are 1,024 slots. An injection from the universe into the slots would require 628≤1,02462^{8} \le 1{,}024, which is false by eleven orders of magnitude: the quotient is about 2.13×10112.13 \times 10^{11} keys per slot on average. No hash function into 1,024 slots is therefore injective, and the argument uses nothing about the chosen function, only the two cardinalities. It is the inequality of exercise 7 read backwards: no injection is possible when the domain is larger than the codomain.

d)

No. hh, not being injective, has no inverse function: knowing h(x)h(x) does not determine xx, it only determines the FIBRE that xx belongs to, that is, the set of all keys that land in the same slot. The practical consequence is the one every implementation applies: a hash table STORES the key next to the value, in the slot. Without it, a search that lands on slot 0 would not know whether it has found k1k_1, k3k_3 or k6k_6. The key field is not a redundancy added for comfort, it is made mandatory by the non-injectivity of hh.

e)

We require a BIJECTION between the set of employees and the set of file numbers in use. Injectivity guarantees that two employees never have the same number, so that a number does identify one person; surjectivity guarantees that no assigned number is left orphaned. By exercise 7, this forces the two cardinalities to be equal, and that is precisely why a directory is NOT built with a hash function: hashing is designed to store quickly, not to identify. If you insist on a short number, it must be assigned by a counter, which is injective by construction, and not by a computation on the name.

Exercise 10: Problem: counting the infinite, from N to Z

Two sets have the same cardinality when there is a bijection from one onto the other. This definition requires no counting, and it is the only one that survives in the infinite: you do not count N\mathbb{N}, you set it against something else.

The figure shows one way to enumerate Z\mathbb{Z}, that is, to make it stand in line: rank 0 for the integer 0, then alternately a negative and a positive.

NZ001−1213−2425−363
  • a) Read the figure and give φ(0)\varphi(0) to φ(6)\varphi(6), then write φ:N→Z\varphi : \mathbb{N} \to \mathbb{Z} as a two-case formula depending on the parity of nn.
  • b) Give φ−1(5)\varphi^{-1}(5) and φ−1(−5)\varphi^{-1}(-5), then the formula for φ−1\varphi^{-1} depending on the sign of kk.
  • c) Why does the fact that φ−1\varphi^{-1} is a well-defined function from Z\mathbb{Z} to N\mathbb{N}, satisfying both compositions, suffice to prove that φ\varphi is bijective?
  • d) Let ψ:N→2N\psi : \mathbb{N} \to 2\mathbb{N}, ψ(n)=2n\psi(n) = 2n, where 2N2\mathbb{N} is the set of even natural numbers. Show that ψ\psi is bijective. Now 2N2\mathbb{N} is a PROPER subset of N\mathbb{N}: what do you conclude?
  • e) Exercise 7 proved that between FINITE sets of the same cardinality, injective implies surjective. At exactly which point does that proof break down for ψ\psi?

Type your answers, the page tells you right or wrong 0/9

a)
b)
c)
d)
e)
Show the solution

Answers

  • a) 0,−1,1,−2,2,−3,30, -1, 1, -2, 2, -3, 3; φ(n)=n2\varphi(n) = \frac{n}{2} if nn is even, −n+12-\frac{n+1}{2} if nn is odd
  • b) φ−1(5)=10\varphi^{-1}(5) = 10, φ−1(−5)=9\varphi^{-1}(-5) = 9; φ−1(k)=2k\varphi^{-1}(k) = 2k if k≥0k \ge 0, −2k−1-2k-1 if k<0k < 0
  • c) Both compositions equal the identity, which gives the injectivity and then the surjectivity of φ\varphi
  • d) ψ\psi is bijective: an infinite set can be in bijection with one of its proper subsets
  • e) The second step: a subset of an INFINITE set can have the same cardinality without being the whole set
a)

The figure gives φ(0)=0\varphi(0) = 0, φ(1)=−1\varphi(1) = -1, φ(2)=1\varphi(2) = 1, φ(3)=−2\varphi(3) = -2, φ(4)=2\varphi(4) = 2, φ(5)=−3\varphi(5) = -3 and φ(6)=3\varphi(6) = 3. Even ranks receive the positives, odd ranks the negatives. The formula is therefore φ(n)=n2\varphi(n) = \frac{n}{2} if nn is even, and φ(n)=−n+12\varphi(n) = -\frac{n+1}{2} if nn is odd. A check on two values, mandatory whenever you write a two-case formula: φ(4)=2\varphi(4) = 2 and φ(5)=−62=−3\varphi(5) = -\frac{6}{2} = -3, which matches the figure. The trap is to write −n2-\frac{n}{2} for the odd ranks, which does not even give an integer.

b)

To reach 55, which is positive, you need an even rank nn with n2=5\frac{n}{2} = 5, so n=10n = 10: φ−1(5)=10\varphi^{-1}(5) = 10. To reach −5-5, which is negative, you need an odd rank with −n+12=−5-\frac{n+1}{2} = -5, so n+1=10n + 1 = 10 and n=9n = 9: φ−1(−5)=9\varphi^{-1}(-5) = 9. The general formula is φ−1(k)=2k\varphi^{-1}(k) = 2k if k≥0k \ge 0, and φ−1(k)=−2k−1\varphi^{-1}(k) = -2k - 1 if k<0k < 0. Check on k=−5k = -5: −2×(−5)−1=10−1=9-2 \times (-5) - 1 = 10 - 1 = 9, as expected. The case k=0k = 0 goes with the positives and gives φ−1(0)=0\varphi^{-1}(0) = 0: a two-case formula requires you to say explicitly on which side the boundary falls, otherwise the function is not defined everywhere, or is defined twice.

c)

Because exhibiting a function gg satisfying g∘φ=idNg \circ \varphi = \mathrm{id}_{\mathbb{N}} AND φ∘g=idZ\varphi \circ g = \mathrm{id}_{\mathbb{Z}} is enough to establish bijectivity, without going back to the definitions. The first equality makes φ\varphi injective, by the result of exercise 5: if g∘φg \circ \varphi is injective, and the identity is, then φ\varphi is. The second makes φ\varphi surjective by the symmetric result: if φ∘g\varphi \circ g is surjective, then φ\varphi is. It is the most economical method of the chapter, and it is the one to use whenever a candidate inverse is easy to compute. Both checks are immediate here: nn even gives φ−1(n/2)=n\varphi^{-1}(n/2) = n, nn odd gives φ−1(−(n+1)/2)=(n+1)−1=n\varphi^{-1}(-(n+1)/2) = (n+1) - 1 = n.

d)

ψ\psi is injective: 2a=2b2a = 2b gives a=ba = b. It is surjective onto 2N2\mathbb{N}: every even natural number can be written 2k2k with kk a natural number, and this kk is the preimage. So ψ\psi is bijective, and N\mathbb{N} and 2N2\mathbb{N} have the same cardinality. Now 2N2\mathbb{N} is a proper subset of N\mathbb{N}, since 1, 3, 5 are not in it. Conclusion: an infinite set can be in bijection with one of its proper subsets, and it therefore has as many elements as half of itself. This is not a paradox, it is the very definition of an infinite set, Dedekind's, and it separates the finite from the infinite far more sharply than the vague idea of going on forever.

e)

The proof in exercise 7 had two steps. The first, ∣ψ(N)∣=∣N∣\lvert \psi(\mathbb{N}) \rvert = \lvert \mathbb{N} \rvert, still holds: injectivity loses no element. It is the SECOND that fails, the one saying that a subset of a finite set with as many elements as the set is the whole set. Here 2N2\mathbb{N} has the same cardinality as N\mathbb{N} and yet is not N\mathbb{N}. The word finite was therefore not a drafting precaution, it was the heart of the argument, and that is the lesson in method to take away: when a result carries a hypothesis, you must be able to say on which line it is used. Note finally that N\mathbb{N}, Z\mathbb{Z}, 2N2\mathbb{N} and even Q\mathbb{Q} all have the same cardinality, but that R\mathbb{R} is in bijection with none of them: not all infinities are equal.

Something missing from this set? A type of exercise your teacher gives, a problem you are stuck on, a mistake you spotted: tell me, I read every request.

Sending goes through your free space: that is how I can answer you and tell you when the exercise is added. An email is enough, no password. Create your space. Rather not create an account? Write to me directly.

What is it about?
I read every request myself, nobody else sees it. No need to write your name or your school.
When your request is dealt with, you hear about it by email and in your space.

By sending, you agree that I read your request to answer it. It is kept with your account, erased with it, and never published: privacy policy.

Previous chapter Set theory and relations, 201-N11 Next chapter Induction and recursion, 201-N11

© Ahmed Squalli Houssaini. Exercise set published at www.letuteurscientifique.ca/en/exercices/cegep-n11-injective-surjective-functions. Free for personal and classroom use; republishing it elsewhere requires written permission (legal notice).

See also

Looking for a discrete mathematics tutor in Montreal?

Get in touch for a first session. With a B.Sc. in computer science from McGill and an M.Sc. in applied computer science from Concordia, I connect injections and bijections to what they become later on: hash tables, primary keys in a database and encryption functions.

Site by Studio Squalli