Dual Numbers for Arbitrary Order Automatic Differentiation
F. Peñuñuri, K. B. Cantún-Avila, R. Peón-Escalante
TL;DR
DNAOAD tackles the problem of scalable arbitrary-order differentiation by introducing a direct, non-nested dual-number representation in Fortran. The method leverages Faà Di Bruno's formula and Bell polynomials to implement the chain rule for high-order derivatives, enabling efficient computation of $D^n f(x)$ without recursive nesting. It provides a Fortran package with double and quadruple precision support, including utilities for gradients, Jacobians, and Hessians, and demonstrates practical use through simple and nested-function examples. The work offers a scalable alternative to memory-intensive nested dual-number approaches (e.g., ForwardDiff) and broader applicability to optimization and physics, with future work aimed at cross-language extensions and performance optimizations.
Abstract
Dual numbers are a well-known tool for computing derivatives of functions. While the theoretical framework for calculating derivatives of arbitrary order is well established, practical implementations remain less developed. One notable implementation is available in the Julia programming language where dual numbers are designed to be nested, enabling the computation of derivatives to arbitrary order. However, this approach has a significant drawback as it struggles with scalability for high-order derivatives. The nested structure quickly consumes memory, making it challenging to compute derivatives of higher orders. In this study, we introduce DNAOAD, a Fortran-based implementation of automatic differentiation capable of handling derivatives of arbitrary order using dual numbers. This implementation employs a direct approach to represent dual numbers without relying on recursive or nested structures. As a result, DNAOAD facilitates the efficient computation of derivatives of very high orders while addressing the memory limitations of existing methods.
