dual-arithmetic: Arithmetic and comparison operators for dual numbers

dual-arithmeticR Documentation

Arithmetic and comparison operators for dual numbers

Description

Implements arithmetic (+, -, *, /, ^), comparison (==, !=, <, >, <=, >=), and logical (&, |) operators. Derivatives follow standard calculus rules (sum, product, quotient, power, chain).

Usage

## S4 method for signature 'dualr,dualr'
e1 + e2

## S4 method for signature 'dualr,numeric'
e1 + e2

## S4 method for signature 'numeric,dualr'
e1 + e2

## S4 method for signature 'dualr,dualr'
e1 - e2

## S4 method for signature 'dualr,numeric'
e1 - e2

## S4 method for signature 'numeric,dualr'
e1 - e2

## S4 method for signature 'dualr,dualr'
e1 * e2

## S4 method for signature 'dualr,numeric'
e1 * e2

## S4 method for signature 'numeric,dualr'
e1 * e2

## S4 method for signature 'dualr,dualr'
e1 / e2

## S4 method for signature 'dualr,numeric'
e1 / e2

## S4 method for signature 'numeric,dualr'
e1 / e2

## S4 method for signature 'dualr,dualr'
e1 ^ e2

## S4 method for signature 'dualr,numeric'
e1 ^ e2

## S4 method for signature 'numeric,dualr'
e1 ^ e2

## S4 method for signature 'dualr,dualr'
Ops(e1, e2)

## S4 method for signature 'dualr,numeric'
Ops(e1, e2)

## S4 method for signature 'numeric,dualr'
Ops(e1, e2)

## S4 method for signature 'dualr,missing'
e1 + e2

## S4 method for signature 'dualr,missing'
e1 - e2

## S4 method for signature 'dualr'
!x

Arguments

e1, e2

Dual or numeric operands.

x

A dual number (for unary !).

Value

A dual for arithmetic ops; logical for comparisons.

Examples

x <- dual_variable(3)
y <- dual_variable(4)

value(x + y)
deriv(x * x)
value(x^2)
deriv(x^2)

x < y
x == y


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