Limits
A limit describes the value a function heads towards as its input gets closer and closer to some point, even when the function is undefined at that exact point. Limits are the foundation everything else in calculus is built on: derivatives and integrals are both limits in disguise.
The idea
Take . At the formula gives , which is meaningless. But for every other we can factor the top (a skill from Algebra) and cancel the common factor:
So near the function behaves exactly like , and its values crowd around . We write
and read it "the limit of as approaches 3 is 6". The limit does not care what happens at , only what happens near it. The graph of is the line with a single hole at .
Numeric evidence
The quickest way to get a feel for a limit is a table: plug in inputs closer and closer to the point, from both sides, and watch the outputs.
def f(x):
return (x**2 - 9) / (x - 3)
print(" x from left f(x) | x from right f(x)")
for k in range(1, 7):
h = 10.0**-k
print(f"{3 - h:14.6f} {f(3 - h):10.6f} | {3 + h:14.6f} {f(3 + h):10.6f}") x from left f(x) | x from right f(x)
2.900000 5.900000 | 3.100000 6.100000
2.990000 5.990000 | 3.010000 6.010000
2.999000 5.999000 | 3.001000 6.001000
2.999900 5.999900 | 3.000100 6.000100
2.999990 5.999990 | 3.000010 6.000010
2.999999 5.999999 | 3.000001 6.000001
Both columns close in on . A table like this is evidence, not proof (a function could misbehave between the sample points), but it is a superb sanity check.
Exact limits with SymPy
SymPy computes limits symbolically with sp.limit(expr, x, point):
import sympy as sp
x = sp.symbols('x')
print(sp.limit((x**2 - 9) / (x - 3), x, 3))
print(sp.limit(sp.sin(x) / x, x, 0))
print(sp.limit((1 + x)**(1 / x), x, 0))
print(sp.limit((sp.sqrt(x + 4) - 2) / x, x, 0))6
1
E
1/4
The second limit, as , is one of the most important in calculus: it is the reason the derivative of is (see Derivatives of Trig Functions). The third one defines Euler's number , which SymPy prints as E.
One-sided limits
Sometimes the function approaches different values from the two sides. Consider : it is for negative and for positive .
The (two-sided) limit exists only when both one-sided limits exist and agree. Here they disagree, so does not exist.
import sympy as sp
x = sp.symbols('x')
g = sp.Abs(x) / x
print("from the left :", sp.limit(g, x, 0, dir='-'))
print("from the right:", sp.limit(g, x, 0, dir='+'))
print("1/x from right:", sp.limit(1 / x, x, 0, dir='+'))
print("1/x from left :", sp.limit(1 / x, x, 0, dir='-'))from the left : -1
from the right: 1
1/x from right: oo
1/x from left : -oo
shows another way a limit can fail: the values grow without bound. Writing is shorthand for "grows past every number", not a claim that the limit is a real number.
Ways a limit can fail to exist
| Behaviour near the point | Example | Limit? |
|---|---|---|
| Removable hole | at 3 | exists (6) |
| Jump | at 0 | does not exist |
| Blows up | at 0 | "" (no finite limit) |
| Wild oscillation | at 0 | does not exist |
The precise definition (–)
"Gets closer and closer" is made exact like this: means that for every tolerance there is a distance such that
In words: you choose how close to you want the output (); I must be able to name how close to the input has to be (). For with , , we have , so always works.
Tip: You will rarely write – proofs as a programmer, but the shape is familiar: it is exactly the contract of a numeric tolerance. "Give me an error budget and I'll tell you how precise the input must be."
In software
- Floating point: the computer never evaluates at "the limit point", it evaluates at nearby floats. Code such as
sin(x)/xmust special-casex == 0(NumPy'snp.sincdoes this), otherwise you getnan. - Convergence loops: iterative algorithms (Newton's method, gradient descent, PageRank) stop when successive values change by less than a tolerance. That is the idea in a
whileloop. - Asymptotic analysis: in Big-O notation we ask how cost behaves as , which is a limit at infinity, the topic of the next lesson.
Exercises
Exercise 1: Cancel the factor
Find .
Answer
7
Solution
Exercise 2: Conjugate trick
Find .
Answer
Solution
Multiply top and bottom by the conjugate :
Exercise 3: One-sided limits of a piecewise function
for and for . Find both one-sided limits at . Does the limit exist?
Answer
Left: 5, right: 5. Yes, the limit is 5.
Solution
Exercise 4: Table versus SymPy
Write a table of for , guess the limit as , then confirm it with SymPy.
Answer
The values approach ; SymPy gives 1/2.
Solution
import math
import sympy as sp
for x in [0.1, 0.01, 0.001]:
print(x, (1 - math.cos(x)) / x**2)
t = sp.symbols('t')
print("SymPy:", sp.limit((1 - sp.cos(t)) / t**2, t, 0))0.1 0.49958347219741783
0.01 0.4999958333473664
0.001 0.49999995832550326
SymPy: 1/2
Test yourself
What is the limit of as ?
- 0
- 2
- 4
- It does not exist
The left-hand limit at a point is 3 and the right-hand limit is 5. What is the two-sided limit?
- 4
- 3
- 5
- It does not exist
Why is a table of values near the point not a proof of a limit?
- Tables are always wrong
- The function could behave differently between or beyond the sampled points
- Computers cannot divide
- Limits only exist at integers