9. The squeeze theorem

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

Some functions can't be computed directly. x^2\sin(1/x) has no algebraic simplification, no factor to cancel, and its oscillating factor has no limit at all. Substitution fails, factoring fails, conjugates fail.

So don't compute it. Trap it.

The statement

Suppose g(x) \le f(x) \le h(x) for all x near a (except possibly at a itself), and \lim_{x\to a}g(x) = \lim_{x\to a}h(x) = L. Then \lim_{x\to a}f(x) = L.

If the bread converges, so does the filling. The two outer functions close in on the same value, and f has nowhere else to be.

Three details are worth reading carefully:

  • The bounds only need to hold near a. What f does far away is irrelevant, and the inequality may fail at a itself. Same "ignore the point" principle as every limit.
  • Both bounds must go to the same L. If g \to 1 and h \to 3, you learn only that f eventually lies in [1,3] — you have not proved a limit exists. Squeezing to different values proves nothing.
  • You never learn anything about f's formula. The theorem gives you the limit while the function itself stays a black box, which is exactly why it works when nothing else does.

The pattern to recognise

Almost every squeeze in practice is the same situation:

(\text{something bounded}) \times (\text{something} \to 0)

A bounded factor can't rescue a vanishing one. If |b(x)| \le M and c(x) \to 0, then

-M|c(x)| \;\le\; b(x)c(x) \;\le\; M|c(x)|

and both bounds go to 0, so b(x)c(x) \to 0.

That single observation handles most textbook squeezes. Train yourself to spot the bounded factor — usually a sine, cosine, or something living in [-1,1] — and the vanishing factor multiplying it.

The classic

\lim_{x\to0} x^2 \sin\!\left(\frac1x\right)

The sine has no limit at 0 (§1.2), so the product rule for limits is unavailable — it requires both factors to converge. But sine is bounded no matter what it's doing:

-1 \le \sin\!\left(\frac1x\right) \le 1

Multiply through by x^2, which is positive for x \neq 0 so the inequalities keep their direction:

-x^2 \le x^2\sin\!\left(\frac1x\right) \le x^2

Both -x^2 and x^2 go to 0, so

\lim_{x\to0}x^2\sin\!\left(\frac1x\right) = 0

The function still oscillates infinitely often on the way in — that never stops. But it does so inside a shrinking envelope, and the envelope wins.

Watch the sign discipline. Multiplying an inequality by x^2 \ge 0 is safe. Multiplying by x, which changes sign at 0, is not — the inequalities would flip on one side and the sandwich would fall apart. That's the standard mistake, and the reason |x| shows up in careful write-ups.

Where you've already used it

Archimedes' polygons in §0.1 were a squeeze in everything but name:

\frac{n s_n}{2} < \pi < \frac{n s_n}{2c_n}

The unknown \pi was trapped between two computable sequences, and both converged to the same value.

And the small-angle sandwich from §0.4 —

\cos\theta < \frac{\sin\theta}{\theta} < 1

— is the squeeze that proves \lim_{\theta\to0}\frac{\sin\theta}{\theta} = 1, which is the next lesson and the foundation of all trigonometric calculus.

The pattern recurs at every scale of this course. It is how you get a limit when the function itself refuses to cooperate.

A related tool: the comparison theorem

The same idea with one bound instead of two: if f(x) \le g(x) near a and both limits exist, then \lim f \le \lim g.

Note it's \le even if the original inequality was strict. f(x) < g(x) everywhere does not give \lim f < \lim g — take f(x) = 0 and g(x) = x^2 near 0, where f < g for all x \neq 0 but both limits are 0. Strict inequalities go soft in the limit. It's a small point that causes real errors in analysis proofs.

Doing it in Python

The envelope closing:

from math import sin

def f(x):
    return x * x * sin(1 / x)

print(f"{'x':>10} {'-x^2':>14} {'f(x)':>14} {'x^2':>14}")
for k in range(1, 8):
    x = 10.0 ** -k
    print(f"{x:>10.0e} {-x*x:>14.3e} {f(x):>14.3e} {x*x:>14.3e}")

print("\nthe filling never stops wobbling; the bread still crushes it to 0")

The sandwich holds at every point, not just the nice ones:

from math import sin
import random

random.seed(7)
worst = 0.0
for _ in range(200_000):
    x = random.uniform(-0.5, 0.5)
    if x == 0:
        continue
    f = x * x * sin(1 / x)
    assert -x * x <= f <= x * x
    worst = max(worst, abs(f) / (x * x))

print(f"200000 random points checked, all inside the envelope")
print(f"closest approach to the boundary: |f| / x^2 reached {worst:.6f}")
print("it gets arbitrarily close to 1 -- the bounds are tight, not slack")

And the mistake to avoid — bounds that don't converge to the same thing:

from math import sin

def f(x):
    return sin(1 / x)

print("sin(1/x) is trapped between -1 and 1 everywhere. so what?")
for k in range(3, 8):
    x = 10.0 ** -k
    print(f"  x={x:.0e}  -1 <= {f(x):+.6f} <= 1")

print("\nboth bounds are constant and unequal. the squeeze says nothing,")
print("and indeed no limit exists. squeezing to DIFFERENT values proves nothing.")

Worked example

Find \lim_{x\to0}\sqrt{x}\,\cos\!\left(\frac{1}{x}\right) for x > 0.

The cosine oscillates without limit, so no product rule. Bound it:

-1 \le \cos\!\left(\frac1x\right) \le 1

Multiply by \sqrt x, which is positive for x > 0, so the directions hold:

-\sqrt x \le \sqrt x\cos\!\left(\frac1x\right) \le \sqrt x

Both \pm\sqrt x \to 0 as x \to 0^+, so the limit is \boxed{0}.

Note the domain restriction is doing real work here in two ways: \sqrt x needs x \ge 0 to be defined at all, and it needs to be non-negative for the multiplication to preserve the inequalities. This is a one-sided limit by necessity.

A variant that fails. What about \lim_{x\to0}\frac{1}{x}\cos\left(\frac1x\right)? The same bounding gives

-\frac{1}{|x|} \le \frac{1}{x}\cos\!\left(\frac1x\right) \le \frac{1}{|x|}

and the bounds run to \pm\infty. The squeeze is useless, and correctly so: this function oscillates with growing amplitude and has no limit. The theorem never lies — when the bounds don't converge, it simply declines to tell you anything.

Your turn

1. Find \lim_{x\to0}x^4\cos\!\left(\frac{2}{x}\right).

2. Suppose 3x \le f(x) \le x^3 + 2 for all x near 1. What is \lim_{x\to1}f(x)?

3. Explain why the squeeze theorem cannot be used on \lim_{x\to0}\frac{\sin(1/x)}{x}.

Solutions

1. \cos is bounded regardless of its argument:

-1 \le \cos\!\left(\frac2x\right) \le 1

Multiply by x^4 \ge 0:

-x^4 \le x^4\cos\!\left(\frac2x\right) \le x^4

Both bounds \to 0, so the limit is \boxed{0}.

The 2 inside the cosine changes nothing — the argument's details are irrelevant, only boundedness matters. That indifference is the theorem's power.

2. Evaluate both bounds at 1: 3(1) = 3, and 1^3 + 2 = 3. They agree.

\lim_{x\to1}3x = 3 = \lim_{x\to1}(x^3+2)

so f is squeezed and \boxed{\lim_{x\to1}f(x) = 3}.

Note we learned the limit of f without ever knowing what f is. That's the theorem at its most characteristic — and it's how the sandwich in §0.4 will pin down \frac{\sin\theta}{\theta}, a quantity with no elementary closed form near 0.

3. Because the bounds don't converge. The numerator is bounded in [-1,1], giving

-\frac{1}{|x|} \le \frac{\sin(1/x)}{x} \le \frac{1}{|x|}

but \frac{1}{|x|} \to \infty. Both bounds run away, so the squeeze gives no information.

That's the correct outcome, not a limitation of the technique: the function genuinely has no limit, oscillating with unbounded amplitude. The squeeze needs a factor going to zero, not merely a bounded one — here \frac1x blows up instead.

Check yourself in code

Verify the envelope for f(x) = x^2\sin(1/x).

For x = 10^{-1}, 10^{-2}, \ldots, 10^{-6}, print -x^2, f(x), and x^2 in scientific notation with 2 decimals, plus whether the sandwich -x^2 \le f(x) \le x^2 holds.

Print exactly this:

x=1e-01  -1.00e-02 <= -5.44e-03 <= 1.00e-02  ok=True
x=1e-02  -1.00e-04 <= -5.06e-05 <= 1.00e-04  ok=True
x=1e-03  -1.00e-06 <= 8.27e-07 <= 1.00e-06  ok=True
x=1e-04  -1.00e-08 <= -3.06e-09 <= 1.00e-08  ok=True
x=1e-05  -1.00e-10 <= 3.57e-12 <= 1.00e-10  ok=True
x=1e-06  -1.00e-12 <= -3.50e-13 <= 1.00e-12  ok=True
from math import sin

def f(x):
    return x * x * sin(1 / x)

for k in range(1, 7):
    x = 10.0 ** -k
    # print the lower bound, f(x), the upper bound, and whether the sandwich holds
    print(f"x={x:.0e}  ...")
from math import sin

def f(x):
    return x * x * sin(1 / x)

for k in range(1, 7):
    x = 10.0 ** -k
    lo, hi, mid = -x * x, x * x, f(x)
    print(f"x={x:.0e}  {lo:.2e} <= {mid:.2e} <= {hi:.2e}  ok={lo <= mid <= hi}")

When a function resists every direct method, bound it above and below by functions that don't, and if the bounds converge to the same value the function is dragged along. The pattern to recognise is bounded times vanishing. Keep the sign discipline when multiplying inequalities, and remember that bounds converging to different values prove nothing at all.

Next: the squeeze that earns its keep — proving \lim_{x\to0}\frac{\sin x}{x} = 1, and with it the derivative of every trigonometric function.