Logarithmic Differentiation
Logarithmic differentiation takes \ln of both sides of y=f(x), simplifies with log laws, differentiates, and multiplies back by y. It is the method for exponents that contain x, as in x^x, and for products or quotients with many factors, because the logarithm turns powers, products and quotients into simple sums.
When it helps
Three situations call for it.
- A variable in the exponent and in the base. The table of derivatives covers a variable base with a constant exponent, x^n, and a constant base with a variable exponent, a^x. It has no row for a function such as x^x, where both change.
- Many factors. The product and quotient rules still work, but each extra factor adds a term, and the bookkeeping grows quickly.
- Roots and powers inside a quotient. The logarithm brings each exponent down as a coefficient, which makes the differentiation one short term per factor.
The method
- Name the function and take logarithms. Write y=f(x), then \ln y=\ln f(x). This needs y>0; the case of negative values is handled in the section on absolute values.
- Simplify with the log laws. Turn the right side into a sum of simple terms.
- Differentiate both sides with respect to x. Since y depends on x, the left side gives \dfrac{d}{dx}\ln y=\dfrac1y\cdot y'=\dfrac{y'}{y}. This is the chain rule, and it is the same step used in implicit differentiation.
- Solve for y'. Multiply both sides by y.
- Substitute the original expression for y.
The log laws used in step 2, valid for a,b>0:
| Law | Formula |
|---|---|
| Product | \ln(ab)=\ln a+\ln b |
| Quotient | \ln\dfrac ab=\ln a-\ln b |
| Power | \ln\left(a^n\right)=n\ln a |
Example: y=x^x
This function is defined for x>0. Follow the five steps.
Take logarithms and apply the power law: \ln y=\ln\left(x^x\right)=x\ln x.
Differentiate both sides. The right side is a product, so use the product rule: \frac{y'}{y}=1\cdot\ln x+x\cdot\frac1x=\ln x+1.
Multiply by y and substitute y=x^x: y'=x^x(\ln x+1).
There is a second way to see the same result. Rewrite x^x=e^{x\ln x} for x>0. The chain rule gives e^{x\ln x}\cdot(\ln x+1), which is x^x(\ln x+1) again.
Example: y=x^{\sin x}
Here x>0 again. Taking logarithms gives \ln y=\sin x\cdot\ln x. Differentiate with the product rule:
\frac{y'}{y}=\cos x\cdot\ln x+\sin x\cdot\frac1x.
Multiply by y=x^{\sin x}:
y'=x^{\sin x}\left(\cos x\ln x+\frac{\sin x}{x}\right).
The same steps work for any f(x)^{g(x)} with f>0. From \ln y=g\ln f we get \dfrac{y'}{y}=g'\ln f+\dfrac{g f'}{f}, so
\frac{d}{dx}f^g=f^g\left(g'\ln f+\frac{g f'}{f}\right).
The two terms have a meaning. The first, f^g g'\ln f, is the exponential rule applied as if the base were constant. The second, f^g\dfrac{g f'}{f}=g f^{g-1}f', is the power rule applied as if the exponent were constant. A variable base and a variable exponent contribute one term each, and the derivative is their sum. Setting f=x and g=x returns the first example.
Example: a long product and quotient
Differentiate y=\frac{(x^2+1)^3(x-2)^4}{(3x+5)^2}.
Take logarithms and use the product, quotient and power laws: \ln y=3\ln(x^2+1)+4\ln(x-2)-2\ln(3x+5).
Differentiate each term. For each logarithm, \dfrac{d}{dx}\ln u=\dfrac{u'}{u}, with u' the derivative of the expression inside:
\frac{y'}{y}=3\cdot\frac{2x}{x^2+1}+4\cdot\frac{1}{x-2}-2\cdot\frac{3}{3x+5}=\frac{6x}{x^2+1}+\frac{4}{x-2}-\frac{6}{3x+5}.
Multiply by y and substitute:
y'=\frac{(x^2+1)^3(x-2)^4}{(3x+5)^2}\left(\frac{6x}{x^2+1}+\frac{4}{x-2}-\frac{6}{3x+5}\right).
Leaving the answer in the form y'=y\cdot(\dots) is acceptable. It is exactly equal to the simplified version, and combining everything over a common denominator produces a long expression that is harder to read and easier to get wrong. The unsimplified form also shows its structure: each term in the bracket belongs to one factor of y. If a later step needs zeros of y', combine the bracket at that point.
Domains and absolute values
The logarithm \ln y exists only for y>0. When y or one of its factors can be negative, use \ln\lvert y\rvert instead. For y\ne 0,
\frac{d}{dx}\ln\lvert y\rvert=\frac{y'}{y}.
For y<0 this follows because \ln\lvert y\rvert=\ln(-y) and \dfrac{-y'}{-y}=\dfrac{y'}{y}. The absolute values drop out of the final formula, so the result is the same one you would get by ignoring them. They only make the method valid on intervals where a factor is negative.
In the long example, x^2+1 is always positive, but x-2 and 3x+5 can be negative. Writing \ln\lvert x-2\rvert and \ln\lvert 3x+5\rvert gives the same bracket, because \dfrac{d}{dx}\ln\lvert x-2\rvert=\dfrac{1}{x-2}. The formula holds for x\ne 2 and x\ne-\frac53. The point x=2 needs a separate look: there y=0 and the term \dfrac4{x-2} is undefined, even though y' itself exists and equals 0 because (x-2)^4 is a factor of y.
For x^x and x^{\sin x} the base must be positive anyway, so plain \ln is enough.
Mistakes to avoid
- Using the power rule on x^x. The power rule assumes a constant exponent. Applied here it gives x\cdot x^{x-1}=x^x, which is only the second term of the correct answer and misses x^x\ln x.
- Forgetting to multiply by y. After step 3 you have \dfrac{y'}{y}, not y'. The answer is y'=y\cdot(\dots), with y written out.
- Losing a coefficient. When pulling down exponents, keep every factor: \ln\left[(3x+5)^2\right]=2\ln(3x+5), and the inner derivative 3 then multiplies the 2 to give 6.
- Splitting a sum inside the logarithm. The log laws handle products, quotients and powers. They do nothing for sums, so \ln(x^2+1) stays as it is.
A numeric check at one point catches a missing factor right away.
Try it: Open
x^xwith its steps. The calculator shows a note titled “Logarithmic differentiation”, and the first step carries the same title: with f=x and g=x it applies the general formula y'=f^g\left(g'\ln f+\dfrac{g f'}{f}\right) from this article instead of walking through the five steps. The result is printed as x^x(\ln x+1). Its domain line reads x\in(0,\infty), the same x>0 this article uses.
Frequently asked questions
Why can’t I use the power rule on x^x?
The power rule \dfrac{d}{dx}x^n=nx^{n-1} is derived for a fixed exponent n. In x^x the exponent changes with x, and that change adds its own term. The general formula above shows both parts: the power-rule part, x\cdot x^{x-1}, and the exponential-rule part, x^x\ln x. Only their sum is the derivative.
Do I always need absolute values inside the log?
No. If the quantity inside the logarithm is positive on the interval you work on, as with x>0 for x^x, plain \ln is fine. Use \ln\lvert\cdot\rvert when a factor can be negative. Both give the same derivative formula, so the absolute value is a safeguard for the domain.
Is log differentiation ever required, or only convenient?
For a function with x in both the base and the exponent, you need either this method or the rewrite f^g=e^{g\ln f} with the chain rule, which is the same idea in different clothes. For long products and quotients it is only convenient, since the product and quotient rules always work. Choose it when it saves you steps.
Where to go next
- Implicit differentiation: the same trick of differentiating an equation in which y depends on x.
- How to check a derivative: ways to confirm a result like x^x(\ln x+1).
- Table of derivatives and basic rules: the formulas that avoid this method when only the base or only the exponent varies.
To test your own work, take the exponent-and-base problems from this page to logarithmic differentiation in the calculator and use its “Check your answer” box, which accepts any equivalent form of your derivative.