Staging higher-order automatic differentiation with fusion

Automatic differentiation (AD) is a family of algorithms that efficiently compute derivatives by interpreting or transforming the source code of numeric programs. Owing to its efficiency and accuracy, AD has many applications in scientific computing and machine learning. The correctness and efficiency of AD algorithms has been the subject of much research, in particular that of reverse-mode AD, which is most efficient for computing gradients of functions in many variables. The correctness of simpler reverse-mode AD algorithms has been studied, but the performance of these algorithms lags behind that of mainstream AD frameworks, which often rely on auxiliary data structures or non-obvious optimizations. The aim of this paper is to reduce this performance gap by relating elegant interpreter-based AD variants to compilers which generate efficient derivative code that resembles tape-based AD. Our approach builds further on the Nagata numbers reverse-mode AD algorithm due to van den Berg et al., reverse-engineering their algorithm in terms of established program transformation techniques from abstract algebra and functional programming. We transform the existing interpreter-based approach into an efficient code generator by means of staging with Template Haskell, leveraging a fold fusion variant for staged programs, and algebraic preservation maps to perform correct-by-construction binding time improvements. The approach is adapted to a tower-based AD approach to support higher order derivatives, and extended to support additional primitives and custom differential operators, providing a correct-by-construction code generator for higher-order AD. Benchmarks show that the resulting generated code achieves speedups compared to the reference implementation of 14.6x up to 2206x on first-order derivatives, and 18.9x up to 4.73 * 10^3x on higher-order derivatives.

Authors

Institutions

Publication Details

Journal
Zenodo (CERN European Organization for Nuclear Research)
Published
2026-12-02
DOI
https://doi.org/10.5281/zenodo.24682241
Primary Topic
Logic, programming, and type systems
Type
article
Field-Weighted Citation Impact
0.00
Controls
|||
ALL TIME
JAN
FEB
MAR
APR
MAY
JUN
JUL
AUG
SEP
OCT
NOV
article

Staging higher-order automatic differentiation with fusion

Tom Schrijvers, Samuel Klumpers
Zenodo (CERN European Organization for Nuclear Research)
Logic, programming, and type systems
article

Staging higher-order automatic differentiation with fusion

Tom Schrijvers, Samuel Klumpers
article en

Abstract

Automatic differentiation (AD) is a family of algorithms that efficiently compute derivatives by interpreting or transforming the source code of numeric programs. Owing to its efficiency and accuracy, AD has many applications in scientific computing and machine learning. The correctness and efficiency of AD algorithms has been the subject of much research, in particular that of reverse-mode AD, which is most efficient for computing gradients of functions in many variables. The correctness of simpler reverse-mode AD algorithms has been studied, but the performance of these algorithms lags behind that of mainstream AD frameworks, which often rely on auxiliary data structures or non-obvious optimizations. The aim of this paper is to reduce this performance gap by relating elegant interpreter-based AD variants to compilers which generate efficient derivative code that resembles tape-based AD. Our approach builds further on the Nagata numbers reverse-mode AD algorithm due to van den Berg et al., reverse-engineering their algorithm in terms of established program transformation techniques from abstract algebra and functional programming. We transform the existing interpreter-based approach into an efficient code generator by means of staging with Template Haskell, leveraging a fold fusion variant for staged programs, and algebraic preservation maps to perform correct-by-construction binding time improvements. The approach is adapted to a tower-based AD approach to support higher order derivatives, and extended to support additional primitives and custom differential operators, providing a correct-by-construction code generator for higher-order AD. Benchmarks show that the resulting generated code achieves speedups compared to the reference implementation of 14.6x up to 2206x on first-order derivatives, and 18.9x up to 4.73 * 10^3x on higher-order derivatives.

Zenodo (CERN European Organization for Nuclear Research)
KU Leuven (BE)
Logic, programming, and type systems
AI Navigator

Ask Laika to Summarize, Analyze, and Connect papers live on the map.

Summarize Papers & Methodologies

Extract key findings, datasets, and comparative methods across publications.

Benchmark Rankings & Visual Analytics

Rank top research institutions, authors, funders, topics, and journals by Field-Weighted Citation Impact (FWCI) and paper volume with instant charts.

Connect Distant Disciplines

Bridge topological clusters on the map to find hidden collaborative intersections.

Laika access coming soon