Inverse Functions and Logarithms
An inverse function runs a function backwards: if sends to , then sends back to . 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 is one-to-one if it never takes the same value twice: implies . 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. is; on is not, since .
The inverse
If is one-to-one with domain and range , its inverse has domain and range and is defined by
so the cancellation equations hold: for in , and for in . Note that means the inverse function, not .
To find a formula: write , solve for in terms of , then rename as . The graph of is the reflection of the graph of in the line , because is on one graph exactly when is on the other.
A useful theorem (proved with the precise definition of continuity): if is one-to-one and continuous on an interval, then is continuous too. In chapter 3 we will also see that the slope of at is : reflecting in turns into .
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 ( would need ), and correspondingly is undefined at : the domain and range swap roles, exactly as the definition says.
Logarithms
For , , the exponential is one-to-one from onto , so it has an inverse, the logarithm to base :
The natural logarithm is the inverse of , so and . Each exponent law turns into a log law. For example, the product law: put and , so and . Then , and taking gives .
Change of base explains the mystery slopes of the previous lesson. Since , we have , and
so the slope of at 0 is , which is 1 exactly when .
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 is . 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: is just below 53, so its floor is 52, but the rounded float is exactly 53.0.
Inverse trigonometric functions
is not one-to-one on , but it is on . The inverse of that restricted sine is arcsin ():
The restriction means the cancellation law only works on the restricted interval: only for in .
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 the answer is , the angle in 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 , instead of atan(y/x), which cannot tell the point from (atan2).
In software
Logarithms convert multiplication into addition: they are the reason binary search and balanced trees cost , 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 becomes a sample from any distribution with CDF .
Exercises
Exercise 1: An inverse value without a formula
Explain why is one-to-one and find and .
Answer
is strictly increasing, so one-to-one. and .
Solution
and are both strictly increasing, so their sum is: gives . We need with : try , . For 12: gives . Solving the cubic for a general formula is not needed.
Exercise 2: An exponential equation
Solve .
Answer
or .
Solution
Put : , so or . Take : or .
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 and without a calculator.
Answer
4 and 2.
Solution
Exercise 4: Restricted inverses
Find the exact values of and .
Answer
and .
Solution
, and the angle in with sine is . , and the angle in with tangent is . Neither equals the original angle, because and lie outside the restricted intervals.
Exercise 5: Count digits in code
Use logarithms to find how many decimal digits has, and check against len(str(3**500)).
Answer
239 digits.
Solution
.
import math
print(math.floor(500 * math.log10(3)) + 1, len(str(3**500)))239 239
Test yourself
What is ?
- 10
- 7
What does mean for a one-to-one function ?
- The function with exactly when
- reflected in the -axis
What is , approximately?
- 3
- −0.1416
- 0.1416
- It is undefined