Skip to content

Compile time derivatives of arbitrary functions in n dimensions

License

Notifications You must be signed in to change notification settings

sv1990/automatic-differentiation

Repository files navigation

AD: Automatic differentiation

This library allows you to take the exact derivative of any function at compile time.

Examples

The library is most easily described by the following two examples.

One-dimensional

// Define a variable name
constexpr auto x = ad::_0;

// Define the function
constexpr auto f = (x + 1) * (x - 1);

// Take the first two derivatives
constexpr auto df  = f.derive();
constexpr auto d2f = df.derive();

std::cout << d2f(5) << '\n';

It is also possible to use the functions

  • ad::cos
  • ad::exp
  • ad::pow
  • ad::sin
  • ad::sqrt
  • ad::tan
  • ad::log
  • ad::sinh
  • ad::cosh
  • ad::tanh
  • ad::asin
  • ad::acos
  • ad::atan
  • ad::asinh
  • ad::acosh
  • ad::atanh

Multidimensional

// Define variable names
constexpr auto x = ad::_0;
constexpr auto y = ad::_1;

// Define the function
constexpr auto f = x * x * y;

// Take the first derivatives
constexpr auto dxf = f.derive(x);
constexpr auto dyf = f.derive(y); // Alternatively f.derive<1>()

// Take the second derivatives
constexpr auto dxxf = f.derive(x, x);
constexpr auto dyyf = f.derive(y, y);
constexpr auto dxyf = f.derive(x, y);

About

Compile time derivatives of arbitrary functions in n dimensions

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published