Science
vautodiff
Exact derivatives, by forward mode automatic differentiation on dual numbers.
Released v1.0.0 · 2026-09-28use "stdlib/autodiff.ven"
Forward mode automatic differentiation on dual numbers: a function built from the module's own arithmetic and trigonometry calls gets an exact first derivative with no formula written by hand. It covers one input variable, and the function must call the module's operations rather than the plain operators.
print Dual(3.0, 1.0)
Reference (19 functions)
API reference
dual_variable(v)
dual_variable(3.0)dual_add(a, b)
Adds two Duals (or Dual-and-Number mixes), propagating both derivatives.
dual_add(dual_variable(2.0), dual_constant(3.0))dual_subtract(a, b)
Subtracts two Duals (or Dual-and-Number mixes), propagating both derivatives.
dual_subtract(dual_variable(5.0), dual_constant(2.0))dual_multiply(a, b)
Multiplies two Duals (or Dual-and-Number mixes) using the product rule.
dual_multiply(dual_variable(3.0), dual_variable(3.0))dual_divide(a, b)
Divides two Duals (or Dual-and-Number mixes) using the quotient rule.
dual_divide(dual_variable(6.0), dual_constant(2.0))dual_negate(a)
Negates a Dual (or Number), flipping the sign of both value and derivative.
dual_negate(dual_variable(4.0))dual_power(a, n)
Raises a Dual (or Number) to a CONSTANT real exponent n.
dual_power(dual_variable(2.0), 3)dual_sqrt(a)
Gives back the square root of a Dual (or Number), with its derivative.
dual_sqrt(dual_variable(4.0))dual_exp(a)
Gives back e raised to a Dual (or Number), with its derivative.
dual_exp(dual_variable(0.0))dual_natural_log(a)
Gives back the natural logarithm of a Dual (or Number), with its derivative.
dual_natural_log(dual_variable(2.0))dual_sin(a)
Gives back the sine of a Dual (or Number), with its derivative.
dual_sin(dual_variable(0.0))dual_cos(a)
Gives back the cosine of a Dual (or Number), with its derivative.
dual_cos(dual_variable(0.0))dual_tan(a)
Gives back the tangent of a Dual (or Number), with its derivative.
dual_tan(dual_variable(0.0))dual_equals(a, b)
Tests whether two Duals (or Dual-and-Number mixes) have equal value AND equal derivative.
dual_equals(dual_variable(2.0), dual_constant(2.0))derivative(f, x0)
THE MAIN ENTRY POINT: gives back the exact derivative of f at x0.
make f(x)
give dual_sin(dual_multiply(x, x))
derivative(f, 2.0)value_and_derivative(f, x0)
make f(x)
give dual_sin(dual_multiply(x, x))
value_and_derivative(f, 2.0)