CoreDPPL: Towards a Sound Composition of Differentiation, ODE Solving, and Probabilistic Programming

Oscar Eriksson, Anders Ågren Thuné, Johannes Borgström, David BromanarXiv 2025 · DOI · arXiv

Introduction

In modern scientific computing, researchers frequently combine three powerful paradigms: Probabilistic Programming (PPL) for Bayesian inference, Differentiable Programming for optimization via automatic differentiation (AD), and Ordinary Differential Equation (ODE) solvers for physical modeling. However, composing these tools is mathematically hazardous. For instance, differentiating a function with random branching is often ill-defined, and ODE solutions require specific continuity properties that random effects can easily violate. CoreDPPL addresses this by providing a formal, unified foundation that guarantees these compositions are mathematically sound.

The CoreDPPL Framework

CoreDPPL is a higher-order calculus that introduces a novel type system to track both randomness and differentiability. The system employs effects to distinguish between deterministic (Det) and random (Rnd) computations. More uniquely, it uses coeffects to track differentiability levels for real numbers:

  • A (Analytic): Represents smooth functions.
  • P (Piecewise Analytic): Handles functions with "kinks," such as abs or if statements.
  • N (Non-differentiable): Used for functions that cannot be differentiated, like realizations of a Wiener process.
Interactions between differentiation, ODE solving, and probabilistic inference in CoreDPPL.

Methods and Formalization

The authors defined a small-step operational semantics to explicitly manage the interactions between infer (probabilistic inference), diff (differentiation), and solve (ODE integration). To ensure the logic is robust, the entire type system and its safety proofs—specifically Progress and Preservation—were mechanized and proven in the Agda proof assistant. A prototype was implemented by extending Miking CorePPL, a compiler for universal probabilistic programming.

Case Studies and Results

The language's expressiveness was evaluated through three complex case studies:

  1. ODE Sensitivities: Computing how ODE solutions change with parameters.
  2. Random ODEs (RODEs): Modeling systems driven by continuous but non-differentiable noise.
  3. Bayesian Parameter Estimation: Using the Lotka-Volterra model to estimate biological growth rates from noisy data.
Code example for Bayesian parameter estimation and resulting posterior distribution of sensitivities.

A key result is the "Deterministic Guarantee": a theorem proving that "deterministically typed" terms are independent of random seeds and weights. This ensures that derivatives calculated during optimization are not corrupted by the stochastic nature of the inference engine. The implementation successfully handled the Lotka-Volterra "stress test," producing posterior distributions for sensitivities that matched theoretical expectations.

Conclusion and Future Work

CoreDPPL represents a significant step toward bringing higher-order PPLs, first-class AD, and ODE primitives into a single, sound mathematical framework. While currently focused on forward-mode AD and ODEs, future work aims to extend the system to Differential-Algebraic Equations (DAEs), implement reverse-mode AD, and automate differentiability type inference to reduce the need for manual annotations.

Summary updated

Abstract

In recent years, there has been extensive research on how to extend general-purpose programming language semantics with domain-specific modeling constructs. Two areas of particular interest are (i) universal probabilistic programming where Bayesian probabilistic models are encoded as programs, and (ii) differentiable programming where differentiation operators are first class or differential equations are part of the language semantics. These kinds of languages and their language constructs are usually studied separately or composed in restrictive ways. In this paper, we study and formalize the combination of probabilistic programming constructs, first-class differentiation, and ordinary differential equations in a higher-order setting. We propose formal semantics for a core of such differentiable probabilistic programming language (DPPL), where the type system tracks random computations and rejects unsafe compositions during type checking. The semantics and its type system are formalized, mechanized, and proven sound in Agda with respect to abstract language constructs.
BibTeX
@misc{eriksson2025coredppl,
  author = {Oscar Eriksson and Anders Ågren Thuné and Johannes Borgström and David Broman},
  title = {{CoreDPPL: Towards a Sound Composition of Differentiation, ODE Solving, and Probabilistic Programming}},
  year = {2025},
  eprint = {2503.13970},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2503.13970},
}
Figure