autodiff!() { /* proc-macro */ }Expand description
Compute the partial derivative of a given expression w.r.t a particular variable. At the moment, the macro only supports expressions defined within the same scope.
§Examples
§Basic arithmetic
extern crate rsdiff_macros as macros;
use macros::autodiff;
fn main() {
let x = 3f64;
let y = 4f64;
assert_eq!(y, autodiff!(x: x * y));
assert_eq!(x, autodiff!(y: x * y));
assert_eq!(1f64, autodiff!(x: x + y));
}§Trigonometric functions
extern crate rsdiff_macros as macros;
use macros::autodiff;
fn main() {
let x = 2f64;
assert_eq!(autodiff!(x: x.cos()), -x.sin());
assert_eq!(autodiff!(x: x.sin()), x.cos());
assert_eq!(autodiff!(x: x.tan()), x.cos().powi(2).recip());
}