Universal Semantics for the Stochastic Lambda-Calculus

Pedro H. Azevedo de Amorim, Dexter Kozen, Radu Mardare, Prakash Panangaden, Michael Roberts

Probabilistic programming has emerged as a powerful paradigm for modeling uncertainty, yet its theoretical foundations—particularly for higher-order functional languages like the $\lambda$-calculus—have long faced a significant hurdle: the gap between abstract mathematical models and the step-by-step execution of programs. This paper introduces the first sound and adequate semantics for the stochastic $\lambda$-calculus that supports unrestricted $\beta$-reduction, providing a robust bridge between theory and practice.

The Challenge: Static vs. Dynamic Scoping of Randomness

A central difficulty in probabilistic semantics is managing the "source of randomness." In earlier influential models, such as those by Bacci et al. (2018), random variables were "packaged" with functions at the time of their definition—a form of static scoping. While mathematically elegant in certain contexts, this approach made standard $\beta$-reduction (the core mechanism of function application) unsound.

If a random argument is passed to a function that uses it multiple times, static scoping might lead to the "reuse" of the same random coin flip. This violates the fundamental requirement of probabilistic independence. Consequently, these earlier models lacked a proven "operational semantics" (how a program runs) that matched their "denotational semantics" (what a program mathematically represents).

Formalizing the Solution: Scottifying the Cantor Space

To resolve these issues, the authors propose a shift to dynamic scoping of randomness. In this model, random coins are supplied at function call time rather than definition time. This ensures that every probabilistic decision consumes a fresh, independent source of randomness.

To handle the infinite sequences of coin flips ($2^\omega$) required for non-terminating or complex probabilistic programs, the authors utilize domain theory. They embed the Cantor space of infinite bitstreams into a Scott domain ($2^{\le \omega}$), which includes finite prefixes. This "Scottification" allows them to prove that any computation that halts only ever depends on a finite prefix of the infinite random bitstream.

Commutative diagrams illustrating the extension of functions on infinite bitstreams to the Scott domain.

As shown in the diagrams above, functions defined on the Cantor space ($2^\omega$) are extended to the Scott domain ($2^{\le \omega}$). This formalization ensures that the semantics remain continuous and computable, providing a rigorous foundation for the stochastic model.

Key Theoretical Innovations

The paper introduces several novel formalisms to achieve a "universal" semantics:

  • The Linearity of Randomness: The authors treat randomness as a linear resource. You cannot "copy" a random bitstream; you must "consume" it. During function application, the infinite bitstream is split into three disjoint subsequences—one for the function, one for the argument, and one for the application itself—maintaining strict probabilistic independence.
  • Capsules: To represent infinite, recursive behavior without complex fixpoint constructors, the authors use capsules (pairs of terms and environments). This co-algebraic representation simplifies the handling of recursion.
  • Tree Processes: These are used to characterize how different execution styles (big-step vs. small-step) consume coins. This allows the authors to prove that even if two execution methods use coins in different patterns, they remain statistically equivalent.

Main Results: Soundness and Adequacy

The crowning achievement of this work is the proof of Soundness and Adequacy (Theorem 18). This theorem establishes that the mathematical denotational model and the operational execution rules are perfectly synchronized. If the mathematical model predicts a certain probability for a program's outcome, the execution rules are guaranteed to yield exactly that result.

Furthermore, the authors demonstrate the equivalence of "big-step" (evaluating a whole term) and "small-step" (evaluating bit-by-bit) rules. This equivalence is vital for practical applications, such as building reliable compilers and debuggers for probabilistic languages.

Future Directions

While this work provides a solid foundation for discrete probabilistic choice, several avenues for future research remain. The current calculus focuses on binary choices ($\oplus$), though the authors suggest the framework could be extended to continuous distributions (the Reals, $\mathbb{R}$). Additionally, the model does not yet explicitly handle "soft conditioning" (e.g., observe statements), which is essential for Bayesian inference. Integrating these features while maintaining the sound domain-theoretic foundations established here will be a key focus for the next generation of probabilistic programming research.

Summary updated

BibTeX
@inproceedings{amorim2021universal,
  author = {Pedro H. Azevedo de Amorim and Dexter Kozen and Radu Mardare and Prakash Panangaden and Michael Roberts},
  title = {{Universal Semantics for the Stochastic Lambda-Calculus}},
  booktitle = {LICS},
  year = {2021},
  doi = {10.1109/lics52264.2021.9470747},
}
Figure