Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.A recipe that remembers how it changes
A program is a long recipe of tiny steps: multiply, add, take a sine. Each tiny step has a simple, known rate of change. Automatic differentiation follows the recipe and, at every step, also tracks how a small nudge to the inputs would change that step’s result. Chaining these tiny rates together, via the chain rule, gives the exact derivative of the whole program.
Backpropagation, which trains every neural network, is reverse-mode AD. Trajectory optimizers, differentiable simulators and system-identification tools for spacecraft and robots rely on AD for exact gradients and Jacobians at little more than the cost of running the model.
- 1. AD computes derivatives by…
- 2. Backpropagation is which AD mode?
- 3. AD derivatives are…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.Evaluation traces and computation graphs
Write the program as a sequence of elementary operations . This forms a directed acyclic graph from inputs to outputs.
Forward mode (tangents)
Carry alongside each value:
Seeding gives the Jacobian-vector product in one pass.
Reverse mode (adjoints)
Run the primal pass and store intermediate values. Then set and sweep backwards:
This gives the vector-Jacobian product , and so the full gradient of a scalar output in one sweep.
- 1. Forward mode computes…
- 2. Reverse mode needs to store…
- 3. When a variable is used twice, its adjoint is…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 40 minUndergraduate students and practising engineers.Cost: which mode when?
For , the full Jacobian costs
- forward mode: JVP passes;
- reverse mode: VJP passes.
Each pass costs a small constant times one evaluation of (the “cheap gradient principle”: a gradient costs at most about 4–5 function evaluations; Griewank and Walther, 2008). Neural-network losses have and , so reverse mode wins. Sensitivities of a long state trajectory to a few parameters have small , so forward mode wins.
Memory and checkpointing
Reverse mode stores the trace, so memory grows with program length. Checkpointing stores only some states and recomputes the rest. This trades compute for memory (Griewank’s revolve; gradient checkpointing in deep learning).
Engines
- Operator overloading (tape): PyTorch, autograd, JAX tracing.
- Source transformation: Tapenade, Enzyme.
- Higher order: forward-over-reverse gives Hessian-vector products.
- 1. Full Jacobian of f: ℝ¹⁰⁰⁰ → ℝ² is cheapest with…
- 2. Gradient checkpointing trades…
- 3. Hessian-vector products are obtained by…
Level 3: Advanced
★★★★☆ Advanced⏱ 40 minGraduate level, with full derivations and proofs.Correctness of reverse mode
Define , holding the other independent paths fixed. By the multivariable chain rule, depends on only through its children, so . Processing nodes in reverse topological order guarantees every child adjoint is final before it’s used. ∎
The dot-product test
For any : . Evaluating both sides with independently coded JVP and VJP routines is a sharp test that the adjoint code is the true transpose. It’s standard practice in adjoint-based data assimilation and seismic imaging.
Matrix-calculus building blocks
For : JVP , VJP , . For an elementwise : . Backprop is these rules applied layer by layer.
Exercise 3.1: adjoints for f = ln x₁ + x₁x₂ − sin x₂ at (2, 5)
, and .
- 1. Reverse topological order ensures…
- 2. VJP of y = Wx with respect to x:
- 3. ∂f/∂x₁ for ln x₁ + x₁x₂ − sin x₂ at (2, 5):
Level 4: Expert
★★★★★ Expert⏱ 35 minResearchers: original papers and open problems.Jacobians of a learned controller
A small policy network maps a 200-beam range scan to a 3-dimensional velocity command. Its input–output Jacobian is used for sensitivity analysis, adversarial-robustness checks and Lipschitz estimates. Building it with forward mode takes 200 JVPs; reverse mode takes 3 VJPs. The two agree to 1e−16, and the dot-product test confirms the VJP is the exact transpose of the JVP.
AD in AI, robotics and aerospace
- Deep learning: backpropagation (Rumelhart, Hinton and Williams, 1986) is reverse-mode AD (Linnainmaa, 1970). JAX offers
jvp,vjp,jacfwdandjacrev. - Optimal control and trajectory optimization: CasADi uses AD for exact Jacobians and Hessians. Adjoint methods give sensitivities of long trajectories.
- Differentiable simulators: MuJoCo MJX, Brax and Warp provide gradients through contact dynamics for policy learning.
- Earth and space science: 4D-Var data assimilation and adjoint CFD rely on reverse-mode sensitivities; the dot-product test is a standard QA step.
References
- A. Griewank, A. Walther (2008). Evaluating Derivatives, 2nd ed. SIAM.
- A. Baydin, B. Pearlmutter, A. Radul, J. Siskind (2018). “Automatic differentiation in machine learning: a survey.” JMLR, 18(153).
- S. Linnainmaa (1970). “The representation of the cumulative rounding error of an algorithm as a Taylor expansion of the local rounding errors.” Master’s thesis, University of Helsinki.
- D. Rumelhart, G. Hinton, R. Williams (1986). “Learning representations by back-propagating errors.” Nature, 323.
- J. Bradbury et al. (2018). JAX: composable transformations of Python+NumPy programs. github.com/google/jax.
- A. Paszke et al. (2019). “PyTorch: an imperative style, high-performance deep learning library.” NeurIPS.
- T. Chen et al. (2016). “Training deep nets with sublinear memory cost.” arXiv:1604.06174.
- W. Moses, V. Churavy (2020). “Instead of rewriting foreign code for machine learning, automatically synthesize fast gradients.” NeurIPS (Enzyme).
- J. Andersson et al. (2019). “CasADi.” Mathematical Programming Computation, 11.