ωPAP Spaces: Reasoning Denotationally About Higher-Order, Recursive Probabilistic and Differentiable Programs

Mathieu Huot, Alexander K. Lew, Vikash K. Mansinghka, Sam Staton

Abstract

Modern programming languages increasingly integrate higher-order functions, recursion, probabilistic sampling, and automatic differentiation (AD). However, providing a rigorous mathematical foundation—denotational semantics—for these features has proven difficult. This paper introduces ωPAP spaces, a framework based on piecewise analytic functions that provides a "just-right" domain for reasoning about such programs. By restricting program meanings to this space, the authors prove the correctness of AD in the presence of recursion and discontinuities, and establish that probabilistic programs possess well-behaved density functions suitable for inference.

Introduction

In computer science, denotational semantics assigns mathematical meanings to programs, allowing developers and researchers to reason about code behavior formally. For modern machine learning frameworks like PyTorch or probabilistic languages like Stan, this task is exceptionally challenging. These languages combine features that usually exist in tension: higher-order functions (functions as first-class data), general recursion, and non-smooth operations like if-then-else or ReLU.

Historically, finding a suitable function space for these programs has been a "Goldilocks" problem. If the space is too broad (e.g., all measurable functions), it includes pathological cases that prevent us from proving useful properties. If it is too narrow (e.g., smooth functions), it cannot represent the branching logic essential to real-world software. Presented at LICS 2023, this work introduces ωPAP spaces as a solution to this dilemma.

The ωPAP Framework

The foundation of this framework is the PAP function (Piecewise Analytic under analytic Partition). A PAP function is one that can be decomposed into pieces where each piece is defined by a convergent power series (analytic). This allows for the inclusion of common primitives like exp, log, and comparison operators while excluding "monsters" of real analysis like the Cantor function.

To support the full expressive power of modern languages, the authors extend PAP functions into ωPAP spaces using category theory (specifically, ω-concrete sheaves). This extension enables the model to handle:

  • Higher-order functions: Passing functions as arguments or returning them as results.
  • General recursion: Programs that may loop indefinitely or call themselves recursively.
  • Partiality: Using a "partiality monad" to account for programs that might diverge or crash.
  • Probability: Using a "measure monad" to handle random sampling and scoring (soft constraints).

Key Insights: Differentiation and Probability

Automatic Differentiation (AD) Correctness

Standard calculus often fails when applied to programs with "jumps" or discontinuities. The authors utilize intensional derivatives—a method of defining derivatives based on the program's structure rather than just its input-output mapping. They provide a denotational proof that AD correctly computes these derivatives even in complex, recursive, and branching code. This simplifies previous proofs that relied on more cumbersome operational "trace" reasoning.

The Density Problem in Probabilistic Programming

In probabilistic programming, we often need to compute a "density" for inference algorithms like Markov Chain Monte Carlo (MCMC). However, many programs—such as those defining a point on a line within a 3D space—have zero density under standard Lebesgue measures. The authors solve this by proving that every ωPAP program of type real^n denotes a distribution that is "absolutely continuous" with respect to s-Hausdorff measures. This provides a formal theoretical justification for density-based inference in highly expressive languages.

Randomization as a Safety Net

A significant result of this work is the formalization of why gradient descent works in practice despite non-smoothness. While AD might provide "incorrect" gradients at specific points (like the exact tip of a ReLU function), these points are mathematically rare. The authors prove a novel theorem (Theorem III.8) stating that if the initialization and learning rate are drawn from a continuous distribution, gradient descent using AD-computed gradients will converge to a stationary point with probability 1.

Conclusion and Future Work

ωPAP spaces offer a robust theoretical bridge between the high-level abstractions of modern programming and the rigorous requirements of real analysis. By excluding pathological functions while retaining the primitives used by programmers, the framework provides the first comprehensive denotational proof for the correctness of AD and density existence in recursive, higher-order settings.

Future research directions include extending the formal proof from forward-mode to reverse-mode AD (backpropagation), fully characterizing the class of density functions produced by ωPAP programs, and developing tools to automatically verify the differentiability of user-written code based on these mathematical principles.

Summary updated

BibTeX
@inproceedings{huot2023pap,
  author = {Mathieu Huot and Alexander K. Lew and Vikash K. Mansinghka and Sam Staton},
  title = {{ωPAP Spaces: Reasoning Denotationally About Higher-Order, Recursive Probabilistic and Differentiable Programs}},
  booktitle = {LICS},
  year = {2023},
  doi = {10.1109/lics56636.2023.10175739},
}
Figure