Paperlane

no. 21 · Tuesday 24 November 2026

Extracting Exact Lie Derivatives Without Backpropagation: A Dual Compiler for Neural Control Barrier Functions

Mohammadreza Kamaldar

math.DS · v5

Abstract

A safety filter based on a neural control barrier function (CBF) evaluates, at each control cycle, the trained network and its Lie derivatives along the system vector fields. This paper presents a compiler whose emitted C++ code performs this evaluation on embedded processors by forward-mode differentiation with dual numbers. The derivatives are exact in the sense of automatic differentiation, which means that they are free of truncation error and subject to floating-point roundoff. One evaluation of the network in this arithmetic, called a dual pass, returns the barrier value and its Lie derivative along one vector field, and an extension to hyper-dual numbers returns the second-order Lie derivatives of CBFs of relative degree two. Apart from scalar variables, the memory that a dual pass writes is at most four floating-point numbers per neuron of the widest layer and does not depend on the network depth. On an ESP32-S3 microcontroller, we compare the emitted code with code for reverse-mode differentiation (i.e., backpropagation), which is also generated before the program runs and uses fixed-size arrays. In three experiments, the reverse-mode code has a lower execution time than the dual and hyper-dual passes executed one after the other. For single-input networks, the measurements do not establish such an ordering between the reverse-mode code and a variant of the dual pass that propagates the real part once. For networks of increasing depth, the working memory of the dual passes is constant, whereas that of the reverse-mode code increases. While the emitted code runs, no dynamic allocation is recorded. We report the maximum observed execution time of the complete filter step, which includes the dynamics and a breakpoint search for the quadratic program with input bounds and one affine constraint. The compiler and the experiments are open source.

fields
Dynamical Systems, Rings and Algebras