Limits, Derivatives, and Differentials
If linear algebra is the "data language" of machine learning, telling computers how to represent and organize data, then calculus is the "optimization behavior" of machine learning, telling computers how to learn and improve from data. From gradient descent in deep learning to motion simulation in physics engines, calculus is ubiquitous in modern computing technology and serves as a key bridge connecting traditional software development with artificial intelligence.
From Practical Problems to Mathematical Theory
The birth of calculus is one of the most exciting chapters in the history of mathematics. In the 17th century, the wave of the Scientific Revolution swept across Europe. The development of physics and astronomy raised numerous questions about motion and change: How do planets move around the sun? What trajectory does a cannonball follow? How do we define the instantaneous velocity of a moving object at a given moment? These questions troubled the greatest scientists of the time, because traditional mathematical tools could only handle "static" quantities and could not precisely describe "dynamic" changes.
In the 1660s, the English scientist Isaac Newton, while studying the motion of objects and planetary orbits, developed a mathematical method called the Method of Fluxions. Using this method, he successfully calculated instantaneous velocities of non-uniform motion, the slopes of tangent lines to curves, and the curvature of planetary orbits. Almost simultaneously, the German mathematician Gottfried Leibniz, while studying tangent lines and area problems for curves, independently developed a similar system of notation and methods.
The contribution of Newton and Leibniz lies in their unification of two seemingly unrelated types of problems -- finding tangents (differential problems) and finding areas (integral problems) -- under a single framework, and discovering the inverse relationship between them. This is the famous Fundamental Theorem of Calculus. This theorem reveals that differentiation and integration are inverse operations, much like the relationship between multiplication and division, or exponentiation and logarithms.
Although calculus was quickly applied to physics, astronomy, engineering, and other fields with great success after its birth, its theoretical foundation had long-standing gaps. The expositions of Newton and Leibniz were filled with the concept of infinitesimals -- quantities that are not zero yet close to zero. This concept was logically self-contradictory: if it is not zero, it can be further divided; if it is zero, it cannot serve as a denominator. This ambiguity drew sharp criticism. In 1734, The Analyst satirized that such reasoning was "neither correct mathematics nor reliable logic."
The rigorous formalization of calculus took nearly two hundred years of effort. In the early 19th century, the French mathematician Augustin-Louis Cauchy gave a rigorous definition of limits, placing calculus on the foundation of limits rather than vague infinitesimals. In the late 19th century, the German mathematician Karl Weierstrass further refined the definition of limits using the language, ultimately placing calculus on a solid logical foundation. Interestingly, in the 1960s, the American mathematician Abraham Robinson, through Non-standard Analysis, re-endowed infinitesimals with rigorous mathematical meaning -- but that is another story.
Calculus in Machine Learning
For software developers accustomed to object-oriented programming, design patterns, and microservice architectures, calculus may seem like a somewhat "out-of-place" abstract discipline. After all, in most software development work, we are more accustomed to discrete ways of thinking: data is discrete (integers, strings, booleans), operations are discrete (assignment, conditionals, loops), and state spaces are discrete (finite or countably infinite sets of states). This reflects the nature of computers -- a Turing Machine is a discrete state machine, and digital computers represent everything with finite bits. However, when software development enters the field of machine learning and artificial intelligence, the situation is entirely different. A key problem in machine learning is optimization -- finding optimal model parameters from vast amounts of data. This problem is continuous: the parameter space is continuous (the real numbers), the loss function is a continuous function, and the optimization process involves finding extrema in a continuous space. In this context, writing machine learning code requires the language of calculus to describe and solve problems. The core concept of calculus is the rate of change. The derivative captures how sensitively one quantity changes with respect to another -- when the input changes by a tiny amount, how much does the output change? This concept is ubiquitous in machine learning:
- The derivative of the loss function with respect to a parameter tells us: if we increase the parameter slightly, will the loss increase or decrease? By how much? This guides how we adjust parameters.
- The derivative of the activation function determines how gradients flow during backpropagation, affecting the training effectiveness of the network.
- The learning rate is essentially a step-size parameter that controls the magnitude of each parameter update -- too large and we may overshoot the optimum, too small and convergence is too slow.
- ...
Understanding these concepts not only helps us correctly use machine learning frameworks (such as PyTorch, TensorFlow) but also enables us to diagnose training problems, design better model architectures, and choose appropriate optimization strategies.
Rigorous Definition of Limits and Continuity
Before formally approaching derivatives, let us first understand the concept of limits through the intuitive approach used in high school curricula. Limits are the prelude to calculus theory, describing the trend of a function's value as the independent variable approaches some value. Consider the simple function . When , the denominator is zero and the function value is undefined. However, if we observe how the function values change as approaches 1:
| 0.9 | 1.9 |
| 0.99 | 1.99 |
| 0.999 | 1.999 |
| 1.001 | 2.001 |
| 1.01 | 2.01 |
| 1.1 | 2.1 |
We can see that as approaches 1 from both sides, approaches 2. This is the intuitive meaning of a limit: as gets arbitrarily close to some value , the function value gets arbitrarily close to some value , denoted as . Note that the limit concerns the process of "approaching" , not the function value when equals . In the example above, does not even exist, but is fully determined.
While the intuitive understanding of limits in high school curricula helps build conceptual understanding, mathematics requires rigor. In the 19th century, the German mathematician Karl Weierstrass gave the rigorous definition of limits: Let a function be defined on some punctured neighborhood of a point (a neighborhood that does not include the point itself). If there exists a constant such that for any arbitrarily small positive number , there exists a positive number such that whenever , we have , then is called the limit of the function as . This is what is now called the language, which uses two inequalities to precisely characterize what "arbitrarily close" means mathematically:
- means the distance between and is less than ( is sufficiently close to )
- means the distance between and is less than ( is sufficiently close to )
The picture described by the language is: no matter how close you want to be to (given ), I can find a range where is sufficiently close to (determine ) such that within this range achieves the desired closeness. For readers not specializing in mathematics, understanding the logical structure depicted by is more important than memorizing specific proofs. In practical applications, we mainly rely on intuitive understanding of limits and operational rules to solve problems.
Yes, limits also have operational rules. These rules tell us that limit operations can "penetrate" addition, subtraction, multiplication, and division -- we can take the limit of each part separately and then perform the corresponding operation. Let , , then the following operational rules hold:
- Addition:
- Subtraction:
- Multiplication:
- Division: (when )
Intuitively, "continuity" means the graph of a function can be drawn without lifting the pen. But only after rigorously clarifying limits can we precisely define continuity. Continuity is a mathematical concept describing that a function has "no breaks." Its mathematical definition states that a function is continuous at point if and only if the following three conditions are satisfied:
- is defined
- exists
The third condition unifies the limit value with the function value: "the limit equals the function value" is precisely what "continuity" truly means. Continuous functions have many useful properties. For example, the Intermediate Value Theorem tells us: if a continuous function takes values and on the interval , then for any value between and , there exists such that . This theorem is often used in numerical computation for finding roots of equations (such as the bisection method).
Definition and Geometric Meaning of Derivatives
We begin with the physical problem that Newton considered to introduce derivatives. Suppose an object moves along a straight line, and its position is a function of time , . Over the time interval , the distance traveled by the object is . The average velocity can then be expressed as:
This is the concept of the average rate of change: the change in the function value divided by the change in the independent variable. But how should we define the instantaneous velocity of the object at a specific instant ? Intuitively, if we let the time interval become smaller and smaller, the average velocity gets closer and closer to the instantaneous velocity. As approaches zero, the limit of the average velocity is the instantaneous velocity:
More generally, suppose a function is defined on some neighborhood of a point . If the limit exists, then the function is said to be differentiable at , and this limit value is called the derivative of at , denoted by or (the former is Lagrange's notation, the latter is Leibniz's notation; both are still widely used today). The fraction in this definition is called the difference quotient, representing the average rate of change of the function over the interval . The derivative is the limit of the difference quotient as , i.e., the instantaneous rate of change. Another equivalent definition of the derivative is:
These two definitions are equivalent; simply let to convert between them.
The derivative has a very intuitive geometric meaning: the slope of the tangent line. Consider the graph of the function . At the point , draw a tangent line. The slope of this tangent line is . First, consider a secant line passing through the two points and . The slope of the secant line is:
This is exactly the difference quotient. As , the point approaches along the curve. Observe the figure below: as the two points through which the secant passes gradually get closer, the secant approaches the tangent, eventually coinciding with it. Therefore, the derivative is the slope of the tangent line.

Figure: The process of a secant line gradually approaching a tangent line
Derivatives of Common Functions
Mastering the derivative formulas of basic functions is the foundation of differential calculus. Just as learning arithmetic requires memorizing the multiplication table first, being proficient in basic formulas greatly simplifies the differentiation process. This section introduces the derivative formulas for power functions, exponential functions, logarithmic functions, and trigonometric functions, as well as the rules for differentiating sums, differences, products, and quotients of functions. These formulas, combined with the operational rules, enable us to handle differentiation problems for most common functions. It is particularly noteworthy that these formulas appear frequently in machine learning. For instance, the property that the derivative of equals itself makes it central to probability distributions (such as Softmax), while the derivative of is indispensable in maximum likelihood estimation.
Power Functions
For the power function (where is a positive integer), its derivative is: . This formula can be generalized to any real number , for example:
- , then
- , then
Exponential and Logarithmic Functions
For the natural exponential function : . This is a very special property: the derivative of is itself. This property gives a central role in differential equations, probability theory, and other fields.
For the general exponential function (where ):
For the natural logarithmic function :
For the general logarithmic function (where ):
Trigonometric Functions
Derivatives of basic trigonometric functions:
Function Derivative Note that the derivatives of sine and cosine form a cycle: , , and differentiating twice more returns to . This property is very useful when solving differential equations.
Similar to the operational rules for limits, there are corresponding derivative rules for addition, subtraction, multiplication, and division of functions:
Sum Rule:
Difference Rule:
Product Rule:
Quotient Rule:
Differentials and Linear Approximation
A differential can be understood as another way of expressing the derivative. Suppose a function is differentiable at a point . Then is called the differential of the function at . Here, is the increment of the independent variable (an independent quantity), and is the differential of the dependent variable. The difference between the differential and the derivative is that the derivative is a ratio , while the differential and are independent quantities. If the derivative of a function at is 12, then its differential at is , meaning that if the independent variable has a small increment , the increment in the function value is approximately 12 times .
An important application of differentials is linear approximation, which aims to transform complex function calculations into relatively simple differential calculations. When is small, the function increment can be approximated by the differential :
Geometrically, this formula means: near the point , we use the tangent line (a straight line) to approximate the curve. Linear approximation is very useful in engineering calculations. For example, to compute , let , take , , then:
This result differs from the exact value by only about . The geometric significance of linear approximation is that on a tiny scale, we can use a straight line segment to approximately represent curves of various shapes -- as long as the scale is small enough, the two are approximately equal in length.
Higher-Order Derivatives
If the derivative of a function is itself differentiable, we can differentiate again to obtain the second derivative:
The second derivative has many valuable physical and geometric meanings. For example, in physics, if represents position as a function of time, then is velocity, and the second derivative represents acceleration. Geometrically, the second derivative reflects the concavity of a function:
- If , the function is convex at (bowl-shaped, opening upward)
- If , the function is concave at (bowl-shaped, opening downward)
- If , then may be an inflection point
In machine learning, the loss functions we typically wish to minimize are convex functions, where the second derivative is non-negative and the function graph is "bowl-shaped upward," meaning there is a unique global minimum. Determining the convexity or concavity of a function is very important for assessing whether optimization algorithms (such as gradient descent) can converge stably.
Continuing the generalization, for some functions we can compute third-order, fourth-order, and even higher-order derivatives. For example:
- , then (every order of derivative is itself)
- , then , , , (cycles every four orders)
Summary
Derivatives reveal a simple yet profound idea: any continuously changing quantity can be characterized by its trend of change at a given point. Starting from the instantaneous velocity problem that Newton pondered, derivatives push the average rate of change to its limit, yielding a precise expression for the instantaneous rate of change. This leap from a static ratio to a dynamic limit is not only a mathematical advancement but also a shift in way of thinking -- we can now use a single number to describe the tendency of a function to change at a particular point. Geometrically, the derivative is the slope of the tangent line, providing us with a way to understand curves (nonlinear) through straight lines (linear).
Differentials transform the abstract "rate of change" into a concrete "amount of change," allowing us to simplify complex function calculations through linear approximation. This idea is particularly evident in machine learning: Taylor expansions decompose complex functions into a series of polynomials, gradient descent relies on first-order derivatives to guide the optimization direction, and the convexity or concavity of loss functions is revealed by second-order derivatives -- all of these are direct applications of differential calculus in modern artificial intelligence. The concepts of limits, derivatives, differentials, and higher-order derivatives build progressively upon each other, forming a mathematical framework for understanding the continuously changing world and laying a solid foundation for the next chapter on multivariate differential calculus.
Exercises
Must a differentiable function always be continuous? Is a continuous function always differentiable?
Reference Answer
If a function is differentiable at a point , then is continuous at .
Proof Sketch: Differentiability implies that exists. To prove continuity, we need to show .
As , the first term approaches (the derivative exists), and the second term approaches 0, so the product approaches 0.
However, continuity does not imply differentiability. A classic counterexample is at : the function is continuous, but it has a "corner" at this point where the left and right derivatives are not equal, and therefore it is not differentiable.
Using the definition of a limit, prove that .
Reference Answer
To prove , we need to show that for any , there exists such that whenever , we have .
Compute:
To ensure , we only need .
Therefore, take . When , we have .
This proves .
Using the definition of the derivative, find for .
Reference Answer
By the definition of the derivative:
Compute:
Therefore:
Or directly verify using the power rule: , so .
Find the derivatives of the following functions:
Reference Answer
- Apply the power rule and sum/difference rules:
- Apply the product rule :
- Apply the quotient rule :
Let . Find:
- The intervals where the function is increasing and decreasing
- The intervals of concavity and inflection points
Reference Answer
First, find the first derivative:
Set , obtaining .
- When or , , the function is increasing
- When , , the function is decreasing
Find the second derivative:
Set , obtaining .
- When , , the function is concave
- When , , the function is convex
Therefore, is an inflection point, with coordinates .
Use linear approximation to estimate (in radians), and compare the error with the exact value.
Reference Answer
Let , take , .
Linear approximation formula:
Compute:
- , so
Therefore:
Exact value:
Error:
Relative error:
We can see that for small angles, is a very good approximation.
