Skip to content

Tomius/auto_derive

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Auto derive

This is a C++14 library offering a way to compile-time derive a mathematical function, so run-time only the derivative is executed. This technique is called Automatic differentiation, hence the name of the lib.

Example:

#include "auto_derive/all.hpp"

int main() {
  AUTO_DERIVE_VARIABLE(double, x);
  AUTO_DERIVE_VARIABLE(double, y);

  constexpr auto f = pow(x+y, 3) - 2*x*y;

  constexpr auto dfdy = derive(f, y);

  double dfdy_evaluated = dfdy(x=2, y=4.2);

  std::cout << "derive(" << f << ", " << y << ") = " << dfdy << std::endl;
  std::cout << dfdy << " if x=2 and y=4.2 is " << dfdy_evaluated << std::endl;
}

It will result the following output:

derive(pow(x+y,3)-2*x*y, y) = 3*pow(x+y,2)-2*x
3*pow(x+y,2)-2*x if x=2 and y=4.2 is 111.32

For more details see how_to_use.cpp.

About

C++14 automatic differentiation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages