MAT2033 · Week 4 · sets and functions

Functions: one-to-one, onto, inverse, composition, floor and ceiling

The template for proving a function is one-to-one and onto, inverse functions, composition, and floor/ceiling. A 1-1/onto proof and a floor/ceiling computation are almost certain on the midterm.

functiondomaincodomainrangeimagepreimageone-to-one (injective)onto (surjective)bijectioninverse functioncompositionidentity functionfloor functionceiling functionincreasing function

You know the concept of a function from high school math, but in discrete mathematics a function is not a formula, it is a mapping. An almost certain midterm question: “Determine whether ff is one-to-one, onto, both or neither. Prove your answers. If it is a bijection, find its inverse.” This question is solved with a template. It is usually accompanied by a floor/ceiling computation or a composition.

Golden rules:

  1. Function = exactly one output for every element of the domain. If there are two outputs or none, it is not a function.
  2. A 1-1 proof starts with f(x)=f(y)f(x) = f(y) and ends with x=yx = y.
  3. An onto proof starts with an arbitrary yy, you solve for xx, and you say that xx is in the domain.
  4. To say “not”, one concrete example is enough.
  5. The domain and codomain change the answer. The same formula can be a bijection on R\mathbb{R} and not on Z\mathbb{Z}.

Definition

Let AA and BB be nonempty sets. A function f:A→Bf: A \to B assigns to each aa in AA exactly one f(a)f(a) from BB.

TermMeaningFor f:Z→Zf: \mathbb{Z} \to \mathbb{Z}, f(x)=x2f(x) = x^2
Domainthe input set AAZ\mathbb{Z}
Codomainthe set of allowed outputs BBZ\mathbb{Z}
Rangethe values that actually appear, f(A)f(A){0,1,4,9,… }\{0, 1, 4, 9, \dots\}
Image of aaf(a)f(a)f(−3)=9f(-3) = 9
Preimage of SSf−1(S)={a∣f(a)∈S}f^{-1}(S) = \{a \mid f(a) \in S\}f−1({4,9})={−3,−2,2,3}f^{-1}(\{4, 9\}) = \{-3, -2, 2, 3\}

The range is always a subset of the codomain. The definition of preimage does not require an inverse function; it is defined for every function.

Things that are not functions: f:R→Rf: \mathbb{R} \to \mathbb{R}, f(x)=1/xf(x) = 1/x (no output for x=0x = 0), or f(x)=±xf(x) = \pm\sqrt{x} (two outputs). If a finite mapping is given, check that each input has exactly one arrow leaving it.

One-to-one, onto, bijection

PropertyDefinitionIntuition
One-to-one (injective)f(a)=f(b)⇒a=bf(a) = f(b) \Rightarrow a = btwo players never wear the same jersey number
Onto (surjective)∀b∈B ∃a∈A, f(a)=b\forall b \in B\ \exists a \in A,\ f(a) = bevery jersey number has been given to someone
Bijection1-1 and ontoplayers and numbers match exactly

The contrapositive form of the 1-1 definition is also used: a≠b⇒f(a)≠f(b)a \ne b \Rightarrow f(a) \ne f(b).

Shortcuts for finite sets. If ∣A∣>∣B∣\lvert A \rvert > \lvert B \rvert, ff cannot be 1-1 (pigeonhole). If ∣A∣<∣B∣\lvert A \rvert < \lvert B \rvert, it cannot be onto. If ∣A∣=∣B∣\lvert A \rvert = \lvert B \rvert, 1-1 and onto are the same thing; showing one is enough.

Template and worked examples

Example 1. f:R→Rf: \mathbb{R} \to \mathbb{R}, f(x)=4−3xf(x) = 4 - 3x.

One-to-one. Suppose f(x) = f(y). Then 4 − 3x = 4 − 3y, so −3x = −3y
and x = y. Hence f is one-to-one.
Onto. Let y ∈ R be arbitrary. Take x = (4 − y)/3. Then x ∈ R and
f(x) = 4 − 3·(4 − y)/3 = 4 − (4 − y) = y. Hence f is onto.
So f is a bijection, and f⁻¹(y) = (4 − y)/3.

Where did you find xx? On scratch paper you solved y=4−3xy = 4 - 3x for xx. On the exam, write the result, not the scratch work, and don’t forget to say "x∈Rx \in \mathbb{R}".

Example 2. g:Z→Zg: \mathbb{Z} \to \mathbb{Z}, g(n)=n2g(n) = n^2.

  • Not 1-1: g(2)=g(−2)=4g(2) = g(-2) = 4, but 2≠−22 \ne -2.
  • Not onto: since g(n)≥0g(n) \ge 0, −1-1 never appears. (Or 2: it is not a perfect square.)

Example 3. h:Z→Zh: \mathbb{Z} \to \mathbb{Z}, h(n)=⌊n/2⌋h(n) = \lfloor n/2 \rfloor.

  • Not 1-1: h(4)=h(5)=2h(4) = h(5) = 2.
  • Onto: for m∈Zm \in \mathbb{Z} take n=2mn = 2m, h(2m)=mh(2m) = m.

Example 4. f:Z→Zf: \mathbb{Z} \to \mathbb{Z}, f(n)=2n+3f(n) = 2n + 3 versus f:R→Rf: \mathbb{R} \to \mathbb{R}, f(x)=2x+3f(x) = 2x + 3. Both are 1-1. The real version is onto (x=y−32x = \tfrac{y-3}{2}). The integer version is not onto: 2n+32n + 3 is always odd, and no integer maps to 00.

PITFALL · Skipping that xx is in the domain in an onto proof. You found x=y−32x = \tfrac{y - 3}{2}. If the domain is R\mathbb{R}, no problem. If the domain is Z\mathbb{Z}, this xx is not an integer for most yy, and the proof collapses. The sentence “Take x=⋯∈Ax = \dots \in A” is half the marks.

Inverse function

If ff is a bijection, f−1:B→Af^{-1}: B \to A, f−1(b)=a  ⟺  f(a)=bf^{-1}(b) = a \iff f(a) = b. If it is not a bijection, there is no inverse function: if it is not 1-1, some bb has two ways back; if it is not onto, some bb have no way back at all.

Method: write y=f(x)y = f(x) and isolate xx. Check: f−1(f(x))=xf^{-1}(f(x)) = x.

For a finite function, reverse the arrows: if f(1)=cf(1) = c, f(2)=af(2) = a, f(3)=bf(3) = b then f−1(a)=2f^{-1}(a) = 2, f−1(b)=3f^{-1}(b) = 3, f−1(c)=1f^{-1}(c) = 1.

Composition

For f:A→Bf: A \to B, g:B→Cg: B \to C, (g∘f)(x)=g(f(x))(g \circ f)(x) = g(f(x)). It is read right to left: first ff, then gg.

Example. f(x)=x+2f(x) = x + 2, g(x)=3x2g(x) = 3x^2. (g∘f)(x)=3(x+2)2(g \circ f)(x) = 3(x + 2)^2, (f∘g)(x)=3x2+2(f \circ g)(x) = 3x^2 + 2. In general g∘f≠f∘gg \circ f \ne f \circ g.

Useful facts:

  • If ff and gg are 1-1, then g∘fg \circ f is also 1-1. If both are onto, g∘fg \circ f is also onto.
  • If g∘fg \circ f is 1-1, then ff is 1-1 (question 12). If g∘fg \circ f is onto, then gg is onto.
  • f−1∘f=ιAf^{-1} \circ f = \iota_A (identity function), f∘f−1=ιBf \circ f^{-1} = \iota_B.

Floor and ceiling

FunctionDefinitionEquivalent inequality
⌊x⌋\lfloor x \rfloor (floor)the greatest integer less than or equal to xx⌊x⌋=n  ⟺  n≤x<n+1\lfloor x \rfloor = n \iff n \le x < n + 1
⌈x⌉\lceil x \rceil (ceiling)the smallest integer greater than or equal to xx⌈x⌉=n  ⟺  n−1<x≤n\lceil x \rceil = n \iff n - 1 < x \le n
⌊2.4⌋ = 2     ⌈2.4⌉ = 3
⌊−2.4⌋ = −3   ⌈−2.4⌉ = −2     (for negatives, "chop off the decimals" is WRONG)
⌊3⌋ = ⌈3⌉ = 3

Properties (nn an integer): ⌊x+n⌋=⌊x⌋+n\lfloor x + n \rfloor = \lfloor x \rfloor + n, ⌈x+n⌉=⌈x⌉+n\lceil x + n \rceil = \lceil x \rceil + n, ⌈−x⌉=−⌊x⌋\lceil -x \rceil = -\lfloor x \rfloor, x−1<⌊x⌋≤x≤⌈x⌉<x+1x - 1 < \lfloor x \rfloor \le x \le \lceil x \rceil < x + 1. Careful: ⌊x+y⌋\lfloor x + y \rfloor is in general not ⌊x⌋+⌊y⌋\lfloor x \rfloor + \lfloor y \rfloor (x=y=0.5x = y = 0.5: 11 versus 00).

Worked proof: ⌊2x⌋=⌊x⌋+⌊x+12⌋\lfloor 2x \rfloor = \lfloor x \rfloor + \lfloor x + \tfrac12 \rfloor

Write x=n+εx = n + \varepsilon, n=⌊x⌋n = \lfloor x \rfloor, 0≤ε<10 \le \varepsilon < 1. Two cases:

Case 1: 0 ≤ ε < 1/2.
  2x = 2n + 2ε with 0 ≤ 2ε < 1, so ⌊2x⌋ = 2n.
  x + 1/2 = n + (ε + 1/2) with 1/2 ≤ ε + 1/2 < 1, so ⌊x + 1/2⌋ = n.
  Right side: n + n = 2n. Equal.
Case 2: 1/2 ≤ ε < 1.
  2x = 2n + 1 + (2ε − 1) with 0 ≤ 2ε − 1 < 1, so ⌊2x⌋ = 2n + 1.
  x + 1/2 = (n + 1) + (ε − 1/2) with 0 ≤ ε − 1/2 < 1/2, so ⌊x + 1/2⌋ = n + 1.
  Right side: n + (n + 1) = 2n + 1. Equal.  ∎

The general trick in floor/ceiling proofs: write xx as “integer part + fraction” and split into cases by the range of the fraction.

Common mistakes

Wrong ideaThe truth
Range = codomainThe range is a subset of the codomain; if equal, the function is onto
Trying a few values for a 1-1 prooff(x)=f(y)⇒x=yf(x) = f(y) \Rightarrow x = y is general algebra
Not saying x∈Ax \in A in an onto proofIf the domain is Z\mathbb{Z}, the xx you found may not be an integer
2x+32x + 3 is a bijection everywhereIt is not onto on Z→Z\mathbb{Z} \to \mathbb{Z}
(g∘f)(x)=f(g(x))(g \circ f)(x) = f(g(x))It is g(f(x))g(f(x)); ff first
f−1(y)=1/f(y)f^{-1}(y) = 1/f(y)The inverse function is not the multiplicative inverse
⌊−2.3⌋=−2\lfloor -2.3 \rfloor = -2It is −3-3; floor always goes down
⌊x+y⌋=⌊x⌋+⌊y⌋\lfloor x + y \rfloor = \lfloor x \rfloor + \lfloor y \rfloorGuaranteed only if one of them is an integer
Writing the inverse of a function that is not a bijectionThe inverse exists only for a bijection

Test yourself

Exam-style questions. Solve them on paper first, then reveal the answer.

Question 1easy

Evaluate ⌊−3.7⌋\lfloor -3.7 \rfloor, ⌈−3.7⌉\lceil -3.7 \rceil, ⌊5.2⌋\lfloor 5.2 \rfloor, ⌈5⌉\lceil 5 \rceil and ⌊−12+⌈32⌉⌋\lfloor -\tfrac12 + \lceil \tfrac32 \rceil \rfloor.

Show answer
−4, −3, 5, 5, 1

Think on the number line: floor goes left (down), ceiling goes right (up). The integer to the left of −3.7-3.7 is −4-4, to the right is −3-3. The floor and the ceiling of an integer are both itself: ⌈5⌉=5\lceil 5 \rceil = 5. The last expression from the inside out: ⌈1.5⌉=2\lceil 1.5 \rceil = 2, −0.5+2=1.5-0.5 + 2 = 1.5, ⌊1.5⌋=1\lfloor 1.5 \rfloor = 1.

Question 2easy

Let f:{1,2,3,4}→{a,b,c}f: \{1, 2, 3, 4\} \to \{a, b, c\} with f(1)=bf(1) = b, f(2)=af(2) = a, f(3)=bf(3) = b, f(4)=cf(4) = c. Find the range of ff. Is ff one-to-one? Onto?

Show answer
Range {a, b, c}; onto but not one-to-one

The values that appear are a,b,ca, b, c: the range equals the codomain, so it is onto. But f(1)=f(3)=bf(1) = f(3) = b, two different inputs give the same output: it is not one-to-one. No function from a 4-element set to a 3-element set can be 1-1 anyway.

Question 3medium

Let f:Z→Zf: \mathbb{Z} \to \mathbb{Z}, f(n)=3n−1f(n) = 3n - 1. Is ff one-to-one? Onto? Prove your answers.

Show answer
One-to-one, not onto (0 has no preimage)

1-1: Suppose f(m)=f(n)f(m) = f(n). Then 3m−1=3n−13m - 1 = 3n - 1, so 3m=3n3m = 3n, m=nm = n.
Not onto: for y=0y = 0, 3n−1=0⇒n=13∉Z3n - 1 = 0 \Rightarrow n = \tfrac13 \notin \mathbb{Z}. No integer maps to 0. If the domain were R\mathbb{R} it would be onto; watch the domain.

Question 4medium

Let f:R→Rf: \mathbb{R} \to \mathbb{R}, f(x)=x2−4xf(x) = x^2 - 4x. Is ff one-to-one? Onto? Justify.

Show answer
Neither: f(0) = f(4) = 0, and f(x) ≥ −4 so −5 is not attained

Not 1-1: f(0)=0f(0) = 0, f(4)=16−16=0f(4) = 16 - 16 = 0, but 0≠40 \ne 4. Not onto: x2−4x=(x−2)2−4≥−4x^2 - 4x = (x - 2)^2 - 4 \ge -4. For example −5-5 never appears. To claim "not", one concrete example is enough.

Question 5medium

Show that f:R→Rf: \mathbb{R} \to \mathbb{R}, f(x)=7−2xf(x) = 7 - 2x is a bijection and find f−1f^{-1}.

Show answer
f⁻¹(y) = (7 − y)/2

1-1: 7−2x=7−2y⇒−2x=−2y⇒x=y7 - 2x = 7 - 2y \Rightarrow -2x = -2y \Rightarrow x = y.
Onto: Let y∈Ry \in \mathbb{R}. Take x=7−y2∈Rx = \tfrac{7 - y}{2} \in \mathbb{R}. Then f(x)=7−(7−y)=yf(x) = 7 - (7 - y) = y.
Since it is a bijection the inverse exists, and we already found it in the onto step: f−1(y)=7−y2f^{-1}(y) = \tfrac{7 - y}{2}. Check: f−1(f(3))=f−1(1)=3f^{-1}(f(3)) = f^{-1}(1) = 3.

Question 6medium

Let f(x)=2x+1f(x) = 2x + 1 and g(x)=x2−3g(x) = x^2 - 3 on R\mathbb{R}. Find (f∘g)(x)(f \circ g)(x), (g∘f)(x)(g \circ f)(x), (f∘g)(2)(f \circ g)(2) and (g∘f)(2)(g \circ f)(2).

Show answer
(f∘g)(x) = 2x² − 5, (g∘f)(x) = 4x² + 4x − 2, (f∘g)(2) = 3, (g∘f)(2) = 22

f∘gf \circ g: first gg, then ff. f(g(x))=2(x2−3)+1=2x2−5f(g(x)) = 2(x^2 - 3) + 1 = 2x^2 - 5. g(f(x))=(2x+1)2−3=4x2+4x−2g(f(x)) = (2x + 1)^2 - 3 = 4x^2 + 4x - 2. At x=2x = 2: f(g(2))=f(1)=3f(g(2)) = f(1) = 3, g(f(2))=g(5)=22g(f(2)) = g(5) = 22. They differ: composition is not commutative.

Question 7hard

Let f:R−{1}→R−{2}f: \mathbb{R} - \{1\} \to \mathbb{R} - \{2\}, f(x)=2x+1x−1f(x) = \dfrac{2x + 1}{x - 1}. Prove that ff is a bijection and find f−1f^{-1}.

Show answer
f⁻¹(y) = (y + 1)/(y − 2)

1-1: if 2x+1x−1=2y+1y−1\tfrac{2x+1}{x-1} = \tfrac{2y+1}{y-1}, cross-multiplying gives (2x+1)(y−1)=(2y+1)(x−1)(2x+1)(y-1) = (2y+1)(x-1), that is 2xy−2x+y−1=2xy−2y+x−12xy - 2x + y - 1 = 2xy - 2y + x - 1. Simplifying gives −3x=−3y-3x = -3y, x=yx = y.
Onto: let y≠2y \ne 2 be given. Solve y=2x+1x−1y = \tfrac{2x+1}{x-1}: yx−y=2x+1⇒x(y−2)=y+1⇒x=y+1y−2yx - y = 2x + 1 \Rightarrow x(y - 2) = y + 1 \Rightarrow x = \tfrac{y+1}{y-2}. It is defined because y≠2y \ne 2. Also x≠1x \ne 1 (otherwise y+1=y−2y + 1 = y - 2). So xx is in the domain and f(x)=yf(x) = y.f−1(y)=y+1y−2f^{-1}(y) = \tfrac{y+1}{y-2}. You can see why 2 is removed from the codomain: there is no solution for y=2y = 2.

Question 8medium

Let f:Z→Zf: \mathbb{Z} \to \mathbb{Z}, f(n)=⌈n/2⌉f(n) = \lceil n/2 \rceil. Is ff one-to-one? Onto?

Show answer
Onto but not one-to-one

Not 1-1: f(1)=⌈0.5⌉=1f(1) = \lceil 0.5 \rceil = 1 and f(2)=1f(2) = 1. Onto: for any m∈Zm \in \mathbb{Z} take n=2mn = 2m, f(2m)=⌈m⌉=mf(2m) = \lceil m \rceil = m.

Question 9easy

Data is stored in bytes of 8 bits. How many bytes are needed for 1000 bits? For 1001 bits?

Show answer
125 and 126

A partial byte still takes up a whole byte, so round up: ⌈1000/8⌉=⌈125⌉=125\lceil 1000/8 \rceil = \lceil 125 \rceil = 125, ⌈1001/8⌉=⌈125.125⌉=126\lceil 1001/8 \rceil = \lceil 125.125 \rceil = 126. "How many are needed" questions use ceiling, "how many fit completely" questions use floor.

Question 10hard

Prove that ⌈x+n⌉=⌈x⌉+n\lceil x + n \rceil = \lceil x \rceil + n for every real xx and every integer nn.

Show answer
Let m = ⌈x⌉, so m − 1 < x ≤ m; then m + n − 1 < x + n ≤ m + n, so ⌈x + n⌉ = m + n.

Ceiling definition: ⌈y⌉=m\lceil y \rceil = m if and only if m−1<y≤mm - 1 < y \le m and mm is an integer. Let m=⌈x⌉m = \lceil x \rceil: m−1<x≤mm - 1 < x \le m. Add nn to every side: (m+n)−1<x+n≤m+n(m + n) - 1 < x + n \le m + n. Since m+nm + n is an integer, by the definition ⌈x+n⌉=m+n=⌈x⌉+n\lceil x + n \rceil = m + n = \lceil x \rceil + n. ∎ In floor/ceiling proofs always use this inequality definition.

Question 11medium

How many functions are there from {1,2,3}\{1, 2, 3\} to {a,b}\{a, b\}? How many of them are one-to-one? How many are onto?

Show answer
8 functions, 0 one-to-one, 6 onto

There are 2 choices for each input: 23=82^3 = 8. To be 1-1 you need 3 different outputs but the codomain has 2 elements: 0. The only functions that are not onto are the 2 constant functions that send everything to aa or everything to bb: 8−2=68 - 2 = 6.

Question 12hard

Let f:A→Bf: A \to B and g:B→Cg: B \to C. Prove that if g∘fg \circ f is one-to-one, then ff is one-to-one.

Show answer
f(x) = f(y) ⇒ g(f(x)) = g(f(y)) ⇒ x = y

Suppose f(x)=f(y)f(x) = f(y) for x,y∈Ax, y \in A. Apply gg to both sides: g(f(x))=g(f(y))g(f(x)) = g(f(y)), i.e. (g∘f)(x)=(g∘f)(y)(g \circ f)(x) = (g \circ f)(y). Since g∘fg \circ f is one-to-one, x=yx = y. Hence ff is one-to-one. ∎ Note: gg does not need to be 1-1; this claim is only about ff.

Verification: Finite functions were counted by generating all mappings; 1-1/onto claims over Z were checked in the window -300..300, inverses and compositions at sample points, and floor/ceiling identities on 50,000 random values with node (verify/MAT2033/04.mjs).

Review card

f: A→B: EVERY element of A gets EXACTLY ONE output. A domain, B codomain, the values that appear are the range. 1-1 proof: "Suppose f(x)=f(y). Then ... so x=y." NOT 1-1: a concrete example f(a)=f(b), a≠b (for x²: f(1)=f(−1)) Onto proof: "Let y∈B. Take x=(solve y=f(x) for x). x∈A and f(x)=y." NOT onto: find a y that never appears (3n−1=0 → n=1/3 ∉ Z) The domain matters: 2x+3 is a bijection R→R, not onto Z→Z Bijection ⇔ inverse exists. f⁻¹: solve y=f(x) for x. Check f⁻¹(f(x))=x (g∘f)(x) = g(f(x)), f FIRST. In general g∘f ≠ f∘g g∘f 1-1 ⇒ f 1-1 g∘f onto ⇒ g onto Finite, |A|=|B|: 1-1 ⇔ onto. If |A|>|B| it cannot be 1-1. ⌊x⌋=n ⇔ n ≤ x < n+1 ⌈x⌉=n ⇔ n−1 < x ≤ n ⌊−2.3⌋=−3 ⌈−2.3⌉=−2 ⌊x+n⌋=⌊x⌋+n ⌈−x⌉=−⌊x⌋ "how many are needed" is ceiling, "how many fit completely" is floor