NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Approximations in Probabilistic Programs

Ekansh Sharma, Daniel M. RoyarXiv 2019

Abstract

We study a first-order probabilistic programming language (PPL) extended with a new language construct, $\mathbf{stat}$, which converts the description of an ergodic Markov chain's kernel into a sample from its unique stationary distribution. We demonstrate that standard Bayesian constructs, $\mathbf{norm}$ and $\mathbf{score}$, are eliminable from this extended language through an explicit program transformation implementing a Markov chain Monte Carlo (MCMC) algorithm. Furthermore, we address the problem of approximately implementing the semantics of this language—specifically when $\mathbf{stat}$ expressions are nested—using finite unrolling. Under uniform ergodicity assumptions, we provide the first quantitative error bounds and convergence results for these approximate implementations, showing that the total error decays exponentially with the number of MCMC iterations.

Introduction

In Bayesian modeling, Probabilistic Programming Languages (PPLs) allow researchers to specify complex models and automatically derive posterior distributions. However, a significant gap exists between the "ideal" mathematical semantics of these programs and their practical implementations. While the mathematical posterior is exact, computing it usually requires approximations like Markov Chain Monte Carlo (MCMC).

In "Approximations in Probabilistic Programs," Sharma and Roy tackle a fundamental challenge: how to formally reason about the errors introduced when ideal semantics are replaced by finite-step MCMC approximations. This is particularly difficult in the context of nested approximations, where the output of one MCMC process serves as the input or parameter for another.

The $\mathbf{stat}$ Construct and Eliminability

The authors introduce a new primitive to the first-order probabilistic language: $\mathbf{stat}(t_0, \lambda x.t_1)$. This construct takes an initial distribution ($t_0$) and a Markov kernel ($t_1$) and represents the unique stationary distribution of that chain.

A key theoretical contribution of the paper is the proof of eliminability. The authors show that standard PPL features like score (likelihood weighting) and norm (normalization) can be rewritten using only $\mathbf{stat}$ and sample. By viewing the Metropolis-Hastings algorithm as a formal program transformation, they demonstrate that $\mathbf{stat}$ is a sufficiently powerful primitive to capture the essence of Bayesian inference. This transformation is inspired by the "Trace-MH" algorithm but simplified to allow for rigorous formal analysis.

Approximate Compilation

Because we cannot practically sample from a stationary distribution in infinite time, the authors define an approximate compiler. This compiler replaces the ideal $\mathbf{stat}$ term with an $\text{Iterate}^N$ term, which runs the Markov chain for exactly $N$ steps.

To measure the discrepancy between the ideal program and its finite approximation, the authors utilize Total Variation (TV) distance. The central challenge is that if a Markov kernel is even slightly perturbed—as happens frequently in nested programs—the stationary distribution can change drastically or even vanish. To provide guarantees, the authors rely on the assumption of uniform ergodicity, a property where a Markov chain converges to its target at a geometric rate regardless of its starting point.

Key Results: Quantitative Error Bounds

The paper’s primary contribution is the derivation of formal error bounds for these approximations.

  • Theorem 5.3 (Eliminability): Confirms that $\mathbf{stat}$ is a sufficient primitive for Bayesian modeling, allowing for the construction of a full PPL using only sampling and stationary distributions.
  • Theorem 6.2 (Quantitative Error Bounds): This provides a formula for the total error of a program. For a program containing multiple (and potentially nested) $\mathbf{stat}$ terms, the total error is bounded by a sum of terms that decay exponentially as the number of iterations ($N_i$) increases.

Essentially, if the underlying Markov chains are well-behaved (uniformly ergodic), the error of the entire program—regardless of the complexity of nesting—decays exponentially as computation time increases. This provides a "safe zone" for composing probabilistic modules without the risk of exploding errors.

Limitations and Future Directions

As a theoretical work, these results rely on mathematical proofs rather than empirical benchmarks. The authors note several areas for future extension:

  1. Uniformity Assumption: Uniform ergodicity is a strong condition that may not hold for models with heavy tails or complex constraints. Relaxing this to "geometric ergodicity" remains an open problem.
  2. Language Scope: The current framework is limited to first-order languages. Extending these proofs to higher-order languages, where functions are first-class citizens, is a significant next step.
  3. Inference Sophistication: The current transformation uses a simple proposal kernel. Analyzing more advanced kernels within this formal framework could lead to tighter bounds for state-of-the-art PPL implementations.

Conclusion

By treating MCMC as a formal compiler pass, Sharma and Roy bridge the gap between the measure-theoretic ideals of probabilistic programming and the reality of finite computation. Their work provides a rigorous foundation for understanding how errors propagate in complex, nested Bayesian models, ensuring that as we increase our computational budget, our approximations converge predictably to the truth.

Summary updated

BibTeX
@misc{sharma2019approximations,
  author = {Ekansh Sharma and Daniel M. Roy},
  title = {{Approximations in Probabilistic Programs}},
  year = {2019},
  eprint = {1912.06791},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1912.06791},
}
Figure