Mathematical Foundations

III.11 · Calculus

Is a flat point a valley, a peak — or neither?

At a point where the gradient vanishes, second derivatives decide the shape — when they can. Compare a surface with its quadratic model and meet the cases where the test cannot decide.

Read curvature from second derivatives

Contours of f = x² + y²

Contours of f = x² + y². At (0, 0) the dashed lines are the principal curvature directions (eigenvectors of the Hessian, eigenvalues ≈ 2.0000 and 2.0000). Classification: minimum.

Quadratic model Q(δ) near the point

Near the point, solid contours of f and dashed contours of its quadratic model share the same levels. Close to the point they agree; farther away higher-order terms separate them.

Point
(0, 0)
Height
0
Gradient
(0, 0)
Curvature along x
2
Curvature along y
2
Mixed partials (both orders)
0 = 0 (symmetric)
Determinant
4
Principal curvatures (eigenvalues)
2
Second eigenvalue
2
Curvature in the chosen direction
2
Second-derivative test
local minimum

Exact values use =; binary64 approximations use ≈. Undefined values state their reason.

det H > 0 and f_xx > 0: both principal curvatures are positive, so the critical point is a strict local minimum.

∇f=[00],H=[2002]\nabla f=\begin{bmatrix}0\\0\end{bmatrix},\quad H=\begin{bmatrix}2&0\\0&2\end{bmatrix}
det⁡H=4,tr⁡H=4\det H=4,\quad \operatorname{tr}H=4
uTHu≈2.000000(θ=30∘)\mathbf u^{\mathsf T}H\mathbf u\approx 2.000000\quad(\theta=30^\circ)
Q(δ)=f(p)+∇f⋅δ+12 δTH δQ(\delta)=f(p)+\nabla f\cdot\delta+\tfrac12\,\delta^{\mathsf T}H\,\delta

Is the point critical?

∇f = 0: the test may be applied.

∇f=[00],H=[2002]\nabla f=\begin{bmatrix}0\\0\end{bmatrix},\quad H=\begin{bmatrix}2&0\\0&2\end{bmatrix}

from −2 to 2, up to 2 decimal places

from −2 to 2, up to 2 decimal places

from −180 to 180, whole numbers only

Drag the point or choose a surface. Dashed lines on the map are the principal curvature directions; the right plane compares solid contours of f with dashed contours of its quadratic model.

At the bottom of the bowl x2+y2x^2+y^2 both principal curvatures are 22 and the test reports a minimum. Choose Saddle: the curvatures are 22 and −2-2. Now choose x⁴ + y⁴ and x² + y³: both have a zero gradient and a singular Hessian at the origin, the test is inconclusive, and indeed the first is a minimum while the second is neither a minimum nor a maximum.

Intuition: how the slope itself changes

The gradient says which way is uphill. Second derivatives say how that slope changes as you move — how the surface curves. Along a direction u\mathbf u, the curvature of the slice t↦f(p+tu)t\mapsto f(p+t\mathbf u) at t=0t=0 is a number; positive means the slice bends upward. A minimum curves upward in every direction, a maximum downward in every direction, and a saddle upward in some directions and downward in others.

Definition

The Hessian of ff at pp is the matrix of second partial derivatives,

H=[fxxfxyfyxfyy].H=\begin{bmatrix}f_{xx}&f_{xy}\\ f_{yx}&f_{yy}\end{bmatrix}.

For smooth functions (and all polynomials) the mixed partials agree, fxy=fyxf_{xy}=f_{yx}, so HH is symmetric. The curvature along a unit vector u\mathbf u is uTHu\mathbf u^{\mathsf T}H\mathbf u; its extreme values are the eigenvalues of HH, the principal curvatures, along the eigenvector directions.

Second-derivative test. At a critical point (∇f=0\nabla f=\mathbf 0): if det⁡H>0\det H>0 and fxx>0f_{xx}>0, a strict local minimum; if det⁡H>0\det H>0 and fxx<0f_{xx}<0, a strict local maximum; if det⁡H<0\det H<0, a saddle; if det⁡H=0\det H=0, the test is inconclusive.

Mechanics: what the explorer computes

All second partials, the determinant and the trace are exact; both mixed partials are computed separately and compared. The classification is an exact rational decision. Principal curvatures are binary64 roots from the exact trace and discriminant. The right plane draws contours of the quadratic model Q(δ)=f(p)+∇f⋅δ+12δTHδQ(\boldsymbol\delta)=f(p)+\nabla f\cdot\boldsymbol\delta+\tfrac12\boldsymbol\delta^{\mathsf T}H\boldsymbol\delta with the same levels as ff. If the point is not critical, the stage says that the test does not apply.

Derivation: why the determinant decides

Near a critical point f(p+δ)≈f(p)+12δTHδf(p+\boldsymbol\delta)\approx f(p)+\tfrac12\boldsymbol\delta^{\mathsf T}H\boldsymbol\delta. For a symmetric HH with eigenvalues λ1,λ2\lambda_1,\lambda_2 and orthonormal eigenvectors, writing δ\boldsymbol\delta in that basis gives

12δTHδ=12(λ1c12+λ2c22).\tfrac12\boldsymbol\delta^{\mathsf T}H\boldsymbol\delta=\tfrac12(\lambda_1c_1^2+\lambda_2c_2^2).

If both eigenvalues are positive the quadratic is positive for every δ≠0\boldsymbol\delta\ne\mathbf 0 (minimum); both negative, a maximum; opposite signs, a saddle. Since det⁡H=λ1λ2\det H=\lambda_1\lambda_2 and tr⁡H=λ1+λ2\operatorname{tr}H=\lambda_1+\lambda_2, the sign of det⁡H\det H tells whether the signs agree, and fxxf_{xx} (or the trace) tells which. If det⁡H=0\det H=0 some eigenvalue is zero, the quadratic is flat in that direction, and higher-order terms decide.

Worked example

f(x,y)=x3−3x+y2f(x,y)=x^3-3x+y^2 has ∇f=(3x2−3, 2y)\nabla f=(3x^2-3,\,2y), so its critical points are (±1,0)(\pm1,0). The Hessian is

H=[6x002].H=\begin{bmatrix}6x&0\\0&2\end{bmatrix}.

At (1,0)(1,0): det⁡H=12>0\det H=12>0, fxx=6>0f_{xx}=6>0 — a minimum. At (−1,0)(-1,0): det⁡H=−12<0\det H=-12<0 — a saddle.

Replay the worked derivation

Is the point critical?

∇f = 0: the test may be applied.

∇f=[00],H=[−6002]\nabla f=\begin{bmatrix}0\\0\end{bmatrix},\quad H=\begin{bmatrix}-6&0\\0&2\end{bmatrix}
Replay: check criticality, compute the Hessian, apply the test at (−1, 0).

When the test is inconclusive

For x4+y4x^4+y^4, x2+y3x^2+y^3 and the monkey saddle x3−3xy2x^3-3xy^2, the origin is critical and det⁡H=0\det H=0. The first has a minimum, the second takes negative values along the negative yy-axis and positive values along the xx-axis, and the monkey saddle goes down in three directions and up in three. Same Hessian test result, three different shapes: second derivatives alone cannot decide, and the quadratic model on the right is visibly degenerate.

Executable reference code

The reference computes exact Hessians with Fraction, checks symmetry of mixed partials and classifies critical points, reporting the degenerate cases as inconclusive. The NumPy version computes eigenvalues with numpy.linalg.eigh and verifies that uTHu\mathbf u^{\mathsf T}H\mathbf u lies between them for many directions.

code/python/calculus_hessian.py
"""Exact Hessians, symmetric mixed partials and the second-derivative test (III.11)."""
from fractions import Fraction as F


def d(p, var):
    k = 0 if var == "x" else 1
    out = {}
    for (i, j), c in p.items():
        e = (i, j)[k]
        if e:
            key = (i - 1, j) if k == 0 else (i, j - 1)
            out[key] = out.get(key, 0) + c * e
    return out


def ev(p, x, y):
    return sum(c * x**i * y**j for (i, j), c in p.items())


def classify(p, x, y):
    if ev(d(p, "x"), x, y) != 0 or ev(d(p, "y"), x, y) != 0:
        return "not critical"
    fxx, fyy = ev(d(d(p, "x"), "x"), x, y), ev(d(d(p, "y"), "y"), x, y)
    fxy, fyx = ev(d(d(p, "x"), "y"), x, y), ev(d(d(p, "y"), "x"), x, y)
    assert fxy == fyx
    det = fxx * fyy - fxy * fxy
    if det < 0:
        return "saddle"
    if det == 0:
        return "inconclusive"
    return "minimum" if fxx > 0 else "maximum"


well = {(3, 0): F(1), (1, 0): F(-3), (0, 2): F(1)}           # x**3 - 3x + y**2
assert classify(well, F(1), F(0)) == "minimum"
assert classify(well, F(-1), F(0)) == "saddle"
assert classify(well, F(0), F(1, 2)) == "not critical"
for degenerate in ({(4, 0): F(1), (0, 4): F(1)}, {(2, 0): F(1), (0, 3): F(1)}, {(3, 0): F(1), (1, 2): F(-3)}):
    assert classify(degenerate, F(0), F(0)) == "inconclusive"
code/python/calculus_hessian_numpy.py
"""Directional curvature u^T H u lies between the eigenvalues of a symmetric Hessian (III.11)."""
import numpy as np

H = np.array([[6.0, 1.5], [1.5, 2.0]])
lam, V = np.linalg.eigh(H)
theta = np.linspace(0, np.pi, 721)
U = np.stack([np.cos(theta), np.sin(theta)], axis=1)
curv = np.einsum("ni,ij,nj->n", U, H, U)
assert lam[0] - 1e-12 <= curv.min() and curv.max() <= lam[1] + 1e-12
assert np.isclose(curv.max(), lam[1], atol=1e-4) and np.isclose(np.prod(lam), np.linalg.det(H))

Explore

Drag the point away from a critical point: the classification becomes “not a critical point” even though the Hessian still describes curvature. Change the direction angle and watch uTHu\mathbf u^{\mathsf T}H\mathbf u move between the two principal curvatures. On the double well, move from (1,0)(1,0) toward (−1,0)(-1,0) and find where det⁡H\det H changes sign.

Common mistakes

Applying the test at a point where ∇f≠0\nabla f\ne\mathbf 0. Concluding “minimum” or “maximum” when det⁡H=0\det H=0. Using only fxxf_{xx} and fyyf_{yy} and forgetting the mixed term fxyf_{xy}, which rotates the principal directions.

Numerical considerations

Deciding det⁡H=0\det H=0 in floating point is a tolerance choice, not a fact: nearly singular Hessians make classification sensitive to rounding. The explorer decides exactly because its inputs are rational. Numerically, eigenvalues of symmetric matrices are well conditioned, but the eigenvectors of nearly repeated eigenvalues are not.

Engineering and ML connections

Newton’s method for optimisation solves Hδ=−∇fH\boldsymbol\delta=-\nabla f; curvature also explains why gradient descent zig-zags in narrow valleys and how step sizes relate to the largest eigenvalue (VI.5). In high dimensions most critical points of loss landscapes are saddles. This chapter supplies the vocabulary; the optimisation algorithms come later.

Exercises

calculation

Compute a Hessian

f(x, y) = x³ − 3x + y². Give f_xx, f_xy and f_yy at (1, 0).

calculation

The determinant test

At the critical point (−1, 0) of x³ − 3x + y², give det H.

calculation

Curvature in a direction

H = [[2, 0], [0, −2]]. Give uᵀHu for u = (1, 0) and for u = (0, 1).

prediction

det H = 0

At the origin, x⁴ + y⁴ and x² + y³ both have det H = 0. What can the second-derivative test conclude?

Choose one answer

prediction

Where the test applies

At a point with ∇f ≠ 0 and det H > 0, is it a local minimum?

Choose one answer

Summary and checkpoints

The Hessian collects second partial derivatives and is symmetric for smooth functions. At a critical point its determinant and diagonal classify minima, maxima and saddles; when det⁡H=0\det H=0 the test is inconclusive. The quadratic model is the local second-order picture. Next, III.12 turns from rates to accumulation: integrals.

The map of the book

97 of 97 chapters written · eight Parts

demo Foundation demo Try the live vector example Open as a page

Part I

Mathematical Language

The notation and mental objects everything else uses.

9 of 9 chapters written

  1. I.1 Scalars, quantities, units, powers and roots available
  2. I.2 Coordinates and points available
  3. I.3 Vectors: components, magnitude, and direction reference chapter available
  4. I.4 Algebraic expressions, equations and inequalities available
  5. I.5 Functions as input → transformation → output available
  6. I.6 Essential function families available
  7. I.7 Sets, intervals, and relations available
  8. I.8 Indexed quantities and summation available
  9. I.9 The notation map for ML available

Part II

Linear Algebra

Matrices as transformations: the strongest foundation in the book.

19 of 19 chapters written

  1. II.1 Vector addition and subtraction available
  2. II.2 Scalar multiplication and vector scaling available
  3. II.3 Norms, magnitude, and normalization available
  4. II.4 Dot product, angle, and orthogonality available
  5. II.5 Projection and distance to a direction available
  6. II.6 Linear combinations and span available
  7. II.7 Linear independence, basis, and coordinates available
  8. II.8 Matrices as linear transformations available
  9. II.9 Matrix × vector available
  10. II.10 Matrix × matrix as composition available
  11. II.11 Transpose and orthogonality available
  12. II.12 Determinant: orientation and area/volume scaling available
  13. II.13 Linear systems as intersecting constraints available
  14. II.14 Gaussian elimination and row operations available
  15. II.15 Rank and invertibility available
  16. II.16 Inverse matrices available
  17. II.17 Eigenvalues and eigenvectors available
  18. II.18 Orthogonal bases and least-squares geometry available
  19. II.19 Singular Value Decomposition available

Part III

Calculus

Change, local approximation, and sensitivity made visible.

15 of 15 chapters written

  1. III.1 Limits through approach available
  2. III.2 Continuity and local behavior available
  3. III.3 Derivative as secant → tangent available
  4. III.4 Derivative as rate of change and local linear model available
  5. III.5 Derivative rules available
  6. III.6 Chain rule available
  7. III.7 Multivariable functions and partial derivatives available
  8. III.8 Gradient and directional derivatives available
  9. III.9 Jacobian available
  10. III.10 Computational graphs and automatic differentiation available
  11. III.11 Hessian and curvature available
  12. III.12 Integrals as accumulation available
  13. III.13 Fundamental derivative/integral connection available
  14. III.14 Numerical differentiation available
  15. III.15 Numerical integration available

Part IV

Probability

Uncertainty through sample spaces, evidence, and repetition.

16 of 16 chapters written

  1. IV.1 Random experiments, outcomes, and sample spaces available
  2. IV.2 Events and probability mass available
  3. IV.3 Counting and finite probability where needed available
  4. IV.4 Conditional probability as restricted sample space available
  5. IV.5 Independence available
  6. IV.6 Bayes' theorem as probability-mass update available
  7. IV.7 Random variables available
  8. IV.8 PMF, PDF, and CDF available
  9. IV.9 Bernoulli and Binomial distributions available
  10. IV.10 Uniform and Gaussian distributions available
  11. IV.11 Expectation available
  12. IV.12 Variance and standard deviation available
  13. IV.13 Joint, marginal, and conditional distributions available
  14. IV.14 Covariance and correlation available
  15. IV.15 Law of Large Numbers available
  16. IV.16 Central Limit Theorem available

Part V

Statistics

From observed data to estimates, intervals, and likelihood.

10 of 10 chapters written

  1. V.1 Data summaries: mean, median, mode available
  2. V.2 Spread: variance, standard deviation, robust interpretation available
  3. V.3 Population, sample, and sampling variability available
  4. V.4 Estimators and estimation available
  5. V.5 Confidence intervals through repeated sampling available
  6. V.6 Covariance matrices and multivariate spread available
  7. V.7 Regression fundamentals available
  8. V.8 Likelihood available
  9. V.9 Maximum Likelihood Estimation available
  10. V.10 Maximum A Posteriori estimation available

Part VI

Optimization

Learning as repeated parameter updates governed by an objective.

10 of 10 chapters written

  1. VI.1 Objective functions and optimization landscapes available
  2. VI.2 Local vs global optima and stationary points available
  3. VI.3 Convexity available
  4. VI.4 Gradient descent flagship chapter available
  5. VI.5 Learning rate and convergence behavior available
  6. VI.6 Momentum available
  7. VI.7 Stochastic and mini-batch gradient descent available
  8. VI.8 Adam intuition available
  9. VI.9 Constraints and projected/penalized intuition available
  10. VI.10 Numerical stopping and optimization diagnostics available

Part VII

Information Theory

Logarithms, entropy, and the loss behind token prediction.

8 of 8 chapters written

  1. VII.1 Logarithms and log probabilities in computation available
  2. VII.2 Self-information available
  3. VII.3 Entropy available
  4. VII.4 Cross entropy and negative log-likelihood available
  5. VII.5 KL divergence available
  6. VII.6 Logits and softmax available
  7. VII.7 Numerical stability: log-sum-exp and stable softmax available
  8. VII.8 From token logits to language-model loss available

Part VIII

Numerical Computing

Why equivalent expressions behave differently on real machines.

10 of 10 chapters written

  1. VIII.1 Floating-point representation available
  2. VIII.2 Rounding and representation error available
  3. VIII.3 Error propagation and conditioning available
  4. VIII.4 Catastrophic cancellation available
  5. VIII.5 Overflow and underflow available
  6. VIII.6 Stable algorithms available
  7. VIII.7 Numerical linear algebra realities available
  8. VIII.8 Sparse matrices and sparse structure available
  9. VIII.9 Vectorized computation available
  10. VIII.10 Reproducibility, random seeds, and nondeterminism available