TExcelTAD
Home › Calculus Essentials › Continuity

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

ff is continuous at aa when three things all hold:

1. f(a) is defined2. lim⁡x→af(x) exists3. the limit equals the value: lim⁡x→af(x)=f(a)\begin{aligned} &1.\ f(a) \text{ is defined} \\ &2.\ \lim_{x \to a} f(x) \text{ exists} \\ &3.\ \text{the limit equals the value: } \lim_{x \to a} f(x) = f(a) \end{aligned}

ff is continuous on an interval if it is continuous at every point of it. Polynomials, sin⁡\sin, cos⁡\cos, exe^x are continuous everywhere; rational functions, ln⁡x\ln x, x\sqrt{x} and tan⁡x\tan x 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 f(a)f(a) is missing or wrong x2−1x−1\frac{x^2 - 1}{x - 1} at 1
Jump left and right limits differ ⌊x⌋\lfloor x \rfloor (floor(x)) at any integer
Infinite function blows up 1x−2\frac{1}{x - 2} at 2
Oscillating no limit because of endless wiggling sin⁡(1/x)\sin(1/x) at 0

A removable discontinuity can be repaired by (re)defining a single value. For x2−1x−1\frac{x^2 - 1}{x - 1} the limit at 1 is 2, so defining f(1)=2f(1) = 2 makes it continuous.

python · try it yourself
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 0/00/0 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

f(x)={x2+kfor x<13x−1for x≥1f(x) = \begin{cases} x^2 + k & \text{for } x < 1 \\ 3x - 1 & \text{for } x \ge 1 \end{cases}

At x=1x = 1 the right piece gives 22, the left piece approaches 1+k1 + k. Continuity needs 1+k=21 + k = 2, so k=1k = 1.

The Intermediate Value Theorem

If ff is continuous on [a,b][a, b] and NN is any number between f(a)f(a) and f(b)f(b), then there is some cc in (a,b)(a, b) with f(c)=Nf(c) = N.

The most useful case is N=0N = 0: 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.

python · try it yourself
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 (230≈1.07×1092^{30} \approx 1.07 \times 10^9). The theorem needs continuity: 1/x1/x changes sign on [−1,1][-1, 1] but has no root, because it is not continuous at 0.

In software

  • Bisection everywhere: git bisect finds 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 g(x)=x2−4x+3x−3g(x) = \dfrac{x^2 - 4x + 3}{x - 3} at x=3x = 3, and say how to fix it.

Answer

Removable; define g(3)=2g(3) = 2.

Solution
x2−4x+3=(x−1)(x−3)g(x)=x−1 for x≠3, so lim⁡x→3g(x)=2g(3) itself is undefined (0/0), so the discontinuity is removable: set g(3)=2.\begin{aligned} &x^2 - 4x + 3 = (x - 1)(x - 3) \\ &g(x) = x - 1 \text{ for } x \ne 3, \text{ so } \lim_{x \to 3} g(x) = 2 \\ &g(3) \text{ itself is undefined } (0/0), \text{ so the discontinuity is removable: set } g(3) = 2. \end{aligned}

Exercise 2: Choose the constant

Find cc so that h(x)=cx+4h(x) = cx + 4 for x<2x < 2 and h(x)=x2−ch(x) = x^2 - c for x≥2x \ge 2 is continuous.

Answer

c=0c = 0

Solution
left limit at 2: 2c+4value at 2: 4−ccontinuity: 2c+4=4−c  ⟹  3c=0  ⟹  c=0\begin{aligned} &\text{left limit at 2: } && 2c + 4 \\ &\text{value at 2: } && 4 - c \\ &\text{continuity: } && 2c + 4 = 4 - c \implies 3c = 0 \implies c = 0 \end{aligned}

Exercise 3: Prove a root exists

Show that cos⁡x=x\cos x = x has a solution between 0 and 1.

Answer

f(x)=cos⁡x−xf(x) = \cos x - x is continuous with f(0)=1>0f(0) = 1 > 0 and f(1)≈−0.46<0f(1) \approx -0.46 < 0, so the IVT gives a root.

Solution
f(x)=cos⁡x−x is continuous everywhere (difference of continuous functions)f(0)=1−0=1>0f(1)=cos⁡1−1≈−0.4597<00 lies between f(0) and f(1), so some c in (0,1) has f(c)=0, i.e. cos⁡c=c.\begin{aligned} &f(x) = \cos x - x \text{ is continuous everywhere (difference of continuous functions)} \\ &f(0) = 1 - 0 = 1 > 0 \\ &f(1) = \cos 1 - 1 \approx -0.4597 < 0 \\ &0 \text{ lies between } f(0) \text{ and } f(1), \text{ so some } c \text{ in } (0, 1) \text{ has } f(c) = 0, \text{ i.e. } \cos c = c. \end{aligned}

Exercise 4: Bisect it

Use 40 steps of bisection on [0,1][0, 1] to approximate the solution of cos⁡x=x\cos x = x to 6 decimals.

Answer

x≈0.739085x \approx 0.739085

Solution
python · try it yourself
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 aa?

  1. f(a)f(a) is defined
  2. lim⁡x→af(x)\lim_{x \to a} f(x) exists
  3. ff is differentiable at aa
  4. lim⁡x→af(x)=f(a)\lim_{x \to a} f(x) = f(a)

What type of discontinuity does ⌊x⌋\lfloor x \rfloor (floor) have at x=3x = 3?

  1. Removable
  2. Infinite
  3. Oscillating
  4. Jump

ff is continuous on [0,4][0, 4], f(0)=−3f(0) = -3 and f(4)=5f(4) = 5. What does the Intermediate Value Theorem guarantee?

  1. ff has a maximum at 4
  2. f(c)=0f(c) = 0 for some cc in (0,4)(0, 4)
  3. ff is increasing
  4. f(2)=1f(2) = 1