Limits and Continuity
A continuous function is one whose graph you can draw without lifting your pencil. This lesson turns that picture into a definition using limits, lists the limit laws that let you compute most limits by plugging in, classifies the ways a function can fail to be continuous, and uses the Intermediate Value Theorem to justify the bisection method, a root finder used in real code.
Limit laws
If and as , then limits combine the way you would hope:
| Law | Result |
|---|---|
| sum / difference | |
| constant multiple | |
| product | |
| quotient | , provided |
| power and root | , ( for even ) |
Together with and , these laws say: for polynomials, and for rational functions where the denominator is not 0, the limit is just the value. .
When direct substitution gives , the laws do not apply yet: simplify first (factor, cancel, use a conjugate), then substitute. That is the method from Introduction to Limits.
What continuity means
A function is continuous at when three things hold:
In words: the value the function approaches is the value it actually has. A function is continuous on an interval if it is continuous at every point of it.
Polynomials, , and are continuous everywhere. Rational functions, , and are continuous wherever they are defined. Sums, products, quotients (with nonzero denominator) and compositions of continuous functions are continuous.
Kinds of discontinuity
| Kind | Example at or 1 | What goes wrong | Fixable? |
|---|---|---|---|
| removable (hole) | at 1 | limit exists but is missing or wrong | yes: define |
| jump | at 1, or the sign function at 0 | left and right limits differ | no |
| infinite | at 0 | the function blows up | no |
| oscillating | at 0 | no limit at all | no |
Jump discontinuities are everywhere in code: floor, round, integer division, if thresholds and price tiers all jump.
import math
def one_sided(f, a, h=1e-9):
return f(a - h), f(a + h)
tests = {
"floor(x) at 1": (math.floor, 1),
"x^2 at 1": (lambda x: x * x, 1),
"(x^2-1)/(x-1) at 1": (lambda x: (x * x - 1) / (x - 1), 1),
"1/x at 0": (lambda x: 1 / x, 0),
}
for name, (f, a) in tests.items():
left, right = one_sided(f, a)
try:
value = f(a)
except ZeroDivisionError:
value = "undefined"
print(f"{name:<20} left {left:>14.6g} right {right:>14.6g} f(a) = {value}")floor(x) at 1 left 0 right 1 f(a) = 1
x^2 at 1 left 1 right 1 f(a) = 1
(x^2-1)/(x-1) at 1 left 2 right 2 f(a) = undefined
1/x at 0 left -1e+09 right 1e+09 f(a) = undefined
floor jumps from 0 to 1, is continuous, the rational function has a removable hole (both sides approach 2, no value at 1), and has an infinite discontinuity. Note that evaluating "just next to" is a heuristic: it shows what is happening, but floating point can hide or invent jumps.
The Intermediate Value Theorem
If is continuous on and is any number between and , then for at least one between and . A continuous graph cannot get from one height to another without passing through every height in between.
The most useful case: if and have opposite signs, has a root between and . This is the guarantee behind the bisection method: keep halving the interval, keeping the half where the sign changes.
def bisect(f, a, b, tol=1e-10):
fa = f(a)
assert fa * f(b) < 0, "need a sign change"
steps = 0
while b - a > tol:
m = (a + b) / 2
if fa * f(m) <= 0:
b = m
else:
a, fa = m, f(m)
steps += 1
return (a + b) / 2, steps
f = lambda x: x**3 - x - 2 # f(1) = -2 < 0, f(2) = 4 > 0
root, steps = bisect(f, 1, 2)
print(f"root ≈ {root:.10f} after {steps} halvings, f(root) = {f(root):.1e}")
g = lambda x: 1 / x # sign change on [-1, 2] but NOT continuous
print("1/x on [-1, 2]:", bisect(g, -1, 2))root ≈ 1.5213797068 after 34 halvings, f(root) = 1.4e-10
1/x on [-1, 2]: (-1.4551915228366852e-11, 35)
Each halving gains one binary digit, so about 34 steps reach starting from width 1. The second call is a warning: changes sign on but has no root, and bisection happily "finds" the discontinuity at 0. The theorem needs continuity. The same halving idea, on sorted data instead of a function, is binary search; git bisect uses it to find the commit that broke a build.
In software
- Thresholds and rounding. A tiny change in input can cause a big change in output at a jump: a price rounded to cents, a pixel coordinate floored, a score crossing a cutoff. Testing just below and just above each threshold catches off-by-one bugs.
- Smooth animation. UI animations and camera moves must be continuous (no teleporting), and usually their speed must be continuous too, which is why easing curves are designed carefully.
- Optimisation. Gradient-based training needs continuous (and smooth) loss functions; the step function is replaced by the continuous sigmoid in neural networks for this reason.
Continuity in more depth: Continuity, Limit Laws and Continuity (in depth).
Exercises
Exercise 1: Plug in
Find as .
Answer
Solution
Exercise 2: Classify
Classify the discontinuities of .
Answer
Removable at (limit 4), infinite at .
Solution
Exercise 3: Make it continuous
Choose so that for and for is continuous.
Answer
Solution
Exercise 4: Bisection for
Use the bisect function from the lesson on over . Why is a root guaranteed there, and how many halvings does it take?
Answer
and with continuous, so the IVT guarantees a root; after 34 halvings.
Solution
def bisect(f, a, b, tol=1e-10):
fa = f(a)
steps = 0
while b - a > tol:
m = (a + b) / 2
if fa * f(m) <= 0:
b = m
else:
a, fa = m, f(m)
steps += 1
return (a + b) / 2, steps
root, steps = bisect(lambda x: x * x - 5, 2, 3)
print(f"{root:.10f}", steps)2.2360679775 34
Test yourself
Which condition is NOT part of the definition of continuity at ?
- is defined
- as exists
- is differentiable at
is continuous on , and . What does the Intermediate Value Theorem guarantee?
- has a maximum of 2
- is increasing
- for some in
What type of discontinuity does math.floor have at ?
- Removable
- Infinite
- Oscillating
- Jump