Almost-sure termination is an important correctness property for probabilistic programs, and a number of program logics have been developed for establishing it. However, these logics have mostly been developed for first-order programs written in languages with specific syntactic patterns for looping. In this paper, we consider almost-sure termination for higher-order probabilistic programs with general references. This combination of features allows for recursion and looping to be encoded through a variety of patterns. Therefore, rather than developing proof rules for reasoning about particular recursion patterns, we instead propose an approach based on proving refinement between a higher-order program and a simpler probabilistic model, in such a way that the refinement preserves termination behavior. By proving a refinement, almost-sure termination behavior of the program can then be established by analyzing the simpler model. We present this approach in the form of Caliper, a higher-order separation logic for proving termination-preserving refinements. Caliper uses probabilistic couplings to carry out relational reasoning between a program and a model. To handle the range of recursion patterns found in higher-order programs, Caliper uses guarded recursion, in particular the principle of Löb induction. A technical novelty is that Caliper does not require the use of transfinite step indexing or other technical restrictions found in prior work on guarded recursion for termination-preservation refinement. We demonstrate the flexibility of this approach by proving almost-sure termination of several examples, including first-order loop constructs, a random list generator, treaps, and a sampler for Galton-Watson trees that uses higher-order store. All the results have been mechanized in the Coq proof assistant.
Modular Verification for Almost-Sure Termination of Probabilistic Programs
在这项工作中,我们考虑几乎肯定终止问题的概率程序,询问是否一个给定的概率程序终止概率为1。可伸缩的程序分析方法通常依赖于模块化作为其理论基础。在非概率程序中,Floyd-霍尔逻辑的经典变式规则(V-规则)为模块化分析提供了基础。将该规则扩展到概率程序的几乎确定终止是相当棘手的,并且在[Fioriti and Hermanns 2015]中提出了一个概率变体。虽然所提出的概率变量谨慎地解决了可积性的关键问题,我们表明,所提出的模块化规则仍然是不健全的几乎肯定终止的概率程序。除了建立以前的规则的不健全,我们的贡献如下:首先,我们提出了一个健全的模块规则几乎确定终止的概率程序。我们的方法是基于一个新的概念下降上鞅。其次,对于算法方法,我们考虑下降上鞅是线性的,并表明它们可以在多项式时间合成。最后,我们提出了各种基准测试和几个自然的例子,模拟各种类型的嵌套而循环的概率程序的实验结果,并证明我们的方法是能够有效地证明其几乎肯定的终止属性。