dual-math: Math group generic for dual numbers

dual-mathR Documentation

Math group generic for dual numbers

Description

Implements all standard mathematical functions for dual numbers via the chain rule: f(dual(a, b)) = dual(f(a), df(a) * b).

Supported functions: abs, sign, sqrt, floor, ceiling, trunc, round, exp, expm1, log, log2, log10, log1p, cos, sin, tan, cospi, sinpi, tanpi, acos, asin, atan, cosh, sinh, tanh, acosh, asinh, atanh, gamma, lgamma, digamma, trigamma, cumsum, factorial, lfactorial.

Usage

## S4 method for signature 'dualr'
exp(x)

## S4 method for signature 'dualr'
sqrt(x)

## S4 method for signature 'dualr'
Math(x)

Arguments

x

A dual number.

Value

A dual with the function applied to the value and the derivative propagated via the chain rule.

Examples

x <- dual_variable(pi / 4)
value(sin(x))
deriv(sin(x))

y <- dual_variable(2)
value(exp(y))
deriv(exp(y))
deriv(log(y))


nabla documentation built on Feb. 11, 2026, 1:06 a.m.