Skip to content

XAD The Comprehensive Tool for Automatic Differentiation

XAD is a comprehensive open-source C++ library for automatic differentiation. It targets production-quality code at any scale, striving for both ease of use and high performance.

Latest Release: v1.2.0
Adouble x0 = 1.3, x1 = 5.2;  
Adouble y = func(x0, x1);
derivative(y) = 1.0;
cout << "dy/dx0=" << derivative(x0) << "\n"
     << "dy/dx1=" << derivative(x1) << "\n";

Automatic Differentiation

Automatic differentiation (also called algorithmic differentiation) is a set of techniques for calculating partial derivatives of functions specified as computer programs. Since every program execution is always composed of a sequence of simple operations with known derivatives (arithmetics and mathematical functions like sin, exp, log, etc.), the chain rule can be applied repeatedly to calculate partial derivatives automatically. XAD implements this using operator-overloading in C++, allowing to compute derivatives with minimal changes to the program. See automatic differentation mathematical background for more details.

Key Features

Any Order, Mode, Precision

Calculate derivatives in forward and adjoint modes, for any order – both in single and double precision.


Battle-tested in large-scale production code-bases, over 98% test coverage, and supporting a wide range of math functions.

Blindingly Fast

Optimised for maximum performance, e.g. via expression templates and efficient taping.


Manage tape memory and achieve higher performance via checkpointing.

External Functions

Integrate functions from external libraries into the AD tape or manually optimise parts of the differentiated code.

Thread-safe tape

Safely use multiple tapes from multiple threads in parallel code.