Slope, Flow, and Smoothness
Part 4 of Math for GDL: derivatives, gradients, divergence, the Laplacian and gradient descent, and why the direction called downhill depends on a choice you may not know you made. Every claim is checked in NumPy.
Fit a linear model with two inputs by gradient descent, using the best fixed step size. With both inputs measured in metres, it reaches the best fit, to six digits, in 7 steps. Now record the second input in centimetres instead. Nothing that matters changes: same data, same model, same best predictions. The second weight just becomes 100 times smaller. Gradient descent now needs 57,001 steps. In millimetres it needs about 5.7 million.
The function being minimised did not change, and neither did its minimum. What changed hides inside the word gradient. The gradient is more than a list of partial derivatives: it is the vector that an inner product assigns to the derivative. Changing units quietly changes the inner product. By the end of this post, that sentence will be a proposition, and 57,001 will come out of a formula.
This is Part 4 of Math for GDL. The series works through a review paper by Sáez de Ocáriz Borde & Bronstein (2025), called the review below, one section at a time. Parts 1, 2 and 3 built static structure: sets and maps, symmetry, and the length, distance and angle of a vector space. This part covers §3, and things start to move. Calculus asks how a quantity changes when you move a little. Each of its tools leans on a structure from Part 3:
| Tool | What it measures | What it needs |
|---|---|---|
| Limit, continuity | whether small moves give small changes | a distance (Part 3, metrics) |
| Derivative | the rate of change along a direction | adding and scaling (vector space) and a norm |
| Gradient | the direction of fastest increase | an inner product |
| Divergence, Laplacian | outflow and curvature of a field | coordinates, volume, and an inner product |
Table of contents
Notation
| Symbol | Meaning |
|---|---|
| \( f : \mathbb{R}^n \to \mathbb{R} \) | A scalar field, such as a loss |
| \( F : \mathbb{R}^n \to \mathbb{R}^m \) | A vector field; with \( m = n \) it can have a divergence |
| \( \partial_d f(x) \) | The directional derivative of \( f \) at \( x \) along \( d \) |
| \( \nabla f(x) \) | The gradient: the vector with \( \langle \nabla f(x), d \rangle = \partial_d f(x) \) |
| \( J_F(x) \) | The Jacobian: the \( m \times n \) matrix of partial derivatives |
| \( \operatorname{div} F = \nabla \cdot F \) | Divergence: \( \sum_i \partial F_i / \partial x_i \) |
| \( \Delta f \) | Laplacian: \( \operatorname{div} \nabla f = \sum_i \partial^2 f / \partial x_i^2 \) |
| \( \nabla^2 f \), \( H \) | The Hessian: the matrix of second partial derivatives |
| \( \eta \) | The learning rate (step size) of gradient descent |
| \( \kappa \) | Condition number: largest over smallest curvature of a quadratic |
Continuity and smoothness
If limits and \( \mathcal{C}^k \) classes are familiar, skim to the Lipschitz bound for networks at the end of this section.
A function is continuous at \( x_0 \) if \( f(x) \) gets as close as you like to \( f(x_0) \) once \( x \) is close enough to \( x_0 \). The review's picture is a graph you can draw without lifting your pen. Close enough needs a distance, which is the first reason Part 3 came before this one. Continuity says nothing about how fast \( f \) can change. A stronger condition does.
Definition 1 (Lipschitz continuity). A function \( f : \mathbb{R}^n \to \mathbb{R}^m \) is Lipschitz with constant \( L \) if \( \|f(x) - f(y)\| \le L\, \|x - y\| \) for all \( x, y \).
In words: no slope of \( f \) is steeper than \( L \). The absolute value \( |x| \) is Lipschitz with \( L = 1 \), even though it has a corner at 0. The square root is continuous on \( [0, \infty) \) but not Lipschitz, because its slope \( 1/(2\sqrt{x}) \) grows without bound as \( x \to 0 \).
The review's \( \mathcal{C}^k \) classes ask for more: derivatives that exist and are continuous. \( \mathcal{C}^1 \) means the first derivatives do, and \( \mathcal{C}^\infty \) means derivatives of every order do. Being differentiable is weaker than being \( \mathcal{C}^1 \). The function \( x^2 \sin(1/x) \), set to 0 at 0, has a derivative everywhere. Near 0, though, that derivative keeps hitting \( +1 \) and \( -1 \), while \( f'(0) = 0 \). The derivative exists but is not continuous.
Why ML cares. A ReLU network is Lipschitz, and its constant is at most the product of its layers' spectral norms. A matrix's spectral norm is the most it can stretch a vector, \( \max_{\|v\| = 1} \|Wv\| \). ReLU itself is 1-Lipschitz, so each layer multiplies the constant by at most its own stretch. For a random three-layer network in the notebook the bound is 162, while the largest ratio observed over 5,000 pairs of inputs is about 20. The bound holds, but it is loose. Spectral normalization (Miyato et al. 2018) divides each weight matrix by its spectral norm. That forces the bound to 1, which keeps a GAN's discriminator from changing too sharply.
Scalar fields, vector fields, signals
A scalar field assigns a number to each point, \( f : \mathbb{R}^n \to \mathbb{R} \): the temperature in a room, or a loss as a function of the weights. A vector field assigns a vector, \( F : \mathbb{R}^n \to \mathbb{R}^m \): the velocity of a fluid, or the gradient of a loss at every point. The review then generalises the domain. A signal is a function from a domain \( \Omega \) to a space of channels \( \mathbb{R}^m \), where \( \Omega \) need not be a vector space at all. This is Part 3's function space \( \mathcal{F}(\Omega) \) with more than one number per point. The four weather stations carry a signal with one channel (temperature). An RGB image is a signal on a pixel grid with three. The features on a graph's nodes are a signal with as many channels as features.
Derivatives and the gradient
Definition 2 (Directional derivative). The directional derivative of a scalar field \( f \) at \( x \) along \( d \in \mathbb{R}^n \) is $$ \partial_d f(x) = \lim_{\epsilon \to 0} \frac{f(x + \epsilon d) - f(x)}{\epsilon}. $$ The partial derivatives \( \partial f / \partial x_i \) are the directional derivatives along the coordinate axes \( e_i \).
For smooth \( f \), the map \( d \mapsto \partial_d f(x) \) is linear: doubling the direction doubles the rate, and the rates along \( d_1 \) and \( d_2 \) add up to the rate along \( d_1 + d_2 \). This linear map is the derivative of \( f \) at \( x \). It turns a direction into a number, so it is not yet a vector in the same space as \( x \). To get a vector you need an inner product. (The review's formula also writes \( \partial_d f \) as \( f_{x_i} \), which is notation for a partial derivative. The two agree only when \( d = e_i \).)
Definition 3 (Gradient). Given an inner product \( \langle \cdot, \cdot \rangle \) on \( \mathbb{R}^n \), the gradient of \( f \) at \( x \) is the unique vector \( \nabla f(x) \) with $$ \langle \nabla f(x), d \rangle = \partial_d f(x) \quad \text{for every direction } d. $$
With the dot product, taking \( d = e_i \) gives \( (\nabla f)_i = \partial f / \partial x_i \), the familiar list of partial derivatives. The review defines the gradient this way, but first calls it a linear functional. That name belongs to the derivative, the map from directions to numbers. The gradient is the vector the inner product assigns to it. With another inner product, the same derivative gives a different vector.
Proposition 1 (The gradient depends on the inner product). Let \( \langle u, v \rangle_M = u^\top M v \) for a symmetric positive definite matrix \( M \), and let \( g \) be the vector of partial derivatives of \( f \) at \( x \). Then the gradient of \( f \) for this inner product is \( M^{-1} g \).
Proof
We need the vector \( v \) with \( \langle v, d \rangle_M = \partial_d f(x) \) for all \( d \). Check \( v = M^{-1} g \): $$ \begin{aligned} \langle M^{-1} g, d \rangle_M &= (M^{-1} g)^\top M d && \text{; definition of } \langle \cdot, \cdot \rangle_M \\ &= g^\top M^{-1} M d && \text{; } M \text{ is symmetric} \\ &= g^\top d = \partial_d f(x) && \text{; dot-product gradient} \end{aligned} $$ It is the only such vector, because \( \langle v - v', d \rangle_M = 0 \) for all \( d \) forces \( v = v' \). ∎
Take the smooth test function \( f(w) = \log(1 + e^{w_1 - 2 w_2}) + \tfrac{1}{2} w_1^2 \) at \( w = (0.3, -0.4) \). With \( M = \operatorname{diag}(1, 9) \), which counts the second coordinate three times as long, the gradient turns by 46°. A change of units is a change of this kind: recording an input in centimetres rescales one coordinate, and the gradient direction moves with it. That is half of the opening puzzle.
The other half is the claim, also in the review, that the gradient points in the direction of steepest increase. Steepest among which steps? Among all steps of length 1, and length needs a norm. Fig. 2 shows the answer for the three norms whose unit balls appear in Part 3's Fig. 3.
For \( L_2 \), Cauchy–Schwarz from Part 3 shows in one line that the negative gradient wins: \( \langle g, d \rangle \ge -\|g\|\,\|d\| = -\|g\| \), with equality only for \( d = -g/\|g\| \). For the other two norms the minimiser sits at a corner of the ball, and the familiar negative gradient is no longer the steepest step.
Why ML cares. Sign-based optimizers such as signSGD (Bernstein et al. 2018) update every weight by the same amount, against the sign of its partial derivative. That is steepest descent for \( L_\infty \), the middle panel of Fig. 2. Whether plain gradient descent, sign descent or something else is the right downhill depends on which geometry on the weights you trust.
Vector fields have derivatives too. For \( F : \mathbb{R}^n \to \mathbb{R}^m \), the derivative is a matrix, the Jacobian \( J_F(x) \), with entry \( (i, j) \) equal to \( \partial F_i / \partial x_j \). It is the best linear approximation of \( F \) near \( x \): \( F(x + d) \approx F(x) + J_F(x)\, d \). For a scalar field it is a single row, the transpose of the dot-product gradient.
Computing derivatives
The review lists three finite-difference approximations of \( f'(x) \): forward \( (f(x+h) - f(x))/h \), backward, and central \( (f(x+h) - f(x-h))/2h \). Taylor's theorem bounds their errors: proportional to \( h \) for forward differences and to \( h^2 \) for central ones. The review discusses only this truncation error, so it is easy to conclude that a smaller \( h \) is always better. On a computer it is not (Fig. 3).
Here forward differences never get below about \( 2 \times 10^{-9} \). Central differences get below \( 10^{-11} \), at a much larger step. At \( h = 10^{-15} \) both are wrong in the second digit. Finite differences are for checking derivatives, which is how the notebook uses them. To compute the gradients of a network, the chain rule does better.
Proposition 2 (Chain rule). If \( f : \mathbb{R}^n \to \mathbb{R}^m \) and \( g : \mathbb{R}^m \to \mathbb{R}^p \) are differentiable, then \( J_{g \circ f}(x) = J_g\big(f(x)\big)\, J_f(x) \).
A network is a composition of layers (Part 1), so the Jacobian of the loss with respect to a layer's weights is a product of Jacobians, one per layer. Backpropagation evaluates that product from the loss end. The loss is a single number, so the product starts as a row vector. Each step then multiplies that vector by one layer's Jacobian, which is cheap. The notebook does this by hand for a two-layer network and matches all 15 partial derivatives of the first layer against central differences. Central differences needed 2 forward passes per weight, 30 in all. For a model with a billion weights that would be two billion passes. Backpropagation needs one pass forward and one back, however many weights there are.
Why ML cares. Rumelhart et al. (1986) popularised backpropagation for training multi-layer networks. Deep learning frameworks implement it as reverse-mode automatic differentiation. It computes the whole gradient at a small constant multiple of the cost of evaluating the loss, however many weights there are (Baydin et al. 2018).
Integrals
A short refresher; skip to Divergence if you are comfortable with Riemann sums.
The integral \( \int_\Omega f \, dV \) adds up \( f \) over a domain. The Riemann integral defines it as a limit of sums over small pieces, and the same sums are one way to compute it. How fast they converge depends on where each piece is sampled. For \( \int_0^1 e^x \, dx \), sums that use the left end of each of \( N \) pieces have error proportional to \( 1/N \) (about \( 0.86/N \)), while sums that use the midpoint have error proportional to \( 1/N^2 \) (about \( 0.072/N^2 \)). Both approach \( e - 1 \), the value the fundamental theorem of calculus gives: if \( F' = f \), then \( \int_a^b f \, dx = F(b) - F(a) \). Integrals already appeared in Part 3, in the inner product of functions \( \langle f, g \rangle = \int f g \). The next two sections rely on them.
Divergence
Definition 4 (Divergence). The divergence of a vector field \( F = (F_1, \ldots, F_n) : \mathbb{R}^n \to \mathbb{R}^n \) is the scalar field $$ \operatorname{div} F = \sum_{i=1}^n \frac{\partial F_i}{\partial x_i} = \nabla \cdot F. $$
The review writes the field as \( F : \mathbb{R}^n \to \mathbb{R}^m \), but the sum only makes sense when \( m = n \): each output component is differentiated along its own input direction. Picture \( F \) as the velocity of a fluid. The divergence at a point measures how much fluid leaves a tiny region around it, per unit volume. Positive divergence is a source; negative divergence is a sink.
Theorem 1 (Divergence theorem). For a bounded region \( \Omega \subseteq \mathbb{R}^n \) with smooth boundary \( \partial \Omega \), outward unit normal \( \hat n \), and a \( \mathcal{C}^1 \) field \( F \), $$ \int_\Omega \operatorname{div} F \, dV = \int_{\partial \Omega} \langle F, \hat n \rangle \, dS. $$
In words: what the sources inside produce equals what flows out through the boundary. For \( F = (x^2, xy) \) on the unit square, \( \operatorname{div} F = 2x + x = 3x \), whose integral over the square is \( 3/2 \). On the boundary, fluid leaves through only two edges: the right edge contributes \( \int_0^1 1 \, dy = 1 \) and the top edge \( \int_0^1 x \, dx = 1/2 \). Both sides give \( 3/2 \). (The theorem is stated for smooth boundaries, but it also holds with corners like the square's.)
The divergence theorem turns the product rule into integration by parts, and that gives the most useful identity in this section. Two linear maps \( T \) and \( T^* \) are adjoint when \( \langle T u, v \rangle = \langle u, T^* v \rangle \) for all \( u, v \): the transpose of a matrix, generalised. Gradient and divergence are adjoint, up to a sign and a boundary term.
Proposition 3 (Gradient and divergence are adjoint). Let \( \Omega \) be as in Theorem 1, and let \( f \) and \( F \) be \( \mathcal{C}^1 \). With the inner products \( \langle f, g \rangle = \int_\Omega f g \) and \( \langle F, G \rangle = \int_\Omega F \cdot G \), $$ \langle \nabla f, F \rangle = -\langle f, \operatorname{div} F \rangle + \int_{\partial \Omega} f\, \langle F, \hat n \rangle \, dS. $$ In particular \( \langle \nabla f, F \rangle = -\langle f, \operatorname{div} F \rangle \) whenever \( f = 0 \) or \( \langle F, \hat n \rangle = 0 \) on the boundary.
Proof
Apply the divergence theorem to the field \( f F \): $$ \begin{aligned} \int_{\partial \Omega} f \langle F, \hat n \rangle \, dS &= \int_\Omega \operatorname{div}(f F) \, dV && \text{; Theorem 1} \\ &= \int_\Omega \sum_i \frac{\partial (f F_i)}{\partial x_i} \, dV && \text{; Definition 4} \\ &= \int_\Omega \big( \nabla f \cdot F + f \operatorname{div} F \big) \, dV && \text{; product rule} \\ &= \langle \nabla f, F \rangle + \langle f, \operatorname{div} F \rangle && \text{; the inner products} \end{aligned} $$ Rearrange. ∎
The notebook checks both cases on the unit square. With \( f = \sin(\pi x) \sin(\pi y) \), which vanishes on the boundary, both sides equal \( -0.3468 \) for the field \( F = (x^2 + y, \cos xy) \). With \( f = 1 + x \) they differ by 2.2232, which is exactly the boundary term.
Aside: a slip in the review's integration by parts
The review's derivation of Proposition 3 writes \( \int_\Omega \frac{\partial f}{\partial x_i} F_i \, dx = \int_\Omega f F_i \, dx - \int_\Omega f \frac{\partial F_i}{\partial x_i} \, dx \). The first term on the right should be \( \int_\Omega \frac{\partial (f F_i)}{\partial x_i} \, dx \), the integral of a derivative, which is what the divergence theorem turns into a boundary integral. As written, it has no derivative at all, and the identity is false: take \( f = 1 \) and \( F_i = 1 \), and the left side is 0 while the right side is the volume of \( \Omega \). The review's next expression, the boundary integral, is correct.
The Laplacian
Definition 5 (Laplacian). The Laplacian of a scalar field is the divergence of its gradient, $$ \Delta f = \operatorname{div} \nabla f = \sum_{i=1}^n \frac{\partial^2 f}{\partial x_i^2}. $$
The Laplacian at a point compares \( f \) there with its average on a small surrounding sphere. It is at most zero at a local peak, at least zero at a dip, and zero where \( f \) equals that average. Proposition 3 links it to an energy.
Proposition 4 (Dirichlet energy). If \( f \) is \( \mathcal{C}^2 \) and \( f = 0 \) on the boundary of \( \Omega \), then $$ \langle f, \Delta f \rangle = -\langle \nabla f, \nabla f \rangle = -\int_\Omega \|\nabla f\|^2 \le 0. $$ The quantity \( \int_\Omega \|\nabla f\|^2 \) is the Dirichlet energy of \( f \): how much \( f \) varies.
Proof
Apply Proposition 3 with \( F = \nabla f \); the boundary term vanishes because \( f = 0 \) there: \( \langle \nabla f, \nabla f \rangle = -\langle f, \operatorname{div} \nabla f \rangle = -\langle f, \Delta f \rangle \). ∎
The review states this identity without the minus sign and without the boundary condition. Its version would make \( \langle f, \Delta f \rangle \) a non-negative energy. With \( \Delta = \operatorname{div} \nabla \), as the review defines it, the sign is negative. For \( f = \sin(\pi x) \sin(\pi y) \) on the unit square, \( \langle f, \Delta f \rangle = -\pi^2/2 \approx -4.93 \). The review's margin note mentions the fix that many authors use: define the Laplacian as \( -\operatorname{div} \nabla \), and the identity holds as written. Graph Laplacians, coming in Part 8, use that sign.
Theorem 2 (Rotation invariance). For every \( \mathcal{C}^2 \) function \( f \) and every orthogonal matrix \( A \) (a rotation or reflection), \( \Delta (f \circ A)(x) = (\Delta f)(A x) \).
Proof
Write \( \Delta f = \operatorname{tr}(\nabla^2 f) \), the trace of the Hessian. Then $$ \begin{aligned} \Delta (f \circ A)(x) &= \operatorname{tr}\big( A^\top \nabla^2 f(Ax)\, A \big) && \text{; chain rule, twice} \\ &= \operatorname{tr}\big( \nabla^2 f(Ax)\, A A^\top \big) && \text{; } \operatorname{tr}(XY) = \operatorname{tr}(YX) \\ &= \operatorname{tr}\big( \nabla^2 f(Ax) \big) = (\Delta f)(Ax) && \text{; } A A^\top = I \end{aligned} $$ ∎
The review calls this invariance: the operator \( \Delta \) looks the same in every rotated coordinate system. In the language of Part 2, the map \( f \mapsto \Delta f \) on signals is equivariant: rotate the input and the output rotates with it, \( \Delta(f \circ A) = (\Delta f) \circ A \).
On a pixel grid, the Laplacian becomes the five-point stencil: add the four neighbours, subtract four times the centre, and divide by the squared grid spacing. That stencil is the kernel \( \left(\begin{smallmatrix} 0 & 1 & 0 \\ 1 & -4 & 1 \\ 0 & 1 & 0 \end{smallmatrix}\right) \) from Part 2's Fig. 1, the one that looks the same after a 90° turn. Theorem 2 explains that symmetry: on a grid, quarter-turns are the rotations that survive. With spacing \( 10^{-3} \) the stencil matches the exact Laplacian of a test function to six decimal places.
Why ML cares. Replace the pixel grid by a graph, and the stencil becomes average over your neighbours. Graph convolutional networks (Kipf & Welling 2017) build each layer on this operation. Li et al. (2018) showed that a graph convolution is a form of Laplacian smoothing. That explains a known failure, called oversmoothing: stack too many layers and the node features blur together, like the F in Fig. 4.
Gradient descent
Training treats the loss \( \mathcal{L}(w) \) as a scalar field over the weights and steps against its gradient: $$ w_{t+1} = w_t - \eta \, \nabla \mathcal{L}(w_t). $$ The opening puzzle lives in the simplest case, a quadratic loss \( \mathcal{L}(w) = \tfrac{1}{2} w^\top H w \) (least squares is one, after shifting the minimum to 0). Its Hessian \( H \) is the matrix of second derivatives. Its eigenvalues are the curvatures along special directions, the eigenvectors. Call the smallest curvature \( \mu \) and the largest \( L \). Their ratio \( \kappa = L / \mu \) is the condition number.
Proposition 5 (Gradient descent on a quadratic). Gradient descent converges for every starting point if and only if \( 0 < \eta < 2/L \). The best fixed step, \( \eta = 2/(\mu + L) \), shrinks the distance to the minimum by a factor of at most $$ \frac{\kappa - 1}{\kappa + 1} \quad \text{per step}. $$
Proof
Since \( \nabla \mathcal{L}(w) = H w \), each step is \( w_{t+1} = (I - \eta H) w_t \). Along an eigenvector of \( H \) with eigenvalue \( \lambda \), this multiplies the coordinate by \( 1 - \eta \lambda \), so every coordinate shrinks exactly when \( |1 - \eta \lambda| < 1 \) for every eigenvalue \( \lambda \) (all lie in \( [\mu, L] \)). For \( \eta > 0 \) that means \( \eta < 2/L \). The worst factor, \( \max(|1 - \eta \mu|, |1 - \eta L|) \), is smallest when the two are equal: \( \eta = 2/(\mu + L) \), giving \( 1 - 2\mu/(\mu + L) = (L - \mu)/(L + \mu) = (\kappa - 1)/(\kappa + 1) \). ∎
To shrink the error by a factor of \( 10^6 \), you need about $$ \frac{\ln 10^6}{\ln \frac{\kappa + 1}{\kappa - 1}} \;\approx\; \frac{\kappa}{2} \ln 10^6 \quad \text{steps, for large } \kappa. $$ Now the puzzle is arithmetic. Recording an input in centimetres multiplies that column of the data by 100, which multiplies its curvature by \( 100^2 = 10^4 \). In metres the curvatures are nearly equal and \( \kappa \approx 1.26 \): 7 steps. In centimetres \( \kappa \approx 8{,}250 \), and \( (\kappa/2) \ln 10^6 \approx 57{,}000 \). Gradient descent took 57,001 steps.
The fix comes from the other half of the puzzle, Proposition 1: use an inner product that matches the units, and the gradient changes with them. Dividing each coordinate of the gradient by its own curvature brings every unit back to 5 steps. That is the gradient for the inner product \( \langle u, v \rangle_D \), where \( D \) is the diagonal of \( H \). Using all of \( H \) is Newton's method, and it needs a single step.
There is also a principled way to pick the inner product. The natural gradient (Amari 1998) uses the inner product given by the Fisher information of the model (the average outer product of the gradient of its log-likelihood). That inner product changes along with the parametrization. So for a change of units, natural-gradient steps do not depend on how the weights are measured. For any other smooth reparametrization, they agree to first order. For this least-squares problem the Fisher information is proportional to \( H \). The notebook checks that natural-gradient steps in metres and in centimetres give the same predictions at every step.
Why ML cares. This is one reason inputs are standardized before training. LeCun et al. (1998) recommend shifting each input to mean zero and scaling inputs to similar variance, so that the curvature along different weights is comparable. Adaptive optimizers rescale each coordinate of the gradient itself, which amounts to a diagonal inner product estimated on the fly. Rescaling coordinates has a limit, though. When inputs are strongly correlated, the loss forms a long, narrow valley that runs diagonally, and no per-coordinate scaling can shorten it. In the notebook, two inputs with correlation near 0.999 still need 12,120 steps after rescaling. That is why LeCun et al. also recommend decorrelating inputs where possible.
Stepping back, §3.7 of the review notes that finding global optima of generic high-dimensional functions is NP-hard. It argues that the geometry of the data domain gives extra regularity to exploit. The rest of the series is about that geometry.
Quick summary
Each tool from this post, with its example.
| Tool | In one line | Example in this post | In ML |
|---|---|---|---|
| Lipschitz constant | a bound on every slope | ReLU net: bound 162, observed 20 | spectral normalization |
| Gradient | the vector an inner product assigns to the derivative | \( M = \operatorname{diag}(1, 9) \) turns it by 46° | preconditioning, natural gradient |
| Steepest descent | depends on the norm | \( L_\infty \): move every weight by the same amount | signSGD |
| Finite differences | check derivatives; error has a best \( h \) | \( h \approx 3 \times 10^{-9} \) forward, \( 3 \times 10^{-6} \) central | gradient checking |
| Chain rule | Jacobians multiply | 15 weights matched by hand | backpropagation |
| Divergence | outflow per unit volume | \( F = (x^2, xy) \): both sides \( 3/2 \) | minus the adjoint of the gradient |
| Laplacian | value against neighbours' average | heat flow on the F; Part 2's kernel | graph convolution, oversmoothing |
| Gradient descent | \( (\kappa - 1)/(\kappa + 1) \) per step | metres 7 steps, centimetres 57,001 | input standardization |
Open questions
Questions I'm carrying into the next parts:
- What replaces the grid? The five-point stencil needs neighbours in four fixed directions. On a sphere, a mesh or a graph there is no such grid. What plays the role of the gradient and the Laplacian there? (§4 and §7 of the review.)
- Which inner product on the weights? The natural gradient picks one from the model's statistics, at a cost that grows quickly with the number of weights. How far do cheaper diagonal or block approximations get?
- Why does gradient descent work at all on non-convex losses? The analysis here is for quadratics. Real losses have many minima and saddle points, yet training usually succeeds.
Next, Part 5 turns to §4.1, §4.2 and §4.4: topology and the manifold hypothesis. Topology drops distances altogether and keeps only the idea of nearness. That turns out to be enough to say when two shapes are the same. It is also enough to ask whether real data lives on a low-dimensional surface.
Code
All checks in this post, and Figs. 1 to 4, are in
math-gdl-04-calculus.ipynb
(NumPy and Matplotlib; runs in seconds). Each demo ends with a short exercise, such as
making the two inputs correlated and seeing whether per-coordinate rescaling still
rescues gradient descent.
To skip the setup, open the
interactive playground.
It runs the same checks in your browser and adds controls for the exercises. The first
load can take up to half a minute while Python starts up. Its source is
math-gdl-04-calculus-playground.py,
a marimo notebook.
Corrections are welcome at .
Previous: Part 3, Length, Distance, and Angle. Next: Part 5, Shape Without Distance. Series overview: Eight Puzzles That Helped Me Understand Geometric Deep Learning.
Citation
Cited as:
Pham, Anh-Duy. (Nov 2026). Slope, flow, and smoothness. Math for GDL, Part 4. https://www.adpham.de/blog/math-gdl-04-calculus.html
Or
@article{pham2026mathgdl04,
title = "Slope, Flow, and Smoothness",
author = "Pham, Anh-Duy",
journal = "www.adpham.de",
year = "2026",
month = "Nov",
url = "https://www.adpham.de/blog/math-gdl-04-calculus.html"
}
References
- Sáez de Ocáriz Borde, H. & Bronstein, M. M. “Mathematical Foundations of Geometric Deep Learning.” arXiv:2508.02723 (2025).
- Miyato, T., Kataoka, T., Koyama, M. & Yoshida, Y. “Spectral normalization for generative adversarial networks.” International Conference on Learning Representations (2018).
- Bernstein, J., Wang, Y.-X., Azizzadenesheli, K. & Anandkumar, A. “signSGD: Compressed optimisation for non-convex problems.” Proceedings of the 35th International Conference on Machine Learning, PMLR 80, 560–569 (2018).
- Rumelhart, D. E., Hinton, G. E. & Williams, R. J. “Learning representations by back-propagating errors.” Nature 323, 533–536 (1986).
- Baydin, A. G., Pearlmutter, B. A., Radul, A. A. & Siskind, J. M. “Automatic differentiation in machine learning: a survey.” Journal of Machine Learning Research 18(153), 1–43 (2018).
- Kipf, T. N. & Welling, M. “Semi-supervised classification with graph convolutional networks.” International Conference on Learning Representations (2017).
- Li, Q., Han, Z. & Wu, X.-M. “Deeper insights into graph convolutional networks for semi-supervised learning.” Proceedings of the AAAI Conference on Artificial Intelligence 32 (2018).
- Amari, S. “Natural gradient works efficiently in learning.” Neural Computation 10(2), 251–276 (1998).
- LeCun, Y., Bottou, L., Orr, G. B. & Müller, K.-R. “Efficient BackProp.” In Neural Networks: Tricks of the Trade, Lecture Notes in Computer Science 1524, Springer (1998).