CALCULUS / 1. LIMITS & CONTINUITY

Limits & Continuity

The foundation — what happens as we get infinitely close


EXPLANATION

A limit describes the value a function approaches as the input approaches some value — even if the function is not defined there.

lim(x→a) f(x) = L means: as x gets arbitrarily close to a, f(x) gets arbitrarily close to L.

One-sided limits:
• lim(x→a⁻) f(x) → approach from the LEFT
• lim(x→a⁺) f(x) → approach from the RIGHT
• Limit exists only if both sides agree

Continuity: f is continuous at a if:
1. f(a) is defined
2. lim(x→a) f(x) exists
3. lim(x→a) f(x) = f(a)

Why limits matter for calculus:
The derivative is defined as a limit:
f'(x) = lim(Δx→0) [f(x+Δx) - f(x)] / Δx

This is the "instantaneous rate of change" — the slope at exactly one point, not between two points.

Important limits to know:
• lim(x→0) sin(x)/x = 1
• lim(x→0) (eˣ - 1)/x = 1
• lim(x→∞) (1 + 1/x)ˣ = e

DIAGRAM

f(x) = (x²-1)/(x-1) — undefined at x=1

  But as x→1:
  (x²-1)/(x-1) = (x+1)(x-1)/(x-1) = x+1 → 2

  lim(x→1) f(x) = 2   even though f(1) is undefined

  Left and right limits:
  f(x) = |x|/x
  x→0⁻: f(x) = -1   (approach from negative side)
  x→0⁺: f(x) = +1   (approach from positive side)
  Limits disagree → limit does NOT exist at x=0
  → function not differentiable at x=0 (like ReLU!)

  Derivative as a limit:
  slope of tangent = lim(Δx→0) [f(x+Δx) - f(x)] / Δx

CODE

PYTHON
1import numpy as np
2import matplotlib.pyplot as plt
3from sympy import *
4
5x = symbols('x')
6
7# ── Symbolic limits with sympy ────────────────────────────────────
8print("Computing limits symbolically:")
9print(f"lim(x->1) (x^2-1)/(x-1) = {limit((x**2-1)/(x-1), x, 1)}") # 2
10print(f"lim(x->0) sin(x)/x = {limit(sin(x)/x, x, 0)}") # 1
11print(f"lim(x->0) (e^x-1)/x = {limit((exp(x)-1)/x, x, 0)}") # 1
12print(f"lim(x->inf) (1+1/x)^x = {limit((1+1/x)**x, x, oo)}") # e
13
14# ── Numerical demonstration of a limit ───────────────────────────
15def f(x_val): return (x_val**2 - 1) / (x_val - 1)
16
17# Approach x=1 from both sides
18print("
19Approaching x=1 from left:")
20for dx in [0.1, 0.01, 0.001, 0.0001]:
21 print(f" f(1 - {dx}) = {f(1 - dx):.6f}")
22
23print("Approaching x=1 from right:")
24for dx in [0.1, 0.01, 0.001, 0.0001]:
25 print(f" f(1 + {dx}) = {f(1 + dx):.6f}")
26# Both converge to 2.0 → limit exists
27
28# ── Derivative from first principles (limit definition) ───────────
29def derivative_numerical(f, x_val, dx=1e-7):
30 """Numerical derivative using limit definition."""
31 return (f(x_val + dx) - f(x_val)) / dx
32
33f_cubic = lambda x: x**3
34x_point = 2.0
35numerical = derivative_numerical(f_cubic, x_point)
36exact = 3 * x_point**2 # d/dx(x^3) = 3x^2
37print(f"
38Derivative of x^3 at x=2:")
39print(f" Numerical (limit): {numerical:.6f}")
40print(f" Exact (3x^2): {exact:.6f}")
41print(f" Error: {abs(numerical - exact):.2e}")
42
43# ── Continuity check ──────────────────────────────────────────────
44# ReLU is continuous but NOT differentiable at x=0
45relu = lambda x: np.maximum(0, x)
46x_vals = np.linspace(-3, 3, 1000)
47# Left derivative at 0: 0, Right derivative at 0: 1 → DNE
← PREVOverviewNEXT →2. Derivatives — Intuition