RMath

rmath.calculus

Industrial-grade tools for automatic differentiation and numerical integration.

Proven: Forward-Mode AD

The Dual number implementation allows exact gradient computation alongside regular math operations, without the overhead of building a reverse-mode tape.

dual_math.py
from rmath.calculus import Dual

# f(x) = x^2 + 5x + 10
# Initialize x = 3 with a derivative seed of 1.0
x = Dual(3.0, 1.0)

# Perform math naturally (note right-side constants)
y = x**2 + x * 5.0 + 10.0

# Analytical result: f(3) = 34, f'(3) = 2(3) + 5 = 11
print(f"f(3)  : {y.value}")
print(f"f'(3) : {y.derivative}")
f(3) : 34.0 f'(3) : 11.0

Numerical Integration

RMath provides high-speed parallel implementations of common integration rules, suitable for large-scale datasets.

integrate.py
import rmath.vector as rv
import rmath.calculus as rc

# Integrate sin(x) from 0 to PI
x = rv.linspace(0.0, 3.1415926535, 1000)
y = x.sin()

area = rc.integrate_trapezoidal(x, y)
print(f"Trapezoidal Area: {area:.6f}")

# Functional Simpson's Rule
area_simpson = rc.integrate_simpson(lambda x: x**2, 0.0, 1.0, 100)
print(f"Simpson's Area  : {area_simpson:.6f}")
Trapezoidal Area: 2.000000 Simpson's Area : 0.333333