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 f 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:
Function = exactly one output for every element of the domain. If there are two outputs or none, it is not a function.
A 1-1 proof starts with f(x)=f(y) and ends with x=y.
An onto proof starts with an arbitrary y, you solve for x, and you say that x is in the domain.
To say “not”, one concrete example is enough.
The domain and codomain change the answer. The same formula can be a bijection on R and not on Z.
Definition
Let A and B be nonempty sets. A functionf:A→B assigns to each a in A exactly one f(a) from B.
Term
Meaning
For f:Z→Z, f(x)=x2
Domain
the input set A
Z
Codomain
the set of allowed outputs B
Z
Range
the values that actually appear, f(A)
{0,1,4,9,…}
Image of a
f(a)
f(−3)=9
Preimage of S
f−1(S)={a∣f(a)∈S}
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→R, f(x)=1/x (no output for x=0), or f(x)=±x (two outputs). If a finite mapping is given, check that each input has exactly one arrow leaving it.
One-to-one, onto, bijection
Property
Definition
Intuition
One-to-one (injective)
f(a)=f(b)⇒a=b
two players never wear the same jersey number
Onto (surjective)
∀b∈B∃a∈A,f(a)=b
every jersey number has been given to someone
Bijection
1-1 and onto
players and numbers match exactly
The contrapositive form of the 1-1 definition is also used: a=b⇒f(a)=f(b).
Shortcuts for finite sets. If ∣A∣>∣B∣, f cannot be 1-1 (pigeonhole). If ∣A∣<∣B∣, it cannot be onto. If ∣A∣=∣B∣, 1-1 and onto are the same thing; showing one is enough.
Template and worked examples
Example 1.f:R→R, f(x)=4−3x.
One-to-one. Suppose f(x) = f(y). Then 4 − 3x = 4 − 3y, so −3x = −3yand x = y. Hence f is one-to-one.Onto. Let y ∈ R be arbitrary. Take x = (4 − y)/3. Then x ∈ R andf(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 x? On scratch paper you solved y=4−3x for x. On the exam, write the result, not the scratch work, and don’t forget to say "x∈R".
Example 2.g:Z→Z, g(n)=n2.
Not 1-1: g(2)=g(−2)=4, but 2=−2.
Not onto: since g(n)≥0, −1 never appears. (Or 2: it is not a perfect square.)
Example 3.h:Z→Z, h(n)=⌊n/2⌋.
Not 1-1: h(4)=h(5)=2.
Onto: for m∈Z take n=2m, h(2m)=m.
Example 4.f:Z→Z, f(n)=2n+3 versus f:R→R, f(x)=2x+3. Both are 1-1. The real version is onto (x=2y−3). The integer version is not onto: 2n+3 is always odd, and no integer maps to 0.
PITFALL · Skipping that x is in the domain in an onto proof. You found x=2y−3. If the domain is R, no problem. If the domain is Z, this x is not an integer for most y, and the proof collapses. The sentence “Take x=⋯∈A” is half the marks.
Inverse function
If f is a bijection, f−1:B→A, f−1(b)=a⟺f(a)=b. If it is not a bijection, there is no inverse function: if it is not 1-1, some b has two ways back; if it is not onto, some b have no way back at all.
Method: write y=f(x) and isolate x. Check: f−1(f(x))=x.
For a finite function, reverse the arrows: if f(1)=c, f(2)=a, f(3)=b then f−1(a)=2, f−1(b)=3, f−1(c)=1.
Composition
For f:A→B, g:B→C, (g∘f)(x)=g(f(x)). It is read right to left: first f, then g.
Example.f(x)=x+2, g(x)=3x2. (g∘f)(x)=3(x+2)2, (f∘g)(x)=3x2+2. In general g∘f=f∘g.
Useful facts:
If f and g are 1-1, then g∘f is also 1-1. If both are onto, g∘f is also onto.
If g∘f is 1-1, then f is 1-1 (question 12). If g∘f is onto, then g is onto.
f−1∘f=ιA (identity function), f∘f−1=ιB.
Floor and ceiling
Function
Definition
Equivalent inequality
⌊x⌋ (floor)
the greatest integer less than or equal to x
⌊x⌋=n⟺n≤x<n+1
⌈x⌉ (ceiling)
the smallest integer greater than or equal to x
⌈x⌉=n⟺n−1<x≤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 (n an integer): ⌊x+n⌋=⌊x⌋+n, ⌈x+n⌉=⌈x⌉+n, ⌈−x⌉=−⌊x⌋, x−1<⌊x⌋≤x≤⌈x⌉<x+1. Careful: ⌊x+y⌋ is in general not ⌊x⌋+⌊y⌋ (x=y=0.5: 1 versus 0).
Worked proof: ⌊2x⌋=⌊x⌋+⌊x+21⌋
Write x=n+ε, n=⌊x⌋, 0≤ε<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 x as “integer part + fraction” and split into cases by the range of the fraction.
Common mistakes
Wrong idea
The truth
Range = codomain
The range is a subset of the codomain; if equal, the function is onto
Trying a few values for a 1-1 proof
f(x)=f(y)⇒x=y is general algebra
Not saying x∈A in an onto proof
If the domain is Z, the x you found may not be an integer
2x+3 is a bijection everywhere
It is not onto on Z→Z
(g∘f)(x)=f(g(x))
It is g(f(x)); f first
f−1(y)=1/f(y)
The inverse function is not the multiplicative inverse
⌊−2.3⌋=−2
It is −3; floor always goes down
⌊x+y⌋=⌊x⌋+⌊y⌋
Guaranteed only if one of them is an integer
Writing the inverse of a function that is not a bijection
The 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⌋, ⌈−3.7⌉, ⌊5.2⌋, ⌈5⌉ and ⌊−21+⌈23⌉⌋.
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 is −4, to the right is −3. The floor and the ceiling of an integer are both itself: ⌈5⌉=5. The last expression from the inside out: ⌈1.5⌉=2, −0.5+2=1.5, ⌊1.5⌋=1.
Question 2easy
Let f:{1,2,3,4}→{a,b,c} with f(1)=b, f(2)=a, f(3)=b, f(4)=c. Find the range of f. Is f one-to-one? Onto?
Show answer
Range {a, b, c}; onto but not one-to-one
The values that appear are a,b,c: the range equals the codomain, so it is onto. But f(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→Z, f(n)=3n−1. Is f 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). Then 3m−1=3n−1, so 3m=3n, m=n. Not onto: for y=0, 3n−1=0⇒n=31∈/Z. No integer maps to 0. If the domain were R it would be onto; watch the domain.
Question 4medium
Let f:R→R, f(x)=x2−4x. Is f 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)=0, f(4)=16−16=0, but 0=4. Not onto: x2−4x=(x−2)2−4≥−4. For example −5 never appears. To claim "not", one concrete example is enough.
Question 5medium
Show that f:R→R, f(x)=7−2x is a bijection and find f−1.
Show answer
f⁻¹(y) = (7 − y)/2
1-1: 7−2x=7−2y⇒−2x=−2y⇒x=y. Onto: Let y∈R. Take x=27−y∈R. Then f(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)=27−y. Check: f−1(f(3))=f−1(1)=3.
Question 6medium
Let f(x)=2x+1 and g(x)=x2−3 on R. Find (f∘g)(x), (g∘f)(x), (f∘g)(2) and (g∘f)(2).
f∘g: first g, then f. f(g(x))=2(x2−3)+1=2x2−5. g(f(x))=(2x+1)2−3=4x2+4x−2. At x=2: f(g(2))=f(1)=3, g(f(2))=g(5)=22. They differ: composition is not commutative.
Question 7hard
Let f:R−{1}→R−{2}, f(x)=x−12x+1. Prove that f is a bijection and find f−1.
Show answer
f⁻¹(y) = (y + 1)/(y − 2)
1-1: if x−12x+1=y−12y+1, cross-multiplying gives (2x+1)(y−1)=(2y+1)(x−1), that is 2xy−2x+y−1=2xy−2y+x−1. Simplifying gives −3x=−3y, x=y. Onto: let y=2 be given. Solve y=x−12x+1: yx−y=2x+1⇒x(y−2)=y+1⇒x=y−2y+1. It is defined because y=2. Also x=1 (otherwise y+1=y−2). So x is in the domain and f(x)=y.f−1(y)=y−2y+1. You can see why 2 is removed from the codomain: there is no solution for y=2.
Question 8medium
Let f:Z→Z, f(n)=⌈n/2⌉. Is f one-to-one? Onto?
Show answer
Onto but not one-to-one
Not 1-1: f(1)=⌈0.5⌉=1 and f(2)=1. Onto: for any m∈Z take n=2m, f(2m)=⌈m⌉=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, ⌈1001/8⌉=⌈125.125⌉=126. "How many are needed" questions use ceiling, "how many fit completely" questions use floor.
Question 10hard
Prove that ⌈x+n⌉=⌈x⌉+n for every real x and every integer n.
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 if and only if m−1<y≤m and m is an integer. Let m=⌈x⌉: m−1<x≤m. Add n to every side: (m+n)−1<x+n≤m+n. Since m+n is an integer, by the definition ⌈x+n⌉=m+n=⌈x⌉+n. ∎ In floor/ceiling proofs always use this inequality definition.
Question 11medium
How many functions are there from {1,2,3} to {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=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 a or everything to b: 8−2=6.
Question 12hard
Let f:A→B and g:B→C. Prove that if g∘f is one-to-one, then f is one-to-one.
Show answer
f(x) = f(y) ⇒ g(f(x)) = g(f(y)) ⇒ x = y
Suppose f(x)=f(y) for x,y∈A. Apply g to both sides: g(f(x))=g(f(y)), i.e. (g∘f)(x)=(g∘f)(y). Since g∘f is one-to-one, x=y. Hence f is one-to-one. ∎ Note: g does not need to be 1-1; this claim is only about f.
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