Skip to main content

Module autodiff

Module autodiff 

Source
Expand description

Automatic differentiation using dual numbers.

A dual number a + b·ε where ε² = 0 carries both the value and the derivative of a function at a point. Evaluating f(Dual(x, 1)) yields Dual(f(x), f'(x)) in a single forward pass — no symbolic differentiation needed, and it works for arbitrary compositions.

This module provides:

  • Dual — a 1st-order dual number type with full arithmetic
  • eval — evaluate an Expr AST with dual numbers
  • derivative — compute f'(x) at a point for any parseable expression
  • gradient — compute the gradient of a multivariate expression
  • jacobian — compute the Jacobian of a system of expressions

Structs§

Dual
A first-order dual number: value + deriv * ε where ε² = 0.

Functions§

derivative
Compute the derivative of f(var) at x using automatic differentiation.
eval
Evaluate an Expr AST using dual numbers, returning the value and derivative.
gradient
Compute the gradient of a multivariate expression at a point.
jacobian
Compute the Jacobian matrix of a system of expressions.