14–16 min read Calculus & Functional Analysis Part 4 Opening (21 / 32)
Part 4 — Calculus (Inaugural Lesson)

Lesson 14.21: Limits & Continuity

What happens when a function's input approaches a specific destination arbitrarily closely? Does the output settle smoothly onto a definite target, or does the curve fracture into sudden jumps, holes, or infinite chasms? The entire edifice of differential calculus, machine learning gradient descent, and neural network optimization rests on these two foundational pillars: Limits and Continuity.

1 Introduction: What Happens as You Approach a Point?

Suppose an autonomous car is speeding toward a speed-trap sensor. Even without knowing the exact millisecond the vehicle crosses the threshold line, we can track and analyze its trajectory as it gets closer and closer to that destination with arbitrary precision.

In mathematics, this fundamental concept is called a Limit. A limit investigates what value a function's output $f(x)$ approaches as its input $x$ approaches a target value $a$.

🎯

Why Limits and Continuity Form the Core of AI

In real-world mathematical modeling, functions often encounter points of division by zero ($\frac{0}{0}$ indeterminate forms). Limits enable us to bypass undefined arithmetic points by studying the "local neighborhood behavior". Meanwhile, Continuity guarantees that a function has no sudden tears, jumps, or missing values—a requirement for smooth loss landscapes in gradient descent and backpropagation.

2 What is a Limit?

Let $f(x)$ be a function. If the values of $f(x)$ can be made arbitrarily close to a real number $L$ by taking $x$ sufficiently close to $a$ (on either side of $a$, but where $x \ne a$), we say that the limit of $f(x)$ as $x$ approaches $a$ is $L$.

Formal Mathematical Notation
$$\lim_{x \to a} f(x) = L$$

Pronounced: "The limit of $f(x)$ as $x$ approaches $a$ equals $L$"

Anatomy of the Limit Notation:

  • $x$: The independent variable (Input).
  • $a$: The specific constant value that the input approaches ($x \to a$).
  • $f(x)$: The function being investigated (Output).
  • $L$: The target value the output converges toward (Limiting Value).
  • Critical Principle: $x$ never needs to actually equal $a$! The limit is strictly concerned with how $f(x)$ behaves in the immediate vicinity of $a$, not at $x = a$ itself.

Numerical Inspection: $f(x) = x + 2$ as $x \to 3$

Observe how $f(x)$ behaves as $x$ approaches $3$ from values smaller than $3$ (left) and larger than $3$ (right):

Input $x$ (Approaching from Left) Output $f(x) = x + 2$ Input $x$ (Approaching from Right) Output $f(x) = x + 2$
2.9 4.9 3.1 5.1
2.99 4.99 3.01 5.01
2.999 4.999 3.001 5.001

From both directions, as $x$ gets closer to $3$, $f(x)$ unmistakably converges toward $5$:

$$\lim_{x \to 3} (x + 2) = 5$$

3 Difference Between Limit and Function Value

A universal trap in introductory calculus is assuming that finding a limit simply means evaluating the function at $x = a$. The function's actual value $f(a)$ and its limit $\lim_{x \to a} f(x)$ are distinct mathematical concepts!

Consider the classic rational function:

$$f(x) = \frac{x^2 - 4}{x - 2}$$

Direct substitution of $x = 2$ fails catastrophically:

$$f(2) = \frac{2^2 - 4}{2 - 2} = \frac{0}{0} \quad (\text{Undefined / Division by Zero})$$

At $x = 2$, $f(2)$ does not exist in standard arithmetic. Does that mean we know nothing about the function's trajectory near $x = 2$?

No! Under the definition of a limit, $x \ne 2$. Because $x - 2 \ne 0$, we are mathematically justified in factoring the numerator and canceling the common factor:

$$\lim_{x \to 2} \frac{x^2 - 4}{x - 2} = \lim_{x \to 2} \frac{(x - 2)(x + 2)}{x - 2} = \lim_{x \to 2} (x + 2) = 2 + 2 = 4$$
Function Value $f(a)$:

The exact output produced when inputting $a$. At $x=2$, this function produces no output ($f(2) = \text{Undefined}$).

Limit $\lim_{x \to a} f(x)$:

The target height that surrounding points converge toward. As $x \to 2$, the limit cleanly exists and equals 4 ($\lim = 4$).

4 Graphical Interpretation: The Geometry of Limits

Visually, evaluating a limit corresponds to following the curve from both the left and right toward the coordinate $x = a$. Even if a hollow circle (hole) exists at $(2, 4)$, the two curve branches aim directly at the same height:

x y x = 2 y = 4 Hole at (2, 4) At $x = 2$, a hole exists on the curve, yet both left and right trajectories meet at $y = 4$ ($\lim_{x \to 2} f(x) = 4$).

5 One-Sided Limits: Left-Hand and Right-Hand Limits

Along the real line, an input can approach target $a$ from two distinct directions: from numbers smaller than $a$, or from numbers larger than $a$.

Left-Hand Limit (LHL)

As $x$ approaches $a$ from values strictly smaller than $a$ ($x \to a^-$):

$$\lim_{x \to a^-} f(x) = L_1$$

The minus superscript ($a^-$) signifies approach from the negative/left side.

Right-Hand Limit (RHL)

As $x$ approaches $a$ from values strictly greater than $a$ ($x \to a^+$):

$$\lim_{x \to a^+} f(x) = L_2$$

The plus superscript ($a^+$) signifies approach from the positive/right side.

Two-Sided Limit Existence Theorem
$$\lim_{x \to a} f(x) = L \iff \lim_{x \to a^-} f(x) = \lim_{x \to a^+} f(x) = L$$

A general two-sided limit exists if and only if both one-sided limits exist, are finite, and equal the exact same value!

Counter-Example: When a Limit Fails to Exist (DNE)

Consider the piecewise function:

$$f(x) = \begin{cases} x + 1, & x \lt 2 \\ x + 3, & x \gt 2 \end{cases}$$

Left-Hand Limit: $\lim_{x \to 2^-} (x + 1) = 2 + 1 = 3$.
Right-Hand Limit: $\lim_{x \to 2^+} (x + 3) = 2 + 3 = 5$.
Because $3 \ne 5$, the curves do not meet. Therefore:

$$\lim_{x \to 2} f(x) \quad \text{Does Not Exist (DNE)}$$

6 Fundamental Limit Laws

Assuming that $\lim_{x \to a} f(x) = L$ and $\lim_{x \to a} g(x) = M$ exist as finite real numbers:

Limit Law Formula Condition / Remarks
Constant Rule $\lim_{x \to a} c = c$ The limit of a constant is the constant itself
Sum & Difference $\lim [f(x) \pm g(x)] = L \pm M$ Limits distribute over addition and subtraction
Constant Multiple $\lim [c \cdot f(x)] = c \cdot L$ Constant factors factor out of limits
Product Rule $\lim [f(x) \cdot g(x)] = L \cdot M$ The limit of a product is the product of limits
Quotient Rule $\lim \frac{f(x)}{g(x)} = \frac{L}{M}$ Strictly requires $M \ne 0$
Power & Root Rule $\lim [f(x)]^n = L^n, \quad \lim \sqrt[n]{f(x)} = \sqrt[n]{L}$ Requires $L \gt 0$ for even roots ($n=2, 4\dots$)

Direct Substitution for Polynomials:

Because polynomials are continuous everywhere across $\mathbb{R}$, their limit is evaluated by direct evaluation:

$$\lim_{x \to 2} (3x^2 + 2x + 1) = 3(2)^2 + 2(2) + 1 = 12 + 4 + 1 = 17$$

7 Indeterminate Forms: What to Do with $0/0$?

When direct substitution yields $\frac{0}{0}$ or $\frac{\infty}{\infty}$, this is known as an Indeterminate Form. It is not an answer—it indicates that a common factor $(x - a)$ is causing simultaneous vanishing in numerator and denominator:

Technique 1: Algebraic Factorization

Example: $\lim_{x \to 3} \frac{x^2 - 9}{x - 3}$

$$= \lim_{x \to 3} \frac{(x - 3)(x + 3)}{x - 3}$$ $$= \lim_{x \to 3} (x + 3) = 3 + 3 = \mathbf{6}$$

Cancels the vanishing $(x - 3)$ term cleanly.

Technique 2: Conjugate Multiplication

Example: $\lim_{x \to 0} \frac{\sqrt{x + 1} - 1}{x}$

$$= \lim_{x \to 0} \frac{(\sqrt{x+1}-1)(\sqrt{x+1}+1)}{x(\sqrt{x+1}+1)}$$ $$= \lim_{x \to 0} \frac{x}{x(\sqrt{x+1}+1)} = \frac{1}{1+1} = \mathbf{\frac{1}{2}}$$

Eliminates radicals using $(a-b)(a+b) = a^2 - b^2$.

8 Infinite Limits and Limits at Infinity

Infinity ($\infty$) manifests in two distinct calculus contexts:

1. Infinite Limits (Vertical Asymptote)

As input $x$ approaches a finite value, the output blows up to $\pm\infty$:

$$\lim_{x \to 0} \frac{1}{x^2} = +\infty$$

The line $x = 0$ is a Vertical Asymptote.

2. Limits at Infinity (Horizontal Asymptote)

As input $x$ grows arbitrarily large ($x \to \infty$), the output stabilizes onto a finite value:

$$\lim_{x \to \infty} \frac{2x + 1}{x + 3} = \lim_{x \to \infty} \frac{2 + \frac{1}{x}}{1 + \frac{3}{x}} = 2$$

The line $y = 2$ is a Horizontal Asymptote.

9 Continuity: The Unbroken Function

Intuitively, a function is continuous if its graph can be traced without lifting your pencil from the paper.

Rigorous mathematical analysis establishes three mandatory conditions for a function $f(x)$ to be Continuous at a point $x = a$:

The 3 Tests for Continuity
1
Condition 1: $f(a)$ must be defined ($a$ is in the domain).
2
Condition 2: $\lim_{x \to a} f(x)$ must exist ($\text{LHL} = \text{RHL}$).
3
Condition 3: The limit must equal the function value: $\lim_{x \to a} f(x) = f(a)$.

10 Classification of Discontinuities

If any of the three continuity tests fails, the function exhibits a Discontinuity. There are three primary types:

1. Removable (Hole) Hole

The limit exists, but $f(a)$ is undefined or differs from the limit.

$$f(x) = \frac{x^2 - 1}{x - 1}, \ x \ne 1$$

Can be "repaired" by redefining $f(1) = 2$.

2. Jump Discontinuity Step

Left and right limits exist and are finite, but are unequal ($\text{LHL} \ne \text{RHL}$).

$$f(x) = \begin{cases} 1, & x \lt 0 \\ 3, & x \ge 0 \end{cases}$$

Common in Heaviside step functions and threshold gates.

3. Infinite Discontinuity Asymptote

The function blows up to positive or negative infinity as $x \to a$.

$$f(x) = \frac{1}{x - 2}$$

A vertical asymptote occurs at $x = 2$.

11 Testing Continuity in Piecewise Functions

In engineering and algorithmic modeling, piecewise equations must often be tuned to guarantee smooth transitions:

Problem: For what value of constant $k$ is the following function continuous at $x = 2$?

$$f(x) = \begin{cases} x + 1, & x \lt 2 \\ kx - 1, & x \ge 2 \end{cases}$$
Step 1: Compute Left-Hand Limit (Branch $x \lt 2$)
$$\lim_{x \to 2^-} f(x) = \lim_{x \to 2^-} (x + 1) = 2 + 1 = 3$$
Step 2: Compute Right-Hand Limit (Branch $x \ge 2$)
$$\lim_{x \to 2^+} f(x) = \lim_{x \to 2^+} (kx - 1) = 2k - 1$$
Step 3: Equate Limits for Continuity ($\text{LHL} = \text{RHL}$)
$$3 = 2k - 1 \implies 2k = 4 \implies k = 2$$
Step 4: Verify Function Value $f(2)$

With $k=2$, $f(2) = 2(2) - 1 = 3$, matching both one-sided limits.

$$k = 2 \quad \text{guarantees seamless continuity at } x = 2$$

12 Real-World Applications in Computer Science and AI

Limits and continuity drive foundational algorithms in engineering, machine learning, and computer graphics:

1. Physics & Instantaneous Velocity

Average velocity across an interval is $\frac{\Delta s}{\Delta t}$. Taking the limit as time interval $\Delta t \to 0$ yields instantaneous velocity—the exact foundational limit that defines derivatives in physics engines and robotics.

2. Machine Learning & Gradient Descent

Gradient descent relies on continuous differentiability. If loss surfaces exhibit jump discontinuities, gradient updates oscillate violently or explode. Smooth activation functions (GELU, Swish) preserve continuous derivative flows through deep neural networks.

3. Computer Graphics & Parametric Splines

In 3D CAD modeling and animation, curves joined together must maintain $C^0$ continuity (connected positions), $C^1$ continuity (matching tangents), and $C^2$ continuity (matching curvature) to prevent visible seams or jarring camera movement.

4. Digital Signal Processing & Sampling

Converting continuous analog audio into discrete digital samples requires continuous low-pass filtering. Discontinuities in signals create high-frequency Gibbs ringing artifacts that distort audio reconstruction.

13 Python & SymPy Implementation: Limits and Continuity

The Python symbolic mathematics library sympy evaluates exact algebraic limits and directional one-sided limits effortlessly:

limits_demo.py Python 3 + SymPy
import sympy as sp

x = sp.Symbol('x')

# 1. Resolving Indeterminate 0/0 Form: (x^2 - 4)/(x - 2) as x -> 2
f1 = (x**2 - 4) / (x - 2)
limit1 = sp.limit(f1, x, 2)
print("Limit of (x^2 - 4)/(x - 2) as x -> 2:", limit1)  # Output: 4

# 2. Classic Trigonometric Limit: sin(x)/x as x -> 0
f2 = sp.sin(x) / x
limit2 = sp.limit(f2, x, 0)
print("Limit of sin(x)/x as x -> 0:", limit2)  # Output: 1

# 3. One-Sided Limits (Directional): 1/x as x -> 0
f3 = 1 / x
lhl = sp.limit(f3, x, 0, dir='-')  # Left-hand
rhl = sp.limit(f3, x, 0, dir='+')  # Right-hand
print(f"1/x as x->0: LHL = {lhl}, RHL = {rhl}")  # -oo and +oo

# 4. Limits at Infinity: (2x + 1)/(x + 3) as x -> oo
f4 = (2*x + 1) / (x + 3)
limit_inf = sp.limit(f4, x, sp.oo)
print("Limit as x -> oo:", limit_inf)  # Output: 2

14 8 Common Pitfalls and Traps

Avoid these classic stumbling blocks encountered when first navigating calculus:

1. Equating Limit with Function Value

A function can have a perfectly defined finite limit at a point where it is completely undefined.

2. Checking Only One Side

A two-sided limit exists if and only if both left and right limits agree ($\text{LHL} = \text{RHL}$).

3. Treating $0/0$ as Zero or Undefined

$0/0$ is an indeterminate form—a call for algebraic simplification, not a finished mathematical answer.

4. Treating $\infty$ as a Finite Number

$\pm\infty$ represents unbounded divergence, not a point in the real number system $\mathbb{R}$.

5. Assuming Limit Existence Implies Continuity

Continuity requires all three conditions: $f(a)$ exists, $\lim f(x)$ exists, and both values are equal.

6. Using Wrong Piecewise Branches

Always select $x \lt a$ formulas for left-hand limits and $x \gt a$ formulas for right-hand limits.

7. Forgetting the $x \ne a$ Precondition

Canceling terms like $(x - 2)/(x - 2) = 1$ is valid under limits solely because $x$ approaches but never equals $2$.

8. Catastrophic Floating-Point Cancellation

In numerical algorithms, setting step size $h \lt 10^{-15}$ causes machine epsilon subtraction cancellation, yielding severe numeric noise.

Calculus Laboratory: Limits & Continuity Workbench

Experiment with approaching holes, tuning piecewise continuity, and secant-to-tangent convergence (No quiz)

Select Function:
Step Distance ($\delta = |x - a|$): 0.200

Slide left toward $\delta \to 0$ to observe left and right markers converge onto the hole/limit!

Two-Sided Approximations:
Left ($x = a - \delta$)
x: 1.800 | f: 3.800
Right ($x = a + \delta$)
x: 2.200 | f: 4.200
Analysis: LHL = 3.80, RHL = 4.20 $\to$ Target L = 4.00
Left Probe (LHL) Right Probe (RHL) Hole / Limit Point

Key Takeaways

1. Definition of Limit

The value that output $f(x)$ approaches as input $x$ approaches $a$. The input never needs to equal $a$.

2. Limit vs. Function Value

A function can possess a valid finite limit at a point where the function value itself is undefined ($0/0$).

3. One-Sided Limits

A general two-sided limit exists if and only if both left-hand and right-hand limits agree ($\text{LHL} = \text{RHL}$).

4. Indeterminate Forms

$0/0$ is an algebraic signal that factoring, rationalizing, or simplification will unveil the hidden limit.

5. Infinite Limits & Asymptotes

Output divergence produces vertical asymptotes; long-term behavior ($x \to \infty$) produces horizontal asymptotes.

6. The 3 Continuity Tests

$f(a)$ must be defined, $\lim_{x \to a} f(x)$ must exist, and the limit must equal the value ($\lim = f(a)$).

7. Types of Discontinuity

Removable (hole in curve), Jump (step difference), and Infinite (vertical asymptote) discontinuities.

8. Foundation of Derivatives

Instantaneous rates of change are defined by the difference quotient limit $\lim_{h \to 0} \frac{f(x+h)-f(x)}{h}$.

9. AI Optimization

Continuous activation functions ensure smooth gradient updates, preventing numerical instability in backpropagation.

🚀
Part 4 Launch

Welcome to Part 4: Calculus & Optimization!

You have laid the foundational bedrock of calculus. In upcoming lessons, we will expand limits into Derivatives, the Chain Rule, Multivariable Gradients, and Backpropagation—the engine that trains modern AI!