13. Continuity and its failure modes

📖 Reading · 13 min
💡 Every code box below is live — edit it and hit Run.

Informally: a function is continuous if you can draw its graph without lifting the pen. That picture is a good guide and a bad definition — it says nothing about functions too wild to draw, and it hides which of several distinct things has gone wrong when continuity fails.

The real definition is one line, and it's a statement about limits.

The definition

f is continuous at a if \displaystyle\lim_{x\to a}f(x) = f(a).

That single equation quietly demands three separate things, and each can fail on its own:

  1. f(a) existsa is in the domain.
  2. \lim_{x\to a}f(x) exists — both one-sided limits exist and agree.
  3. They're equal — the value the function is heading for is the value it takes.

Recall §1.0's whole point: the limit deliberately ignores f(a). Continuity is precisely the condition that ignoring it didn't matter.

And that is why continuity is worth naming. Continuity is what makes substitution legal. Every time you evaluate a limit by plugging in, you are using continuity, whether or not you say so.

Continuity on an interval

f is continuous on an open interval if it's continuous at every point in it. On a closed interval [a,b], the endpoints only get a one-sided requirement:

\lim_{x\to a^+}f(x) = f(a), \qquad \lim_{x\to b^-}f(x) = f(b)

This isn't pedantry. f(x) = \sqrt{x} is continuous on [0,\infty), and it had better be — there is nothing to the left of 0 to approach from, so demanding a two-sided limit there would rule out a perfectly well-behaved function for no reason.

What's continuous

The useful headline: every elementary function is continuous on its domain.

Family Continuous on
Polynomials all of \mathbb{R}
Rational functions everywhere the denominator is nonzero
\sqrt[n]{x} its domain (x \ge 0 for even n)
e^x, \sin x, \cos x all of \mathbb{R}
\ln x x > 0
\tan x everywhere except \frac{\pi}{2} + k\pi

And continuity survives every construction:

  • f + g, f - g, fg are continuous where f and g are;
  • f/g is continuous where both are and g \neq 0;
  • f \circ g is continuous where g is continuous and f is continuous at g(a).

Put together, these say: if you built a function out of elementary pieces using ordinary operations, it's continuous wherever it's defined, and you can evaluate limits by substitution. The interesting cases are always the boundary points — where a denominator vanishes, or a piecewise rule changes.

The composition rule, used constantly

The composition case deserves its own line, because you'll use it every day without noticing:

\lim_{x\to a}f(g(x)) = f\!\left(\lim_{x\to a}g(x)\right) \quad \text{if } f \text{ is continuous at } \lim g

A continuous function can be moved through a limit. That's what lets you write

\lim_{x\to0}\sqrt{\frac{\sin x}{x}} = \sqrt{\lim_{x\to0}\frac{\sin x}{x}} = \sqrt1 = 1

The continuity of \sqrt{\cdot} at 1 is the entire justification for that first step. Skip it and the manoeuvre is unlicensed — and there are functions for which it genuinely fails.

The failure modes, classified

§1.2 catalogued how limits fail; here they are again as discontinuities.

Removable. The limit exists but f(a) is missing or wrong.

f(x) = \frac{x^2-4}{x-2} has \lim_{x\to2}f = 4 and no f(2). Define f(2) = 4 and it's continuous. "Removable" is literal.

Jump. Both one-sided limits exist and differ. \lfloor x \rfloor at every integer, \frac{|x|}{x} at 0. No redefinition of f(a) can help — the problem is the mismatch between the sides.

Infinite. At least one one-sided limit is \pm\infty. \frac1x at 0, \tan x at \frac\pi2. Also unrepairable, and it's the vertical-asymptote case.

Oscillatory. No one-sided limit exists at all. \sin(1/x) at 0. The nastiest kind, and the one no numerical method detects.

The diagnostic procedure is always the same: compute both one-sided limits, then compare them to each other and to f(a).

Doing it in Python

Checking the three conditions, one function at a time:

def report(name, f, a, h=1e-7):
    try:
        value = f(a)
        value_str = f"{value:.6f}"
    except (ZeroDivisionError, ValueError):
        value_str = "undefined"
    left, right = f(a - h), f(a + h)
    print(f"{name:<22} f({a})={value_str:<12} left={left:<12.6f} right={right:<12.6f}")

report("(x^2-4)/(x-2) at 2", lambda x: (x*x - 4) / (x - 2), 2)
report("abs(x)/x at 0", lambda x: abs(x) / x, 0)
report("x^2 at 2", lambda x: x * x, 2)

print("\nrow 1: limit exists (4) but no value -- removable")
print("row 2: sides disagree -- jump")
print("row 3: value equals both sides -- continuous")

Continuity is what makes substitution legal, and here's the failure when it isn't:

from math import sin, sqrt

# f continuous at the inner limit: moving it through is fine
inner = [sin(x) / x for x in (1e-6,)][0]
print(f"sqrt(lim sin(x)/x)  = {sqrt(1.0):.10f}")
print(f"lim sqrt(sin(x)/x)  = {sqrt(sin(1e-6) / 1e-6):.10f}")

# a discontinuous outer function: the swap is NOT licensed
def step(y):
    return 0.0 if y < 1 else 1.0

print(f"\nstep(lim sin(x)/x)  = {step(1.0):.1f}")
print(f"lim step(sin(x)/x)  = {step(sin(1e-6) / 1e-6):.1f}")
print("sin(x)/x approaches 1 from BELOW, so the step never fires. the values differ.")

Finding the constant that repairs a piecewise function:

def make(c):
    def f(x):
        return c * x + 1 if x < 2 else x * x - c
    return f

print(f"{'c':>5} {'left limit':>12} {'right limit':>12} {'continuous':>12}")
for c in (-1, 0, 1, 2):
    f = make(c)
    left, right = f(2 - 1e-9), f(2)
    print(f"{c:>5} {left:>12.6f} {right:>12.6f} {abs(left-right) < 1e-6!s:>12}")

print("\nsolving 2c+1 = 4-c gives c=1, and only that row matches")

Worked example

Where is f(x) = \dfrac{x^2-x-6}{x^2-9} discontinuous, and of what kind?

The denominator vanishes at x = \pm3, so those are the only candidates — everywhere else this is a rational function with a nonzero denominator, hence continuous.

Factor both:

f(x) = \frac{(x-3)(x+2)}{(x-3)(x+3)} = \frac{x+2}{x+3} \qquad (x \neq 3)

At x = 3: the factor cancelled. The reduced form gives \frac{5}{6}, and both one-sided limits agree on it, but f(3) is undefined — 3 was never in the domain, and cancelling doesn't put it back. Removable discontinuity; defining f(3) = \frac56 repairs it.

At x = -3: the factor survived. The numerator there is -3+2 = -1 \neq 0, so the quotient blows up. From the left, x + 3 is small negative, giving \frac{-1}{\text{small neg}} = +\infty; from the right, -\infty. Infinite discontinuity, a vertical asymptote.

The rule to take away, same as §1.2's: factor first. Whether a zero of the denominator cancels decides whether you have a hole or an asymptote, and you cannot tell them apart before factoring — both present as division by zero.

Your turn

1. Find c making f(x) = \begin{cases}x^2 + c & x < 3\\ 2x + 1 & x \ge 3\end{cases} continuous everywhere.

2. Classify the discontinuities of g(x) = \dfrac{x-1}{x^2-1}.

3. Is h(x) = \begin{cases}x\sin(1/x) & x \neq 0\\ 0 & x = 0\end{cases} continuous at 0?

Solutions

1. Away from 3 both pieces are polynomials and continuous, so 3 is the only point to check. Continuity needs the two sides and the value to agree:

\lim_{x\to3^-}f(x) = 9 + c, \qquad \lim_{x\to3^+}f(x) = f(3) = 7

Set them equal: 9 + c = 7, so \boxed{c = -2}.

2. Factor: g(x) = \frac{x-1}{(x-1)(x+1)} = \frac{1}{x+1} for x \neq 1.

At x = 1: the factor cancels, both sides give \frac12, and g(1) is undefined — removable.

At x = -1: nothing cancels, numerator is -2 \neq 0infinite, a vertical asymptote.

3. Yes. We need \lim_{x\to0}x\sin(1/x) = h(0) = 0.

The sine is bounded, x \to 0, so by the squeeze (§1.3):

-|x| \le x\sin\!\left(\frac1x\right) \le |x| \implies \lim_{x\to0}x\sin\!\left(\frac1x\right) = 0

which matches h(0) = 0. Continuous.

Worth pausing on: this function oscillates infinitely often in every neighbourhood of 0 — you emphatically cannot draw it without lifting the pen — and it is nonetheless continuous there. The pen picture is intuition, not definition. (In §2.1 you'll find this same function is continuous at 0 but not differentiable there, which is the sharper statement.)

Check yourself in code

Find the constant that makes a piecewise function continuous.

For f(x) = \begin{cases}cx + 1 & x < 2\\ x^2 - c & x \ge 2\end{cases} and c \in \{-1, 0, 1, 2\}, print the left limit (evaluate at 2 - 10^{-9}), the right value f(2), and whether they agree to within 10^{-6}. Then print the working value of c.

Print exactly this:

c=-1  left=-1.000000  right=5.000000  continuous=False
c=0   left=1.000000  right=4.000000  continuous=False
c=1   left=3.000000  right=3.000000  continuous=True
c=2   left=5.000000  right=2.000000  continuous=False
continuous when c=1
def make(c):
    def f(x):
        return c * x + 1 if x < 2 else x * x - c
    return f

good = []
for c in (-1, 0, 1, 2):
    f = make(c)
    left, right = f(2 - 1e-9), f(2)
    # print the two sides and whether they agree; remember which c worked
    print(f"c={c:<3} ...")
def make(c):
    def f(x):
        return c * x + 1 if x < 2 else x * x - c
    return f

good = []
for c in (-1, 0, 1, 2):
    f = make(c)
    left, right = f(2 - 1e-9), f(2)
    ok = abs(left - right) < 1e-6
    if ok:
        good.append(c)
    print(f"c={c:<3} left={left:.6f}  right={right:.6f}  continuous={ok}")

print(f"continuous when c={good[0]}")

Continuity at a is the single equation \lim_{x\to a}f(x) = f(a), which demands the value exist, the limit exist, and the two agree. It's what makes substitution legal and what lets you move a function through a limit. Elementary functions are continuous on their domains, and every construction preserves it, so the only places to check are denominators' zeros and the joins of piecewise rules — where the discontinuity is removable, a jump, infinite, or oscillatory according to how the one-sided limits behave.

Next: the two theorems that continuity buys you, and which underwrite every root-finding algorithm you'll ever run.