22. eˣ, ln x, and logarithmic differentiation
§0.3 argued that e exists because differentiating b^x leaves a base-dependent constant out front, and e is the base making that constant 1. Now we can state it as a theorem and use it.
The exponential
\frac{d}{dx}e^x = e^x
e^x is its own derivative. No other function does this except constant multiples Ce^x — and that uniqueness is exactly why §13's differential equations are full of exponentials.
The derivation, from §0.3:
\frac{e^{x+h}-e^x}{h} = e^x\cdot\frac{e^h-1}{h} \longrightarrow e^x \cdot 1
The factoring works because e^{x+h} = e^xe^h, and the limit \lim_{h\to0}\frac{e^h-1}{h} = 1 is the definition of e.
For a general base, write b = e^{\ln b} so b^x = e^{x\ln b}, and the chain rule gives
\frac{d}{dx}b^x = b^x\ln b
Every exponential is its own derivative scaled by \ln b. For b = e the scale is 1; that's the whole story.
With the chain rule, the form you'll actually use:
\frac{d}{dx}e^{u} = e^u u', \qquad \frac{d}{dx}e^{kx} = ke^{kx}, \qquad \frac{d}{dx}e^{-t/\tau} = -\frac1\tau e^{-t/\tau}
That last one is every decay process in science, and the -\frac1\tau out front is why \tau is called the time constant.
The logarithm
\frac{d}{dx}\ln x = \frac1x \qquad (x > 0)
Derivation. \ln is the inverse of \exp, so e^{\ln x} = x. Differentiate both sides with respect to x, using the chain rule on the left:
e^{\ln x}\cdot\frac{d}{dx}\ln x = 1
But e^{\ln x} = x, so
x \cdot \frac{d}{dx}\ln x = 1 \implies \frac{d}{dx}\ln x = \frac1x \qquad\blacksquare
That's implicit differentiation (§2.9) arriving early, and it's the standard way to differentiate any inverse — the subject of the next lesson.
The result is remarkable in a way that's easy to miss. \ln is a transcendental function, and its derivative is the simplest possible rational function. Run that backwards and it says \int\frac{1}{x}dx = \ln|x| — which is why \ln is unavoidable in §4, and why \frac1x is the one power the power rule for integration can't handle.
Other bases and the chain rule version:
\frac{d}{dx}\log_b x = \frac{1}{x\ln b}, \qquad \frac{d}{dx}\ln u = \frac{u'}{u}
The expression \frac{u'}{u} is called the logarithmic derivative, and it measures relative rate of change — growth per unit of current size. It's what "5% per year" means, and it's the natural quantity when scale is arbitrary.
Why \ln|x|, not \ln x
\ln x needs x>0, but \frac1x is perfectly well-defined for x<0. The antiderivative that covers both is \ln|x|:
for x < 0, \frac{d}{dx}\ln(-x) = \frac{1}{-x}\cdot(-1) = \frac1x ✓
So \frac{d}{dx}\ln|x| = \frac1x on both sides of zero. Worth carrying into §4, where dropping the absolute value is a standard source of wrong answers.
Logarithmic differentiation
Here's a technique, not just a formula.
When to use it: the function is a product, quotient, or power of several factors, and the direct rules would be miserable.
How: take \ln of both sides, use the log laws to break the product into a sum, differentiate implicitly, and multiply back by y.
Example. y = x^x.
The power rule needs a constant exponent; the exponential rule needs a constant base. This has neither, so neither rule applies. But:
\ln y = x\ln x
Differentiate both sides. Left side by the chain rule (y is a function of x), right side by the product rule:
\frac{y'}{y} = 1\cdot\ln x + x\cdot\frac1x = \ln x + 1
Multiply by y:
y' = x^x(\ln x + 1)
Check the shape. y' = 0 when \ln x = -1, i.e. x = 1/e \approx 0.368. And indeed x^x has its minimum there, with value (1/e)^{1/e} \approx 0.6922 — a fact you cannot get from any other method nearly as cleanly.
A messier example.
y = \frac{x^3\sqrt{x^2+1}}{(3x+2)^5}
Direct differentiation means quotient rule wrapping a product wrapping two chain rules. Instead:
\ln y = 3\ln x + \tfrac12\ln(x^2+1) - 5\ln(3x+2)
The entire structure collapsed into a sum. Differentiate term by term:
\frac{y'}{y} = \frac3x + \frac{x}{x^2+1} - \frac{15}{3x+2}
y' = \frac{x^3\sqrt{x^2+1}}{(3x+2)^5}\left[\frac3x + \frac{x}{x^2+1} - \frac{15}{3x+2}\right]
Powers became coefficients, products became sums, quotients became differences. That's the log laws from §0.3 doing exactly what they were invented for.
The power rule, finally complete
§2.2 proved \frac{d}{dx}x^n = nx^{n-1} for positive integers and §2.3 extended it to negative ones. For any real n and x > 0:
y = x^n \implies \ln y = n\ln x \implies \frac{y'}{y} = \frac{n}{x} \implies y' = \frac{n}{x}\cdot x^n = nx^{n-1}
Done, including n = \pi and n = \sqrt2. The power rule holds for every real exponent, and this is the argument that proves it.
Doing it in Python
The self-derivative property, and how special it is:
from math import exp, log
def numerical(f, x, h=1e-6):
return (f(x + h) - f(x - h)) / (2 * h)
print(f"{'x':>6} {'e^x':>14} {'d/dx e^x':>14} {'2^x':>12} {'d/dx 2^x':>12} {'2^x ln2':>12}")
for x in (0.0, 1.0, 2.0, 3.0):
print(f"{x:>6} {exp(x):>14.8f} {numerical(exp, x):>14.8f} "
f"{2**x:>12.6f} {numerical(lambda t: 2**t, x):>12.6f} {2**x * log(2):>12.6f}")
print("\ne^x is its own derivative exactly; 2^x is its own derivative times ln 2")
\ln and \frac1x:
from math import log
def numerical(f, x, h=1e-6):
return (f(x + h) - f(x - h)) / (2 * h)
print(f"{'x':>8} {'d/dx ln x':>14} {'1/x':>14}")
for x in (0.5, 1.0, 2.0, 10.0):
print(f"{x:>8} {numerical(log, x):>14.8f} {1/x:>14.8f}")
print("\nand on the negative side, with the absolute value:")
for x in (-0.5, -2.0):
print(f"{x:>8} {numerical(lambda t: log(abs(t)), x):>14.8f} {1/x:>14.8f}")
Logarithmic differentiation on x^x, which no other rule reaches:
from math import log, exp
def numerical(f, x, h=1e-6):
return (f(x + h) - f(x - h)) / (2 * h)
f = lambda x: x ** x
rule = lambda x: x**x * (log(x) + 1)
print(f"{'x':>8} {'x^x':>12} {'rule':>14} {'numerical':>14}")
for x in (0.5, 1/exp(1), 1.0, 2.0, 3.0):
print(f"{x:>8.4f} {f(x):>12.6f} {rule(x):>14.8f} {numerical(f, x):>14.8f}")
print(f"\nthe derivative is 0 at x = 1/e = {1/exp(1):.6f}, where x^x bottoms out")
The messy quotient, both ways:
import sympy as sp
x = sp.Symbol('x', positive=True)
y = x**3 * sp.sqrt(x**2 + 1) / (3*x + 2)**5
direct = sp.diff(y, x)
log_way = y * sp.diff(sp.log(y).rewrite(sp.log).expand(force=True), x)
print("direct and log-differentiation agree:",
sp.simplify(direct - log_way) == 0)
print(f"\nlog form: ln y = {sp.expand_log(sp.log(y), force=True)}")
print(f"y'/y = {sp.simplify(sp.diff(sp.expand_log(sp.log(y), force=True), x))}")
The power rule for an irrational exponent:
from math import pi, sqrt
def numerical(f, x, h=1e-6):
return (f(x + h) - f(x - h)) / (2 * h)
for n in (pi, sqrt(2), -sqrt(3)):
x = 2.0
print(f"n={n:>10.6f} numeric {numerical(lambda t: t**n, x):>14.8f} "
f"rule {n * x**(n-1):>14.8f}")
print("\nproved by logarithmic differentiation, not by the binomial theorem")
Worked example
Differentiate y = (\sin x)^x for \sin x > 0.
Variable base and variable exponent again — neither the power rule nor the exponential rule applies. Take logs:
\ln y = x\ln(\sin x)
Differentiate. Left side is \frac{y'}{y}; right side needs the product rule, and its second factor needs the chain rule:
\frac{y'}{y} = 1\cdot\ln(\sin x) + x\cdot\frac{\cos x}{\sin x}
= \ln(\sin x) + x\cot x
Multiply back:
y' = (\sin x)^x\left[\ln(\sin x) + x\cot x\right]
Check at x = \frac\pi2: there \sin x = 1, \ln 1 = 0, and \cot(\pi/2) = 0, so y' = 0. Does that make sense? y = (\sin x)^x has \sin x at its maximum of 1 at \pi/2, and 1^x = 1 regardless of the exponent — so the function peaks there and is flat ✓.
The general recipe for anything of the form u(x)^{v(x)}:
\frac{d}{dx}u^v = u^v\left[v'\ln u + \frac{vu'}{u}\right]
which you can either memorise or, better, re-derive by taking logs each time. The second is more reliable and takes four lines.
Your turn
1. \dfrac{d}{dx}e^{3x^2}
2. \dfrac{d}{dx}\ln(x^2+1)
3. \dfrac{d}{dx}\dfrac{(x+1)^2(2x-3)^4}{\sqrt{x}} using logarithmic differentiation.
4. \dfrac{d}{dx}x^{\ln x}
Solutions
1. Chain rule, outer e^\square:
e^{3x^2}\cdot 6x = \boxed{6xe^{3x^2}}
2. \frac{d}{dx}\ln u = \frac{u'}{u} with u = x^2+1:
\boxed{\frac{2x}{x^2+1}}
3. Take logs, and note \sqrt x = x^{1/2} so its log is \frac12\ln x:
\ln y = 2\ln(x+1) + 4\ln(2x-3) - \tfrac12\ln x
Differentiate:
\frac{y'}{y} = \frac{2}{x+1} + \frac{8}{2x-3} - \frac{1}{2x}
\boxed{y' = \frac{(x+1)^2(2x-3)^4}{\sqrt x}\left[\frac{2}{x+1} + \frac{8}{2x-3} - \frac{1}{2x}\right]}
The chain rule contributed the factor 2 inside the (2x-3) term: $\frac{d}{dx} 4\ln(2x-3) = 4\cdot\frac{2}{2x-3}$. Forgetting it is the usual slip.
4. Both base and exponent involve x. Logs:
\ln y = \ln x\cdot\ln x = (\ln x)^2
Differentiate the right side with the chain rule:
\frac{y'}{y} = 2\ln x\cdot\frac1x = \frac{2\ln x}{x}
\boxed{y' = x^{\ln x}\cdot\frac{2\ln x}{x} = 2x^{\ln x - 1}\ln x}
Note y' = 0 at x = 1, where \ln x = 0 — and x^{\ln x} does have its minimum value 1 there, since the exponent and the log both vanish.
Check yourself in code
Confirm the exponential and logarithmic derivative rules, and use logarithmic differentiation on x^x.
Print, all to 8 decimals: \frac{d}{dx}e^x at x=2 against e^2; \frac{d}{dx}2^x at x=2 against 2^2\ln2; \frac{d}{dx}\ln x at x=3 against 1/3; and \frac{d}{dx}x^x at x=2 against x^x(\ln x + 1). Use central differences with h = 10^{-6}.
Print exactly this:
e^x numeric 7.38905610 rule 7.38905610
2^x numeric 2.77258872 rule 2.77258872
ln x numeric 0.33333333 rule 0.33333333
x^x numeric 6.77258872 rule 6.77258872
from math import exp, log
def numerical(f, x, h=1e-6):
return (f(x + h) - f(x - h)) / (2 * h)
cases = [
("e^x", exp, 2.0, exp(2)),
("2^x", lambda t: 2 ** t, 2.0, 2**2 * log(2)),
("ln x", log, 3.0, 1 / 3),
("x^x", lambda t: t ** t, 2.0, 2**2 * (log(2) + 1)),
]
for name, f, x, rule in cases:
# print the central difference and the rule value
print(f"{name:<6} ...")
from math import exp, log
def numerical(f, x, h=1e-6):
return (f(x + h) - f(x - h)) / (2 * h)
cases = [
("e^x", exp, 2.0, exp(2)),
("2^x", lambda t: 2 ** t, 2.0, 2**2 * log(2)),
("ln x", log, 3.0, 1 / 3),
("x^x", lambda t: t ** t, 2.0, 2**2 * (log(2) + 1)),
]
for name, f, x, rule in cases:
print(f"{name:<6} numeric {numerical(f, x):.8f} rule {rule:.8f}")
e^x is the unique function equal to its own derivative, b^x differentiates to b^x\ln b, and \ln x differentiates to \frac1x — proved by differentiating e^{\ln x} = x. Logarithmic differentiation takes logs first to turn products into sums, quotients into differences, and exponents into coefficients; it's the only way to handle u(x)^{v(x)}, and it's what finally proves the power rule for irrational exponents.
Next: the general principle behind that e^{\ln x} = x trick — differentiating any inverse function, including the inverse trig ones.