Invariants are key to formal loop verification as they capture loop properties that are valid before and after each loop iteration. Yet, generating invariants is a notorious task already for syntactically restricted classes of loops. Rather than generating invariants for given loops, in this paper we synthesise loops that exhibit a predefined behaviour given by an invariant. From the perspective of formal loop verification, the synthesised loops are thus correct by design and no longer need to be verified. To overcome the hardness of reasoning with arbitrarily strong invariants, in this paper we construct simple (non-nested) while loops with linear updates that exhibit polynomial equality invariants. Rather than solving arbitrary polynomial equations, we consider loop properties defined by a single quadratic invariant in any number of variables. We present a procedure that, given a quadratic equation, decides whether a loop with affine updates satisfying this equation exists. Furthermore, if the answer is positive, the procedure synthesises a loop and ensures its variables achieve infinitely many different values.
翻译:不变性是形式化循环验证的关键,它们捕捉了每次循环迭代前后均成立的循环性质。然而,即使对于语法受限的循环类,生成不变性也是一项艰巨任务。本文不针对给定循环生成不变性,而是综合出具有由不变量定义的预设行为的循环。从形式化循环验证的角度来看,这样综合出的循环天生正确,无需再验证。为了克服使用任意强不变量进行推理的困难,本文构造了具有线性更新的简单(非嵌套)while循环,这些循环表现出多项式等式不变性。我们并非求解任意多项式方程,而是考虑由单个二次不变量定义的循环性质(变量个数不限)。我们提出一个过程:给定一个二次方程,该过程可判定是否存在满足该方程的仿射更新循环。进一步地,若答案为肯定,该过程将综合出一个循环并确保其变量能达到无穷多个不同值。