The Limit of a Function
A limit describes the value that approaches as approaches a number , without ever looking at itself. This lesson gives the working (intuitive) definition, one-sided and infinite limits, vertical asymptotes, and the ways numerical guessing can fool you.
The survey lesson Limits introduces the idea with tables. Here we are more careful about what the notation claims and where the evidence breaks down. The fully rigorous version comes in The Precise Definition of a Limit.
The working definition
means: we can make as close to as we like by taking sufficiently close to , on either side of , but not equal to . Three consequences follow directly from the wording.
- need not be defined at . The quotient has no value at , yet its limit there is .
- Even when is defined, it does not matter. Change to and the limit at is still .
- The limit is a single number , the same from both sides. If the two sides head to different places, there is no (two-sided) limit.
One-sided limits
as (left-hand limit) restricts attention to ; (right-hand limit) restricts to . The basic link is a theorem:
Example: the floor function at has left limit and right limit , so as does not exist, even though .
import math
import sympy as sp
x = sp.symbols('x')
print("left of 3:", [math.floor(3 - 10**-k) for k in range(1, 5)])
print("right of 3:", [math.floor(3 + 10**-k) for k in range(1, 5)])
print("SymPy left :", sp.limit(sp.floor(x), x, 3, dir='-'))
print("SymPy right:", sp.limit(sp.floor(x), x, 3, dir='+'))
print("hole at 1 :", sp.limit((x**2 - 1)/(x - 1), x, 1))left of 3: [2, 2, 2, 2]
right of 3: [3, 3, 3, 3]
SymPy left : 2
SymPy right: 3
hole at 1 : 2
Infinite limits and vertical asymptotes
means can be made arbitrarily large (larger than any number you name) by taking close enough to , . This is a description of how the limit fails to exist, not a claim that it equals a number. Similarly for and for one-sided versions.
The line is a vertical asymptote of if at least one of the six statements as , , holds.
Example: . Near the numerator is close to and the denominator is a small number whose sign matches the side:
| side | numerator | denominator | quotient |
|---|---|---|---|
| small, positive | |||
| small, negative |
So is a vertical asymptote. Other standard examples: as , and as .
When numerical guessing fails
Tables are useful but limited. Two classic traps:
Trap 1, oscillation. . Sample and every value is , suggesting the limit at is . Sample and every value is . The function oscillates between and infinitely often near ; the limit does not exist.
Trap 2, catastrophic cancellation. has limit at , but in floating point 1 − cos(1e-8) is exactly 0.0, because cos(1e-8) rounds to 1.0.
import math
print("sin(pi/x) on x = 1/n :", [round(math.sin(math.pi * n), 12) + 0.0 for n in (10, 100, 1000)])
print("sin(pi/x) on x = 2/(4n+1) :", [round(math.sin(math.pi * (4*n + 1) / 2), 12) for n in (10, 100, 1000)])
for x in [1e-2, 1e-4, 1e-6, 1e-8]:
naive = (1 - math.cos(x)) / x**2
stable = 2 * math.sin(x/2)**2 / x**2 # same function, rewritten
print(f"x={x:g} naive={naive:.10f} stable={stable:.10f}")sin(pi/x) on x = 1/n : [0.0, 0.0, 0.0]
sin(pi/x) on x = 2/(4n+1) : [1.0, 1.0, 1.0]
x=0.01 naive=0.4999958333 stable=0.4999958333
x=0.0001 naive=0.4999999970 stable=0.4999999996
x=1e-06 naive=0.5000444503 stable=0.5000000000
x=1e-08 naive=0.0000000000 stable=0.5000000000
The naive column drifts and then collapses to purely because of rounding. The identity removes the subtraction of nearly equal numbers, and the stable column stays on the true values, which are and so approach .
Tip: Treat a table as a hypothesis generator. Confirm with algebra, a theorem from Calculating Limits Using the Limit Laws, or a symbolic tool such as
sympy.limit.
A picture of the oscillation
import numpy as np
import matplotlib.pyplot as plt
xs = np.linspace(0.005, 0.5, 4000)
plt.figure(figsize=(6, 3.5))
plt.plot(xs, np.sin(np.pi / xs), lw=0.7)
plt.plot(-xs, np.sin(np.pi / -xs), lw=0.7, color="C0")
plt.title("y = sin(π/x): no limit at 0"); plt.grid(alpha=0.3)
seen = int(np.sum(np.diff(np.sign(np.sin(np.pi / xs))) != 0))
true = len([n for n in range(1, 1000) if 0.005 < 1/n <= 0.5]) # zeros at x = 1/n
print("sign changes seen by 4000 samples:", seen)
print("true zeros in (0.005, 0.5] :", true)sign changes seen by 4000 samples: 117
true zeros in (0.005, 0.5] : 198
Even 4000 evenly spaced samples miss most of the oscillations close to : the zeros crowd together faster than any fixed grid can resolve. That is the oscillation trap again, this time in a plot.
In software
- Special-casing singular points. is defined at by its limit ; NumPy's
np.sincand audio resampling code do exactly that. Any formula with a removable needs such a branch. - Numerical stability. Library functions
math.expm1(x)(for ) andmath.log1p(x)(for ) exist because the naive formulas suffer the cancellation shown above near . - Asymptotes in plots. Plotting or naively connects to with a vertical line; good plotting code detects the asymptote and breaks the curve.
Exercises
Exercise 1: Ignore the value at the point
for and . Find as .
Answer
Solution
Exercise 2: One-sided limits
Let . Find the one-sided limits at . Does the limit exist?
Answer
Left , right ; no limit.
Solution
Exercise 3: Vertical asymptote
Find as . Is a vertical asymptote?
Answer
from both sides; yes.
Solution
Exercise 4: Fool the table
Show numerically that sampling at suggests a limit of at , then find another sequence of points that gives .
Answer
gives , so the limit does not exist.
Solution
import math
f = lambda x: math.cos(math.pi / x)
print([round(f(1/(2*n)), 9) for n in (5, 50, 500)])
print([round(f(1/(2*n + 1)), 9) for n in (5, 50, 500)])[1.0, 1.0, 1.0]
[-1.0, -1.0, -1.0]
Two sequences tending to give different limiting values, so no single works.
Test yourself
If and as exists, what can you conclude about the limit?
- It equals 7
- Nothing: the value does not determine the limit
- It is not 7
- It is infinite
Which statement defines a vertical asymptote ?
- is undefined
- as approaches from at least one side
- has a hole at
- The left and right limits differ
Why does evaluate to 0.0 in floating point at x = 1e-8?
- The limit really is 0
cos(1e-8)rounds to exactly 1.0, so the numerator cancels to 0- Python cannot compute cosines of small numbers
- underflows to 0