Weakest preconditions are a useful notion for program verification as they reduce a problem of program verification to a problem of constraint solving. Category-theoretic generalisations of weakest preconditions have been studied to capture various computational effects and various properties in a unified framework. In this paper, we propose a novel and general relationship between weakest precondition transformers and CPS transformations for higher-order functional languages with general computational effects and recursion. Technically, this gives a syntactic counterpart of the categorically-defined generic weakest precondition transformer in [Aguirre & Katsumata, 2020]. The usefulness of our results is threefold. (1) Since CPS transformations purify effectful programs, various verification problems for effectful programs can be reduced to verification problems for pure programs. This syntactic reduction makes it easier to solve the verification problems and potentially facilitates combinations with other sophisticated verification methods tailored for pure programs. (2) We capture two existing verification methods, namely, verification of event sequences [Kobayashi et al., 2018] and expected cost [Avanzini et al., 2021] as instances of our framework. (3) Our results streamline the process of extending weakest precondition transformers for imperative programs to those for higher-order programs. We show two such extensions: analysis of higher moments of cost and the conditional weakest pre-expectation for higher-order probabilistic programs. These extensions demonstrate that our theoretical framework can produce novel verification methods.
RWTH Aachen University(亚琛工业大学);Saarland University(萨尔大学);University College London(伦敦大学学院)
我们研究加权规划,指定数学模型的编程范式。更具体地说,我们研究的加权程序就像通常的命令式程序一样,具有两个额外的功能:(1)不确定性分支和(2)加权执行轨迹。权重可以是数字,也可以是其他对象,如字母表中的单词、多项式、形式幂级数或基数。我们认为,加权规划作为一种范式,可以用来指定数学模型超越概率分布(如概率规划)。我们开发了最弱的预条件和最弱的自由预条件风格的演算à la Dijkstra,用于推理加权程序指定的数学模型。我们提出了几个案例研究。例如,我们使用加权规划来模拟滑雪租赁问题-一个优化问题。我们不仅模型的优化问题本身,而且最好的确定性在线算法解决这个问题的加权程序。通过最弱前提式推理,可以在源代码级确定在线算法的竞争比。