TExcelTAD
Home › Calculus Essentials › L'Hôpital's Rule

L'Hôpital's Rule

L'Hôpital's rule evaluates limits that come out as 0/00/0 or ∞/∞\infty/\infty by comparing how fast the top and bottom change: replace both by their derivatives and try again. It turns many "indeterminate" limits into one-line calculations, and it explains which functions win in a growth race.

The rule

Suppose f(x)→0f(x) \to 0 and g(x)→0g(x) \to 0 (or both →±∞\to \pm\infty) as x→ax \to a, and ff, gg are differentiable near aa with g′(x)≠0g'(x) \ne 0 there. Then

lim⁡x→af(x)g(x)=lim⁡x→af′(x)g′(x)(if the right-hand limit exists)\lim_{x \to a} \frac{f(x)}{g(x)} = \lim_{x \to a} \frac{f'(x)}{g'(x)} \qquad \text{(if the right-hand limit exists)}

It also works for one-sided limits and for a=±∞a = \pm\infty. Note: you differentiate the top and bottom separately. This is not the quotient rule.

Why it works, for the 0/00/0 case with f(a)=g(a)=0f(a) = g(a) = 0: near aa, both functions look like their tangent lines,

f(x)g(x)≈f′(a)(x−a)g′(a)(x−a)=f′(a)g′(a)\frac{f(x)}{g(x)} \approx \frac{f'(a)(x - a)}{g'(a)(x - a)} = \frac{f'(a)}{g'(a)}

Examples

lim⁡x→0sin⁡3xx:00→lim⁡3cos⁡3x1=3lim⁡x→0ex−1−xx2:00→ex−12x: 00 again→ex2→12lim⁡x→∞ln⁡xx:∞∞→1/x1→0lim⁡x→∞x3ex:∞∞ three times→6ex→0\begin{aligned} &\lim_{x \to 0} \frac{\sin 3x}{x}{:} && \tfrac{0}{0} \to \lim \frac{3\cos 3x}{1} = 3 \\ &\lim_{x \to 0} \frac{e^x - 1 - x}{x^2}{:} && \tfrac{0}{0} \to \frac{e^x - 1}{2x}{:}\ \tfrac{0}{0} \text{ again} \to \frac{e^x}{2} \to \tfrac{1}{2} \\ &\lim_{x \to \infty} \frac{\ln x}{x}{:} && \tfrac{\infty}{\infty} \to \frac{1/x}{1} \to 0 \\ &\lim_{x \to \infty} \frac{x^3}{e^x}{:} && \tfrac{\infty}{\infty} \text{ three times} \to \frac{6}{e^x} \to 0 \end{aligned}

As the second example shows, you may apply the rule repeatedly while the form stays indeterminate.

python · try it yourself
import sympy as sp

x = sp.symbols('x')
cases = [(sp.sin(3 * x), x, 0), (sp.exp(x) - 1 - x, x**2, 0),
         (sp.log(x), x, sp.oo), (x**3, sp.exp(x), sp.oo)]
for f, g, a in cases:
    once = sp.limit(sp.diff(f, x) / sp.diff(g, x), x, a)
    print(f"{str(f / g):<24} direct: {sp.limit(f / g, x, a)!s:<5} after one L'Hôpital step: {once}")
sin(3*x)/x               direct: 3     after one L'Hôpital step: 3
(-x + exp(x) - 1)/x**2   direct: 1/2   after one L'Hôpital step: 1/2
log(x)/x                 direct: 0     after one L'Hôpital step: 0
x**3*exp(-x)             direct: 0     after one L'Hôpital step: 0

Numeric evidence

The second example from the table, approached through shrinking xx. Because ex−1−xe^x - 1 - x subtracts nearly equal numbers, the direct formula loses precision for small xx. math.expm1 computes ex−1e^x - 1 accurately and fixes it:

python · try it yourself
import math

print("    x        naive (e^x-1-x)/x^2     with expm1")
for k in range(1, 9):
    x = 10.0**-k
    naive = (math.exp(x) - 1 - x) / x**2
    stable = (math.expm1(x) - x) / x**2
    print(f"{x:8.0e}   {naive:20.12f}   {stable:.12f}")
    x        naive (e^x-1-x)/x^2     with expm1
   1e-01         0.517091807565   0.517091807565
   1e-02         0.501670841679   0.501670841681
   1e-03         0.500166708385   0.500166708342
   1e-04         0.500016671409   0.500016667083
   1e-05         0.500000696482   0.500001666674
   1e-06         0.499962183698   0.500000166562
   1e-07         0.494336803056   0.500000016372
   1e-08        -0.607747099184   0.500000008431

The stable column settles on 0.5 as L'Hôpital predicts; the naive column drifts away once rounding error (about 10−16/x210^{-16} / x^2) dominates. This is the floating-point lesson again.

Other indeterminate forms

0⋅∞0 \cdot \infty, ∞−∞\infty - \infty, 1∞1^\infty, 000^0 and ∞0\infty^0 must be rewritten as a fraction first.

Form Trick Example
0⋅∞0 \cdot \infty write f⋅g=f1/gf \cdot g = \frac{f}{1/g} xln⁡xx \ln x as x→0+x \to 0^+: ln⁡x1/x→1/x−1/x2=−x→0\frac{\ln x}{1/x} \to \frac{1/x}{-1/x^2} = -x \to 0
∞−∞\infty - \infty common denominator 1x−1sin⁡x\frac{1}{x} - \frac{1}{\sin x} → combine, then L'Hôpital
1∞1^\infty, 000^0, ∞0\infty^0 take ln⁡\ln, find the limit of the exponent (1+2/x)x(1 + 2/x)^x: ln⁡=xln⁡(1+2/x)→2\ln = x \ln(1 + 2/x) \to 2, so the limit is e2e^2
python · try it yourself
import sympy as sp

x = sp.symbols('x', positive=True)
print("x*ln(x), x->0+ :", sp.limit(x * sp.log(x), x, 0, dir='+'))
print("x**x, x->0+    :", sp.limit(x**x, x, 0, dir='+'))
print("(1+2/x)**x     :", sp.limit((1 + 2 / x)**x, x, sp.oo))
print("1/x - 1/sin(x) :", sp.limit(1 / x - 1 / sp.sin(x), x, 0))
x*ln(x), x->0+ : 0
x**x, x->0+    : 1
(1+2/x)**x     : exp(2)
1/x - 1/sin(x) : 0

Note: Check the form first. lim⁡x+1x+2\lim \frac{x + 1}{x + 2} as x→0x \to 0 is simply 1/21/2; blindly applying L'Hôpital would give 1/1=11/1 = 1, which is wrong.

In software

  • Comparing algorithms: lim⁡nlog⁡nn2=lim⁡log⁡nn→0\lim \frac{n \log n}{n^2} = \lim \frac{\log n}{n} \to 0 by L'Hôpital, which is the precise sense in which O(nlog⁡n)O(n \log n) beats O(n2)O(n^2). The same argument shows any polynomial is eventually beaten by an exponential, the reason brute-force search does not scale (DSA).
  • Removable singularities in code: functions like sin⁡(x)/x\sin(x)/x (the sinc function used in signal processing and image resampling), (ex−1)/x(e^x - 1)/x and x⋅ln⁡xx \cdot \ln x (in entropy and cross-entropy, where 0⋅log⁡00 \cdot \log 0 is defined as 0) have limits that libraries hard-code at the bad point. L'Hôpital tells you the right value to plug in.
  • Numerically stable formulas: knowing the limit tells you when to switch to a series or a special function (expm1, log1p, np.sinc) instead of evaluating a formula that cancels catastrophically.

Exercises

Exercise 1: A basic 0/00/0

Find lim⁡x2−9x−3\lim \frac{x^2 - 9}{x - 3} as x→3x \to 3 with L'Hôpital and check it by factoring.

Answer

6

Solution
L’Hoˆpital: lim⁡2x1=6factoring: (x−3)(x+3)x−3=x+3→6\begin{aligned} &\text{L'Hôpital: } && \lim \frac{2x}{1} = 6 \\ &\text{factoring: } && \frac{(x - 3)(x + 3)}{x - 3} = x + 3 \to 6 \end{aligned}

Exercise 2: Twice

Find lim⁡1−cos⁡xx2\lim \frac{1 - \cos x}{x^2} as x→0x \to 0.

Answer

1/21/2

Solution
00→sin⁡x2xstill 00→cos⁡x2→12\begin{aligned} \tfrac{0}{0} &\to \frac{\sin x}{2x} && \text{still } \tfrac{0}{0} \\ &\to \frac{\cos x}{2} \to \tfrac{1}{2} \end{aligned}

Exercise 3: 0⋅∞0 \cdot \infty

Find lim⁡x2ln⁡x\lim x^2 \ln x as x→0+x \to 0^+.

Answer

0

Solution
x2ln⁡x=ln⁡xx−2(∞/∞ form, signs aside)→1/x−2x−3=−x22→0\begin{aligned} x^2 \ln x &= \frac{\ln x}{x^{-2}} && (\infty/\infty \text{ form, signs aside}) \\ &\to \frac{1/x}{-2x^{-3}} = -\frac{x^2}{2} \to 0 \end{aligned}

Exercise 4: The 1∞1^\infty form

Find lim⁡(1+0.05/x)x\lim (1 + 0.05/x)^{x} as x→∞x \to \infty (continuous compounding at 5%), and check numerically with x=106x = 10^6.

Answer

e0.05≈1.051271e^{0.05} \approx 1.051271

Solution
ln⁡L=lim⁡x⋅ln⁡(1+0.05/x)=lim⁡ln⁡(1+0.05/x)1/x00=lim⁡(−0.05/x2)/(1+0.05/x)−1/x2=lim⁡0.051+0.05/x=0.05L=e0.05\begin{aligned} \ln L &= \lim x \cdot \ln(1 + 0.05/x) = \lim \frac{\ln(1 + 0.05/x)}{1/x} && \tfrac{0}{0} \\ &= \lim \frac{(-0.05/x^2)/(1 + 0.05/x)}{-1/x^2} = \lim \frac{0.05}{1 + 0.05/x} = 0.05 \\ L &= e^{0.05} \end{aligned}
python · try it yourself
import math

x = 1e6
print(round((1 + 0.05 / x) ** x, 6), round(math.exp(0.05), 6))
1.051271 1.051271

Test yourself

Which limit can L'Hôpital's rule be applied to directly?

  1. lim⁡x+1x+2\lim \frac{x + 1}{x + 2} as x→0x \to 0
  2. lim⁡x⋅ex\lim x \cdot e^x as x→0x \to 0
  3. lim⁡x2+1x\lim \frac{x^2 + 1}{x} as x→1x \to 1
  4. lim⁡ex−1x\lim \frac{e^x - 1}{x} as x→0x \to 0

What is lim⁡sin⁡5x2x\lim \frac{\sin 5x}{2x} as x→0x \to 0?

  1. 5/25/2
  2. 00
  3. 11
  4. 2/52/5

In L'Hôpital's rule, what do you differentiate?

  1. The quotient f/gf/g with the quotient rule
  2. The numerator and denominator separately
  3. Only the numerator
  4. Only the denominator