4. Exponentials and logarithms
Every other function in the library is here because it's useful. e^x is here because calculus demands it.
This lesson does the algebra you need, and then spends most of its time on one question: out of all the exponential functions 2^x, 3^x, 10^x, why does calculus fixate on the one with the ugly base 2.71828\ldots?
What b^x even means
For positive integers, b^n is repeated multiplication. Everything else is forced by insisting the rule b^{m+n} = b^m b^n keep working:
- b^0 = 1, because b^0 b^n = b^{0+n} = b^n.
- b^{-n} = 1/b^n, because b^{-n}b^n = b^0 = 1.
- b^{1/n} = \sqrt[n]{b}, because (b^{1/n})^n = b^1.
- b^{m/n} = \sqrt[n]{b^m}, by combining those.
That covers every rational exponent. Irrational ones — what is 2^{\sqrt 2}? — have no algebraic construction at all. They're defined by continuity: take rationals closing in on \sqrt 2 and let 2^{\text{that}} follow. That the result exists and is unique is a limit theorem, and a real one; you'll have the tools to prove it in §15.
So even the definition of b^x is already calculus.
Why exponentials matter
Linear growth adds a fixed amount per step. Exponential growth multiplies by a fixed factor per step:
f(x+1) = b \cdot f(x)
That's the signature. Population, compound interest, radioactive decay, viral spread, and the size of the search space in an algorithm all have it, and all are described by Ab^x.
The consequence people underestimate is how completely exponentials dominate polynomials. 2^x overtakes x^{100} eventually — and "eventually" arrives sooner than intuition says. This is why §3's L'Hôpital's rule and §1's limits at infinity keep coming back to the hierarchy
\log x \;\ll\; x^p \;\ll\; b^x \;\ll\; x! \;\ll\; x^x
Every complexity-class argument you've made about algorithms is this hierarchy in disguise.
The number e
Compound interest is the cleanest way in. Invest 1 unit at 100% annual interest, compounded n times a year: each period multiplies by (1 + 1/n), and there are n of them:
\left(1 + \frac{1}{n}\right)^n
More frequent compounding gives more money — but not unboundedly more. It converges:
e = \lim_{n \to \infty}\left(1 + \frac{1}{n}\right)^n = 2.718281828\ldots
Two competing effects fight to a draw: the base creeps toward 1 while the exponent runs to infinity. Neither wins.
That's how e is usually introduced. It is not why it matters.
The definition that explains the obsession
Differentiate b^x from the definition (properly in §2 — here's the shape):
\frac{b^{x+h} - b^x}{h} = \frac{b^x b^h - b^x}{h} = b^x \cdot \frac{b^h - 1}{h}
The b^x factors straight out, and what's left, \frac{b^h - 1}{h}, doesn't depend on x at all. So as h \to 0:
\frac{d}{dx}b^x = C_b \cdot b^x, \qquad C_b = \lim_{h\to 0}\frac{b^h - 1}{h}
Every exponential is its own derivative up to a constant. The constant is the slope of b^x at x = 0, and it depends on the base:
C_2 \approx 0.693, \qquad C_3 \approx 1.099, \qquad C_{10} \approx 2.303
C_2 < 1 < C_3, and C_b increases with b. So there is exactly one base where the constant is precisely 1 — and that is the definition of e:
e \text{ is the base for which } \frac{d}{dx}e^x = e^x
e^x is the unique nonzero function that is its own derivative. Everything else about e — the compound interest limit, the series \sum 1/n!, Euler's formula — follows from that property. It's why e shows up in every differential equation in §13, in the normal distribution, and in the solution of any system whose rate of change is proportional to its size.
And the constant C_b isn't mysterious either. Writing b = e^{\ln b} makes b^x = e^{x \ln b}, and the chain rule (§2) gives
\frac{d}{dx}b^x = b^x \ln b
so C_b = \ln b. That's why C_2 \approx 0.693 — it's \ln 2.
Logarithms
\log_b x is the inverse of b^x: the exponent you must raise b to in order to get x.
\log_b x = y \iff b^y = x
Domain x > 0, because b^y is never zero or negative. Every log law is an exponent law wearing a different hat:
| Exponent law | Log law |
|---|---|
| b^m b^n = b^{m+n} | \log(xy) = \log x + \log y |
| b^m / b^n = b^{m-n} | \log(x/y) = \log x - \log y |
| (b^m)^n = b^{mn} | \log(x^n) = n\log x |
| b^0 = 1 | \log 1 = 0 |
That first one is the whole reason logs were invented — in 1614, to turn multiplication into addition and make astronomical arithmetic tractable. It's also why log scales tame data spanning many orders of magnitude, and why log-likelihood replaces likelihood everywhere in statistics: products of thousands of small probabilities underflow to zero, while sums of their logs don't.
Natural log is \log_e, written \ln. Change of base:
\log_b x = \frac{\ln x}{\ln b}
so all logarithms are the same function up to a constant multiple — which is why calculus only ever bothers with \ln.
The other definition of \ln
There's a second, stranger definition:
\ln x = \int_1^x \frac{1}{t}\,dt
The area under 1/t from 1 to x. It looks like a coincidence and isn't: this is often taken as the primary definition in rigorous treatments, with e defined afterwards as the number whose log is 1.
The reason it works is a scaling symmetry. Stretch the interval [1, x] by a factor k and the curve 1/t shrinks by exactly k, so every rectangle's area is preserved. Hence area(1, xy) = area(1,x) + area(x, xy) = area(1,x) + area(1,y) — the log law, read off a picture. You'll prove it properly in §4.
Doing it in Python
The compound interest limit, converging slowly:
from math import e
print(f"{'n':>12} {'(1+1/n)^n':>16} {'error':>12}")
for k in range(1, 9):
n = 10 ** k
approx = (1 + 1 / n) ** n
print(f"{n:>12} {approx:>16.10f} {approx - e:>12.2e}")
print(f"\ne = {e:.10f}")
print("error drops ~10x per row, and n rises 10x per row: convergence is only")
print("O(1/n) -- ten times the work buys one more correct digit. painfully slow.")
Now hunt for e the way calculus does — by looking for the base whose slope at 0 is exactly 1:
from math import log, e
h = 1e-8
print(f"{'base b':>8} {'slope of b^x at 0':>20} {'ln b':>10}")
for b in (1.5, 2, 2.5, e, 3, 10):
slope = (b ** h - 1) / h
print(f"{b:>8.5f} {slope:>20.6f} {log(b):>10.6f}")
print("\nthe slope at 0 IS ln b -- and it equals 1 exactly when b = e")
The growth-rate hierarchy, made concrete:
from math import log, factorial
print(f"{'x':>5} {'log2(x)':>10} {'x^3':>12} {'2^x':>16} {'x!':>22}")
for x in (5, 10, 20, 30, 40):
print(f"{x:>5} {log(x, 2):>10.2f} {x ** 3:>12} {2 ** x:>16} {factorial(x):>22}")
print("\nx^3 leads at x=5 and is hopeless by x=30; 2^x loses to x! soon after")
And why logs are how you multiply many small probabilities:
from math import log, exp
p = [0.01] * 400 # 400 independent events, each 1% likely
naive = 1.0
for q in p:
naive *= q
log_total = sum(log(q) for q in p)
print(f"direct product : {naive}")
print(f"sum of logs : {log_total:.4f}")
print(f"that is e^{log_total:.1f}, a real number -- the direct product underflowed to 0")
Worked example
Carbon-14 has a half-life of 5730 years. A sample retains 23% of its original ^{14}C. How old is it?
Half-life says the amount is multiplied by \frac12 every 5730 years, so
A(t) = A_0 \left(\frac{1}{2}\right)^{t/5730}
We want A(t)/A_0 = 0.23:
\left(\frac{1}{2}\right)^{t/5730} = 0.23
Take \ln of both sides — the move that gets t out of the exponent:
\frac{t}{5730}\ln(0.5) = \ln(0.23)
t = 5730 \cdot \frac{\ln 0.23}{\ln 0.5} = 5730 \cdot \frac{-1.4697}{-0.6931} \approx 5730 \times 2.1204 \approx 12{,}150 \text{ years}
Sanity check: 23% is a bit less than a quarter, and a quarter takes exactly two half-lives (11,460 years). Slightly more than two half-lives. ✓
The same problem in base e throughout: writing A(t) = A_0e^{-kt} with k = \ln 2 / 5730 \approx 1.21 \times 10^{-4} gives the identical answer. Every exponential can be written in any base; e is chosen because §13's differential equations are cleanest there.
Your turn
1. Solve 3^{2x-1} = 27.
2. Condense 2\ln x - \frac{1}{2}\ln(x+1) into a single logarithm.
3. A bacterial culture doubles every 3 hours, starting from 500 cells. Write P(t) and find when it reaches 10,000.
Solutions
1. Write both sides in base 3: 27 = 3^3, so
3^{2x-1} = 3^3 \implies 2x - 1 = 3 \implies \boxed{x = 2}
The step "equal powers of the same base means equal exponents" is legitimate precisely because 3^x is one-to-one — the horizontal line test from the last lesson, doing real work.
2. Power rule first, then the difference rule:
2\ln x - \tfrac12\ln(x+1) = \ln x^2 - \ln\sqrt{x+1} = \boxed{\ln\!\frac{x^2}{\sqrt{x+1}}}
Valid for x > 0 (needed by \ln x; x + 1 > 0 comes free).
3. Doubling every 3 hours:
P(t) = 500 \cdot 2^{t/3}
Set it to 10,000:
2^{t/3} = 20 \implies \frac{t}{3}\ln 2 = \ln 20 \implies t = \frac{3\ln 20}{\ln 2} = \frac{3 \times 2.9957}{0.6931} \approx 12.97 \text{ hours}
Check: 20 is between 2^4 = 16 and 2^5 = 32, so between 4 and 5 doublings, i.e. between 12 and 15 hours. ✓
Check yourself in code
Show that the slope of b^x at x = 0 is \ln b, and that (1+1/n)^n climbs toward e.
For b = 2, 2.718281828, 3, 10, print the numerical slope \frac{b^h - 1}{h} with h = 10^{-8} alongside \ln b, to 6 decimals. Then print (1+1/n)^n for n = 10^2, 10^4, 10^6 to 6 decimals.
Print exactly this:
b=2.000000 slope=0.693147 ln b=0.693147
b=2.718282 slope=1.000000 ln b=1.000000
b=3.000000 slope=1.098612 ln b=1.098612
b=10.000000 slope=2.302585 ln b=2.302585
n=100 2.704814
n=10000 2.718146
n=1000000 2.718280
from math import log
h = 1e-8
for b in (2, 2.718281828, 3, 10):
slope = (b ** h - 1) / h
print(f"b={b:.6f} slope={slope:.6f} ln b={log(b):.6f}")
# Now the compound-interest limit for n = 100, 10000, 1000000.
from math import log
h = 1e-8
for b in (2, 2.718281828, 3, 10):
slope = (b ** h - 1) / h
print(f"b={b:.6f} slope={slope:.6f} ln b={log(b):.6f}")
for n in (10 ** 2, 10 ** 4, 10 ** 6):
print(f"n={n} {(1 + 1 / n) ** n:.6f}")
b^x means repeated multiplication stretched by continuity to every real exponent; \log_b inverts it and turns products into sums. Every exponential differentiates to a constant times itself, the constant is \ln b, and e is the base that makes the constant 1. That single property is why e^x is unavoidable from here on.
Next: trigonometry, and why calculus refuses to measure angles in degrees.