Goal
Turn derivatives into local predictive models.
The central idea is:
Near an anchor point, a smooth function behaves like a low-degree polynomial whose coefficients are determined by derivatives at that anchor.
A gradient is not merely a direction used by an optimizer. It is the coefficient of the best first-order local model. A Hessian is not merely a curvature table. It supplies the second-order correction that lets the local model bend.
Why Local Models Matter
Suppose evaluating a function is expensive or its formula is complicated. If we already know the function and its derivatives at a point , then we can ask a smaller question:
What simple function behaves like the original function for points close to ?
The answer begins with a constant, then adds increasingly detailed corrections:
known height
+ local slope correction
+ local curvature correction
+ higher-order corrections
This is compression. Instead of carrying the whole function, we carry a local polynomial model.
The model is trustworthy only locally. Moving far from the anchor can make omitted higher-order behavior dominate.
Notation / Symbol Table
| Symbol | Plain-English name | Meaning |
|---|---|---|
| target function | The function being approximated. | |
| anchor point | The point where values and derivatives are known. | |
| target point | The nearby point where we want a prediction. | |
| displacement | How far and in which direction we move from the anchor. | |
| zero-order model | The constant prediction . | |
| first-order model | Constant plus slope or gradient correction. | |
| second-order model | First-order model plus curvature correction. | |
| remainder | The approximation error . | |
| Hessian at | Matrix describing how the gradient changes near . |
The semicolon in separates the point being predicted from the fixed anchor used to build the model.
Start With One Variable
For a smooth scalar function , write the target point as:
The displacement is the small quantity. The Taylor polynomial through second order is:
Equivalently:
Each term has a distinct job:
| Term | Information supplied | Geometric job |
|---|---|---|
| function value | Places the model at the correct height. | |
| first derivative | Tilts the model with the correct local slope. | |
| second derivative | Bends the model with the correct local curvature. |
Why The Factorial Appears
The quadratic correction contains because differentiating twice produces a factor of :
To make that second derivative equal , choose:
The same matching rule gives the degree- Taylor polynomial:
The factorial cancels the repeated factors created when a power is differentiated back down.
Worked Example: Approximating The Exponential
Let:
and anchor at . Every derivative of is , so at zero:
The approximations are:
At :
while:
The curvature term repairs most of the first-order error because the displacement is small.
The Remainder Is The Missing Behavior
Define the remainder after a degree- approximation by:
For a sufficiently smooth function near , the local scaling is:
Read here as a scaling statement: close enough to the anchor, the error is bounded by a constant times .
This gives a useful experiment. If is halved, then locally:
| Model | Leading error scale | Expected error factor after halving |
|---|---|---|
| Constant | about | |
| First order | about | |
| Second order | about |
These ratios are asymptotic, not exact promises at arbitrary distances.
Multivariable First-Order Approximation
Now let:
The first-order Taylor model is:
The shape check is:
This is the differential from Lesson 38 with a finite but small displacement:
The approximation is a tangent hyperplane. The gradient supplies its coefficients.
Multivariable Second-Order Approximation
The Hessian supplies the curvature correction:
The quadratic form is scalar:
The term measures curvature along the actual displacement . If is not a unit vector, its length contributes twice because appears on both sides of the Hessian.
Worked Example: A Quadratic Function
Let:
Anchor at:
and use displacement:
First compute the local data:
The first-order model predicts:
The second-order correction is:
Therefore:
The target point is , and direct evaluation also gives:
The second-order model is exact because the original function is quadratic. There are no third- or higher-order terms to omit.
A Local Model Is Not A Global Identity
The approximation symbol matters:
Equality holds only in special cases, such as using a second-order model for a quadratic function. For a general function, accuracy depends on:
- distance from the anchor,
- size of omitted derivatives,
- smoothness near the path from to ,
- and the chosen approximation order.
A high-order polynomial can still be poor far from its anchor. More terms increase local fidelity; they do not make locality disappear.
From Taylor Models To Optimization
Let be a loss near current parameters . For a proposed update , the first-order model is:
Choosing:
gives the predicted change:
which is negative whenever the gradient is nonzero. This is the local-model justification for gradient descent.
The second-order model is:
If the Hessian is invertible and the quadratic model is locally appropriate, setting the model’s gradient with respect to to zero gives:
Gradient descent trusts slope and controls distance with a learning rate. Newton’s method also uses curvature to rescale and rotate the proposed step.
Why This Matters For Neural Networks
Neural-network training repeatedly builds implicit local models of a loss landscape:
- Backpropagation supplies the gradient for a first-order model.
- Learning rates limit how far we trust that local model.
- Hessian information describes curvature but is expensive to store and use at modern model scale.
- Curvature approximations and Hessian-vector products try to capture useful second-order structure without materializing the full Hessian.
- Flat and sharp directions matter because one scalar learning rate acts across many directions with different curvature.
The Taylor viewpoint unifies these facts: optimization methods differ partly in what local model they build and how much of it they can afford to use.
Connection To Programming
A local quadratic model can be represented without hiding its assumptions:
type Vector = readonly number[];
type Matrix = readonly (readonly number[])[];
const dot = (left: Vector, right: Vector): number =>
left.reduce((sum, value, index) => sum + value * right[index]!, 0);
const multiplyMatrixVector = (
matrix: Matrix,
vector: Vector,
): Vector => matrix.map((row) => dot(row, vector));
const secondOrderTaylor = ({
valueAtAnchor,
gradientAtAnchor,
hessianAtAnchor,
displacement,
}: Readonly<{
valueAtAnchor: number;
gradientAtAnchor: Vector;
hessianAtAnchor: Matrix;
displacement: Vector;
}>): number => {
const linearCorrection = dot(gradientAtAnchor, displacement);
const curvatureAlongDisplacement = dot(
displacement,
multiplyMatrixVector(hessianAtAnchor, displacement),
);
return valueAtAnchor + linearCorrection + 0.5 * curvatureAlongDisplacement;
};
The names preserve the mathematical roles. The function receives local information and a displacement; it does not pretend to know the original function globally.
Common Mistakes
Evaluating Derivatives At The Target Instead Of The Anchor
A Taylor model is built from , , and higher derivatives at the fixed anchor . Evaluating each coefficient at changes the construction.
Forgetting The Displacement
The linear term is not merely or . It is the derivative applied to .
Dropping The One-Half
The second-order term is in one variable and in several variables.
Treating The Hessian Term As A Matrix Output
For a scalar function, is a scalar quadratic form. Shape checking should reduce the full expression to .
Assuming More Terms Guarantee Global Accuracy
Taylor models organize local derivative information. Their useful region depends on the function and anchor, not just the polynomial degree.
Confusing Approximation Error With Numerical Rounding
Remainder error comes from omitted mathematical terms. Floating-point error comes from numerical representation and computation. They are different sources of error.
Exercises
-
In plain language, explain the separate jobs of , , and . Why is the quantity that should be small?
-
For anchored at , derive and . Explain why the second-order model is identical to the first-order model even though is not linear.
-
For anchored at , derive the second-order approximation and use it to estimate . Compare the estimate with a calculator value.
-
Let . Compute first-order approximation errors at and using anchor . Does halving the displacement reduce the error by roughly the factor predicted for a first-order model?
-
Let . At anchor and displacement , compute the first- and second-order Taylor predictions. Verify the second-order prediction by direct evaluation.
-
For a scalar , annotate every factor in with its shape. Explain why the result is scalar and why replacing it with would change its meaning.
-
Use the first-order Taylor model to show that the update predicts a decrease whenever and . State why this remains a local prediction rather than a guarantee for arbitrarily large .
-
Let with symmetric positive-definite . Derive the Newton step from the second-order local model and show that one step reaches the exact minimizer when the Hessian is everywhere.
-
Diagnose the claim: “A second-order approximation must always be better than a first-order approximation.” Give a counterexample involving a distant target, a poorly chosen anchor, or a function whose higher derivatives make the local model unreliable.
-
Implement
firstOrderTaylorandsecondOrderTaylorin TypeScript for vector inputs. Add dimension checks and test them on the quadratic worked example from this lesson.
Readiness Check
You are ready to move into neural-network layers when you can:
- identify the anchor and displacement before calculating,
- reconstruct first- and second-order models rather than recall them as unexplained formulas,
- use gradient and Hessian shapes correctly,
- predict how local error changes when the displacement shrinks,
- and explain gradient descent as optimization of a local first-order model.
Summary
- Taylor approximation replaces a complicated function locally with a derivative-matched polynomial.
- The function value sets height, the gradient sets slope, and the Hessian supplies curvature.
- First-order error is locally quadratic in displacement; second-order error is locally cubic under suitable smoothness.
- In several variables, the linear correction is and the quadratic correction is .
- A quadratic function is represented exactly by its second-order Taylor model.
- Gradient descent and Newton’s method can be understood as decisions made from first- and second-order local models.
- Local accuracy does not imply global accuracy.
Next Lesson
Lesson 40 begins the neural-network phase with perceptrons and linear layers. It will turn affine maps into trainable units, connect weights and biases to decision boundaries, and reuse the local derivative machinery developed in Lessons 35–39.