Continuity
A function is continuous when its graph has no breaks: you could draw it without lifting your pen. Continuity is what lets us trust that small changes in the input cause small changes in the output, and it powers guarantees like "this equation has a root somewhere in this interval", which bisection search relies on.
The definition
is continuous at when three things all hold:
is continuous on an interval if it is continuous at every point of it. Polynomials, , , are continuous everywhere; rational functions, , and are continuous wherever they are defined. Sums, products, quotients (where the denominator is nonzero) and compositions of continuous functions are continuous.
Kinds of discontinuity
| Kind | What fails | Example at the point |
|---|---|---|
| Removable | limit exists but is missing or wrong | at 1 |
| Jump | left and right limits differ | (floor(x)) at any integer |
| Infinite | function blows up | at 2 |
| Oscillating | no limit because of endless wiggling | at 0 |
A removable discontinuity can be repaired by (re)defining a single value. For the limit at 1 is 2, so defining makes it continuous.
import sympy as sp
x = sp.symbols('x')
f = (x**2 - 1) / (x - 1)
print("f(1) by substitution:", f.subs(x, 1))
print("limit at 1:", sp.limit(f, x, 1))
# floor has a jump at 2
print("floor, left of 2 :", sp.limit(sp.floor(x), x, 2, dir='-'))
print("floor, right of 2:", sp.limit(sp.floor(x), x, 2, dir='+'))f(1) by substitution: nan
limit at 1: 2
floor, left of 2 : 1
floor, right of 2: 2
SymPy prints nan (not a number) for the substitution, which is its way of saying "undefined".
Making a piecewise function continuous
A typical design task: choose a constant so that the pieces meet. Let
At the right piece gives , the left piece approaches . Continuity needs , so .
The Intermediate Value Theorem
If is continuous on and is any number between and , then there is some in with .
The most useful case is : if a continuous function changes sign on an interval, it has a root in that interval. That is the entire justification for the bisection method: keep halving the interval, always keeping the half where the sign changes.
def f(x):
return x**3 - x - 2 # continuous, f(1) = -2 < 0, f(2) = 4 > 0
a, b = 1.0, 2.0
for step in range(1, 31):
m = (a + b) / 2
if f(a) * f(m) <= 0:
b = m
else:
a = m
if step in (1, 2, 3, 10, 20, 30):
print(f"step {step:2d}: root in [{a:.10f}, {b:.10f}]")
print("f at midpoint:", f((a + b) / 2))step 1: root in [1.5000000000, 2.0000000000]
step 2: root in [1.5000000000, 1.7500000000]
step 3: root in [1.5000000000, 1.6250000000]
step 10: root in [1.5205078125, 1.5214843750]
step 20: root in [1.5213794708, 1.5213804245]
step 30: root in [1.5213797064, 1.5213797074]
f at midpoint: 6.591687196078055e-10
Each step halves the interval, so 30 steps shrink it by a factor of about a billion (). The theorem needs continuity: changes sign on but has no root, because it is not continuous at 0.
In software
- Bisection everywhere:
git bisectfinds the commit that broke a test by the same halving logic, assuming "good" turns into "bad" once. Binary search on a sorted array is the discrete cousin (see DSA). - Continuous vs discrete: pixels, time steps and floats are discrete, so a game object moving fast can "tunnel" through a thin wall between frames. Physics engines use continuous collision detection to recover the in-between motion (CCD).
- Neural networks: activation functions are chosen to be continuous (sigmoid, tanh, ReLU) so that small weight changes give small output changes, which is what makes training by small steps possible. A step function has a jump and gives gradient-based training nothing to work with.
Exercises
Exercise 1: Classify
Classify the discontinuity of at , and say how to fix it.
Answer
Removable; define .
Solution
Exercise 2: Choose the constant
Find so that for and for is continuous.
Answer
Solution
Exercise 3: Prove a root exists
Show that has a solution between 0 and 1.
Answer
is continuous with and , so the IVT gives a root.
Solution
Exercise 4: Bisect it
Use 40 steps of bisection on to approximate the solution of to 6 decimals.
Answer
Solution
import math
f = lambda x: math.cos(x) - x
a, b = 0.0, 1.0
for _ in range(40):
m = (a + b) / 2
if f(a) * f(m) <= 0:
b = m
else:
a = m
print(round((a + b) / 2, 6))0.739085
Test yourself
Which condition is NOT part of the definition of continuity at ?
- is defined
- exists
- is differentiable at
What type of discontinuity does (floor) have at ?
- Removable
- Infinite
- Oscillating
- Jump
is continuous on , and . What does the Intermediate Value Theorem guarantee?
- has a maximum at 4
- for some in
- is increasing