Functions and Limits — The Starting Line of Calculus
Functions and Limits -- The Starting Line of Calculus
Calculus is the mathematical engine of the AI training process. Before learning derivatives, review the concept of functions, and then understand "limits"—the core idea of calculus.
What is a limit?
A limit describes "what value f(x) approaches when x gets infinitely close to, but not equal to, a certain point."
For example: ( f(x) = \frac{x^2-1}{x-1} ), it is undefined at x=1. But as x approaches 1, f(x) approaches 2.
Left-hand Limit
x → 1⁻ (approaching from the left)
f(0.999) → 2
** Limit
Left and right limits are equal → Exists
( \lim_{x\to 1} f(x) = 2 )
** Right Limit
x → 1⁺ (approaching from the right)
f(1.001) → 2
Continuous = Unbroken
f(x) is continuous at point a: ( \lim_{x\to a} f(x) = f(a) )—the limit at this point equals the function value at this point.
Most loss functions (MSE, cross-entropy) are continuous and differentiable—this is the prerequisite for optimization using gradient descent.
Real-life examples
**Instantaneous velocity
You want to know the velocity at the exact moment of the 3rd second. But the time interval of "an instant" is 0, and the displacement is also 0, making 0/0 meaningless.
The calculus solution: take increasingly shorter time intervals and see what the average velocity approaches. This approaching value is the instantaneous velocity—which is the derivative.
Mathematical definition
[ \lim_{x \to a} f(x) = L ]
Limit laws: the limit of a sum, difference, product, and quotient is the sum, difference, product, and quotient of the limits (provided the limit of the denominator is not 0).
Python hands-on practice
Example
import
numpy
as
np
def
f
(
x
)
:
return
(
x**
2
1
)
/
(
x -
1
)
(
"=== lim_{x->1} (x^2-1)/(x-1) = 2 ==="
)
Approaching from both sides
for
delta
in
[
0.1
,
0.01
,
0.001
,
0.0001
]
:
(
f
"x = {1-delta:.4f}, f(x) = {f(1-delta):.6f}"
)
(
f
"x = {1+delta:.4f}, f(x) = {f(1+delta):.6f}"
)
(
"→ Regardless of which side it approaches from, f(x) approaches 2"
)
Original prompt (Chinese, left untranslated)
=== lim_{x->1} (x^2-1)/(x-1) = 2 ===
x = 0.9000, f(x) = 1.900000
x = 1.1000, f(x) = 2.100000
x = 0.9900, f(x) = 1.990000
x = 1.0100, f(x) = 2.010000
→ 无论从哪边逼近,f(x)都趋近于 2
Application scenarios in AI
The definition of gradient depends on limits
The definition of the derivative itself is a limit: ( f'(x) = \lim_{h \to 0} \frac{f(x+h)-f(x)}{h} ). Although gradient calculation in backpropagation uses analytical differentiation instead of numerical limits, the idea of limits is key to understanding why "the learning rate cannot be too large"—a learning rate that is too large is equivalent to approximating the derivative with too large an h.
Continuity requirement of the loss function
Gradient descent requires the loss function to be almost everywhere differentiable. MSE and cross-entropy are smooth and continuous—this is a prerequisite for them to be standard loss functions. Hinge Loss (used in SVM) is not differentiable at the turning point and requires the use of subgradients.
Activation function selection
ReLU is not differentiable at x=0 (left and right derivatives are not equal), but in practice, the subgradient 0 is used instead, and the model can still train normally. LeakyReLU and GELU are differentiable everywhere, resulting in a smoother gradient flow.