TExcelTAD
Home › Calculus in Depth › Derivatives of Logarithmic Functions

Derivatives of Logarithmic Functions

The natural logarithm is the inverse of exe^x, and implicit differentiation turns that fact into ddxln⁡x=1/x\frac{d}{dx} \ln x = 1/x. This lesson proves it, handles other bases and ln⁡∣x∣\ln\lvert x \rvert, introduces logarithmic differentiation for products, quotients and variable exponents, proves the power rule for every real exponent, and shows that ee is the limit of (1+x)1/x(1 + x)^{1/x}.

For a gentler first look, see Derivatives of Exponentials and Logs. The inverse-function background is in Inverse Functions and Logarithms.

The derivative of ln⁡x\ln x

Let y=ln⁡xy = \ln x for x>0x > 0, so ey=xe^y = x. Differentiate implicitly, as in Implicit Differentiation:

ey⋅y′=1  ⟹  y′=1ey=1xe^y \cdot y' = 1 \qquad\implies\qquad y' = \frac{1}{e^y} = \frac{1}{x}

So ddxln⁡x=1/x\frac{d}{dx} \ln x = 1/x. (That ln⁡\ln is differentiable at all follows from the inverse function theorem: exe^x is differentiable with a derivative that is never 0.)

Other bases. Since log⁡bx=ln⁡x/ln⁡b\log_b x = \ln x / \ln b:

ddxlog⁡bx=1xln⁡b\frac{d}{dx} \log_b x = \frac{1}{x \ln b}

Absolute value. For x<0x < 0, ln⁡∣x∣=ln⁡(−x)\ln\lvert x \rvert = \ln(-x) and the chain rule gives (1/(−x))⋅(−1)=1/x(1/(-x)) \cdot (-1) = 1/x. So

ddxln⁡∣x∣=1xfor every x≠0\frac{d}{dx} \ln\lvert x \rvert = \frac{1}{x} \qquad \text{for every } x \ne 0

With the chain rule: ddxln⁡g(x)=g′(x)/g(x)\frac{d}{dx} \ln g(x) = g'(x)/g(x). This ratio is called the logarithmic derivative of gg; it measures the relative (percentage) rate of change.

Function Derivative
ln⁡x\ln x 1/x1/x
ln⁡∣x∣\ln\lvert x \rvert 1/x1/x
log⁡bx\log_b x 1xln⁡b\frac{1}{x \ln b}
ln⁡g(x)\ln g(x) g′(x)/g(x)g'(x)/g(x)
bxb^x bxln⁡bb^x \ln b
python · try it yourself
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: ln⁡(x+1/x3)=12ln⁡(x+1)−3ln⁡x\ln\left(\sqrt{x+1}/x^3\right) = \frac{1}{2}\ln(x + 1) - 3\ln x, whose derivative is 12(x+1)−3x\frac{1}{2(x + 1)} - \frac{3}{x}, the same fraction. Declaring x positive tells SymPy that the logs are real.

Logarithmic differentiation

To differentiate a messy product or quotient, take ln⁡\ln of both sides first, use the log laws to break it into a sum, then differentiate implicitly.

Example. y=x3x2+1(2x+1)4y = \frac{x^3 \sqrt{x^2 + 1}}{(2x + 1)^4} for x>0x > 0:

ln⁡y=3ln⁡x+12ln⁡(x2+1)−4ln⁡(2x+1)y′y=3x+xx2+1−82x+1y′=[x3x2+1(2x+1)4]⋅[3x+xx2+1−82x+1]\begin{aligned} \ln y &= 3\ln x + \tfrac{1}{2}\ln(x^2 + 1) - 4\ln(2x + 1) \\[1ex] \frac{y'}{y} &= \frac{3}{x} + \frac{x}{x^2 + 1} - \frac{8}{2x + 1} \\[1ex] y' &= \left[\frac{x^3 \sqrt{x^2 + 1}}{(2x + 1)^4}\right] \cdot \left[\frac{3}{x} + \frac{x}{x^2 + 1} - \frac{8}{2x + 1}\right] \end{aligned}

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 f(x)g(x)f(x)^{g(x)} when both base and exponent vary. For y=xxy = x^x (x>0x > 0):

ln⁡y=xln⁡xy′/y=ln⁡x+1y′=xx(ln⁡x+1)\begin{aligned} \ln y &= x \ln x \\ y'/y &= \ln x + 1 \\ y' &= x^x (\ln x + 1) \end{aligned}

Neither the power rule (n⋅xn−1n \cdot x^{n-1} needs a constant exponent) nor the exponential rule (bxln⁡bb^x \ln b needs a constant base) applies on its own; the answer is their sum, x⋅xx−1+xxln⁡xx \cdot x^{x-1} + x^x \ln x.

python · try it yourself
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 x=1/ex = 1/e, where ln⁡x=−1\ln x = -1: that is the minimum of xxx^x on x>0x > 0.

The power rule for every real exponent

For x>0x > 0 and any real rr, let y=xry = x^r. Then ln⁡y=rln⁡x\ln y = r \ln x, so y′/y=r/xy'/y = r/x and

y′=xr⋅rx=r⋅xr−1■y' = x^r \cdot \frac{r}{x} = r \cdot x^{r-1} \qquad \blacksquare

This completes the power rule left open in Derivatives of Polynomials and Exponential Functions, including irrational exponents such as x2x^{\sqrt{2}}.

e as a limit

The derivative of ln⁡x\ln x at x=1x = 1 is 11. Writing that out with the definition:

1=lim⁡h→0ln⁡(1+h)−ln⁡1h=lim⁡h→0ln⁡((1+h)1/h)1 = \lim_{h \to 0} \frac{\ln(1 + h) - \ln 1}{h} = \lim_{h \to 0} \ln\left((1 + h)^{1/h}\right)

Because exp⁡\exp is continuous, (1+h)1/h→e1=e(1 + h)^{1/h} \to e^1 = e. With n=1/hn = 1/h:

e=lim⁡n→∞(1+1n)ne = \lim_{n \to \infty} \left(1 + \frac{1}{n}\right)^n

which is continuous compounding: one unit at 100% interest, compounded nn times a year, approaches ee as n→∞n \to \infty.

Note: Evaluated in floating point, (1+1/n)n(1 + 1/n)^n gets worse for very large nn, because 1+1/n1 + 1/n rounds. Libraries provide math.log1p(x) = ln⁡(1+x)\ln(1 + x) computed accurately for tiny xx; math.exp(n * math.log1p(1/n)) stays accurate.

In software

  • Cross-entropy and log-likelihood: ML losses use −ln⁡p-\ln p. Its derivative −p′/p-p'/p 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: ddziln⁡∑ezj=ezi/∑ezj\frac{d}{dz_i} \ln \sum e^{z_j} = e^{z_i}/\sum e^{z_j}, the softmax. Every LLM's output layer computes this (Generative AI & LLMs).
  • Relative growth in metrics: (ln⁡y)′=y′/y(\ln y)' = y'/y is the percentage growth rate, which is why dashboards plot user counts or revenue on a log axis.
  • Complexity: ddn(nln⁡n)=ln⁡n+1\frac{d}{dn} (n \ln n) = \ln n + 1, the marginal cost of one more element in an O(nlog⁡n)O(n \log n) sort (DSA).

Exercises

Exercise 1: Chain rule with ln

Differentiate y=ln⁡(3x2+5)y = \ln(3x^2 + 5).

Answer

y′=6x3x2+5y' = \frac{6x}{3x^2 + 5}

Solution
y′=(3x2+5)′3x2+5=6x3x2+5y' = \frac{(3x^2 + 5)'}{3x^2 + 5} = \frac{6x}{3x^2 + 5}

Exercise 2: Base 10

Differentiate y=log⁡10(x3)y = \log_{10}(x^3) for x>0x > 0.

Answer

y′=3xln⁡10y' = \frac{3}{x \ln 10}

Solution
log⁡10(x3)=3log⁡10x,so y′=3⋅1xln⁡10=3xln⁡10\log_{10}(x^3) = 3\log_{10} x, \quad \text{so } y' = 3 \cdot \frac{1}{x \ln 10} = \frac{3}{x \ln 10}

Exercise 3: Logarithmic differentiation

Use logarithmic differentiation to find y′y' for y=(x+1)2(x−3)5y = (x + 1)^2(x - 3)^5, then evaluate y′(2)y'(2).

Answer

y′=(x+1)2(x−3)5[2x+1+5x−3]y' = (x + 1)^2(x - 3)^5 \left[\frac{2}{x + 1} + \frac{5}{x - 3}\right]; y′(2)=39y'(2) = 39

Solution
ln⁡∣y∣=2ln⁡∣x+1∣+5ln⁡∣x−3∣y′/y=2x+1+5x−3at x=2: y=9⋅(−1)5=−9,y′/y=23−5=−133y′(2)=y⋅(y′/y)=−9⋅(−133)=39\begin{aligned} &\ln\lvert y \rvert = 2\ln\lvert x + 1 \rvert + 5\ln\lvert x - 3 \rvert \\ &y'/y = \frac{2}{x + 1} + \frac{5}{x - 3} \\ &\text{at } x = 2{:}\ y = 9 \cdot (-1)^5 = -9, \quad y'/y = \tfrac{2}{3} - 5 = -\tfrac{13}{3} \\ &y'(2) = y \cdot (y'/y) = -9 \cdot \left(-\tfrac{13}{3}\right) = 39 \end{aligned}

Note the ∣…∣\lvert \ldots \rvert: x−3<0x - 3 < 0 at x=2x = 2, and ln⁡∣x∣\ln\lvert x \rvert keeps the method valid there. Check:

python · try it yourself
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 y=xsin⁡xy = x^{\sin x} for x>0x > 0.

Answer

y′=xsin⁡x(cos⁡x⋅ln⁡x+sin⁡xx)y' = x^{\sin x} \left(\cos x \cdot \ln x + \frac{\sin x}{x}\right)

Solution
ln⁡y=sin⁡x⋅ln⁡xy′/y=cos⁡x⋅ln⁡x+sin⁡x⋅1xy′=xsin⁡x(cos⁡x⋅ln⁡x+sin⁡xx)\begin{aligned} \ln y &= \sin x \cdot \ln x \\ y'/y &= \cos x \cdot \ln x + \sin x \cdot \frac{1}{x} \\ y' &= x^{\sin x} \left(\cos x \cdot \ln x + \frac{\sin x}{x}\right) \end{aligned}

Exercise 5: Compounding towards e

Write a loop printing (1+1/n)n(1 + 1/n)^n for n=1,10,100,1000,106n = 1, 10, 100, 1000, 10^6 and the gap to math.e.

Answer

The values rise towards e≈2.718282e \approx 2.718282; the gap is roughly e/(2n)e/(2n), about 1.4⋅10−61.4 \cdot 10^{-6} at n=106n = 10^6.

Solution
python · try it yourself
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 ddxln⁡∣x∣\frac{d}{dx} \ln\lvert x \rvert for x<0x < 0?

  1. −1/x-1/x
  2. 1/x1/x
  3. 1/∣x∣1/\lvert x \rvert
  4. It is undefined

What is the derivative of xxx^x?

  1. x⋅xx−1x \cdot x^{x-1}
  2. xxln⁡xx^x \ln x
  3. xx(ln⁡x+1)x^x(\ln x + 1)
  4. ln⁡x+1\ln x + 1

Which fact about ln⁡\ln gives e=lim⁡(1+1/n)ne = \lim (1 + 1/n)^n?

  1. ln⁡1=0\ln 1 = 0
  2. the derivative of ln⁡x\ln x at x=1x = 1 equals 1
  3. ln⁡e=1\ln e = 1 only
  4. ln⁡\ln is negative for x<1x < 1