TExcelTAD
Home › Calculus in Depth › The Limit of a Function

The Limit of a Function

A limit describes the value that f(x)f(x) approaches as xx approaches a number aa, without ever looking at f(a)f(a) itself. This lesson gives the working (intuitive) definition, one-sided and infinite limits, vertical asymptotes, and the ways numerical guessing can fool you.

The survey lesson Limits introduces the idea with tables. Here we are more careful about what the notation claims and where the evidence breaks down. The fully rigorous version comes in The Precise Definition of a Limit.

The working definition

lim⁡x→af(x)=L\lim_{x \to a} f(x) = L

means: we can make f(x)f(x) as close to LL as we like by taking xx sufficiently close to aa, on either side of aa, but not equal to aa. Three consequences follow directly from the wording.

  1. ff need not be defined at aa. The quotient (x2−1)/(x−1)(x^2 - 1)/(x - 1) has no value at 11, yet its limit there is 22.
  2. Even when f(a)f(a) is defined, it does not matter. Change f(1)f(1) to 100100 and the limit at 11 is still 22.
  3. The limit is a single number LL, the same from both sides. If the two sides head to different places, there is no (two-sided) limit.

One-sided limits

lim⁡f(x)=L\lim f(x) = L as x→a−x \to a^- (left-hand limit) restricts attention to x<ax < a; x→a+x \to a^+ (right-hand limit) restricts to x>ax > a. The basic link is a theorem:

lim⁡x→af(x)=L  ⟺  lim⁡x→a−f(x)=L and lim⁡x→a+f(x)=L\lim_{x \to a} f(x) = L \iff \lim_{x \to a^-} f(x) = L \text{ and } \lim_{x \to a^+} f(x) = L

Example: the floor function ⌊x⌋\lfloor x \rfloor at x=3x = 3 has left limit 22 and right limit 33, so lim⁡⌊x⌋\lim \lfloor x \rfloor as x→3x \to 3 does not exist, even though ⌊3⌋=3\lfloor 3 \rfloor = 3.

python · try it yourself
import math
import sympy as sp

x = sp.symbols('x')
print("left  of 3:", [math.floor(3 - 10**-k) for k in range(1, 5)])
print("right of 3:", [math.floor(3 + 10**-k) for k in range(1, 5)])
print("SymPy left :", sp.limit(sp.floor(x), x, 3, dir='-'))
print("SymPy right:", sp.limit(sp.floor(x), x, 3, dir='+'))
print("hole at 1  :", sp.limit((x**2 - 1)/(x - 1), x, 1))
left  of 3: [2, 2, 2, 2]
right of 3: [3, 3, 3, 3]
SymPy left : 2
SymPy right: 3
hole at 1  : 2

Infinite limits and vertical asymptotes

lim⁡x→af(x)=∞\lim_{x \to a} f(x) = \infty

means f(x)f(x) can be made arbitrarily large (larger than any number you name) by taking xx close enough to aa, x≠ax \ne a. This is a description of how the limit fails to exist, not a claim that it equals a number. Similarly for −∞-\infty and for one-sided versions.

The line x=ax = a is a vertical asymptote of y=f(x)y = f(x) if at least one of the six statements f(x)→±∞f(x) \to \pm\infty as x→ax \to a, a−a^-, a+a^+ holds.

Example: f(x)=(x+1)/(x−2)f(x) = (x + 1)/(x - 2). Near x=2x = 2 the numerator is close to 3>03 > 0 and the denominator is a small number whose sign matches the side:

side numerator denominator quotient
x→2+x \to 2^+ ≈3\approx 3 small, positive →+∞\to +\infty
x→2−x \to 2^- ≈3\approx 3 small, negative →−∞\to -\infty

So x=2x = 2 is a vertical asymptote. Other standard examples: ln⁡x→−∞\ln x \to -\infty as x→0+x \to 0^+, and tan⁡x→±∞\tan x \to \pm\infty as x→(π/2)∓x \to (\pi/2)^{\mp}.

When numerical guessing fails

Tables are useful but limited. Two classic traps:

Trap 1, oscillation. g(x)=sin⁡(π/x)g(x) = \sin(\pi/x). Sample x=1/nx = 1/n and every value is sin⁡(nπ)=0\sin(n\pi) = 0, suggesting the limit at 00 is 00. Sample x=2/(4n+1)x = 2/(4n + 1) and every value is sin⁡(2nπ+π/2)=1\sin(2n\pi + \pi/2) = 1. The function oscillates between −1-1 and 11 infinitely often near 00; the limit does not exist.

Trap 2, catastrophic cancellation. (1−cos⁡x)/x2(1 - \cos x)/x^2 has limit 1/21/2 at 00, but in floating point 1 − cos(1e-8) is exactly 0.0, because cos(1e-8) rounds to 1.0.

python · try it yourself
import math

print("sin(pi/x) on x = 1/n      :", [round(math.sin(math.pi * n), 12) + 0.0 for n in (10, 100, 1000)])
print("sin(pi/x) on x = 2/(4n+1) :", [round(math.sin(math.pi * (4*n + 1) / 2), 12) for n in (10, 100, 1000)])

for x in [1e-2, 1e-4, 1e-6, 1e-8]:
    naive = (1 - math.cos(x)) / x**2
    stable = 2 * math.sin(x/2)**2 / x**2      # same function, rewritten
    print(f"x={x:g}  naive={naive:.10f}  stable={stable:.10f}")
sin(pi/x) on x = 1/n      : [0.0, 0.0, 0.0]
sin(pi/x) on x = 2/(4n+1) : [1.0, 1.0, 1.0]
x=0.01  naive=0.4999958333  stable=0.4999958333
x=0.0001  naive=0.4999999970  stable=0.4999999996
x=1e-06  naive=0.5000444503  stable=0.5000000000
x=1e-08  naive=0.0000000000  stable=0.5000000000

The naive column drifts and then collapses to 00 purely because of rounding. The identity 1−cos⁡x=2sin⁡2(x/2)1 - \cos x = 2\sin^2(x/2) removes the subtraction of nearly equal numbers, and the stable column stays on the true values, which are ≈1/2−x2/24\approx 1/2 - x^2/24 and so approach 0.50.5.

Tip: Treat a table as a hypothesis generator. Confirm with algebra, a theorem from Calculating Limits Using the Limit Laws, or a symbolic tool such as sympy.limit.

A picture of the oscillation

python · try it yourself
import numpy as np
import matplotlib.pyplot as plt

xs = np.linspace(0.005, 0.5, 4000)
plt.figure(figsize=(6, 3.5))
plt.plot(xs, np.sin(np.pi / xs), lw=0.7)
plt.plot(-xs, np.sin(np.pi / -xs), lw=0.7, color="C0")
plt.title("y = sin(π/x): no limit at 0"); plt.grid(alpha=0.3)
seen = int(np.sum(np.diff(np.sign(np.sin(np.pi / xs))) != 0))
true = len([n for n in range(1, 1000) if 0.005 < 1/n <= 0.5])   # zeros at x = 1/n
print("sign changes seen by 4000 samples:", seen)
print("true zeros in (0.005, 0.5]       :", true)
sign changes seen by 4000 samples: 117
true zeros in (0.005, 0.5]       : 198

Even 4000 evenly spaced samples miss most of the oscillations close to 00: the zeros x=1/nx = 1/n crowd together faster than any fixed grid can resolve. That is the oscillation trap again, this time in a plot.

In software

  • Special-casing singular points. sinc⁡(x)=sin⁡(x)/x\operatorname{sinc}(x) = \sin(x)/x is defined at 00 by its limit 11; NumPy's np.sinc and audio resampling code do exactly that. Any formula with a removable 0/00/0 needs such a branch.
  • Numerical stability. Library functions math.expm1(x) (for ex−1e^x - 1) and math.log1p(x) (for ln⁡(1+x)\ln(1 + x)) exist because the naive formulas suffer the cancellation shown above near x=0x = 0.
  • Asymptotes in plots. Plotting tan⁡x\tan x or 1/(x−2)1/(x - 2) naively connects +∞+\infty to −∞-\infty with a vertical line; good plotting code detects the asymptote and breaks the curve.

Exercises

Exercise 1: Ignore the value at the point

f(x)=(x2−4x+3)/(x−3)f(x) = (x^2 - 4x + 3)/(x - 3) for x≠3x \ne 3 and f(3)=10f(3) = 10. Find lim⁡f(x)\lim f(x) as x→3x \to 3.

Answer

22

Solution
x2−4x+3=(x−1)(x−3)for x≠3: f(x)=x−1→2 as x→3f(3)=10 is irrelevant to the limit\begin{aligned} &x^2 - 4x + 3 = (x - 1)(x - 3) \\ &\text{for } x \ne 3{:}\ f(x) = x - 1 \to 2 \text{ as } x \to 3 \\ &f(3) = 10 \text{ is irrelevant to the limit} \end{aligned}

Exercise 2: One-sided limits

Let f(x)=∣x−5∣/(x−5)f(x) = \lvert x - 5 \rvert/(x - 5). Find the one-sided limits at 55. Does the limit exist?

Answer

Left −1-1, right 11; no limit.

Solution
x>5: ∣x−5∣=x−5, so f(x)=1x<5: ∣x−5∣=−(x−5), so f(x)=−1the one-sided limits differ, so lim⁡f(x) at 5 does not exist\begin{aligned} &x > 5{:}\ \lvert x - 5 \rvert = x - 5, \text{ so } f(x) = 1 \\ &x < 5{:}\ \lvert x - 5 \rvert = -(x - 5), \text{ so } f(x) = -1 \\ &\text{the one-sided limits differ, so } \lim f(x) \text{ at } 5 \text{ does not exist} \end{aligned}

Exercise 3: Vertical asymptote

Find lim⁡(2−x)/(x+1)2\lim (2 - x)/(x + 1)^2 as x→−1x \to -1. Is x=−1x = -1 a vertical asymptote?

Answer

+∞+\infty from both sides; yes.

Solution
near x=−1 the numerator→3>0the denominator (x+1)2 is positive and→0 from both sidesso the quotient→+∞ on both sides; x=−1 is a vertical asymptote\begin{aligned} &\text{near } x = -1 \text{ the numerator} \to 3 > 0 \\ &\text{the denominator } (x + 1)^2 \text{ is positive and} \to 0 \text{ from both sides} \\ &\text{so the quotient} \to +\infty \text{ on both sides; } x = -1 \text{ is a vertical asymptote} \end{aligned}

Exercise 4: Fool the table

Show numerically that sampling cos⁡(π/x)\cos(\pi/x) at x=1/(2n)x = 1/(2n) suggests a limit of 11 at 00, then find another sequence of points that gives −1-1.

Answer

x=1/(2n+1)x = 1/(2n+1) gives cos⁡((2n+1)π)=−1\cos((2n+1)\pi) = -1, so the limit does not exist.

Solution
python · try it yourself
import math
f = lambda x: math.cos(math.pi / x)
print([round(f(1/(2*n)), 9) for n in (5, 50, 500)])
print([round(f(1/(2*n + 1)), 9) for n in (5, 50, 500)])
[1.0, 1.0, 1.0]
[-1.0, -1.0, -1.0]

Two sequences tending to 00 give different limiting values, so no single LL works.

Test yourself

If f(2)=7f(2) = 7 and lim⁡f(x)\lim f(x) as x→2x \to 2 exists, what can you conclude about the limit?

  1. It equals 7
  2. Nothing: the value f(2)f(2) does not determine the limit
  3. It is not 7
  4. It is infinite

Which statement defines a vertical asymptote x=ax = a?

  1. f(a)f(a) is undefined
  2. f(x)→±∞f(x) \to \pm\infty as xx approaches aa from at least one side
  3. ff has a hole at aa
  4. The left and right limits differ

Why does (1−cos⁡x)/x2(1 - \cos x)/x^2 evaluate to 0.0 in floating point at x = 1e-8?

  1. The limit really is 0
  2. cos(1e-8) rounds to exactly 1.0, so the numerator cancels to 0
  3. Python cannot compute cosines of small numbers
  4. x2x^2 underflows to 0