Limits in Calculus: notation, techniques and worked examples (step by step)

What a limit is, the epsilon-delta definition, indeterminate forms and the techniques to resolve them, with 41 examples worked step by step and checked on a computer.

Illustration of an open notebook with handwritten limit calculations, next to a cup and some books, on a desk at sunset.

What does “limit” mean in Calculus, what does each symbol in the notation stand for, and how do you solve the most common kinds of limits step by step? This post starts with the intuition and the formal definition, explains why some expressions are indeterminate, and works through 41 examples grouped by technique. At the end, every example is checked numerically in Julia and in Python, and one block shows where a computer goes wrong when the calculation is done carelessly.


1. The central idea

When we write

\[\lim_{x\to a} f(x)=L,\]

we are saying that, as \(x\) approaches \(a\), the values of \(f(x)\) approach \(L\). The limit says nothing about the value of \(f\) at \(a\); it is about what happens near \(a\): the function may not even be defined at the point, or may be defined with a different value, and the limit can still exist.

Notation

  • \(\lim\): the “limit” operator.
  • \(x\to a\): “\(x\) tends to \(a\)”, that is, gets closer to \(a\) without having to reach it.
  • \(f(x)\): the function.
  • \(L\): the value of the limit.
  • \(\infty\): infinity. It is not a number; \(x\to\infty\) means that \(x\) grows without bound, and \(f(x)\to\infty\) means that \(f(x)\) exceeds any fixed value.
  • \(a^-\) and \(a^+\), in one-sided limits:
    • \(\lim_{x\to a^-} f(x)\) is the limit from the left, with \(x<a\);
    • \(\lim_{x\to a^+} f(x)\) is the limit from the right, with \(x>a\).

When the limit exists

The (two-sided) limit exists and equals \(L\) if and only if both one-sided limits exist and equal \(L\):

\[\lim_{x\to a} f(x)=L \iff \lim_{x\to a^-} f(x)=\lim_{x\to a^+} f(x)=L.\]

If the one-sided limits differ, or if one of them does not exist, the two-sided limit does not exist.


2. The formal definition (epsilon and delta)

“Gets closer” needs an exact definition for the calculations to have a foundation. The formal definition says that

\[\lim_{x\to a} f(x)=L\]

means that, for every \(\varepsilon>0\), there is a \(\delta>0\) such that

\[0<\lvert x-a\rvert<\delta \ \Longrightarrow\ \lvert f(x)-L\rvert<\varepsilon.\]

In words: however small the tolerance \(\varepsilon\) around \(L\), there is a neighborhood of radius \(\delta\) around \(a\) where \(f(x)\) stays within the tolerance. The condition \(0<\lvert x-a\rvert\) leaves out the point \(a\) itself: the value of \(f(a)\) has no bearing on the limit.

An example of a proof

Let us prove that \(\lim_{x\to 2}(3x^2-5x+1)=3\). The distance to the limit is

\[\lvert 3x^2-5x+1-3\rvert=\lvert 3x^2-5x-2\rvert=\lvert x-2\rvert\cdot\lvert 3x+1\rvert.\]

If \(\lvert x-2\rvert<1\), then \(1<x<3\) and \(\lvert 3x+1\rvert<10\). So, choosing

\[\delta=\min\left(1,\ \frac{\varepsilon}{10}\right),\]

we get \(\lvert x-2\rvert\cdot\lvert 3x+1\rvert<\frac{\varepsilon}{10}\cdot 10=\varepsilon\) whenever \(0<\lvert x-2\rvert<\delta\). The block below checks this choice numerically: for each \(\varepsilon\), the largest distance found inside the interval stays below \(\varepsilon\).

Julia
using Printf

# lim (3x² - 5x + 1) = 3 as x → 2, with δ = min(1, ε/10)
p(x) = 3x^2 - 5x + 1
println("      ε          δ    largest |p(x) - 3| with 0 < |x - 2| < δ")
for ε in (1, 0.1, 0.01, 0.001)
    δ = min(1, ε / 10)
    xs = range(2 - δ, 2 + δ, length = 200_001)[2:end-1]      # points inside the interval
    @printf("%7.3f %10.5f %16.8f\n", ε, δ, maximum(abs(p(x) - 3) for x in xs))
end
# Output
      ε          δ    largest |p(x) - 3| with 0 < |x - 2| < δ
  1.000    0.10000       0.72999240
  0.100    0.01000       0.07029929
  0.010    0.00100       0.00700293
  0.001    0.00010       0.00070002
Python
import numpy as np

# lim (3x² - 5x + 1) = 3 as x → 2, with δ = min(1, ε/10)
p = lambda x: 3 * x**2 - 5 * x + 1
print("      ε          δ    largest |p(x) - 3| with 0 < |x - 2| < δ")
for eps in (1, 0.1, 0.01, 0.001):
    delta = min(1, eps / 10)
    xs = np.linspace(2 - delta, 2 + delta, 200_001)[1:-1]     # points inside the interval
    print(f"{eps:7.3f} {delta:10.5f} {np.max(np.abs(p(xs) - 3)):16.8f}")
# Output
      ε          δ    largest |p(x) - 3| with 0 < |x - 2| < δ
  1.000    0.10000       0.72999240
  0.100    0.01000       0.07029929
  0.010    0.00100       0.00700293
  0.001    0.00010       0.00070002

Infinite limits and limits at infinity

The same idea covers the cases with \(\infty\):

  • \(\lim_{x\to a} f(x)=+\infty\): for every \(M>0\), there is a \(\delta>0\) such that \(0<\lvert x-a\rvert<\delta\) implies \(f(x)>M\).
  • \(\lim_{x\to \infty} f(x)=L\): for every \(\varepsilon>0\), there is an \(N\) such that \(x>N\) implies \(\lvert f(x)-L\rvert<\varepsilon\).

A limit equal to \(\pm\infty\) is a precise way of saying that the limit does not exist as a number, while indicating which way the function grows.


3. Why direct substitution works (when it does)

If \(\lim_{x\to a} f(x)=L\) and \(\lim_{x\to a} g(x)=M\), with \(L\) and \(M\) numbers, then:

  • \(\lim_{x\to a}[f(x)\pm g(x)]=L\pm M\);
  • \(\lim_{x\to a}[f(x)\cdot g(x)]=L\cdot M\);
  • \(\lim_{x\to a}\dfrac{f(x)}{g(x)}=\dfrac{L}{M}\), provided \(M\neq 0\).

Since \(\lim_{x\to a}x=a\) and \(\lim_{x\to a}c=c\), these rules show that, for any polynomial \(p\), \(\lim_{x\to a}p(x)=p(a)\). The same holds for quotients of polynomials where the denominator is not zero, and for roots, sine, cosine, exponential and logarithm at points of their domain.

A function with \(\lim_{x\to a}f(x)=f(a)\) is called a continuous function at \(a\). For such a function, finding the limit is just a matter of substituting. The techniques in the following sections are for the cases where substitution runs into a division by zero or another indeterminate form.


4. Indeterminate forms

When you compute a limit by direct substitution, one of two things can happen:

  • you get a number and, if the function is continuous at the point, the limit is done;
  • you get an indeterminate form, and the expression has to be transformed first.

What an indeterminate form is

It is a form that, on its own, does not determine the value of the limit. The most common one is \(\frac{0}{0}\): numerator and denominator both go to zero, but each may go to zero at a different “speed”. The three limits below all give \(\frac{0}{0}\) on direct substitution, and the results are different:

\[\lim_{x\to 1}\frac{x-1}{x-1}=\lim_{x\to 1}1=1, \qquad \lim_{x\to 1}\frac{(x-1)^2}{x-1}=\lim_{x\to 1}(x-1)=0,\] \[\lim_{x\to 1}\frac{x-1}{(x-1)^2}=\lim_{x\to 1}\frac{1}{x-1}\quad\text{does not exist}\ (-\infty\text{ from the left},\ +\infty\text{ from the right}).\]

The indeterminate forms are:

\[\frac{0}{0},\qquad \frac{\infty}{\infty},\qquad 0\cdot\infty,\qquad \infty-\infty,\qquad 0^0,\qquad 1^\infty,\qquad \infty^0.\]

Note: \(\frac{1}{0}\) is not an indeterminate form. If the numerator goes to a nonzero number and the denominator goes to zero, the quotient grows in absolute value without bound; what remains is to check the sign on each side (section 11, example 2).

Looking at the numbers

Before manipulating the expression, it pays to evaluate the function at points closer and closer to the point, from both sides. The block below does this for \(\frac{x^2-9}{x-3}\) near 3, for \(\frac{\sin x}{x}\) near 0 and for \(\frac{\lvert x\rvert}{x}\) near 0:

Julia
# Values near the point, from both sides
f(x) = (x^2 - 9) / (x - 3)          # 0/0 at x = 3
g(x) = sin(x) / x                    # 0/0 at x = 0
s(x) = abs(x) / x                    # undefined at x = 0
println("     h     f(3 - h)   f(3 + h)     g(-h)      g(h)   s(-h)  s(h)")
for h in (0.1, 0.01, 0.001, 0.0001)
    @printf("%6.4f %10.6f %10.6f %9.6f %9.6f %6.0f %5.0f\n", h, f(3 - h), f(3 + h), g(-h), g(h), s(-h), s(h))
end
# Output
     h     f(3 - h)   f(3 + h)     g(-h)      g(h)   s(-h)  s(h)
0.1000   5.900000   6.100000  0.998334  0.998334     -1     1
0.0100   5.990000   6.010000  0.999983  0.999983     -1     1
0.0010   5.999000   6.001000  1.000000  1.000000     -1     1
0.0001   5.999900   6.000100  1.000000  1.000000     -1     1
Python
import math

# Values near the point, from both sides
f = lambda x: (x**2 - 9) / (x - 3)          # 0/0 at x = 3
g = lambda x: math.sin(x) / x               # 0/0 at x = 0
s = lambda x: abs(x) / x                    # undefined at x = 0
print("     h     f(3 - h)   f(3 + h)     g(-h)      g(h)   s(-h)  s(h)")
for h in (0.1, 0.01, 0.001, 0.0001):
    print(f"{h:6.4f} {f(3 - h):10.6f} {f(3 + h):10.6f} {g(-h):9.6f} {g(h):9.6f} {s(-h):6.0f} {s(h):5.0f}")
# Output
     h     f(3 - h)   f(3 + h)     g(-h)      g(h)   s(-h)  s(h)
0.1000   5.900000   6.100000  0.998334  0.998334     -1     1
0.0100   5.990000   6.010000  0.999983  0.999983     -1     1
0.0010   5.999000   6.001000  1.000000  1.000000     -1     1
0.0001   5.999900   6.000100  1.000000  1.000000     -1     1

The values of \(\frac{x^2-9}{x-3}\) approach 6, those of \(\frac{\sin x}{x}\) approach 1, and those of \(\frac{\lvert x\rvert}{x}\) stay at \(-1\) on one side and \(1\) on the other. The table suggests the limit but does not prove it: the following sections show how to get the exact value.

Techniques for getting out of an indeterminate form

  • Factoring (difference of squares, quadratic trinomial) and taking out a common factor: they reveal a common factor that cancels.
  • Rationalizing: multiplying by the conjugate to remove the root causing the problem.
  • The fundamental trigonometric limits: \(\lim_{x\to 0}\frac{\sin x}{x}=1\) and \(\lim_{x\to 0}\frac{1-\cos x}{x^2}=\frac12\).
  • The squeeze theorem: trapping the function between two others with the same limit.
  • One-sided limits, when the rule of the function changes at the point.
  • Dividing by the highest power, for limits at infinity.
  • Later on, L’Hôpital’s rule (section 14).

Canceling a factor such as \(x-3\) is valid because the limit only looks at points with \(x\neq 3\), where \(\frac{x-3}{x-3}=1\).


5. Direct substitution

If \(f\) is continuous at \(a\), then \(\lim_{x\to a} f(x)=f(a)\).

Example 1

Find \(\lim_{x\to 2}(3x^2-5x+1)\).

\[\begin{aligned} \lim_{x\to 2}(3x^2-5x+1) &=3(2)^2-5(2)+1\\ &=12-10+1\\ &=3 \end{aligned}\]

Example 2

Find \(\lim_{x\to -1}(x^3+4x^2-2x+7)\).

\[\begin{aligned} \lim_{x\to -1}(x^3+4x^2-2x+7) &=(-1)^3+4(-1)^2-2(-1)+7\\ &=-1+4+2+7\\ &=12 \end{aligned}\]

Example 3

Find \(\lim_{x\to 9}\left(\sqrt{x}+\frac{1}{x}\right)\).

\[\begin{aligned} \lim_{x\to 9}\left(\sqrt{x}+\frac{1}{x}\right) &=\sqrt{9}+\frac{1}{9}\\ &=\frac{27}{9}+\frac{1}{9}\\ &=\frac{28}{9} \end{aligned}\]

Example 4

Find \(\lim_{x\to \pi/6}(2\sin x-1)\).

\[\begin{aligned} \lim_{x\to \pi/6}(2\sin x-1) &=2\sin\left(\frac{\pi}{6}\right)-1\\ &=2\cdot \frac12-1\\ &=0 \end{aligned}\]

Example 5

Find \(\lim_{x\to 1}\frac{x^2+1}{x+2}\).

\[\lim_{x\to 1}\frac{x^2+1}{x+2}=\frac{1^2+1}{1+2}=\frac{2}{3}\]

The denominator is 3 at the point, so substitution is valid.


6. Difference of two squares

Use \(a^2-b^2=(a-b)(a+b)\) to bring out the factor that vanishes at the point and cancel it.

Example 1

\(\begin{aligned} \lim_{x\to 3}\frac{x^2-9}{x-3} &=\lim_{x\to 3}\frac{(x-3)(x+3)}{x-3}\\ &=\lim_{x\to 3}(x+3)\\ &=6 \end{aligned}\)

Example 2

\(\begin{aligned} \lim_{x\to 5}\frac{x^2-25}{x-5} &=\lim_{x\to 5}\frac{(x-5)(x+5)}{x-5}\\ &=\lim_{x\to 5}(x+5)\\ &=10 \end{aligned}\)

Example 3

\(\begin{aligned} \lim_{x\to -2}\frac{x^2-4}{x+2} &=\lim_{x\to -2}\frac{(x-2)(x+2)}{x+2}\\ &=\lim_{x\to -2}(x-2)\\ &=-4 \end{aligned}\)

Example 4

\(\begin{aligned} \lim_{x\to 1}\frac{1-x^2}{1-x} &=\lim_{x\to 1}\frac{(1-x)(1+x)}{1-x}\\ &=\lim_{x\to 1}(1+x)\\ &=2 \end{aligned}\)

Example 5

\(\begin{aligned} \lim_{x\to 2}\frac{4-x^2}{2-x} &=\lim_{x\to 2}\frac{(2-x)(2+x)}{2-x}\\ &=\lim_{x\to 2}(2+x)\\ &=4 \end{aligned}\)


7. Quadratic trinomials

If \(x^2+bx+c\) vanishes at \(x=a\), then \(a\) is a root and the trinomial has the factor \(x-a\): \(x^2+bx+c=(x-a)(x-r)\), where \(r\) is the other root.

Example 1

\(\begin{aligned} \lim_{x\to 1}\frac{x^2-3x+2}{x-1} &=\lim_{x\to 1}\frac{(x-1)(x-2)}{x-1}\\ &=\lim_{x\to 1}(x-2)\\ &=-1 \end{aligned}\)

Example 2

\(\begin{aligned} \lim_{x\to 2}\frac{x^2-5x+6}{x-2} &=\lim_{x\to 2}\frac{(x-2)(x-3)}{x-2}\\ &=\lim_{x\to 2}(x-3)\\ &=-1 \end{aligned}\)

Example 3

\(\begin{aligned} \lim_{x\to -1}\frac{x^2+x}{x+1} &=\lim_{x\to -1}\frac{x(x+1)}{x+1}\\ &=\lim_{x\to -1}x\\ &=-1 \end{aligned}\)

Example 4

\(\begin{aligned} \lim_{x\to 3}\frac{x^2-6x+9}{x-3} &=\lim_{x\to 3}\frac{(x-3)^2}{x-3}\\ &=\lim_{x\to 3}(x-3)\\ &=0 \end{aligned}\)

Example 5

\(\begin{aligned} \lim_{x\to 1}\frac{x^2+2x-3}{x-1} &=\lim_{x\to 1}\frac{(x+3)(x-1)}{x-1}\\ &=\lim_{x\to 1}(x+3)\\ &=4 \end{aligned}\)


8. Taking out a common factor

If you get \(\frac{0}{0}\), look for a common factor (such as \(x\), \(x^2\) or \(x-2\)), take it out, cancel, and only then substitute.

Example 1

\(\lim_{x\to 0}\frac{x^2+x}{x}=\lim_{x\to 0}\frac{x(x+1)}{x}=\lim_{x\to 0}(x+1)=1\)

Example 2

\(\lim_{x\to 0}\frac{x^3-4x}{x}=\lim_{x\to 0}\frac{x(x^2-4)}{x}=\lim_{x\to 0}(x^2-4)=-4\)

Example 3

\(\lim_{x\to 0}\frac{x^3-x^2}{x^2}=\lim_{x\to 0}\frac{x^2(x-1)}{x^2}=\lim_{x\to 0}(x-1)=-1\)

Example 4

\(\lim_{x\to 2}\frac{x^2-2x}{x-2}=\lim_{x\to 2}\frac{x(x-2)}{x-2}=\lim_{x\to 2}x=2\)

Example 5

\(\lim_{x\to 0}\frac{7x^4-x^2}{x^2}=\lim_{x\to 0}\frac{x^2(7x^2-1)}{x^2}=\lim_{x\to 0}(7x^2-1)=-1\)


9. Rationalizing

When the indeterminate form comes from a root, multiply numerator and denominator by the conjugate: \((\sqrt{A}-B)(\sqrt{A}+B)=A-B^2\).

Example 1

\(\begin{aligned} \lim_{x\to 4}\frac{\sqrt{x}-2}{x-4} &=\lim_{x\to 4}\frac{\sqrt{x}-2}{x-4}\cdot\frac{\sqrt{x}+2}{\sqrt{x}+2}\\ &=\lim_{x\to 4}\frac{x-4}{(x-4)(\sqrt{x}+2)}\\ &=\lim_{x\to 4}\frac{1}{\sqrt{x}+2}\\ &=\frac{1}{4} \end{aligned}\)

Example 2

\(\begin{aligned} \lim_{x\to 0}\frac{\sqrt{x+1}-1}{x} &=\lim_{x\to 0}\frac{(x+1)-1}{x(\sqrt{x+1}+1)}\\ &=\lim_{x\to 0}\frac{1}{\sqrt{x+1}+1}\\ &=\frac{1}{2} \end{aligned}\)

Example 3

Here the root is in the denominator:

\[\begin{aligned} \lim_{x\to 9}\frac{x-9}{\sqrt{x}-3} &=\lim_{x\to 9}\frac{(x-9)(\sqrt{x}+3)}{x-9}\\ &=\lim_{x\to 9}(\sqrt{x}+3)\\ &=6 \end{aligned}\]

10. Trigonometric limits and the squeeze theorem

The squeeze theorem

If \(g(x)\le f(x)\le h(x)\) for every \(x\) near \(a\) (except possibly at \(a\)) and

\[\lim_{x\to a} g(x)=\lim_{x\to a} h(x)=L,\]

then \(\lim_{x\to a} f(x)=L\). The function in the middle is “squeezed” between two functions heading to the same place.

An example: \(\lim_{x\to 0}x^2\sin\left(\frac{1}{x}\right)\). The function \(\sin(1/x)\) oscillates endlessly near 0 and has no limit, but it always stays between \(-1\) and \(1\). So

\[-x^2\le x^2\sin\left(\frac{1}{x}\right)\le x^2,\]

and, since \(-x^2\to 0\) and \(x^2\to 0\), the limit is \(0\).

Why \(\lim_{x\to 0}\frac{\sin x}{x}=1\)

With \(x\) in radians and \(0<x<\frac{\pi}{2}\), consider the circle of radius 1, the point \(P=(\cos x,\sin x)\) and the point \(T=(1,\tan x)\) on the line tangent to the circle at \((1,0)\). Comparing three areas, all with a vertex at the origin:

\[\underbrace{\frac{\sin x}{2}}_{\text{triangle up to }P} < \underbrace{\frac{x}{2}}_{\text{circular sector}} < \underbrace{\frac{\tan x}{2}}_{\text{triangle up to }T}.\]

Multiplying by \(\frac{2}{\sin x}>0\) and taking reciprocals:

\[\cos x<\frac{\sin x}{x}<1.\]

Since \(\cos x\to 1\), the squeeze theorem gives the limit 1 from the right. Since \(\frac{\sin x}{x}\) is an even function, the same holds from the left. In degrees, the limit would be \(\frac{\pi}{180}\), not 1: the trigonometric limits in this post assume radians.

Example 1

\(\lim_{x\to 0}\frac{\sin x}{x}=1\)

Example 2

\(\begin{aligned} \lim_{x\to 0}\frac{\sin(5x)}{x} &=\lim_{x\to 0}\left(5\cdot\frac{\sin(5x)}{5x}\right)\\ &=5\cdot 1\\ &=5 \end{aligned}\)

With \(u=5x\), when \(x\to 0\) also \(u\to 0\), and \(\frac{\sin u}{u}\to 1\).

Example 3

\(\begin{aligned} \lim_{x\to 0}\frac{1-\cos x}{x^2} &=\lim_{x\to 0}\frac{1-\cos x}{x^2}\cdot\frac{1+\cos x}{1+\cos x}\\ &=\lim_{x\to 0}\frac{1-\cos^2 x}{x^2(1+\cos x)}\\ &=\lim_{x\to 0}\frac{\sin^2 x}{x^2(1+\cos x)}\\ &=\lim_{x\to 0}\left(\frac{\sin x}{x}\right)^2\cdot \frac{1}{1+\cos x}\\ &=1^2\cdot \frac{1}{2}\\ &=\frac{1}{2} \end{aligned}\)

Example 4

\(\begin{aligned} \lim_{x\to 0}\frac{1-\cos(3x)}{x^2} &=\lim_{x\to 0}\left(9\cdot\frac{1-\cos(3x)}{(3x)^2}\right)\\ &=9\cdot \frac{1}{2}\\ &=\frac{9}{2} \end{aligned}\)

Example 5

\(\begin{aligned} \lim_{x\to 0}\frac{\tan x}{x} &=\lim_{x\to 0}\left(\frac{\sin x}{x}\cdot\frac{1}{\cos x}\right)\\ &=1\cdot \frac{1}{1}\\ &=1 \end{aligned}\)


11. One-sided limits

If the rule of the function changes near the point (absolute value, piecewise definition, a denominator that changes sign, a domain restriction), compute \(\lim_{x\to a^-}\) and \(\lim_{x\to a^+}\) separately. Each of them is a one-sided limit.

Example 1

\(\lim_{x\to 0}\frac{\lvert x\rvert}{x}\)

From the right (\(x>0\), so \(\lvert x\rvert=x\)):

\[\lim_{x\to 0^+}\frac{\lvert x\rvert}{x}=\lim_{x\to 0^+}\frac{x}{x}=1\]

From the left (\(x<0\), so \(\lvert x\rvert=-x\)):

\[\lim_{x\to 0^-}\frac{\lvert x\rvert}{x}=\lim_{x\to 0^-}\frac{-x}{x}=-1\]

Since \(1\neq -1\), the two-sided limit does not exist.

Example 2

\(\lim_{x\to 1}\frac{1}{x-1}\)

The numerator is 1 and the denominator goes to zero: this is not an indeterminate form, and the quotient grows in absolute value without bound. What remains is the sign.

  • From the left, \(x-1<0\) and \(\lim_{x\to 1^-}\frac{1}{x-1}=-\infty\).
  • From the right, \(x-1>0\) and \(\lim_{x\to 1^+}\frac{1}{x-1}=+\infty\).

The two-sided limit does not exist, and the line \(x=1\) is a vertical asymptote of the graph.

Example 3

\(\lim_{x\to 4}\sqrt{4-x}\), in the real numbers

The domain requires \(4-x\ge 0\), that is, \(x\le 4\). From the left,

\[\lim_{x\to 4^-}\sqrt{4-x}=\sqrt{0}=0.\]

From the right, \(\sqrt{4-x}\) is not a real number. The answer for the two-sided limit depends on the convention adopted:

  • if the definition requires \(f\) to be defined on both sides of \(a\), only the limit from the left makes sense, and the two-sided limit is not defined;
  • if the definition only considers points in the domain of \(f\) (the \(x\) in the epsilon-delta definition ranges over the domain only), then \(\lim_{x\to 4}\sqrt{4-x}=0\).

Either way, the limit from the left is 0.

Example 4 (a piecewise function)

\[f(x)= \begin{cases} x^2+1, & x<2\\ 5-x, & x\ge 2 \end{cases}\] \[\lim_{x\to 2^-}f(x)=\lim_{x\to 2^-}(x^2+1)=5, \qquad \lim_{x\to 2^+}f(x)=\lim_{x\to 2^+}(5-x)=3.\]

Since \(5\neq 3\), the two-sided limit does not exist. The graph jumps at \(x=2\).

Example 5 (the limit exists and the function is continuous)

\[g(x)= \begin{cases} \dfrac{x^2-1}{x-1}, & x\ne 1\\[4pt] 2, & x=1 \end{cases}\] \[\lim_{x\to 1}g(x)=\lim_{x\to 1}\frac{(x-1)(x+1)}{x-1}=\lim_{x\to 1}(x+1)=2.\]

The limit is 2 and \(g(1)=2\), so \(g\) is continuous at \(x=1\). If \(g(1)\) had been defined with another value, the limit would still be 2, but \(g\) would not be continuous at that point.

Julia
using Plots

sinc_(x) = sin(x) / x
g1 = plot(sinc_, -3π, 3π, lw = 2, color = :steelblue, label = "", title = "sin(x)/x: limit 1 at x = 0",
          xlabel = "x", ylims = (-0.4, 1.2))
scatter!(g1, [0], [1], markersize = 5, color = :white, markerstrokecolor = :steelblue, label = "")
g2 = plot(x -> x^2 + 1, 0, 2, lw = 2, color = :steelblue, label = "", title = "piecewise f: one-sided 5 and 3",
          xlabel = "x", ylims = (0, 6))
plot!(g2, x -> 5 - x, 2, 4, lw = 2, color = :steelblue, label = "")
scatter!(g2, [2], [5], markersize = 5, color = :white, markerstrokecolor = :steelblue, label = "")
scatter!(g2, [2], [3], markersize = 5, color = :steelblue, markerstrokecolor = :steelblue, label = "")
g3 = plot(x -> 1 / (x - 1), -1, 0.95, lw = 2, color = :steelblue, label = "", title = "1/(x - 1): one-sided -∞ and +∞",
          xlabel = "x", ylims = (-10, 10))
plot!(g3, x -> 1 / (x - 1), 1.05, 3, lw = 2, color = :steelblue, label = "")
vline!(g3, [1], ls = :dash, color = :gray, label = "Asymptote x = 1", legend = :bottomright)
plot(g1, g2, g3, layout = (1, 3), size = (1050, 340), titlefontsize = 10, bottom_margin = 5Plots.mm)
savefig("limits-graphs.png")
Python
import numpy as np
import matplotlib.pyplot as plt

fig, (g1, g2, g3) = plt.subplots(1, 3, figsize=(10.5, 3.4))
x = np.linspace(-3 * np.pi, 3 * np.pi, 1000)
g1.plot(x, np.sin(x) / x, lw=2, color="steelblue")
g1.plot([0], [1], "o", mfc="white", color="steelblue")
g1.set(title="sin(x)/x: limit 1 at x = 0", xlabel="x", ylim=(-0.4, 1.2))
x1, x2 = np.linspace(0, 2, 200), np.linspace(2, 4, 200)
g2.plot(x1, x1**2 + 1, lw=2, color="steelblue")
g2.plot(x2, 5 - x2, lw=2, color="steelblue")
g2.plot([2], [5], "o", mfc="white", color="steelblue")
g2.plot([2], [3], "o", color="steelblue")
g2.set(title="piecewise f: one-sided 5 and 3", xlabel="x", ylim=(0, 6))
xa, xb = np.linspace(-1, 0.95, 300), np.linspace(1.05, 3, 300)
g3.plot(xa, 1 / (xa - 1), lw=2, color="steelblue")
g3.plot(xb, 1 / (xb - 1), lw=2, color="steelblue")
g3.axvline(1, ls="--", color="gray", label="Asymptote x = 1")
g3.set(title="1/(x - 1): one-sided -∞ and +∞", xlabel="x", ylim=(-10, 10))
g3.legend(loc="lower right")
fig.tight_layout()
fig.savefig("limits-graphs-py.png", dpi=120)

Three graphs side by side. In the first, the curve of sine of x over x between minus 3 pi and 3 pi, with an open dot at (0, 1), where the function is not defined. In the second, the piecewise function: the parabola x squared plus 1 rises to an open dot at (2, 5), and the line 5 minus x starts at a filled dot at (2, 3). In the third, the curve 1 over x minus 1, which drops to minus infinity to the left of x equals 1 and rises to plus infinity to the right, with a dashed vertical line at x equals 1.

Figure 1 – Three behaviors near a point: a hole with a limit (sin x/x at 0), a jump with different one-sided limits (the piecewise function at 2) and a vertical asymptote (1/(x − 1) at 1). Julia code above.

12. Limits at infinity

For quotients of polynomials, divide numerator and denominator by the highest power of \(x\) in the denominator. The result follows from comparing the degrees:

  • numerator degree lower than the denominator’s: the limit is \(0\);
  • equal degrees: the limit is the ratio of the leading coefficients;
  • numerator degree higher: the quotient goes to \(+\infty\) or \(-\infty\), depending on the signs.

With roots, rationalizing is often needed, because \(\infty-\infty\) is indeterminate too.

Example 1

\(\begin{aligned} \lim_{x\to \infty}\frac{3x^2+1}{x^2-5x} &=\lim_{x\to \infty}\frac{3+\frac{1}{x^2}}{1-\frac{5}{x}}\\ &=\frac{3+0}{1-0}\\ &=3 \end{aligned}\)

Example 2

\(\begin{aligned} \lim_{x\to \infty}\frac{5x-2}{2x^2+1} &=\lim_{x\to \infty}\frac{\frac{5}{x}-\frac{2}{x^2}}{2+\frac{1}{x^2}}\\ &=\frac{0-0}{2+0}\\ &=0 \end{aligned}\)

Example 3

\(\begin{aligned} \lim_{x\to -\infty}\frac{2x^3-x}{x^3+4} &=\lim_{x\to -\infty}\frac{2-\frac{1}{x^2}}{1+\frac{4}{x^3}}\\ &=\frac{2-0}{1+0}\\ &=2 \end{aligned}\)

Example 4 (rationalizing)

\(\begin{aligned} \lim_{x\to \infty}\left(\sqrt{x^2+4x}-x\right) &=\lim_{x\to \infty}\left(\sqrt{x^2+4x}-x\right)\cdot\frac{\sqrt{x^2+4x}+x}{\sqrt{x^2+4x}+x}\\ &=\lim_{x\to \infty}\frac{(x^2+4x)-x^2}{\sqrt{x^2+4x}+x}\\ &=\lim_{x\to \infty}\frac{4x}{\sqrt{x^2+4x}+x}\\ &=\lim_{x\to \infty}\frac{4}{\sqrt{1+\frac{4}{x}}+1}\\ &=\frac{4}{2}\\ &=2 \end{aligned}\)

In the second-to-last step, numerator and denominator were divided by \(x\), using \(\sqrt{x^2+4x}=x\sqrt{1+\frac{4}{x}}\), which holds for \(x>0\).

Example 5

\(\begin{aligned} \lim_{x\to \infty}\frac{x^2+3}{\sqrt{x^4+1}} &=\lim_{x\to \infty}\frac{x^2\left(1+\frac{3}{x^2}\right)}{x^2\sqrt{1+\frac{1}{x^4}}}\\ &=\lim_{x\to \infty}\frac{1+\frac{3}{x^2}}{\sqrt{1+\frac{1}{x^4}}}\\ &=1 \end{aligned}\)

Here \(\sqrt{x^4}=x^2\) for any real \(x\), because \(x^2\ge 0\).


13. The exponential limit and the form \(1^\infty\)

In \(\left(1+\frac{1}{x}\right)^x\), the base goes to 1 and the exponent goes to infinity. It is tempting to say the result is 1, but \(1^\infty\) is indeterminate: the base approaches 1 while the exponent grows. The limit is the number \(e\):

\[\lim_{x\to \infty}\left(1+\frac{1}{x}\right)^x=e\approx 2.718282.\]

With the substitution \(u=x/2\), which also goes to infinity,

\[\lim_{x\to \infty}\left(1+\frac{2}{x}\right)^x =\lim_{u\to \infty}\left[\left(1+\frac{1}{u}\right)^u\right]^2 =e^2\approx 7.389056.\]

14. Later on: L’Hôpital’s rule

With derivatives, the forms \(\frac{0}{0}\) and \(\frac{\infty}{\infty}\) get a general tool. If \(f(x)\to 0\) and \(g(x)\to 0\) (or both go to \(\pm\infty\)), with \(g'(x)\neq 0\) near \(a\), and the limit of \(\frac{f'(x)}{g'(x)}\) exists, then

\[\lim_{x\to a}\frac{f(x)}{g(x)}=\lim_{x\to a}\frac{f'(x)}{g'(x)}.\]

For example, \(\lim_{x\to 3}\frac{x^2-9}{x-3}=\lim_{x\to 3}\frac{2x}{1}=6\), the same result as factoring. One caution: applying L’Hôpital to \(\frac{\sin x}{x}\) gives \(\frac{\cos x}{1}\to 1\), but the formula for the derivative of sine is proved from this very limit; as a proof, the argument would be circular. Derivatives are covered in the post Derivatives (in Portuguese).


15. Checking on a computer

The block below evaluates every example in the post near the point, with \(h=10^{-4}\) on each side, and the limits at infinity at \(x=\pm 10^3\) and \(x=\pm 10^6\):

Julia
# Numerical check of every example in the post
value(f, x) = try f(x) catch; NaN end                    # outside the real domain becomes NaN
fmt(v) = isnan(v) ? lpad("not real", 14) : @sprintf("%14.6f", v)

points = [
    ("3x² - 5x + 1, x → 2",         x -> 3x^2 - 5x + 1,                  2,    "3"),
    ("x³ + 4x² - 2x + 7, x → -1",   x -> x^3 + 4x^2 - 2x + 7,            -1,   "12"),
    ("√x + 1/x, x → 9",             x -> sqrt(x) + 1 / x,                9,    "28/9 ≈ 3.111111"),
    ("2 sin x - 1, x → π/6",        x -> 2sin(x) - 1,                    π/6,  "0"),
    ("(x² + 1)/(x + 2), x → 1",     x -> (x^2 + 1) / (x + 2),            1,    "2/3 ≈ 0.666667"),
    ("(x² - 9)/(x - 3), x → 3",     x -> (x^2 - 9) / (x - 3),            3,    "6"),
    ("(x² - 25)/(x - 5), x → 5",    x -> (x^2 - 25) / (x - 5),           5,    "10"),
    ("(x² - 4)/(x + 2), x → -2",    x -> (x^2 - 4) / (x + 2),            -2,   "-4"),
    ("(1 - x²)/(1 - x), x → 1",     x -> (1 - x^2) / (1 - x),            1,    "2"),
    ("(4 - x²)/(2 - x), x → 2",     x -> (4 - x^2) / (2 - x),            2,    "4"),
    ("(x² - 3x + 2)/(x - 1), x → 1", x -> (x^2 - 3x + 2) / (x - 1),      1,    "-1"),
    ("(x² - 5x + 6)/(x - 2), x → 2", x -> (x^2 - 5x + 6) / (x - 2),      2,    "-1"),
    ("(x² + x)/(x + 1), x → -1",    x -> (x^2 + x) / (x + 1),            -1,   "-1"),
    ("(x² - 6x + 9)/(x - 3), x → 3", x -> (x^2 - 6x + 9) / (x - 3),      3,    "0"),
    ("(x² + 2x - 3)/(x - 1), x → 1", x -> (x^2 + 2x - 3) / (x - 1),      1,    "4"),
    ("(x² + x)/x, x → 0",           x -> (x^2 + x) / x,                  0,    "1"),
    ("(x³ - 4x)/x, x → 0",          x -> (x^3 - 4x) / x,                 0,    "-4"),
    ("(x³ - x²)/x², x → 0",         x -> (x^3 - x^2) / x^2,              0,    "-1"),
    ("(x² - 2x)/(x - 2), x → 2",    x -> (x^2 - 2x) / (x - 2),           2,    "2"),
    ("(7x⁴ - x²)/x², x → 0",        x -> (7x^4 - x^2) / x^2,             0,    "-1"),
    ("(√x - 2)/(x - 4), x → 4",     x -> (sqrt(x) - 2) / (x - 4),        4,    "1/4"),
    ("(√(x + 1) - 1)/x, x → 0",     x -> (sqrt(x + 1) - 1) / x,          0,    "1/2"),
    ("(x - 9)/(√x - 3), x → 9",     x -> (x - 9) / (sqrt(x) - 3),        9,    "6"),
    ("sin x / x, x → 0",            x -> sin(x) / x,                     0,    "1"),
    ("sin(5x)/x, x → 0",            x -> sin(5x) / x,                    0,    "5"),
    ("(1 - cos x)/x², x → 0",       x -> (1 - cos(x)) / x^2,             0,    "1/2"),
    ("(1 - cos 3x)/x², x → 0",      x -> (1 - cos(3x)) / x^2,            0,    "9/2"),
    ("tan x / x, x → 0",            x -> tan(x) / x,                     0,    "1"),
    ("x² sin(1/x), x → 0",          x -> x^2 * sin(1 / x),               0,    "0"),
    ("|x|/x, x → 0",                x -> abs(x) / x,                     0,    "-1 and 1: does not exist"),
    ("1/(x - 1), x → 1",            x -> 1 / (x - 1),                    1,    "-∞ and +∞: does not exist"),
    ("√(4 - x), x → 4",             x -> sqrt(4 - x),                    4,    "0 from the left"),
    ("piecewise f, x → 2",          x -> x < 2 ? x^2 + 1 : 5 - x,        2,    "5 and 3: does not exist"),
    ("g, x → 1",                    x -> x == 1 ? 2.0 : (x^2 - 1) / (x - 1), 1, "2"),
]
h = 1e-4
println("Example                            f(a - h)       f(a + h)   limit")
for (name, f, a, L) in points
    println(rpad(name, 30), fmt(value(f, a - h)), " ", fmt(value(f, a + h)), "   ", L)
end

at_infinity = [
    ("(3x² + 1)/(x² - 5x), x → ∞",   x -> (3x^2 + 1) / (x^2 - 5x),        1,  "3"),
    ("(5x - 2)/(2x² + 1), x → ∞",    x -> (5x - 2) / (2x^2 + 1),          1,  "0"),
    ("(2x³ - x)/(x³ + 4), x → -∞",   x -> (2x^3 - x) / (x^3 + 4),         -1, "2"),
    ("√(x² + 4x) - x, x → ∞",        x -> sqrt(x^2 + 4x) - x,             1,  "2"),
    ("(x² + 3)/√(x⁴ + 1), x → ∞",    x -> (x^2 + 3) / sqrt(x^4 + 1),      1,  "1"),
    ("(1 + 1/x)^x, x → ∞",           x -> (1 + 1 / x)^x,                  1,  "e ≈ 2.718282"),
    ("(1 + 2/x)^x, x → ∞",           x -> (1 + 2 / x)^x,                  1,  "e² ≈ 7.389056"),
]
println("\nExample                       x = ±10³       x = ±10⁶   limit")
for (name, f, sign_, L) in at_infinity
    println(rpad(name, 30), fmt(f(sign_ * 1e3)), " ", fmt(f(sign_ * 1e6)), "   ", L)
end
# Output
Example                            f(a - h)       f(a + h)   limit
3x² - 5x + 1, x → 2                 2.999300       3.000700   3
x³ + 4x² - 2x + 7, x → -1          12.000700      11.999300   12
√x + 1/x, x → 9                     3.111096       3.111127   28/9 ≈ 3.111111
2 sin x - 1, x → π/6               -0.000173       0.000173   0
(x² + 1)/(x + 2), x → 1             0.666622       0.666711   2/3 ≈ 0.666667
(x² - 9)/(x - 3), x → 3             5.999900       6.000100   6
(x² - 25)/(x - 5), x → 5            9.999900      10.000100   10
(x² - 4)/(x + 2), x → -2           -4.000100      -3.999900   -4
(1 - x²)/(1 - x), x → 1             1.999900       2.000100   2
(4 - x²)/(2 - x), x → 2             3.999900       4.000100   4
(x² - 3x + 2)/(x - 1), x → 1       -1.000100      -0.999900   -1
(x² - 5x + 6)/(x - 2), x → 2       -1.000100      -0.999900   -1
(x² + x)/(x + 1), x → -1           -1.000100      -0.999900   -1
(x² - 6x + 9)/(x - 3), x → 3       -0.000100       0.000100   0
(x² + 2x - 3)/(x - 1), x → 1        3.999900       4.000100   4
(x² + x)/x, x → 0                   0.999900       1.000100   1
(x³ - 4x)/x, x → 0                 -4.000000      -4.000000   -4
(x³ - x²)/x², x → 0                -1.000100      -0.999900   -1
(x² - 2x)/(x - 2), x → 2            1.999900       2.000100   2
(7x⁴ - x²)/x², x → 0               -1.000000      -1.000000   -1
(√x - 2)/(x - 4), x → 4             0.250002       0.249998   1/4
(√(x + 1) - 1)/x, x → 0             0.500013       0.499988   1/2
(x - 9)/(√x - 3), x → 9             5.999983       6.000017   6
sin x / x, x → 0                    1.000000       1.000000   1
sin(5x)/x, x → 0                    5.000000       5.000000   5
(1 - cos x)/x², x → 0               0.500000       0.500000   1/2
(1 - cos 3x)/x², x → 0              4.500000       4.500000   9/2
tan x / x, x → 0                    1.000000       1.000000   1
x² sin(1/x), x → 0                  0.000000      -0.000000   0
|x|/x, x → 0                       -1.000000       1.000000   -1 and 1: does not exist
1/(x - 1), x → 1               -10000.000000   10000.000000   -∞ and +∞: does not exist
√(4 - x), x → 4                     0.010000       not real   0 from the left
piecewise f, x → 2                  4.999600       2.999900   5 and 3: does not exist
g, x → 1                            1.999900       2.000100   2
Example                       x = ±10³       x = ±10⁶   limit
(3x² + 1)/(x² - 5x), x → ∞          3.015076       3.000015   3
(5x - 2)/(2x² + 1), x → ∞           0.002499       0.000002   0
(2x³ - x)/(x³ + 4), x → -∞          1.999999       2.000000   2
√(x² + 4x) - x, x → ∞               1.998004       1.999998   2
(x² + 3)/√(x⁴ + 1), x → ∞           1.000003       1.000000   1
(1 + 1/x)^x, x → ∞                  2.716924       2.718280   e ≈ 2.718282
(1 + 2/x)^x, x → ∞                  7.374312       7.389041   e² ≈ 7.389056
Python
# Numerical check of every example in the post
def value(f, x):
    try:
        return f(x)
    except (ValueError, ZeroDivisionError):                # outside the real domain
        return math.nan

fmt = lambda v: f"{'not real':>14}" if math.isnan(v) else f"{v:14.6f}"
sqrt, sin, cos, tan, pi = math.sqrt, math.sin, math.cos, math.tan, math.pi

points = [
    ("3x² - 5x + 1, x → 2",         lambda x: 3*x**2 - 5*x + 1,               2,    "3"),
    ("x³ + 4x² - 2x + 7, x → -1",   lambda x: x**3 + 4*x**2 - 2*x + 7,        -1,   "12"),
    ("√x + 1/x, x → 9",             lambda x: sqrt(x) + 1 / x,                9,    "28/9 ≈ 3.111111"),
    ("2 sin x - 1, x → π/6",        lambda x: 2*sin(x) - 1,                   pi/6, "0"),
    ("(x² + 1)/(x + 2), x → 1",     lambda x: (x**2 + 1) / (x + 2),           1,    "2/3 ≈ 0.666667"),
    ("(x² - 9)/(x - 3), x → 3",     lambda x: (x**2 - 9) / (x - 3),           3,    "6"),
    ("(x² - 25)/(x - 5), x → 5",    lambda x: (x**2 - 25) / (x - 5),          5,    "10"),
    ("(x² - 4)/(x + 2), x → -2",    lambda x: (x**2 - 4) / (x + 2),           -2,   "-4"),
    ("(1 - x²)/(1 - x), x → 1",     lambda x: (1 - x**2) / (1 - x),           1,    "2"),
    ("(4 - x²)/(2 - x), x → 2",     lambda x: (4 - x**2) / (2 - x),           2,    "4"),
    ("(x² - 3x + 2)/(x - 1), x → 1", lambda x: (x**2 - 3*x + 2) / (x - 1),    1,    "-1"),
    ("(x² - 5x + 6)/(x - 2), x → 2", lambda x: (x**2 - 5*x + 6) / (x - 2),    2,    "-1"),
    ("(x² + x)/(x + 1), x → -1",    lambda x: (x**2 + x) / (x + 1),           -1,   "-1"),
    ("(x² - 6x + 9)/(x - 3), x → 3", lambda x: (x**2 - 6*x + 9) / (x - 3),    3,    "0"),
    ("(x² + 2x - 3)/(x - 1), x → 1", lambda x: (x**2 + 2*x - 3) / (x - 1),    1,    "4"),
    ("(x² + x)/x, x → 0",           lambda x: (x**2 + x) / x,                 0,    "1"),
    ("(x³ - 4x)/x, x → 0",          lambda x: (x**3 - 4*x) / x,               0,    "-4"),
    ("(x³ - x²)/x², x → 0",         lambda x: (x**3 - x**2) / x**2,           0,    "-1"),
    ("(x² - 2x)/(x - 2), x → 2",    lambda x: (x**2 - 2*x) / (x - 2),         2,    "2"),
    ("(7x⁴ - x²)/x², x → 0",        lambda x: (7*x**4 - x**2) / x**2,         0,    "-1"),
    ("(√x - 2)/(x - 4), x → 4",     lambda x: (sqrt(x) - 2) / (x - 4),        4,    "1/4"),
    ("(√(x + 1) - 1)/x, x → 0",     lambda x: (sqrt(x + 1) - 1) / x,          0,    "1/2"),
    ("(x - 9)/(√x - 3), x → 9",     lambda x: (x - 9) / (sqrt(x) - 3),        9,    "6"),
    ("sin x / x, x → 0",            lambda x: sin(x) / x,                     0,    "1"),
    ("sin(5x)/x, x → 0",            lambda x: sin(5*x) / x,                   0,    "5"),
    ("(1 - cos x)/x², x → 0",       lambda x: (1 - cos(x)) / x**2,            0,    "1/2"),
    ("(1 - cos 3x)/x², x → 0",      lambda x: (1 - cos(3*x)) / x**2,          0,    "9/2"),
    ("tan x / x, x → 0",            lambda x: tan(x) / x,                     0,    "1"),
    ("x² sin(1/x), x → 0",          lambda x: x**2 * sin(1 / x),              0,    "0"),
    ("|x|/x, x → 0",                lambda x: abs(x) / x,                     0,    "-1 and 1: does not exist"),
    ("1/(x - 1), x → 1",            lambda x: 1 / (x - 1),                    1,    "-∞ and +∞: does not exist"),
    ("√(4 - x), x → 4",             lambda x: sqrt(4 - x),                    4,    "0 from the left"),
    ("piecewise f, x → 2",          lambda x: x**2 + 1 if x < 2 else 5 - x,   2,    "5 and 3: does not exist"),
    ("g, x → 1",                    lambda x: 2.0 if x == 1 else (x**2 - 1) / (x - 1), 1, "2"),
]
h = 1e-4
print("Example                            f(a - h)       f(a + h)   limit")
for name, f, a, L in points:
    print(f"{name:<30s}{fmt(value(f, a - h))} {fmt(value(f, a + h))}   {L}")

at_infinity = [
    ("(3x² + 1)/(x² - 5x), x → ∞",   lambda x: (3*x**2 + 1) / (x**2 - 5*x),   1,  "3"),
    ("(5x - 2)/(2x² + 1), x → ∞",    lambda x: (5*x - 2) / (2*x**2 + 1),      1,  "0"),
    ("(2x³ - x)/(x³ + 4), x → -∞",   lambda x: (2*x**3 - x) / (x**3 + 4),     -1, "2"),
    ("√(x² + 4x) - x, x → ∞",        lambda x: sqrt(x**2 + 4*x) - x,          1,  "2"),
    ("(x² + 3)/√(x⁴ + 1), x → ∞",    lambda x: (x**2 + 3) / sqrt(x**4 + 1),   1,  "1"),
    ("(1 + 1/x)^x, x → ∞",           lambda x: (1 + 1 / x)**x,                1,  "e ≈ 2.718282"),
    ("(1 + 2/x)^x, x → ∞",           lambda x: (1 + 2 / x)**x,                1,  "e² ≈ 7.389056"),
]
print("\nExample                       x = ±10³       x = ±10⁶   limit")
for name, f, sign_, L in at_infinity:
    print(f"{name:<30s}{fmt(f(sign_ * 1e3))} {fmt(f(sign_ * 1e6))}   {L}")
# Output
Example                            f(a - h)       f(a + h)   limit
3x² - 5x + 1, x → 2                 2.999300       3.000700   3
x³ + 4x² - 2x + 7, x → -1          12.000700      11.999300   12
√x + 1/x, x → 9                     3.111096       3.111127   28/9 ≈ 3.111111
2 sin x - 1, x → π/6               -0.000173       0.000173   0
(x² + 1)/(x + 2), x → 1             0.666622       0.666711   2/3 ≈ 0.666667
(x² - 9)/(x - 3), x → 3             5.999900       6.000100   6
(x² - 25)/(x - 5), x → 5            9.999900      10.000100   10
(x² - 4)/(x + 2), x → -2           -4.000100      -3.999900   -4
(1 - x²)/(1 - x), x → 1             1.999900       2.000100   2
(4 - x²)/(2 - x), x → 2             3.999900       4.000100   4
(x² - 3x + 2)/(x - 1), x → 1       -1.000100      -0.999900   -1
(x² - 5x + 6)/(x - 2), x → 2       -1.000100      -0.999900   -1
(x² + x)/(x + 1), x → -1           -1.000100      -0.999900   -1
(x² - 6x + 9)/(x - 3), x → 3       -0.000100       0.000100   0
(x² + 2x - 3)/(x - 1), x → 1        3.999900       4.000100   4
(x² + x)/x, x → 0                   0.999900       1.000100   1
(x³ - 4x)/x, x → 0                 -4.000000      -4.000000   -4
(x³ - x²)/x², x → 0                -1.000100      -0.999900   -1
(x² - 2x)/(x - 2), x → 2            1.999900       2.000100   2
(7x⁴ - x²)/x², x → 0               -1.000000      -1.000000   -1
(√x - 2)/(x - 4), x → 4             0.250002       0.249998   1/4
(√(x + 1) - 1)/x, x → 0             0.500013       0.499988   1/2
(x - 9)/(√x - 3), x → 9             5.999983       6.000017   6
sin x / x, x → 0                    1.000000       1.000000   1
sin(5x)/x, x → 0                    5.000000       5.000000   5
(1 - cos x)/x², x → 0               0.500000       0.500000   1/2
(1 - cos 3x)/x², x → 0              4.500000       4.500000   9/2
tan x / x, x → 0                    1.000000       1.000000   1
x² sin(1/x), x → 0                  0.000000      -0.000000   0
|x|/x, x → 0                       -1.000000       1.000000   -1 and 1: does not exist
1/(x - 1), x → 1               -10000.000000   10000.000000   -∞ and +∞: does not exist
√(4 - x), x → 4                     0.010000       not real   0 from the left
piecewise f, x → 2                  4.999600       2.999900   5 and 3: does not exist
g, x → 1                            1.999900       2.000100   2
Example                       x = ±10³       x = ±10⁶   limit
(3x² + 1)/(x² - 5x), x → ∞          3.015076       3.000015   3
(5x - 2)/(2x² + 1), x → ∞           0.002499       0.000002   0
(2x³ - x)/(x³ + 4), x → -∞          1.999999       2.000000   2
√(x² + 4x) - x, x → ∞               1.998004       1.999998   2
(x² + 3)/√(x⁴ + 1), x → ∞           1.000003       1.000000   1
(1 + 1/x)^x, x → ∞                  2.716924       2.718280   e ≈ 2.718282
(1 + 2/x)^x, x → ∞                  7.374312       7.389041   e² ≈ 7.389056

In every case, the numerical values approach the limit computed by hand, and the cases without a two-sided limit show up as different values on each side (or outside the domain).

Where the computer goes wrong

Numerical checking has its limits. A computer keeps about 16 significant digits, and when two nearly equal numbers are subtracted, the matching digits cancel and the rounding error is what remains. This is catastrophic cancellation. Besides finding the limit, the algebraic manipulations in this post also avoid this problem:

Julia
# Formulas that are equal in theory and different on a computer
naive(x) = (1 - cos(x)) / x^2
stable(x) = 2 * sin(x / 2)^2 / x^2                # 1 - cos x = 2 sin²(x/2)
println("      x    (1 - cos x)/x²   2 sin²(x/2)/x²")
for x in (1e-2, 1e-4, 1e-6, 1e-8)
    @printf("%7.0e %16.12f %16.12f\n", x, naive(x), stable(x))
end

root_naive(x) = sqrt(x^2 + 4x) - x
root_stable(x) = 4 / (sqrt(1 + 4 / x) + 1)        # the rationalized form
println("\n      x    √(x² + 4x) - x   4/(√(1 + 4/x) + 1)")
for x in (1e2, 1e6, 1e10, 1e14, 1e17)
    @printf("%7.0e %16.12f %16.12f\n", x, root_naive(x), root_stable(x))
end

pow_naive(x) = (1 + 1 / x)^x
pow_stable(x) = exp(x * log1p(1 / x))             # log1p(u) = ln(1 + u) without losing precision
println("\n      x      (1 + 1/x)^x   exp(x ln(1 + 1/x))")
for x in (1e4, 1e8, 1e12, 1e16)
    @printf("%7.0e %16.12f %16.12f\n", x, pow_naive(x), pow_stable(x))
end
@printf("e = %.12f\n", exp(1))
# Output
      x    (1 - cos x)/x²   2 sin²(x/2)/x²
  1e-02   0.499995833347   0.499995833347
  1e-04   0.499999996961   0.499999999583
  1e-06   0.500044450291   0.500000000000
  1e-08   0.000000000000   0.500000000000
      x    √(x² + 4x) - x   4/(√(1 + 4/x) + 1)
  1e+02   1.980390271856   1.980390271856
  1e+06   1.999997999985   1.999998000004
  1e+10   2.000000000000   1.999999999800
  1e+14   2.000000000000   2.000000000000
  1e+17   0.000000000000   2.000000000000
      x      (1 + 1/x)^x   exp(x ln(1 + 1/x))
  1e+04   2.718145926825   2.718145926825
  1e+08   2.718281798347   2.718281814868
  1e+12   2.718523496037   2.718281828458
  1e+16   1.000000000000   2.718281828459
e = 2.718281828459
Python
# Formulas that are equal in theory and different on a computer
naive = lambda x: (1 - math.cos(x)) / x**2
stable = lambda x: 2 * math.sin(x / 2)**2 / x**2           # 1 - cos x = 2 sin²(x/2)
print("      x    (1 - cos x)/x²   2 sin²(x/2)/x²")
for x in (1e-2, 1e-4, 1e-6, 1e-8):
    print(f"{x:7.0e} {naive(x):16.12f} {stable(x):16.12f}")

root_naive = lambda x: math.sqrt(x**2 + 4 * x) - x
root_stable = lambda x: 4 / (math.sqrt(1 + 4 / x) + 1)     # the rationalized form
print("\n      x    √(x² + 4x) - x   4/(√(1 + 4/x) + 1)")
for x in (1e2, 1e6, 1e10, 1e14, 1e17):
    print(f"{x:7.0e} {root_naive(x):16.12f} {root_stable(x):16.12f}")

pow_naive = lambda x: (1 + 1 / x)**x
pow_stable = lambda x: math.exp(x * math.log1p(1 / x))     # log1p(u) = ln(1 + u) without losing precision
print("\n      x      (1 + 1/x)^x   exp(x ln(1 + 1/x))")
for x in (1e4, 1e8, 1e12, 1e16):
    print(f"{x:7.0e} {pow_naive(x):16.12f} {pow_stable(x):16.12f}")
print(f"e = {math.exp(1):.12f}")
# Output
      x    (1 - cos x)/x²   2 sin²(x/2)/x²
  1e-02   0.499995833347   0.499995833347
  1e-04   0.499999996961   0.499999999583
  1e-06   0.500044450291   0.500000000000
  1e-08   0.000000000000   0.500000000000
      x    √(x² + 4x) - x   4/(√(1 + 4/x) + 1)
  1e+02   1.980390271856   1.980390271856
  1e+06   1.999997999985   1.999998000004
  1e+10   2.000000000000   1.999999999800
  1e+14   2.000000000000   2.000000000000
  1e+17   0.000000000000   2.000000000000
      x      (1 + 1/x)^x   exp(x ln(1 + 1/x))
  1e+04   2.718145926825   2.718145926825
  1e+08   2.718281798347   2.718281814868
  1e+12   2.718523496037   2.718281828458
  1e+16   1.000000000000   2.718281828459
e = 2.718281828459
  • \(\frac{1-\cos x}{x^2}\) loses precision as \(x\) shrinks and gives 0 at \(x=10^{-8}\), because \(\cos(10^{-8})\) is rounded to exactly 1. The equivalent form \(\frac{2\sin^2(x/2)}{x^2}\), which comes from \(1-\cos x=2\sin^2(x/2)\), has no subtraction and gets it right.
  • \(\sqrt{x^2+4x}-x\) gives 0 at \(x=10^{17}\), because \(x^2+4x\) is rounded to \(x^2\). The rationalized form from example 4 in section 12 stays correct.
  • \(\left(1+\frac{1}{x}\right)^x\) gives 1 at \(x=10^{16}\), because \(1+10^{-16}\) is rounded to 1. Computing \(e^{x\ln(1+1/x)}\) with the function log1p, which computes \(\ln(1+u)\) without adding 1 first, gives \(e\).

A numerical table suggests the limit, but without the analysis it may suggest the wrong value.


Quick reference

  • If the function is continuous at the point, substitute.
  • If you get \(\frac{0}{0}\), factor (difference of squares, trinomial, common factor) or rationalize, and cancel the factor that vanishes.
  • Difference of squares: \(a^2-b^2=(a-b)(a+b)\).
  • Trigonometric, with \(x\) in radians: \(\lim_{x\to 0}\frac{\sin x}{x}=1\) and \(\lim_{x\to 0}\frac{1-\cos x}{x^2}=\frac12\).
  • Squeeze theorem: if \(g\le f\le h\) and \(g,h\to L\), then \(f\to L\).
  • One-sided: compute \(\lim_{x\to a^-}\) and \(\lim_{x\to a^+}\). If they differ, the two-sided limit does not exist.
  • \(\frac{k}{0}\) with \(k\neq 0\) is not indeterminate: the limit is \(\pm\infty\) on each side, depending on the sign.
  • At infinity: compare the degrees (divide by the highest power) and, if there is a root, rationalize.
  • \(1^\infty\) is indeterminate: \(\left(1+\frac{1}{x}\right)^x\to e\).

Comments