TExcelTAD
Home › Calculus in Depth › Inverse Functions and Logarithms

Inverse Functions and Logarithms

An inverse function runs a function backwards: if ff sends xx to yy, then f−1f^{-1} sends yy back to xx. This lesson states when an inverse exists, how to find and graph it, and then uses it to define logarithms as the inverses of exponentials and the inverse trigonometric functions as inverses of restricted sines, cosines and tangents.

For a first look, see Composition and Inverses and Exponential and Logarithmic Functions; for log arithmetic, Logarithm Laws.

One-to-one functions

A function ff is one-to-one if it never takes the same value twice: x1≠x2x_1 \ne x_2 implies f(x1)≠f(x2)f(x_1) \ne f(x_2). Graphically, every horizontal line meets the graph at most once (the horizontal line test). Any function that is strictly increasing or strictly decreasing on its domain is one-to-one. x3x^3 is; x2x^2 on R\mathbb{R} is not, since f(−2)=f(2)f(-2) = f(2).

The inverse

If ff is one-to-one with domain AA and range BB, its inverse f−1f^{-1} has domain BB and range AA and is defined by

f−1(y)=x  ⟺  f(x)=yf^{-1}(y) = x \iff f(x) = y

so the cancellation equations hold: f−1(f(x))=xf^{-1}(f(x)) = x for xx in AA, and f(f−1(y))=yf(f^{-1}(y)) = y for yy in BB. Note that f−1f^{-1} means the inverse function, not 1/f1/f.

To find a formula: write y=f(x)y = f(x), solve for xx in terms of yy, then rename yy as xx. The graph of f−1f^{-1} is the reflection of the graph of ff in the line y=xy = x, because (a,b)(a, b) is on one graph exactly when (b,a)(b, a) is on the other.

A useful theorem (proved with the precise definition of continuity): if ff is one-to-one and continuous on an interval, then f−1f^{-1} is continuous too. In chapter 3 we will also see that the slope of f−1f^{-1} at b=f(a)b = f(a) is 1/f′(a)1/f'(a): reflecting in y=xy = x turns rise/run\text{rise}/\text{run} into run/rise\text{run}/\text{rise}.

python · try it yourself
import sympy as sp

x, y = sp.symbols('x y')
f = (3*x - 2) / (x + 1)          # domain x ≠ −1
sol = sp.solve(sp.Eq(y, f), x)
print("solutions for x:", sol)
finv = sol[0].subs(y, x)
print("f⁻¹(x) =", finv)
print("f⁻¹(f(7/2)) =", sp.simplify(finv.subs(x, f.subs(x, sp.Rational(7, 2)))))
print("f(f⁻¹(x))   =", sp.simplify(f.subs(x, finv)))
solutions for x: [(-y - 2)/(y - 3)]
f⁻¹(x) = (-x - 2)/(x - 3)
f⁻¹(f(7/2)) = 7/2
f(f⁻¹(x))   = x

The value 3 is missing from the range of ff (f(x)=3f(x) = 3 would need −2=3-2 = 3), and correspondingly f−1f^{-1} is undefined at x=3x = 3: the domain and range swap roles, exactly as the definition says.

Logarithms

For b>0b > 0, b≠1b \ne 1, the exponential bxb^x is one-to-one from R\mathbb{R} onto (0,∞)(0, \infty), so it has an inverse, the logarithm to base bb:

log⁡bx=y  ⟺  by=x(x>0)log⁡b(bx)=x for all x,blog⁡bx=x for x>0\begin{aligned} &\log_b x = y \iff b^y = x && (x > 0) \\ &\log_b(b^x) = x \text{ for all } x, \qquad b^{\log_b x} = x \text{ for } x > 0 \end{aligned}

The natural logarithm ln⁡x=log⁡ex\ln x = \log_e x is the inverse of exe^x, so ln⁡e=1\ln e = 1 and ln⁡1=0\ln 1 = 0. Each exponent law turns into a log law. For example, the product law: put u=log⁡bxu = \log_b x and v=log⁡byv = \log_b y, so x=bux = b^u and y=bvy = b^v. Then xy=bu+vxy = b^{u+v}, and taking log⁡b\log_b gives log⁡b(xy)=u+v\log_b(xy) = u + v.

log⁡b(xy)=log⁡bx+log⁡bylog⁡b(x/y)=log⁡bx−log⁡bylog⁡b(xr)=r⋅log⁡bxlog⁡bx=ln⁡x/ln⁡b(change of base)\begin{aligned} \log_b(xy) &= \log_b x + \log_b y & \log_b(x/y) &= \log_b x - \log_b y \\ \log_b(x^r) &= r \cdot \log_b x & \log_b x &= \ln x / \ln b \quad \text{(change of base)} \end{aligned}

Change of base explains the mystery slopes of the previous lesson. Since b=eln⁡bb = e^{\ln b}, we have bh=ehln⁡bb^h = e^{h \ln b}, and

bh−1h=ln⁡b⋅ehln⁡b−1hln⁡b→ln⁡b⋅1=ln⁡b\frac{b^h - 1}{h} = \ln b \cdot \frac{e^{h \ln b} - 1}{h \ln b} \to \ln b \cdot 1 = \ln b

so the slope of bxb^x at 0 is ln⁡b\ln b, which is 1 exactly when b=eb = e.

python · try it yourself
import math

print("ln 2 =", round(math.log(2), 6), "  ln 10 =", round(math.log(10), 6))
print("log₂ 1000 via change of base:", round(math.log(1000) / math.log(2), 6))
n = 2**1000
print("digits of 2^1000:", math.floor(1000 * math.log10(2)) + 1, "check:", len(str(n)))
big = 2**53 - 1
print("floor(log2(2^53 - 1)):", math.floor(math.log2(big)), " exact (bit_length - 1):", big.bit_length() - 1)
ln 2 = 0.693147   ln 10 = 2.302585
log₂ 1000 via change of base: 9.965784
digits of 2^1000: 302 check: 302
floor(log2(2^53 - 1)): 53  exact (bit_length - 1): 52

The number of decimal digits of a positive integer NN is ⌊log⁡10N⌋+1\lfloor \log_{10} N \rfloor + 1. For exact integer work, prefer integer methods such as bit_length(): floating-point logs are rounded, and near a power of the base the floor can come out wrong. The last line shows it: log⁡2(253−1)\log_2(2^{53} - 1) is just below 53, so its floor is 52, but the rounded float is exactly 53.0.

Inverse trigonometric functions

sin⁡x\sin x is not one-to-one on R\mathbb{R}, but it is on [−π/2,π/2][-\pi/2, \pi/2]. The inverse of that restricted sine is arcsin (sin⁡−1\sin^{-1}):

arcsin⁡x=y  ⟺  sin⁡y=x and −π/2≤y≤π/2(−1≤x≤1)arccos⁡x=y  ⟺  cos⁡y=x and 0≤y≤π(−1≤x≤1)arctan⁡x=y  ⟺  tan⁡y=x and −π/2<y<π/2(all real x)\begin{aligned} \arcsin x = y &\iff \sin y = x \text{ and } -\pi/2 \le y \le \pi/2 && (-1 \le x \le 1) \\ \arccos x = y &\iff \cos y = x \text{ and } 0 \le y \le \pi && (-1 \le x \le 1) \\ \arctan x = y &\iff \tan y = x \text{ and } -\pi/2 < y < \pi/2 && (\text{all real } x) \end{aligned}

The restriction means the cancellation law only works on the restricted interval: arcsin⁡(sin⁡x)=x\arcsin(\sin x) = x only for xx in [−π/2,π/2][-\pi/2, \pi/2].

python · try it yourself
import math

for x in [0.5, 1.5, 2.5, 3.0]:
    print(f"x = {x}:  asin(sin x) = {math.asin(math.sin(x)):.4f}")
print("atan2(1, -1) =", round(math.atan2(1, -1), 4), " atan(1/-1) =", round(math.atan(1 / -1), 4))
x = 0.5:  asin(sin x) = 0.5000
x = 1.5:  asin(sin x) = 1.5000
x = 2.5:  asin(sin x) = 0.6416
x = 3.0:  asin(sin x) = 0.1416
atan2(1, -1) = 2.3562  atan(1/-1) = -0.7854

For x=2.5x = 2.5 the answer is π−2.5≈0.6416\pi - 2.5 \approx 0.6416, the angle in [−π/2,π/2][-\pi/2, \pi/2] with the same sine. The same issue is why games use atan2(y, x), which looks at both signs to return the correct angle in (−π,π](-\pi, \pi], instead of atan(y/x), which cannot tell the point (−1,1)(-1, 1) from (1,−1)(1, -1) (atan2).

In software

Logarithms convert multiplication into addition: they are the reason binary search and balanced trees cost O(log⁡n)O(\log n), why log-probabilities are summed in ML and LLM decoding instead of multiplying tiny probabilities (which would underflow), and why decibels and the Richter scale exist (Logarithmic Growth and Scales). Inverse functions appear whenever a mapping is undone: screen-to-world transforms, decoding, atan2 for headings, and inverse-CDF sampling, where a uniform random number uu becomes a sample F−1(u)F^{-1}(u) from any distribution with CDF FF.

Exercises

Exercise 1: An inverse value without a formula

Explain why f(x)=x3+2xf(x) = x^3 + 2x is one-to-one and find f−1(3)f^{-1}(3) and (f−1)(12)(f^{-1})(12).

Answer

ff is strictly increasing, so one-to-one. f−1(3)=1f^{-1}(3) = 1 and f−1(12)=2f^{-1}(12) = 2.

Solution

x3x^3 and 2x2x are both strictly increasing, so their sum is: x1<x2x_1 < x_2 gives f(x1)<f(x2)f(x_1) < f(x_2). We need xx with f(x)=3f(x) = 3: try x=1x = 1, 1+2=31 + 2 = 3. For 12: x=2x = 2 gives 8+4=128 + 4 = 12. Solving the cubic for a general formula is not needed.

Exercise 2: An exponential equation

Solve e2x−5ex+6=0e^{2x} - 5e^x + 6 = 0.

Answer

x=ln⁡2x = \ln 2 or x=ln⁡3x = \ln 3.

Solution

Put u=ex>0u = e^x > 0: u2−5u+6=(u−2)(u−3)=0u^2 - 5u + 6 = (u - 2)(u - 3) = 0, so ex=2e^x = 2 or ex=3e^x = 3. Take ln⁡\ln: x=ln⁡2≈0.693x = \ln 2 \approx 0.693 or x=ln⁡3≈1.099x = \ln 3 \approx 1.099.

python · try it yourself
import sympy as sp

x = sp.symbols('x', real=True)
print(sp.solve(sp.exp(2*x) - 5*sp.exp(x) + 6, x))
[log(2), log(3)]

SymPy writes the natural logarithm as log.

Exercise 3: Log laws

Evaluate log⁡248−log⁡23\log_2 48 - \log_2 3 and 12log⁡381\frac{1}{2} \log_3 81 without a calculator.

Answer

4 and 2.

Solution
log⁡248−log⁡23=log⁡2(48/3)=log⁡216=412log⁡381=log⁡3811/2=log⁡39=2\begin{aligned} \log_2 48 - \log_2 3 &= \log_2(48/3) = \log_2 16 = 4 \\ \tfrac{1}{2} \log_3 81 &= \log_3 81^{1/2} = \log_3 9 = 2 \end{aligned}

Exercise 4: Restricted inverses

Find the exact values of arcsin⁡(sin⁡(5π/6))\arcsin(\sin(5\pi/6)) and arctan⁡(tan⁡(3π/4))\arctan(\tan(3\pi/4)).

Answer

π/6\pi/6 and −π/4-\pi/4.

Solution

sin⁡(5π/6)=12\sin(5\pi/6) = \frac{1}{2}, and the angle in [−π/2,π/2][-\pi/2, \pi/2] with sine 12\frac{1}{2} is π/6\pi/6. tan⁡(3π/4)=−1\tan(3\pi/4) = -1, and the angle in (−π/2,π/2)(-\pi/2, \pi/2) with tangent −1-1 is −π/4-\pi/4. Neither equals the original angle, because 5π/65\pi/6 and 3π/43\pi/4 lie outside the restricted intervals.

Exercise 5: Count digits in code

Use logarithms to find how many decimal digits 35003^{500} has, and check against len(str(3**500)).

Answer

239 digits.

Solution

Digits=⌊500⋅log⁡103⌋+1=⌊238.56…⌋+1=239\text{Digits} = \lfloor 500 \cdot \log_{10} 3 \rfloor + 1 = \lfloor 238.56\ldots \rfloor + 1 = 239.

python · try it yourself
import math

print(math.floor(500 * math.log10(3)) + 1, len(str(3**500)))
239 239

Test yourself

What is ln⁡(e5)+eln⁡2\ln(e^5) + e^{\ln 2}?

  1. 10
  2. 7
  3. e7e^7
  4. 5+e25 + e^2

What does f−1f^{-1} mean for a one-to-one function ff?

  1. 1/f1/f
  2. The function with f−1(y)=xf^{-1}(y) = x exactly when f(x)=yf(x) = y
  3. −f-f
  4. ff reflected in the xx-axis

What is arcsin⁡(sin⁡3)\arcsin(\sin 3), approximately?

  1. 3
  2. −0.1416
  3. 0.1416
  4. It is undefined