Derivatives of Logarithmic Functions
The natural logarithm is the inverse of , and implicit differentiation turns that fact into . This lesson proves it, handles other bases and , introduces logarithmic differentiation for products, quotients and variable exponents, proves the power rule for every real exponent, and shows that is the limit of .
For a gentler first look, see Derivatives of Exponentials and Logs. The inverse-function background is in Inverse Functions and Logarithms.
The derivative of
Let for , so . Differentiate implicitly, as in Implicit Differentiation:
So . (That is differentiable at all follows from the inverse function theorem: is differentiable with a derivative that is never 0.)
Other bases. Since :
Absolute value. For , and the chain rule gives . So
With the chain rule: . This ratio is called the logarithmic derivative of ; it measures the relative (percentage) rate of change.
| Function | Derivative |
|---|---|
import sympy as sp
x = sp.symbols('x', positive=True)
print("d/dx ln(x² + 1) =", sp.diff(sp.log(x**2 + 1), x))
print("d/dx log₂(x) =", sp.diff(sp.log(x, 2), x))
print("d/dx ln(sin x) =", sp.diff(sp.log(sp.sin(x)), x))
print("d/dx ln(√(x+1)/x³) =", sp.simplify(sp.diff(sp.log(sp.sqrt(x + 1) / x**3), x)))d/dx ln(x² + 1) = 2*x/(x**2 + 1)
d/dx log₂(x) = 1/(x*log(2))
d/dx ln(sin x) = cos(x)/sin(x)
d/dx ln(√(x+1)/x³) = (-5*x - 6)/(2*x*(x + 1))
The last one is easier after expanding the log first: , whose derivative is , the same fraction. Declaring x positive tells SymPy that the logs are real.
Logarithmic differentiation
To differentiate a messy product or quotient, take of both sides first, use the log laws to break it into a sum, then differentiate implicitly.
Example. for :
Every factor becomes one simple term. The quotient rule would have produced a long numerator.
Variable exponents
Logarithmic differentiation is the only elementary way to differentiate when both base and exponent vary. For ():
Neither the power rule ( needs a constant exponent) nor the exponential rule ( needs a constant base) applies on its own; the answer is their sum, .
import math
import sympy as sp
x = sp.symbols('x', positive=True)
print("SymPy: d/dx x^x =", sp.diff(x**x, x))
f = lambda t: t**t
h = 1e-6
for a in [0.5, 1 / math.e, 2]:
numeric = (f(a + h) - f(a - h)) / (2*h)
formula = a**a * (math.log(a) + 1)
print(f"x = {a:.4f}: numeric {numeric: .6f} formula {formula: .6f}")SymPy: d/dx x^x = x**x*(log(x) + 1)
x = 0.5000: numeric 0.216978 formula 0.216978
x = 0.3679: numeric 0.000000 formula 0.000000
x = 2.0000: numeric 6.772589 formula 6.772589
The slope is zero at , where : that is the minimum of on .
The power rule for every real exponent
For and any real , let . Then , so and
This completes the power rule left open in Derivatives of Polynomials and Exponential Functions, including irrational exponents such as .
e as a limit
The derivative of at is . Writing that out with the definition:
Because is continuous, . With :
which is continuous compounding: one unit at 100% interest, compounded times a year, approaches as .
Note: Evaluated in floating point, gets worse for very large , because rounds. Libraries provide
math.log1p(x)= computed accurately for tiny ;math.exp(n * math.log1p(1/n))stays accurate.
In software
- Cross-entropy and log-likelihood: ML losses use . Its derivative is the logarithmic derivative, and the log turns products of probabilities into sums, the same trick as logarithmic differentiation (Machine Learning).
- Log-sum-exp and softmax: , the softmax. Every LLM's output layer computes this (Generative AI & LLMs).
- Relative growth in metrics: is the percentage growth rate, which is why dashboards plot user counts or revenue on a log axis.
- Complexity: , the marginal cost of one more element in an sort (DSA).
Exercises
Exercise 1: Chain rule with ln
Differentiate .
Answer
Solution
Exercise 2: Base 10
Differentiate for .
Answer
Solution
Exercise 3: Logarithmic differentiation
Use logarithmic differentiation to find for , then evaluate .
Answer
;
Solution
Note the : at , and keeps the method valid there. Check:
import sympy as sp
x = sp.symbols('x')
print(sp.diff((x + 1)**2 * (x - 3)**5, x).subs(x, 2))39
Exercise 4: A variable exponent
Differentiate for .
Answer
Solution
Exercise 5: Compounding towards e
Write a loop printing for and the gap to math.e.
Answer
The values rise towards ; the gap is roughly , about at .
Solution
import math
for n in [1, 10, 100, 1000, 10**6]:
v = (1 + 1/n)**n
print(f"n = {n:>7}: {v:.6f} gap {math.e - v:.2e}")n = 1: 2.000000 gap 7.18e-01
n = 10: 2.593742 gap 1.25e-01
n = 100: 2.704814 gap 1.35e-02
n = 1000: 2.716924 gap 1.36e-03
n = 1000000: 2.718280 gap 1.36e-06
Test yourself
What is for ?
- It is undefined
What is the derivative of ?
Which fact about gives ?
- the derivative of at equals 1
- only
- is negative for