Automatic Certified Differentiation in Lean
Ramy Shahin
Key points
From the paper's conclusion- We also utilize Lean metaprogramming to manipulate the symbolic structure of the input function, and to construct the derivative function.
Abstract
Automatic differentiation (the automatic computation of numerical function derivatives) has many applications, especially in scientific computing and machine learning. Several approaches to automate the calculation of derivatives have been presented. Common challenges facing those approaches include (1) having to define derivative rules for different classes of functions, (2) having to manipulate program symbols to understand the semantics of the function being differentiated, and construct the derivative function, and (3), more importantly, ensuring that the calculated derivative is correct. In this paper, we present an approach for automatic \emph{certified} differentiation using the Lean proof assistant. By certified, we mean a correctness certificate is computed together with the derivative function and a domain on which the derivative is guaranteed to be valid. Our approach leverages existing derivative theorems included in the Mathlib Lean library instead of having to define our own rules. We also utilize Lean metaprogramming to manipulate the symbolic structure of the input function, and to construct the derivative function. The correctness certificate is computed step-wise as we apply Mathlib theorems. To make the search efficient, we index the derivative theorems by the function they differentiate. We evaluate our approach on 500 randomly generated functions: with the index, all of them are differentiated, with a median time of 0.18\,s per function, 8.6 times faster than without the index.
Read the paper
Discussion
Science Skim's AI key points, plus readers' public thoughts
Readers' thoughts
No reader thoughts yet.
Related papers
- LeanDojo-v2: A Comprehensive Library for AI-Assisted Theorem Proving in LeanarXiv · 2026
- Proving LLM-Generated GPU Kernels Correct and Safe: Floating-Point Verification in Lean and VerCorsarXiv · 2026
- Handling JAXarXiv · 2026
- Beyond LLM Judge: Mechanical Verification for Agentic AutoformalizationarXiv · 2026
- PastaLean: Deterministic transpilation from Python to Lean for VerificationarXiv · 2026
- Lea: An Agent Backbone for Mathematician-Controlled Formalization in LeanarXiv · 2026