that entered that calculation. In such a situation, there is a standard method (in the sense of an algorithmic transformation on the program that calculates the loop energy) that allows a fast evaluation of the gradient with respect to all the geometry parameters. Irrespective of the number $N$ of such parameters, and the complexity of the intermediate expressions, it is possible to obtain the gradient to full numerical accuracy with at most $5$ times the computational effort needed to calculate the scalar function (often even much less). In comparison, the naive direct method of calculating the gradient by comparing function values would require at least $N+1$ full evaluations of the function (and then only give a result with reduced numerical accuracy).

The generic approach that makes this possible, which has become known under the names “automatic/algorithmic differentiation”, “sensitivity backpropagation”, or “adjoint code” [@Speelpenning80; @Griewank89onautomatic] is essentially based on this idea:

-   Every intermediate result used in the calculation gets stored away for later use (i.e. none may be dropped or over-written).

-   To each such intermediate quantity $I_k$ stored, we associate a buffer that can store another number $\bar I_k$, initialized to zero at the beginning of the program. Ultimately, 