Compositional Expected Cost Analysis of Functional Probabilistic Programs

Pedro H. Azevedo de Amorim
2024-02-02
Abstract:Reasoning about resources used during the execution of programs, such as time, is one of the fundamental questions in computer science. When programming with probabilistic primitives, however, different samples may result in different resource usage, making the cost of a program not a single number but a distribution instead.
Programming Languages,Logic in Computer Science
What problem does this paper attempt to address?
The problem that this paper attempts to solve is: how to perform combined expected cost analysis in recursive probabilistic functional programs. Specifically, the paper focuses on the fact that when a program uses probabilistic primitives (such as random sampling), different samples may lead to different resource consumptions, so that the cost of the program is no longer a definite value but a distribution. Therefore, the traditional cost analysis methods for deterministic programs are no longer applicable, and new semantics and techniques need to be developed to handle the expected costs of such programs. ### Specific Background of the Problem 1. **Uncertainty of Resource Consumption**: - In computer science, reasoning about the resources (such as time) used during program execution is one of the fundamental problems. - When programming with probabilistic primitives, different samples may lead to different resource consumptions, making the cost of the program not a single value but a distribution. 2. **Importance of Expected Cost**: - Expected cost is an important indicator for measuring the efficiency of probabilistic programs. It quantifies the resource consumption of a program by averaging all possible execution paths. 3. **Limitations of Existing Work**: - Previous work has mainly focused on cost analysis of deterministic recursive functional programs, lacking systematic semantic research to extend these concepts to more expressive functional languages. - Existing probabilistic cost analysis methods are usually applicable to imperative or first - order languages, or rely on non - combinatorial methods and cannot handle higher - order functions and infinite recursion. ### Goals of the Paper The paper aims to provide a semantic basis for recursive probabilistic functional programs to reason about their expected costs. To this end, the author introduces a Call - By - Push - Value (CBPV) metalanguage called `cert` and defines two specific semantics for it: 1. **Cost Semantics**: - Combine the cost monad with the sub - probability monad using the familiar writer monad transformer to represent the cost distribution of the program. 2. **Expected Cost Semantics**: - Encapsulate the combinatorial structure of the expected cost as a monad, allowing us to give an interpretive semantics that keeps track of the expected cost of the program. ### Main Contributions - Define the `cert` language, including primitives for adding cost and sampling from a uniform distribution. - Define an equivalence theory for reasoning about the expected cost of programs. - Define cost semantics and expected cost semantics and prove that the latter is sound with respect to the former. - Verify the effectiveness of the expected cost semantics through application examples of two stochastic processes and two randomized algorithms. - Prove the soundness of the two semantics with respect to the equivalence theory. Through these works, the paper provides a solid theoretical basis and practical tools for the expected cost analysis of recursive probabilistic functional programs.