Skip to content

forward mode automatic differentiation using dual numbers

License

Notifications You must be signed in to change notification settings

lucaferranti/ForwardModeAD

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ForwardModeAD

license: MITdocs-devlifecycle

NOTE: project at early stages, everything can change overnight!

Lightweight library for forward-mode automatic differentiation using dual numbers and functions overloading. It can compute the derivative, gradient and jacobian of any function, as long as it is written as a combination of overloaded functions.

As a showcase, in a few lines we can implement the Newton method for root finding.

use ForwardModeAD;

proc f(x) {
    return exp(-x) * sin(x) - log(x);
}

var tol = 1e-6, // tolerance to find the root
    cnt = 0, // to count number of iterations
    x0 = 0.5, // initial guess
    valder = f(initdual(x0)); // initial function value and derivative

while abs(valder.value) > tol {
    x0 -= valder.value / valder.derivative;
    valder = f(initdual(x0));
    cnt += 1;
    writeln("Iteration ", cnt, " x = ", x0, " residual = ", valder.value);
}

Documentation

  • latest : documentation of the latest version on main

Contributing

If you encounter bugs or have feature requests, feel free to open an issue. Pull requests are also welcome. More details in the contribution guidelines

License

MIT (c) Luca Ferranti