Introduction
Probabilistic programs are increasingly prevalent in domains ranging from randomized algorithms to cyber-physical systems. Verifying the behavior of these programs is critical, yet challenging due to their inherent randomness. Traditionally, static analysis has focused on deriving raw expectations—the average cost or value a program produces. However, expectations alone provide a limited view of a program's behavior. To provide safety guarantees, developers often need to know the "tail bounds": the probability that a program's cost exceeds a specific threshold.
This paper, originally presented at PLDI '21, introduces a novel framework for automatically deriving symbolic interval bounds on higher central moments (such as variance, skewness, and kurtosis). By capturing the "shape" of a distribution rather than just its average, this approach enables significantly tighter tail bounds than previously possible.
The Challenge: Beyond Expectations
Existing methods typically rely on Markov’s inequality, which uses the first raw moment (the expectation $E[X]$) to bound the probability of extreme events. While sound, these bounds are often very loose. For instance, if the expected cost is $2d$, Markov’s inequality can only tell us that the probability of the cost exceeding $4d$ is at most $1/2$.
To achieve sharper bounds, one must use higher-order central moments and more powerful concentration inequalities, such as Cantelli’s inequality (which uses variance). However, central moments are mathematically difficult to analyze statically. Because variance involves subtraction ($E[(X - E[X])^2]$), a static analyzer cannot simply track upper bounds. To bound the variance from above, the analyzer must simultaneously maintain both upper and lower bounds (an interval) for all underlying raw moments. This dual-bound requirement adds significant complexity to the analysis.
Technical Innovations
The authors overcome these challenges through several key innovations:
- Moment Semirings: They developed an algebraic structure that allows the analysis to compose and "lift" traditional expectation analysis to higher-order moments across program statements.
- Moment-Polymorphic Recursion: Analyzing recursive functions is notoriously difficult because the cost of a function call depends on its symbolic context. The authors introduced a "frame rule" that allows the analysis to decompose complex post-conditions, making recursive calls tractable and modular.
- Template-Based Linear Programming (LP): Instead of using computationally expensive Semidefinite Programming (SDP), the tool uses polynomial templates to represent bounds and reduces the optimization problem to Linear Programming. This choice makes the tool significantly faster and more scalable.
- Soundness via Optional Stopping: To ensure mathematical validity for programs that terminate "almost surely" (but not necessarily in every possible execution), the framework utilizes a recent extension of the Optional Stopping Theorem.
Evaluation and Key Results
The tool was evaluated against a comprehensive suite of benchmarks, including standard sets from prior tools and large-scale synthetic programs.
In a classic random-walk benchmark, the advantages of central moment analysis are clear. While traditional raw-moment methods suggested a tail probability of approximately $1/2$ or $1/4$, the new analysis proved that the probability actually approaches $0$ as the threshold increases.
Beyond precision, the tool demonstrated remarkable scalability. It successfully analyzed synthetic benchmarks containing up to 1,000 recursive functions (nearly 16,000 lines of code) in under 10 seconds, with analysis time growing linearly with program size. The authors also applied the tool to a security case study: a password-checker program designed to thwart timing attacks with random delays. The analysis successfully quantified the attacker's success rate, proving that the added noise was insufficient to hide the timing leak.
Conclusion
By moving from raw expectations to higher central moments, this work provides a powerful new tool for the formal verification of probabilistic systems. The combination of interval-based analysis, efficient LP-based optimization, and support for complex features like recursion sets a new state-of-the-art for automated tail bound derivation. Future work aims to extend these techniques to more complex data structures and higher-order functional programming patterns.
Summary updated