Template-based Program Synthesis using Stellensätze 基于模板的程序合成方法——使用 Stellensätze
AMIR KAFSHDAR GOHARSHADY*, Hong Kong University of Science and Technology, Hong Kong AMIR KAFSHDAR GOHARSHADY*,香港科技大学,香港S. HITARTH, Hong Kong University of Science and Technology, Hong Kong S. HITARTH,香港科技大学,香港FATEMEH MOHAMMADI, KU Leuven, Belgium FATEMEH MOHAMMADI,比利时鲁汶大学HARSHIT JITENDRA MOTWANI, Ghent University, Belgium HARSHIT JITENDRA MOTWANI,比利时根特大学
Abstract 摘要
Template-based synthesis, also known as sketching, is a localized approach to program synthesis in which the programmer provides not only a specification, but also a high-level “sketch” of the program. The sketch is basically a partial program that models the general intuition of the programmer, while leaving the low-level details as unimplemented “holes”. The role of the synthesis engine is then to fill in these holes such that the completed program satisfies the desired specification. In this work, we focus on template-based synthesis of polynomial imperative programs with real variables, i.e. imperative programs in which all expressions appearing in assignments, conditions and guards are polynomials over program variables. While this problem can be solved in a sound and complete manner by a reduction to the first-order theory of the reals, the resulting formulas will contain a quantifier alternation and are extremely hard for modern SMT solvers, even when considering toy programs with a handful of lines. Moreover, the classical algorithms for quantifier elimination are notoriously unscalable and not at all applicable to this use-case. 基于模板的合成,也称为草图合成,是一种局部化的程序合成方法,程序员不仅提供规范,还提供程序的高级“草图”。草图基本上是一个部分程序,体现了程序员的总体直觉,同时将低级细节留作未实现的“空洞”。合成引擎的作用就是填补这些空洞,使得完整的程序满足所需的规范。在本工作中,我们专注于具有实变量的多项式命令式程序的基于模板的合成,即所有出现在赋值、条件和守卫中的表达式都是程序变量上的多项式的命令式程序。虽然该问题可以通过归约到实数的一阶理论以一种健全且完备的方式解决,但所得公式将包含量词交替,对于现代 SMT 求解器来说极其困难,即使是考虑只有几行代码的简单程序也是如此。此外,经典的量词消除算法众所周知难以扩展,完全不适用于此用例。
In contrast, our main contribution is an algorithm, based on several well-known theorems in polyhedral and real algebraic geometry, namely Putinar’s Positivstellensatz, the Real Nullstellensatz, Handelman’s Theorem and Farkas’ Lemma, which sidesteps the quantifier elimination difficulty and reduces the problem directly to Quadratic Programming (QP). Alternatively, one can view our algorithm as an efficient way of eliminating quantifiers in the particular formulas that appear in the synthesis problem. The resulting QP instances can then be handled quite easily by SMT solvers. Notably, our reduction to QP is sound and semi-complete, i.e. it is complete if polynomials of a sufficiently high degree are used in the templates. Thus, we provide the first method for sketching-based synthesis of polynomial programs that does not sacrifice completeness, while being scalable enough to handle meaningful programs. Finally, we provide experimental results over a variety of examples from the literature. 相比之下,我们的主要贡献是一种算法,该算法基于多面体和实代数几何中的几个著名定理,即 Putinar 的 Positivstellensatz、实 Nullstellensatz、Handelman 定理和 Farkas 引理,绕过了量词消除的难题,直接将问题简化为二次规划(QP)。或者,可以将我们的算法视为一种高效的量词消除方法,专门针对合成问题中出现的特定公式。生成的 QP 实例随后可以被 SMT 求解器轻松处理。值得注意的是,我们的 QP 简化是正确且半完备的,即如果模板中使用了足够高次数的多项式,则该方法是完备的。因此,我们提供了首个基于草图的多项式程序合成方法,该方法在不牺牲完备性的前提下,具备处理实际程序的可扩展性。最后,我们还提供了来自文献中各种示例的实验结果。
Additional Key Words and Phrases: program synthesis, sketching, syntax-guided synthesis 附加关键词和短语:程序合成,草图,语法引导合成
1 INTRODUCTION 1 引言
Program Synthesis. Program synthesis is one of the most central research topics not only in the programming languages and verification communities, but in computer science as a whole [Pnueli and Rosner 1989]. It is often called the holy grail of computing [Gulwani et al. 2017]. Generally speaking, the goal in program synthesis is to automate the process of programming, i.e. given a specification, which is often a logical formula, automatically find a program (in a predefined language) that satisfies the specification. 程序合成。程序合成不仅是编程语言和验证领域的核心研究课题之一,也是整个计算机科学中的重要研究方向 [Pnueli 和 Rosner 1989]。它常被称为计算领域的圣杯 [Gulwani 等 2017]。一般来说,程序合成的目标是实现编程过程的自动化,即给定一个规范(通常是逻辑公式),自动找到一个满足该规范的程序(在预定义的语言中)。
Short History. Various formulations of this problem have been studied since the 1950s (e.g. see [Church 1963] which was originally published in 1957). Similar problems were also considered in the context of constructive mathematics as far back as the 1930s [Kolmogoroff 1932; Troelstra 1977]. 简短历史。自 20 世纪 50 年代以来,人们对这一问题的各种形式进行了研究(例如参见 [Church 1963],该文最初发表于 1957 年)。类似的问题也曾在构造数学的背景下被探讨,早至 20 世纪 30 年代 [Kolmogoroff 1932;Troelstra 1977]。
Today, there is a rich body of literature that uses widely different techniques for synthesis. Some notable approaches to program synthesis include deductive synthesis using theorem provers [Green 1981; Manna and Waldinger 1971], counterexample-guided synthesis [Abate et al. 2018; Preiner et al. 2017; Reynolds et al. 2015], evolutionary algorithms [Koza 1994; Krawiec 2016; Sobania et al. 2022], sketching/syntax-guided [Alur et al. 2013; Fedyukovich et al. 2019; Si et al. 2018; Solar-Lezama 2008, 2009], template-based/search-based [Alur et al. 2018; Srivastava et al. 2013], proof-theoretic methods [Srivastava et al. 2010], constraint-solving [Gulwani et al. 2011; Polikarpova et al. 2016], type-guided [Guo et al. 2019; Polikarpova et al. 2016], resource-guided [Knoth et al. 2019], and synthesis based on examples (input-output pairs) [Gulwani 2011; Gulwani et al. 2012; Shaw et al. 1975; Smith 1975]. This is by no means a comprehensive list and there is no way we can do justice to all the work in this area. Moreover, most approaches, including ours, utilize more than one of the paradigms named above. Therefore, we refer to [Gulwani et al. 2017] for a more detailed discussion. 如今,已有大量文献采用各种不同的技术进行程序合成。一些著名的程序合成方法包括使用定理证明器的演绎合成[Green 1981;Manna 和 Waldinger 1971]、基于反例引导的合成[Abate 等 2018;Preiner 等 2017;Reynolds 等 2015]、进化算法[Koza 1994;Krawiec 2016;Sobania 等 2022]、草图/语法引导合成[Alur 等 2013;Fedyukovich 等 2019;Si 等 2018;Solar-Lezama 2008,2009]、基于模板/搜索的合成[Alur 等 2018;Srivastava 等 2013]、证明理论方法[Srivastava 等 2010]、约束求解[Gulwani 等 2011;Polikarpova 等 2016]、类型引导[Guo 等 2019;Polikarpova 等 2016]、资源引导[Knoth 等 2019]以及基于示例(输入-输出对)的合成[Gulwani 2011;Gulwani 等 2012;Shaw 等 1975;Smith 1975]。这绝非详尽无遗的列表,我们也无法全面涵盖该领域的所有工作。此外,大多数方法,包括我们的方法,都结合了上述多种范式。因此,关于更详细的讨论,我们推荐参考[Gulwani 等 2017]。
Search-based/Syntax-guided Synthesis. While the initial classical formulations of program synthesis focused on automated generation of the whole program, given only a specification as a logical/semantic-based formula, it was later realized that scaling this approach is quite challenging and much efficiency can be gained by allowing the programmer to also provide syntactic templates that limit the search space of possible implementations [Alur et al. 2018]. Intuitively speaking, this would let the programmer focus on the high-level ideas behind the program, while relying on the synthesis engine to fill in the low-level details. 基于搜索/语法引导的综合。虽然程序综合的最初经典定义侧重于仅给定作为逻辑/语义公式的规范,自动生成整个程序,但后来人们意识到这种方法的扩展性相当具有挑战性,通过允许程序员提供限制可能实现搜索空间的语法模板,可以大大提高效率[Alur 等,2018]。直观地说,这让程序员能够专注于程序背后的高层思想,同时依赖综合引擎来填充低层细节。
Various formalizations of similar ideas have appeared in the literature. For example, in [Alur et al. 2013], the programmer has to specify a background theory, a correctness specification, which is semantic in nature, and a grammar which is used to syntactically limit the search space of possible implementations. In sketching [Solar-Lezama 2008], the programmer provides the highlevel structure or “sketch” of the implementation, while leaving low-level “holes” for the synthesis engine to fill. In template-based approaches, such as [Srivastava et al. 2013], the programmer additionally provides a template for each hole, e.g. specifying that the hole should be filled by a linear/affine expression or that it should likely utilize a specific set of variables. These approaches have all led to highly successful synthesis engines. In particular, the SyGuS competition [Alur et al. 2019] is a great showcase of the remarkable year-on-year progress in program synthesis. 文献中出现了各种类似思想的形式化表达。例如,在[Alur et al. 2013]中,程序员需要指定一个背景理论、一个语义性质的正确性规范,以及一个用于语法上限制可能实现搜索空间的语法。在草图编程[Solar-Lezama 2008]中,程序员提供实现的高级结构或“草图”,同时留下低级“空洞”供合成引擎填充。在基于模板的方法中,如[Srivastava et al. 2013],程序员还为每个空洞提供一个模板,例如指定该空洞应由线性/仿射表达式填充,或可能利用特定变量集。这些方法都催生了高度成功的合成引擎。特别是,SyGuS 竞赛[Alur et al. 2019]很好地展示了程序合成领域年复一年的显著进展。
Completeness. Given that most variants of program synthesis are undecidable, often due to Rice’s theorem [Rice 1953], it is no surprise that the synthesis algorithms cannot be sound, complete and terminating at the same time. The undecidability also applies to almost all cases of syntax-guided synthesis, since they are more expressive than the verification of specific non-trivial semantic properties. As such, most synthesis engines, including the ones mentioned above, choose to sacrifice completeness and focus on efficient sound algorithms that can handle a wide variety of real-world use-cases. Completeness can only be achieved in limited circumstances, such as template-based synthesis of linear/affine programs with linear/affine invariants [Srivastava et al. 2013]. So, a natural question is to explore and characterize families of programs for which we can find efficient, sound and complete synthesis procedures. Of course, the difficulty lies in obtaining all three desired properties at the same time and not compromising on any of them. 完备性。鉴于大多数程序合成的变体是不可判定的,这通常是由于赖斯定理(Rice’s theorem)[Rice 1953]所致,因此合成算法无法同时具备健全性、完备性和终止性也就不足为奇了。不可判定性同样适用于几乎所有语法引导合成的情况,因为它们比验证特定非平凡语义属性更具表达力。因此,大多数合成引擎,包括上述提到的那些,选择牺牲完备性,专注于能够处理各种现实应用场景的高效健全算法。完备性只能在有限的情况下实现,例如基于模板的线性/仿射程序合成及其线性/仿射不变式[Srivastava et al. 2013]。因此,一个自然的问题是探索并刻画那些可以找到高效、健全且完备的合成过程的程序族。当然,难点在于如何同时获得这三种期望的性质,而不在任何一方面妥协。
Our Setting. In this work, we consider template-based synthesis over polynomial programs, i.e. imperative programs with bounded real variables in which all expressions appearing in the assignments, loop guards, conditionals, and invariants (pre and post-conditions) are polynomials over program variables. See Section 2 for a more formal statement. Following the sketching/templatebased approach, we assume that the programmer provides a sketch of the program, together with one or more holes. The holes can appear both in the program itself or in the invariants and will be filled by polynomial expressions. The programmer can also provide a template for how each hole should be filled by specifying the program variables that can appear in the hole and the 我们的设定。在本工作中,我们考虑基于模板的多项式程序合成,即具有有界实变量的命令式程序,其中赋值、循环守卫、条件语句和不变式(前置条件和后置条件)中出现的所有表达式均为程序变量上的多项式。更正式的描述见第 2 节。遵循草图/基于模板的方法,我们假设程序员提供程序的草图以及一个或多个空洞。空洞可以出现在程序本身或不变式中,并将由多项式表达式填充。程序员还可以为每个空洞提供一个模板,指定可以出现在空洞中的程序变量以及
Proc. ACM Program. Lang., Vol. 1, No. CONF, Article 1. Publication date: January 2018.
Fig. 1. An example polynomial program with holes. 图 1. 一个带有空洞的多项式程序示例。
expected degree of the polynomial expression used for filling it. Note that this is without any loss of generality, since, in the absence of such information, our algorithm can simply iterate over all possible templates with a bounded degree. 用于填充空洞的多项式表达式的预期次数。注意,这并不损失一般性,因为在没有此类信息的情况下,我们的算法可以简单地遍历所有具有有界次数的可能模板。
Example 1.1. As a simple example, consider the program in Figure 1, in which we have three bounded real variables i,si, s, and nn. The programmer has given us a sketch of the program, which includes the desired specification as a precondition and a postcondition. However, it also includes holes that should be filled by the synthesis engine. These holes are shown by dashed boxes. In this case, the programmer asks us to synthesize an invariant and a guard for the while loop, as well as an expression for the right-hand side of the assignment inside the while loop. Moreover, she has provided us with a template for each hole, specifying the variables that she expects would need to appear in that hole and the maximum degree of the polynomial that should be synthesized for filling the hole. For example, the while guard must be an affine (degree 1) polynomial over the variables ii and nn. As we will see in the sequel, given this partial program as input, our approach is able to synthesize the completed program in Figure 2, which basically sums up all the integers from 1 to |__ n __|\lfloor n\rfloor. 示例 1.1. 作为一个简单的例子,考虑图 1 中的程序,其中我们有三个有界实数变量 i,si, s 和 nn 。程序员给出了程序的草图,其中包括作为前置条件和后置条件的期望规范。然而,草图中也包含了应由合成引擎填充的空洞。这些空洞用虚线框表示。在本例中,程序员要求我们合成一个不变式和 while 循环的守卫条件,以及 while 循环内部赋值右侧的表达式。此外,她为每个空洞提供了一个模板,指定了她期望出现在该空洞中的变量以及用于填充空洞的多项式的最大次数。例如,while 循环的守卫必须是变量 ii 和 nn 上的仿射(一次)多项式。正如我们接下来将看到的,给定这个部分程序作为输入,我们的方法能够合成出图 2 中的完整程序,该程序基本上是对从 1 到 |__ n __|\lfloor n\rfloor 的所有整数求和。
@real: \(i, s, n\);
@pre: \(n \geq 1\);
\(i=0\);
\(s=0\);
@invariant: \(s \geq i \cdot(i+1) / 2 \wedge s \leq i \cdot(i+1) / 2 \wedge i \leq n\)
while \((i \leq n-1)\)
\{
\(i=i+1\);
\(s=s+i\);
\}
@post: \((n-1) \cdot n / 2 \leq s \leq n \cdot(n+1) / 2\);
Fig. 2. The synthesized (completed) version of the partial program in Figure 1. 图 2. 图 1 中部分程序的合成(完整)版本。
Decidability and Hardness. Note that the synthesis problem we consider here can be reduced, in polynomial time, to the decision problem of a formula in the first-order theory of the reals and is hence decidable. See Section 4 for more details. However, the resulting formula is quite long and has a quantifier alternation. Thus, it is beyond the reach of modern SMT solvers and quantifier elimination methods, even for toy programs with three lines of code. In the same section, we also show that the problem is (strongly) NP-hard, so no strictly PTIME algorithms can be expected unless P=NP\mathrm{P}=\mathrm{NP}. The NP-hardness holds even in the special case of linear/affine programs. 可判定性与难度。注意,我们这里考虑的综合问题可以在多项式时间内归约为实数一阶理论中公式的判定问题,因此是可判定的。详见第 4 节。然而,得到的公式相当冗长且存在量词交替。因此,即使是只有三行代码的简单程序,也超出了现代 SMT 求解器和量词消除方法的处理能力。在同一节中,我们还证明了该问题是(强)NP-难的,因此除非 P=NP\mathrm{P}=\mathrm{NP} ,否则不可能存在严格的多项式时间算法。即使在线性/仿射程序的特殊情况下,NP-难性依然成立。
Our Contributions. In this work, we consider the problem of template-based synthesis over polynomial imperative programs with bounded real variables. Our contributions are as follows: 我们的贡献。在本工作中,我们考虑了带有有界实变量的多项式命令式程序上的基于模板的综合问题。我们的贡献如下:
Complexity: We prove that the problem is decidable. This is achieved by a reduction to the first-order theory of the reals. We also provide a reduction showing that our problem is (strongly) NP-hard. Note that, as mentioned above, decision procedures for the first-order theory of the reals are notoriously slow and cannot handle even toy programs in practice. 复杂性:我们证明了该问题是可判定的。这是通过归约到实数的一阶理论来实现的。我们还提供了一个归约,表明我们的问题是(强)NP-难的。需要注意的是,如上所述,实数一阶理论的判定程序众所周知非常缓慢,实际上甚至无法处理简单的程序。
Practical Algorithm: We use classical theorems from polyhedral and real algebraic geometry, including Farkas’ Lemma, Handelman’s Theorem, Putinar’s Positivstellensatz ^(1){ }^{1}, and the Real Nullstellensatz ^(2){ }^{2} to obtain a polynomial-time reduction to Quadratic Programming (QP). Since modern solvers, both SMT solvers and numerical ones, are quite efficient in handling real-world QP instances, this leads to a much more scalable approach to program synthesis in comparison to decision procedures for the first-order theory of the reals. 实用算法:我们利用多面体和实代数几何中的经典定理,包括法尔卡斯引理(Farkas’ Lemma)、汉德尔曼定理(Handelman’s Theorem)、普蒂纳正性定理(Putinar’s Positivstellensatz ^(1){ }^{1} )以及实数零点定理(Real Nullstellensatz ^(2){ }^{2} ),将问题多项式时间归约到二次规划(QP)。由于现代求解器,无论是 SMT 求解器还是数值求解器,在处理实际的二次规划实例时都非常高效,这使得该方法相比实数一阶理论的判定程序,在程序综合方面具有更好的可扩展性。
Completeness: Crucially, we prove that our approach is not only sound but also semi-complete, i.e. it is complete as long as polynomials of sufficiently high degree are used in the templates. So, our approach achieves both soundness and completeness, while not suffering from the unscalability of quantifier elimination and decision procedures for the first-order theory of the reals. 完备性:关键是,我们证明了我们的方法不仅是正确的,而且是半完备的,即只要在模板中使用足够高次数的多项式,它就是完备的。因此,我们的方法既实现了正确性又实现了完备性,同时避免了实数一阶理论的量词消除和判定过程的不具扩展性问题。
Experimental Results: We provide extensive experimental results, illustrating the efficiency of our approach and that it can successfully handle a variety of programs. 实验结果:我们提供了大量实验结果,展示了我们方法的高效性以及其成功处理各种程序的能力。
Novelty. The main novelty of our approach is that it can handle a wide family of programs, i.e. polynomial imperative programs, without sacrificing completeness. It is quite rare in program synthesis to achieve soundness, semi-completeness and practical efficiency at the same time. To the best of our knowledge, our method of relying on theorems in real algebraic geometry is also novel in program synthesis. Moreover, we combine these theorems in non-trivial ways and obtain new mathematical results, which are of independent interest. 新颖性:我们方法的主要新颖之处在于,它能够处理广泛的程序类别,即多项式命令式程序,而不牺牲完备性。在程序综合领域,同时实现正确性、半完备性和实际效率是非常罕见的。据我们所知,依赖实代数几何定理的方法在程序综合中也是新颖的。此外,我们以非平凡的方式结合这些定理,获得了新的数学结果,这些结果具有独立的研究价值。
Limitations. The main limitation of our approach is that it can only handle polynomial programs. This is to be expected, since we are using techniques from real algebraic geometry, which are highly dependent on having polynomial expressions/inequalities over real variables. Another limitation is that, although our approach is quite efficient in practice, its runtime is not polynomial in the size of the program or the number of variables. This is a natural consequence of our NP-hardness result and cannot be overcome unless P=NP\mathrm{P}=\mathrm{NP}. 局限性。我们方法的主要局限性在于它只能处理多项式程序。这是可以预料的,因为我们使用的是实代数几何的技术,而这些技术高度依赖于实变量上的多项式表达式/不等式。另一个局限是,尽管我们的方法在实际中相当高效,但其运行时间并不是程序规模或变量数量的多项式时间。这是我们 NP 难度结果的自然后果,除非 P=NP\mathrm{P}=\mathrm{NP} ,否则无法克服。
Related Works. Several previous works use ideas that are similar in spirit to our approach: 相关工作。之前有几项工作使用了与我们方法精神类似的思路:
Template-based Synthesis: The work [Srivastava et al. 2013] provides algorithms based on Farkas’ Lemma for template-based synthesis of linear/affine programs. Since our work can handle polynomial programs of arbitrary degree, [Srivastava et al. 2013]‘s results on linear/affine programs are subsumed by our approach. Moreover, while the use of Farkas’ Lemma is shared among the two approaches, we also use theorems from real algebraic geometry, e.g. Handelman and Putinar, as well as non-trivial combinations of them, which are not considered in [Srivastava et al. 2013]. So, we have a different methodology and handle a wider family of programs. To the best of our knowledge, our algebro-geometric approach is novel in program synthesis. 基于模板的综合:文献[Srivastava et al. 2013]提出了基于 Farkas 引理的线性/仿射程序模板综合算法。由于我们的工作能够处理任意次数的多项式程序,[Srivastava et al. 2013]关于线性/仿射程序的结果被我们的方法所涵盖。此外,尽管两种方法都使用了 Farkas 引理,我们还使用了实代数几何中的定理,例如 Handelman 和 Putinar 定理,以及它们的非平凡组合,而这些在[Srivastava et al. 2013]中未被考虑。因此,我们采用了不同的方法论,并处理了更广泛的程序类别。据我们所知,我们的代数几何方法在程序综合领域是创新的。
Invariant Generation: The work [Chatterjee et al. 2020b] provides template-based algorithms for automated generation of polynomial invariants over polynomial programs with real variables. Note that this is also a special case of our setting, in which the holes are limited to appear only in the invariants. Since we allow holes in both the program itself and the invariants, our setting is strictly more general. Moreover, while [Chatterjee et al. 2020b] also uses Positivstellensätze, it does not consider Nullstellensätze, and thus has a different mathematical basis. The work [Sankaranarayanan et al. 2004b] considers the same problem 不变式生成:[Chatterjee et al. 2020b] 提供了基于模板的算法,用于自动生成带有实变量的多项式程序上的多项式不变式。注意,这也是我们设定的一个特例,其中空洞仅限于出现在不变式中。由于我们允许空洞同时出现在程序本身和不变式中,因此我们的设定更为通用。此外,虽然 [Chatterjee et al. 2020b] 也使用了 Positivstellensätze,但它没有考虑 Nullstellensätze,因此其数学基础不同。[Sankaranarayanan et al. 2004b] 的工作考虑了相同的问题。
as [Chatterjee et al. 2020b] and solves it using Gröbner basis computations. In comparison with both of these approaches, we handle a more general setting and have a different methodology. There are also template-based approaches for generation of linear loop invariants, such as [Colón et al. 2003; Liu et al. 2022; Sankaranarayanan et al. 2004a]. This is an even narrower special case of our setting. Finally, [Feng et al. 2017] considers invariant generation for probabilistic programs and uses a different Positivstellensatz, i.e. that of Stengle, to obtain an automated algorithm. This setting is incomparable to ours due to the presence of probabilistic behavior but absence of holes in the program itself. 如[Chatterjee et al. 2020b]所述,并通过 Gröbner 基计算来解决。与这两种方法相比,我们处理的是更一般的情形,并采用了不同的方法论。还有基于模板的线性循环不变量生成方法,如[Colón et al. 2003; Liu et al. 2022; Sankaranarayanan et al. 2004a]。这实际上是我们设定的一个更狭窄的特例。最后,[Feng et al. 2017]考虑了概率程序的不变量生成,并使用了另一种 Positivstellensatz,即 Stengle 的定理,来获得自动化算法。由于存在概率行为但程序本身没有空洞,这一设定与我们的不可比。
Termination analysis: Template-based algorithms that utilize Farkas’ Lemma or Positivstellensätze have also been considered in the context of termination and reachability analysis [Agrawal et al. 2017; Asadi et al. 2021; Chatterjee et al. 2016, 2020a; Neumann et al. 2020; Takisaka et al. 2018]. However, this is a very different and orthogonal problem and, while there are clear similarities in the approaches, it is not possible to directly or experimentally compare them. Conceptually, the works in termination analysis assume that strong-enough invariants are given as part of the input ^(3){ }^{3} and then reduce the problem of finding an affine/polynomial ranking function, or its probabilistic counterparts, to Linear Programming (LP). This is in contrast to our setting where the reduction is to Quadratic Programming (QP) and a reduction to LP is impossible due to the strong NP-hardness. 终止性分析:基于模板的算法利用 Farkas 引理或 Positivstellensätze 也被应用于终止性和可达性分析的研究中[Agrawal 等,2017;Asadi 等,2021;Chatterjee 等,2016,2020a;Neumann 等,2020;Takisaka 等,2018]。然而,这是一类非常不同且正交的问题,尽管方法上存在明显的相似性,但无法直接或通过实验进行比较。从概念上讲,终止性分析中的工作假设足够强的不变式作为输入 ^(3){ }^{3} 的一部分,然后将寻找仿射/多项式排序函数或其概率对应物的问题归约为线性规划(LP)。这与我们的设置形成对比,我们的归约是到二次规划(QP),由于强 NP 难度,无法归约为 LP。
Organization. In Section 2, we formalize our problem and define the syntax and semantics of our programs. Section 3 is the core of the paper in which we provide our synthesis algorithm and prove that it is sound and semi-complete. We then study the complexity of the problem in Section 4, proving that it is decidable and strongly NP-hard. Finally, Section 5 reports on an implementation of our algorithm and provides experimental results. 组织结构。第 2 节中,我们形式化了我们的问题,并定义了程序的语法和语义。第 3 节是本文的核心,我们在其中提供了合成算法,并证明了其正确性和半完备性。随后,在第 4 节中我们研究了该问题的复杂性,证明了其可判定性和强 NP 难度。最后,第 5 节报告了我们算法的实现情况并提供了实验结果。
2 TEMPLATE-BASED SYNTHESIS OF POLYNOMIAL PROGRAMS 2 基于模板的多项式程序合成
In this work, we focus on imperative polynomial programs. Our programs can have real variables, conditionals and loops. Moreover, they include specifications as pre and post-conditions, as well as invariants for each loop, which are used to prove that the program satisfies the specification. 在本工作中,我们专注于命令式多项式程序。我们的程序可以包含实数变量、条件语句和循环。此外,它们包括作为前置条件和后置条件的规范,以及用于证明程序满足规范的每个循环的不变式。
Variables and Valuations. We assume that our programs have a finite set V={v_(1),dots,v_(k)}\mathbb{V}=\left\{v_{1}, \ldots, v_{k}\right\} of real-valued variables. A valuation is a function val: VrarrR\mathbb{V} \rightarrow \mathbb{R} that assigns a real value to each program variable. 变量与赋值。我们假设程序具有一个有限集合 V={v_(1),dots,v_(k)}\mathbb{V}=\left\{v_{1}, \ldots, v_{k}\right\} 的实值变量。赋值是一个函数 val: VrarrR\mathbb{V} \rightarrow \mathbb{R} ,它为每个程序变量分配一个实数值。
Syntax. We consider programs that can be generated from the following grammar: 语法。我们考虑可以由以下文法生成的程序:
{:[P:=(Phi","C","Phi)],[C:=" skip "|v larr Pi|" if "(Phi){C}" else "{C}∣" while "(Phi","Phi){C}∣C;C],[Phi:=Pi >= 0|(Phi^^Phi)|not Phi],[v inV],[Pi inR[V]]:}\begin{aligned}
& P:=(\Phi, C, \Phi) \\
& C:=\text { skip }|v \leftarrow \Pi| \text { if }(\Phi)\{C\} \text { else }\{C\} \mid \text { while }(\Phi, \Phi)\{C\} \mid C ; C \\
& \Phi:=\Pi \geq 0|(\Phi \wedge \Phi)| \neg \Phi \\
& v \in \mathbb{V} \\
& \Pi \in \mathbb{R}[\mathbb{V}]
\end{aligned}
Intuitively, a program PP consists of a pre-condition, a sequence CC of commands, and a postcondition. We have a special command skip that does not do anything. We also allow assignments, conditionals and while loops. The header of each loop should include both a guard and a loop invariant. Moreover, the right-hand-side of every assignment is a polynomial expression Pi\Pi over program variables, and the guards, invariants and pre and post-conditions are boolean combinations Phi\Phi of polynomial inequalities over V\mathbb{V}. For simplicity, we often write the programs as in Figure 2 to make them more human-readable. We also use standard syntactic sugars, e.g. to allow other boolean operators. 直观地,一个程序 PP 由一个前置条件、一系列 CC 命令和一个后置条件组成。我们有一个特殊命令 skip,它不执行任何操作。我们还允许赋值、条件语句和 while 循环。每个循环的头部应包括守卫和循环不变式。此外,每个赋值的右侧是一个关于程序变量的多项式表达式 Pi\Pi ,而守卫、不变式以及前置和后置条件是关于 V\mathbb{V} 的多项式不等式的布尔组合 Phi\Phi 。为简便起见,我们通常如图 2 所示书写程序,使其更易于人类阅读。我们还使用标准的语法糖,例如允许其他布尔运算符。
Fig. 3. The Polynomial Transition System (PTS) Corresponding to the Program in Figure 2. 图 3. 与图 2 中程序对应的多项式转移系统(PTS)。
Polynomial Assertions. A polynomial assertion over a set VV of variables is a boolean combination of polynomial inequalities of the form p >= 0p \geq 0 in which p inR[V]p \in \mathbb{R}[V]. In the sequel, without loss of generality, our algorithms assume that all polynomial assertions are in disjunctive normal form. 多项式断言。关于一组变量 VV 的多项式断言是多项式不等式的布尔组合,形式为 p >= 0p \geq 0 ,其中 p inR[V]p \in \mathbb{R}[V] 。在后续内容中,且不失一般性,我们的算法假设所有多项式断言均为析取范式。
Polynomial Transition Systems. We define the semantics of our programs using transition systems. A polynomial transition system (PTS) is a tuple ( V,L,ℓ_(0),theta_(0),ℓ_(f),theta_(f),T,I\mathbb{V}, \mathbb{L}, \ell_{0}, \theta_{0}, \ell_{f}, \theta_{f}, \mathcal{T}, \mathbb{I} ) that consists of: 多项式转换系统。我们使用转换系统来定义程序的语义。多项式转换系统(PTS)是一个元组( V,L,ℓ_(0),theta_(0),ℓ_(f),theta_(f),T,I\mathbb{V}, \mathbb{L}, \ell_{0}, \theta_{0}, \ell_{f}, \theta_{f}, \mathcal{T}, \mathbb{I} ),包含:
A finite set V\mathbb{V} of program variables, 一组有限的程序变量 V\mathbb{V} ,
A finite set L\mathbb{L} of locations, 一组有限的位置 L\mathbb{L} ,
An initial polynomial assertion theta_(0)\theta_{0}, 一个初始多项式断言 theta_(0)\theta_{0} ,
A final location l_(f)inLl_{f} \in \mathbb{L}, 一个最终位置 l_(f)inLl_{f} \in \mathbb{L} ,
A final polynomial assertion theta_(f)\theta_{f}, 一个最终多项式断言 theta_(f)\theta_{f} ,
A finite set T\mathcal{T} of transitions. Each transition tau inT\tau \in \mathcal{T} is a tuple ( ℓ,ℓ^('),rho_(tau)\ell, \ell^{\prime}, \rho_{\tau} ), where ℓ,ℓ^(')inL\ell, \ell^{\prime} \in \mathbb{L} are the pre and post locations, and rho_(tau)\rho_{\tau}, called the transition relation, is a polynomial assertion over VuuV^(')\mathbb{V} \cup \mathbb{V}^{\prime}, where V\mathbb{V} represents variables in the pre location and its primed version V^(')\mathbb{V}^{\prime} represents the variables in the post location, i.e. after taking the transition. Specifically, we have V^(')={v^(')∣v inV}\mathbb{V}^{\prime}=\left\{v^{\prime} \mid v \in \mathbb{V}\right\}; 一个有限集合 T\mathcal{T} 的转换。每个转换 tau inT\tau \in \mathcal{T} 是一个元组 ( ℓ,ℓ^('),rho_(tau)\ell, \ell^{\prime}, \rho_{\tau} ),其中 ℓ,ℓ^(')inL\ell, \ell^{\prime} \in \mathbb{L} 是前置和后置位置, rho_(tau)\rho_{\tau} ,称为转换关系,是关于 VuuV^(')\mathbb{V} \cup \mathbb{V}^{\prime} 的多项式断言,其中 V\mathbb{V} 表示前置位置的变量,其带撇号的版本 V^(')\mathbb{V}^{\prime} 表示后置位置的变量,即执行转换后的变量。具体来说,我们有 V^(')={v^(')∣v inV}\mathbb{V}^{\prime}=\left\{v^{\prime} \mid v \in \mathbb{V}\right\} ;
An invariant I\mathbb{I} that maps some of the locations ℓinL\ell \in \mathbb{L} to a polynomial assertion I(ℓ)\mathbb{I}(\ell). Moreover, we have I(ℓ_(0))=theta_(0)\mathbb{I}\left(\ell_{0}\right)=\theta_{0} and I(ℓ_(f))=theta_(f)\mathbb{I}\left(\ell_{f}\right)=\theta_{f}. The set of locations for which an invariant is provided must be a cutset (see further below for a formal definition). 一个不变式 I\mathbb{I} ,它将部分位置 ℓinL\ell \in \mathbb{L} 映射到多项式断言 I(ℓ)\mathbb{I}(\ell) 。此外,我们有 I(ℓ_(0))=theta_(0)\mathbb{I}\left(\ell_{0}\right)=\theta_{0} 和 I(ℓ_(f))=theta_(f)\mathbb{I}\left(\ell_{f}\right)=\theta_{f} 。提供不变式的位置集合必须是一个割集(正式定义见下文)。
The translation from programs to transition systems is intuitive and straightforward. We can have one location ℓinL\ell \in \mathbb{L} for each line of the program, and let ℓ_(0)\ell_{0} correspond to the initial line and ℓ_(f)\ell_{f} to the end of the program. Similarly, theta_(0)\theta_{0} serves as the pre-condition and theta_(f)\theta_{f} as the post-condition. Programs are more human-friendly and hence a nicer way to specify the input to the synthesis problem. In contrast, it is easier to define the algorithms using the more formal notion of PTS. As such, we will define our semantics based on a PTS instead of a program. Below, we fix a PTS (V,L,ℓ_(0),theta_(0),ℓ_(f),theta_(f),T,I)\left(\mathbb{V}, \mathbb{L}, \ell_{0}, \theta_{0}, \ell_{f}, \theta_{f}, \mathcal{T}, \mathbb{I}\right). 从程序到转换系统的翻译直观且简单。我们可以为程序的每一行设一个位置 ℓinL\ell \in \mathbb{L} ,并让 ℓ_(0)\ell_{0} 对应程序的起始行, ℓ_(f)\ell_{f} 对应程序的结束行。同样, theta_(0)\theta_{0} 作为前置条件, theta_(f)\theta_{f} 作为后置条件。程序更符合人类习惯,因此是指定合成问题输入的更好方式。相比之下,使用更形式化的 PTS 概念定义算法更为简便。因此,我们将基于 PTS 而非程序来定义语义。下面,我们固定一个 PTS (V,L,ℓ_(0),theta_(0),ℓ_(f),theta_(f),T,I)\left(\mathbb{V}, \mathbb{L}, \ell_{0}, \theta_{0}, \ell_{f}, \theta_{f}, \mathcal{T}, \mathbb{I}\right) 。
Example 2.1. Figure 3 shows the PTS modeling the program of Figure 2 . We have L={3,4,6,8,9,11}\mathbb{L}=\{3,4,6,8,9,11\} and each location corresponds to a line of code. The invariants are bracketed and shown in green. Note that our algorithm works with polynomial inequalities, so a=ba=b is syntactic sugar for a-b >= 0^^b-a >= 0a-b \geq 0 \wedge b-a \geq 0. 例 2.1 图 3 展示了图 2 中程序的 PTS 建模。我们有 L={3,4,6,8,9,11}\mathbb{L}=\{3,4,6,8,9,11\} ,每个位置对应一行代码。不变式用括号括起并以绿色显示。注意,我们的算法处理多项式不等式,因此 a=ba=b 是 a-b >= 0^^b-a >= 0a-b \geq 0 \wedge b-a \geq 0 的语法糖。
Control Flow Graphs (CFGs). The control flow graph (CFG) of our PTS is a directed graph G=G= ( L,E\mathbb{L}, E ) in which the locations serve as vertices and there is a directed edge from ℓ\ell to ℓ^(')\ell^{\prime} iff there is a transition tau inT\tau \in \mathcal{T} of the form tau=(ℓ,ℓ^('),rho_(tau))\tau=\left(\ell, \ell^{\prime}, \rho_{\tau}\right). 控制流图(CFG)。我们的 PTS 的控制流图(CFG)是一个有向图 G=G= ( L,E\mathbb{L}, E ),其中位置作为顶点,且当且仅当存在形式为 tau=(ℓ,ℓ^('),rho_(tau))\tau=\left(\ell, \ell^{\prime}, \rho_{\tau}\right) 的转换 tau inT\tau \in \mathcal{T} 时,才存在从 ℓ\ell 到 ℓ^(')\ell^{\prime} 的有向边。
Cutsets, Cutpoints and Basic Paths. A subset C subeLC \subseteq \mathbb{L} of vertices of the CFG GG is called a cutset if 割集、割点和基本路径。CFG GG 的顶点子集 C subeLC \subseteq \mathbb{L} 称为割集,如果
(1) ℓ_(0),ℓ_(f)in C\ell_{0}, \ell_{f} \in C; and (1) ℓ_(0),ℓ_(f)in C\ell_{0}, \ell_{f} \in C ;
(2) Every cycle in GG, be it a simple cycle or not, intersects CC. (2) GG 中的每个环,无论是否为简单环,都与 CC 相交。
Assuming we have fixed a cutset CC, every location c in Cc \in C is called a cutpoint. A basic path is a finite sequence of transitions pi=(:tau_(i):)_(i=1)^(m)=(:(ℓ_(i),ℓ_(i)^('),rho_(tau_(i)))_(i=1)^(m):)\pi=\left\langle\tau_{i}\right\rangle_{i=1}^{m}=\left\langle\left(\ell_{i}, \ell_{i}^{\prime}, \rho_{\tau_{i}}\right)_{i=1}^{m}\right\rangle such that: 假设我们已经固定了一个割集 CC ,每个位置 c in Cc \in C 被称为割点。一个基本路径是一个有限的转换序列 pi=(:tau_(i):)_(i=1)^(m)=(:(ℓ_(i),ℓ_(i)^('),rho_(tau_(i)))_(i=1)^(m):)\pi=\left\langle\tau_{i}\right\rangle_{i=1}^{m}=\left\langle\left(\ell_{i}, \ell_{i}^{\prime}, \rho_{\tau_{i}}\right)_{i=1}^{m}\right\rangle ,满足:
ℓ_(i)=ℓ_(i-1)^(')\ell_{i}=\ell_{i-1}^{\prime} for all i > 1i>1. 对于所有 i > 1i>1 , ℓ_(i)=ℓ_(i-1)^(')\ell_{i}=\ell_{i-1}^{\prime} 。
ℓ_(1)\ell_{1} and ℓ_(m)^(')\ell_{m}^{\prime} are cutpoints, but no internal location ℓ_(i)\ell_{i} with 1 < i <= m1<i \leq m is a cutpoint. ℓ_(1)\ell_{1} 和 ℓ_(m)^(')\ell_{m}^{\prime} 是割点,但没有内部位置 ℓ_(i)\ell_{i} ,其中 1 < i <= m1<i \leq m 是割点。
We define the transition relation rho_(pi)\rho_{\pi} of the basic path pi\pi as rho_(tau_(m))@rho_(tau_(m-1))@cdots@rho_(tau_(1))\rho_{\tau_{m}} \circ \rho_{\tau_{m-1}} \circ \cdots \circ \rho_{\tau_{1}}. Informally, rho_(pi)\rho_{\pi} is the transition relation resulting from going through all the transitions of pi\pi one-by-one and is hence equal to the sequential composition of rho_(tau_(i))\rho_{\tau_{i}} 's. If pi\pi is the empty path, then we let rho_(pi)\rho_{\pi} be the identity relation ^^_(v inV)v=v^(')\wedge_{v \in \mathbb{V}} v=v^{\prime}. 我们定义基本路径 pi\pi 的转换关系 rho_(pi)\rho_{\pi} 为 rho_(tau_(m))@rho_(tau_(m-1))@cdots@rho_(tau_(1))\rho_{\tau_{m}} \circ \rho_{\tau_{m-1}} \circ \cdots \circ \rho_{\tau_{1}} 。非正式地, rho_(pi)\rho_{\pi} 是通过依次经过 pi\pi 的所有转换得到的转换关系,因此等于 rho_(tau_(i))\rho_{\tau_{i}} 的顺序组合。如果 pi\pi 是空路径,那么我们令 rho_(pi)\rho_{\pi} 为恒等关系 ^^_(v inV)v=v^(')\wedge_{v \in \mathbb{V}} v=v^{\prime} 。
Example 2.2. In the PTS of Figure 3, the cutpoints shown in red form a cutset C={3,6,11}C=\{3,6,11\}. In this example, our non-empty basic paths are (:tau_(1),tau_(2):),(:tau_(4):)\left\langle\tau_{1}, \tau_{2}\right\rangle,\left\langle\tau_{4}\right\rangle, and (:tau_(3),tau_(5),tau_(6):)\left\langle\tau_{3}, \tau_{5}, \tau_{6}\right\rangle. 例 2.2. 在图 3 的 PTS 中,红色显示的切点形成了一个割集 C={3,6,11}C=\{3,6,11\} 。在此示例中,我们的非空基本路径是 (:tau_(1),tau_(2):),(:tau_(4):)\left\langle\tau_{1}, \tau_{2}\right\rangle,\left\langle\tau_{4}\right\rangle 和 (:tau_(3),tau_(5),tau_(6):)\left\langle\tau_{3}, \tau_{5}, \tau_{6}\right\rangle 。
Remark on Invariants. It is straightforward to see that it suffices to specify invariants in a cutset only and that the invariants can then be inductively expanded to every other line [Colón et al. 2003]. In the sequel, we assume that a cutset CC is fixed and that the invariant I\mathbb{I} assigns a polynomial assertion I(ℓ)\mathbb{I}(\ell) to every cutpoint ℓin C\ell \in C. This also fits our simple syntax above in which the invariant is only provided for the while loops and the start and end of the program (in the form of pre and post conditions). Nevertheless, our algorithmic approaches consider the PTS and can hence work with any arbitrary cutset CC. 关于不变式的说明。显而易见,只需在割集中指定不变式,然后不变式即可归纳地扩展到其他所有行 [Colón 等,2003]。在下文中,我们假设固定了一个割集 CC ,且不变式 I\mathbb{I} 为每个切点 ℓin C\ell \in C 分配了一个多项式断言 I(ℓ)\mathbb{I}(\ell) 。这也符合我们上面简单的语法,其中不变式仅为 while 循环以及程序的开始和结束(以前置和后置条件的形式)提供。然而,我们的算法方法考虑的是 PTS,因此可以处理任意割集 CC 。
States. A state of the PTS is a pair sigma=(ℓ,val)\sigma=(\ell, v a l) in which ℓinL\ell \in \mathbb{L} is a location and val:VrarrRv a l: \mathbb{V} \rightarrow \mathbb{R} is a valuation. Intuitively, a state specifies which line of the program we are in and what values are taken by our program variables. 状态。PTS 的一个状态是一个对 sigma=(ℓ,val)\sigma=(\ell, v a l) ,其中 ℓinL\ell \in \mathbb{L} 是一个位置, val:VrarrRv a l: \mathbb{V} \rightarrow \mathbb{R} 是一个赋值。直观地说,状态指定了程序当前所在的行以及程序变量所取的值。
Runs. A run of our PTS is a sequence R=(:sigma_(i):)_(i=0)^(m)=(:(ℓ_(i),val_(i)):)_(i=0)^(m)R=\left\langle\sigma_{i}\right\rangle_{i=0}^{m}=\left\langle\left(\ell_{i}, v a l_{i}\right)\right\rangle_{i=0}^{m} of states such that: 运行。我们的 PTS 的一次运行是一个状态序列 R=(:sigma_(i):)_(i=0)^(m)=(:(ℓ_(i),val_(i)):)_(i=0)^(m)R=\left\langle\sigma_{i}\right\rangle_{i=0}^{m}=\left\langle\left(\ell_{i}, v a l_{i}\right)\right\rangle_{i=0}^{m} ,满足:
val_(0)|==theta_(0)v a l_{0} \models \theta_{0}, i.e. the run starts with the initial location ℓ_(0)\ell_{0} and an initial valuation that satisfies the precondition theta_(0)\theta_{0}; val_(0)|==theta_(0)v a l_{0} \models \theta_{0} ,即运行从初始位置 ℓ_(0)\ell_{0} 开始,且初始赋值满足前置条件 theta_(0)\theta_{0} ;
For every i < mi<m, there exists a transition tau_(i)inT\tau_{i} \in \mathcal{T} that allows us to go from sigma_(i)\sigma_{i} to sigma_(i+1)\sigma_{i+1}. More formally: 对于每个 i < mi<m ,存在一个转换 tau_(i)inT\tau_{i} \in \mathcal{T} ,允许我们从 sigma_(i)\sigma_{i} 到达 sigma_(i+1)\sigma_{i+1} 。更正式地说:
tau_(i)=(ℓ_(i),ℓ_(i+1),rho_(tau_(i)))\tau_{i}=\left(\ell_{i}, \ell_{i+1}, \rho_{\tau_{i}}\right); and tau_(i)=(ℓ_(i),ℓ_(i+1),rho_(tau_(i)))\tau_{i}=\left(\ell_{i}, \ell_{i+1}, \rho_{\tau_{i}}\right) ;并且
(val_(i),val_(i+1)^('))|==rho_(tau_(i))\left(v a l_{i}, v a l_{i+1}^{\prime}\right) \models \rho_{\tau_{i}}, i.e. if we consider val_(i)v a l_{i} as a valuation on V\mathbb{V} and val_(i+1)v a l_{i+1} as a valuation on V^(')\mathbb{V}^{\prime}, then they jointly satisfy the transition condition rho_(tau_(i))\rho_{\tau_{i}}. (val_(i),val_(i+1)^('))|==rho_(tau_(i))\left(v a l_{i}, v a l_{i+1}^{\prime}\right) \models \rho_{\tau_{i}} ,即如果我们将 val_(i)v a l_{i} 视为 V\mathbb{V} 上的一个赋值,将 val_(i+1)v a l_{i+1} 视为 V^(')\mathbb{V}^{\prime} 上的一个赋值,那么它们共同满足转换条件 rho_(tau_(i))\rho_{\tau_{i}} 。
Valid Runs. A run R=(:sigma_(i):)_(i=0)^(m)=(:(ℓ_(i),val_(i)):)_(i=0)^(m)R=\left\langle\sigma_{i}\right\rangle_{i=0}^{m}=\left\langle\left(\ell_{i}, v a l_{i}\right)\right\rangle_{i=0}^{m} is called valid iff for every ii for which ℓ_(i)\ell_{i} has an associated invariant I(ℓ_(i))\mathbb{I}\left(\ell_{i}\right), we have val_(i)|==I(ℓ_(i))v a l_{i} \models \mathbb{I}\left(\ell_{i}\right). Intuitively, a run is valid if it always satisfies the invariant. Specifically, if ℓ_(m)=ℓ_(f)\ell_{m}=\ell_{f}, then we must have val_(m)=theta_(f)v a l_{m}=\theta_{f} in order for the run to be valid. 有效运行。一个运行 R=(:sigma_(i):)_(i=0)^(m)=(:(ℓ_(i),val_(i)):)_(i=0)^(m)R=\left\langle\sigma_{i}\right\rangle_{i=0}^{m}=\left\langle\left(\ell_{i}, v a l_{i}\right)\right\rangle_{i=0}^{m} 被称为有效,当且仅当对于每个 ii ,如果 ℓ_(i)\ell_{i} 有一个关联的不变式 I(ℓ_(i))\mathbb{I}\left(\ell_{i}\right) ,则我们有 val_(i)|==I(ℓ_(i))v a l_{i} \models \mathbb{I}\left(\ell_{i}\right) 。直观地说,一个运行是有效的,如果它始终满足该不变式。具体来说,如果 ℓ_(m)=ℓ_(f)\ell_{m}=\ell_{f} ,那么为了使该运行有效,我们必须有 val_(m)=theta_(f)v a l_{m}=\theta_{f} 。
Valid Transition Systems. A transition system (PTS) is called valid iff every run of the PTS is valid. 有效的转换系统。一个转换系统(PTS)被称为有效,当且仅当该 PTS 的每个运行都是有效的。
Inductively Valid Transition System. A PTS is called inductively valid with respect to a cutset CC, iff it satisfies the following conditions for all cutpoints ℓ,ℓ^(')in C\ell, \ell^{\prime} \in C and valuations (val, val’) over VuuV^(')\mathbb{V} \cup \mathbb{V}^{\prime} : 归纳有效的转换系统。一个 PTS 被称为相对于割集 CC 归纳有效,当且仅当它对所有割点 ℓ,ℓ^(')in C\ell, \ell^{\prime} \in C 和 VuuV^(')\mathbb{V} \cup \mathbb{V}^{\prime} 上的赋值(val, val’)满足以下条件:
Initiation: For every basic path pi\pi from ℓ_(0)\ell_{0} to ℓ\ell, we have 初始化:对于从 ℓ_(0)\ell_{0} 到 ℓ\ell 的每条基本路径 pi\pi ,我们有
" val "|==theta_(0)^^(val,val^('))|==rho_(pi)=>val^(')|==I(ℓ)^(')\text { val } \vDash \theta_{0} \wedge\left(v a l, v a l^{\prime}\right) \vDash \rho_{\pi} \Rightarrow v a l^{\prime} \vDash \mathbb{I}(\ell)^{\prime}
Here, I(ℓ)^(')\mathbb{I}(\ell)^{\prime} is the same as I(ℓ)\mathbb{I}(\ell), except that every program variable v inVv \in \mathbb{V} is replaced with its primed version v^(')v^{\prime}. 这里, I(ℓ)^(')\mathbb{I}(\ell)^{\prime} 与 I(ℓ)\mathbb{I}(\ell) 相同,只是每个程序变量 v inVv \in \mathbb{V} 被替换为其带撇号的版本 v^(')v^{\prime} 。
Consecution: For every basic path pi\pi from ℓ\ell to ℓ^(')\ell^{\prime}, we have 连续性:对于从 ℓ\ell 到 ℓ^(')\ell^{\prime} 的每条基本路径 pi\pi ,我们有
" val "|==I(ℓ)^^(val,val^('))|==rho_(pi)=>val^(')|==I(ℓ^('))^(')\text { val } \models \mathbb{I}(\ell) \wedge\left(v a l, v a l^{\prime}\right) \vDash \rho_{\pi} \Rightarrow v a l^{\prime} \vDash \mathbb{I}\left(\ell^{\prime}\right)^{\prime}
Finalization: For every basic path pi\pi from ℓ\ell to ℓ_(f)\ell_{f}, we have 终结性:对于从 ℓ\ell 到 ℓ_(f)\ell_{f} 的每条基本路径 pi\pi ,我们有
" val "|==I(ℓ)^^(val,val^('))|==rho_(pi)=>val^(')|==theta_(f)^(')\text { val } \models \mathbb{I}(\ell) \wedge\left(v a l, v a l^{\prime}\right) \vDash \rho_{\pi} \Rightarrow v a l^{\prime} \vDash \theta_{f}^{\prime}
The intuition behind inductive validity is similar to that of inductive invariants [Colón et al. 2003]. Informally, a PTS is inductively valid if we can prove that it is valid by breaking each run into a sequence of basic paths and then show its validity by an inductive argument. It is straightforward to see that every inductively valid PTS is indeed valid [Chatterjee et al. 2020b; Colón et al. 2003]. Moreover, the finalization and initiation conditions above can be considered as special cases of consecution. We are including them separately to emphasize the point that validity requires the PTS to satisfy its specification (as specified by pre and post-conditions). 归纳有效性的直觉与归纳不变式[Colón 等,2003]类似。非正式地说,如果我们能通过将每次运行分解为一系列基本路径,并通过归纳论证证明其有效性,则一个 PTS 是归纳有效的。很容易看出,每个归纳有效的 PTS 确实是有效的[Chatterjee 等,2020b;Colón 等,2003]。此外,上述终结性和起始条件可以视为连续性的特例。我们单独列出它们,是为了强调有效性要求 PTS 满足其规范(由前置条件和后置条件指定)。
Non-determinism. Note that, in order to simplify the presentation, we did not include nondeterminism in the syntax of our programs. However, our transition systems have built-in support for non-determinism since one can have several outgoing transitions from the same node or, alternatively, a transition that does not uniquely specify the post-valuation val^(')v a l^{\prime} in terms of the pre-valuation val. Therefore, all the results in the sequel are trivially extensible to the case of non-deterministic polynomial programs. 非确定性。请注意,为了简化表述,我们在程序的语法中未包含非确定性。然而,我们的转换系统内置了对非确定性的支持,因为同一节点可以有多个出边转换,或者转换本身不能唯一地根据前置赋值 val 指定后置赋值 val^(')v a l^{\prime} 。因此,后续所有结果都可以轻松扩展到非确定性多项式程序的情况。
Our goal is to synthesize a valid PTS, given a sketch that includes holes in it. To do this, we first define variants of our programs and transition systems which can also include holes. 我们的目标是给定包含空洞的草图,合成一个有效的 PTS。为此,我们首先定义可以包含空洞的程序和转换系统的变体。
Sketches of Polynomial Programs. In this work, we assume that the programmer provides a sketch of the implementation. The sketch is a partial program, i.e. a program with holes, which is generated using the following grammar: 多项式程序的草图。在本工作中,我们假设程序员提供了实现的草图。该草图是一个部分程序,即带有空洞的程序,其生成遵循以下文法:
{:[P:=(Phi","C","Phi)],[C:=" skip "|v larr Pi|v larr H∣" if "(Phi){C}" else "{C}∣" while "(Phi","Phi){C}∣C;C],[Phi:=Pi >= 0|H >= 0|(Phi^^Phi)∣not Phi],[H:=( bar(V)","d)],[v inV],[Pi inR[V]],[ bar(V)subeV],[d inN]:}\begin{aligned}
& P:=(\Phi, C, \Phi) \\
& C:=\text { skip }|v \leftarrow \Pi| v \leftarrow H \mid \text { if }(\Phi)\{C\} \text { else }\{C\} \mid \text { while }(\Phi, \Phi)\{C\} \mid C ; C \\
& \Phi:=\Pi \geq 0|H \geq 0|(\Phi \wedge \Phi) \mid \neg \Phi \\
& H:=(\overline{\mathbb{V}}, d) \\
& v \in \mathbb{V} \\
& \Pi \in \mathbb{R}[\mathbb{V}] \\
& \overline{\mathbb{V}} \subseteq \mathbb{V} \\
& d \in \mathbb{N}
\end{aligned}
The main difference between this grammar and the previous one is the introduction of a new non-terminal HH which models a hole. Note that holes can appear in assignments or as part of the assertions Phi\Phi, be it in guards of if/while or the invariants or even pre and post-conditions. For each hole, the programmer specifies a set bar(V)\overline{\mathbb{V}} of variables which she expects might need to appear in filling the hole, as well as a maximum degree d inNd \in \mathbb{N}, requiring that the hole should be filled by a polynomial of degree at most dd. As an example, see the sketch in Figure 1 in which the holes are shown in boxes. As usual, we do not follow the grammar exactly in order to make the sketch more human-readable. For example, we wrote the invariant outside the while loop, instead of having it as the second parameter in the while header. 该文法与之前文法的主要区别在于引入了一个新的非终结符 HH ,用于表示一个空洞。请注意,空洞可以出现在赋值语句中,也可以作为断言 Phi\Phi 的一部分,无论是在 if/while 的守卫中,还是不变式,甚至是前置条件和后置条件中。对于每个空洞,程序员需要指定一个变量集合 bar(V)\overline{\mathbb{V}} ,表示她预计在填充该空洞时可能需要用到的变量,以及一个最大次数 d inNd \in \mathbb{N} ,要求该空洞应由次数最多为 dd 的多项式填充。举例来说,见图 1 中的草图,其中空洞用方框表示。和往常一样,为了使草图更易于理解,我们没有严格遵循文法。例如,我们将不变式写在了 while 循环外部,而不是作为 while 头部的第二个参数。
Template and Symbolic Polynomials and Assertions. Let V\mathbb{V} be our finite set of program variables and T\mathbb{T} a separate finite set of template variables. We define a symbolic polynomial over ( V,T\mathbb{V}, \mathbb{T} ) as a polynomial over V\mathbb{V} whose every coefficient is itself a polynomial over T\mathbb{T}. More formally, every symbolic polynomial over (V,T)(\mathbb{V}, \mathbb{T}) is of the form p in(R[T])[V]p \in(\mathbb{R}[\mathbb{T}])[\mathbb{V}]. We say a symbolic polynomial pp is a template if every coefficient of pp, when considered as a polynomial over T\mathbb{T}, has degree 0 or 1 . Symbolic (resp. template) polynomial assertions are simply defined as boolean combinations of 模板与符号多项式及断言。设 V\mathbb{V} 为我们有限的程序变量集合, T\mathbb{T} 为另一个有限的模板变量集合。我们定义在( V,T\mathbb{V}, \mathbb{T} )上的符号多项式为在 V\mathbb{V} 上的多项式,其每个系数本身是 T\mathbb{T} 上的多项式。更正式地说,每个在 (V,T)(\mathbb{V}, \mathbb{T}) 上的符号多项式形式为 p in(R[T])[V]p \in(\mathbb{R}[\mathbb{T}])[\mathbb{V}] 。当符号多项式 pp 的每个系数作为 T\mathbb{T} 上的多项式时,其次数为 0 或 1,我们称该符号多项式 pp 为模板。符号(分别为模板)多项式断言简单地定义为
Fig. 4. The SPTS Corresponding to the Sketch Program of Figure 1. For brevity, we have not included equalities of the form v^(')=vv^{\prime}=v that ensure a variable vv does not change in a transition. See Figure 3 for details of these equalities. The cutpoints are shown in red. 图 4. 与图 1 的草图程序对应的 SPTS。为简洁起见,我们未包含形如 v^(')=vv^{\prime}=v 的等式,这些等式确保变量 vv 在转换中不发生变化。有关这些等式的详细信息,请参见图 3。切入点以红色显示。
symbolic (resp. template) polynomial inequalities. As mentioned before, our algorithms assume without loss of generality that all assertions are in disjunctive normal form. 符号(分别为模板)多项式不等式的布尔组合。如前所述,我们的算法在不失一般性的前提下假设所有断言均为析取范式。
Sketches of Polynomial Transition Systems. A sketch of a polynomial transition system (SPTS) is tuple ( V,T,L,ℓ_(0),theta_(0),ℓ_(f),theta_(f),T,I\mathbb{V}, \mathbb{T}, \mathbb{L}, \ell_{0}, \theta_{0}, \ell_{f}, \theta_{f}, \mathcal{T}, \mathbb{I} ) in which all parts serve the same purposes and are defined similarly as in a PTS. The only differences are: 多项式转换系统的草图。多项式转换系统草图(SPTS)是一个元组( V,T,L,ℓ_(0),theta_(0),ℓ_(f),theta_(f),T,I\mathbb{V}, \mathbb{T}, \mathbb{L}, \ell_{0}, \theta_{0}, \ell_{f}, \theta_{f}, \mathcal{T}, \mathbb{I} ),其中所有部分的作用和定义方式与 PTS 中相同。唯一的区别是:
The assertions theta_(0),theta_(f)\theta_{0}, \theta_{f} and invariants I(ℓ)\mathbb{I}(\ell) are now template polynomials over (V,T)(\mathbb{V}, \mathbb{T}). 断言 theta_(0),theta_(f)\theta_{0}, \theta_{f} 和不变式 I(ℓ)\mathbb{I}(\ell) 现在是定义在 (V,T)(\mathbb{V}, \mathbb{T}) 上的模板多项式。
The transition relations rho_(tau)\rho_{\tau} are now template polynomials over (VuuV^('),T)\left(\mathbb{V} \cup \mathbb{V}^{\prime}, \mathbb{T}\right). 转换关系 rho_(tau)\rho_{\tau} 现在是定义在 (VuuV^('),T)\left(\mathbb{V} \cup \mathbb{V}^{\prime}, \mathbb{T}\right) 上的模板多项式。
Moreover, we always assume TnnV=O/\mathbb{T} \cap \mathbb{V}=\emptyset. 此外,我们总是假设 TnnV=O/\mathbb{T} \cap \mathbb{V}=\emptyset 。
Example 2.3. Figure 4 shows a sketch polynomial transition system (SPTS) corresponding to the sketch program of Figure 1. To obtain this SPTS, we introduced 21 new template variables T={t_(0),dots,t_(20)}\mathbb{T}=\left\{t_{0}, \ldots, t_{20}\right\} and replaced each hole with a template polynomial that corresponds to the programmer’s desire for that hole. Note that the invariant of location 6 and the transition relations for tau_(3),tau_(4)\tau_{3}, \tau_{4} and tau_(6)\tau_{6} are now symbolic, i.e. they are polynomials over the program variables {i,s,n}\{i, s, n\} in which every coefficient is itself a polynomial over T\mathbb{T}. In this case, all coefficients are simply variables in T\mathbb{T}. Our goal is to find suitable concrete real values for each t_(i)t_{i} such that the SPTS of Figure 4 becomes a valid PTS, e.g. that of Figure 3. 示例 2.3。图 4 展示了与图 1 中的草图程序对应的草图多项式转换系统(SPTS)。为了得到该 SPTS,我们引入了 21 个新的模板变量 T={t_(0),dots,t_(20)}\mathbb{T}=\left\{t_{0}, \ldots, t_{20}\right\} ,并用对应于程序员对该空洞期望的模板多项式替换了每个空洞。注意,位置 6 的不变式以及 tau_(3),tau_(4)\tau_{3}, \tau_{4} 和 tau_(6)\tau_{6} 的转换关系现在是符号化的,即它们是程序变量 {i,s,n}\{i, s, n\} 上的多项式,其中每个系数本身是 T\mathbb{T} 上的多项式。在本例中,所有系数仅仅是 T\mathbb{T} 中的变量。我们的目标是为每个 t_(i)t_{i} 找到合适的具体实数值,使得图 4 的 SPTS 成为一个有效的 PTS,例如图 3 所示的那种。
We now have all the needed ingredients to formalize our Template-Based Synthesis problem over Polynomial programs (TBSP): 我们现在拥有了形式化多项式程序上的基于模板的综合问题(TBSP)所需的所有要素:
TBSP. Given a sketch of a polynomial transition system Gamma=(V,T,L,ℓ_(0),theta_(0),ℓ_(f),theta_(f),T,I)\Gamma=\left(\mathbb{V}, \mathbb{T}, \mathbb{L}, \ell_{0}, \theta_{0}, \ell_{f}, \theta_{f}, \mathcal{T}, \mathbb{I}\right), find a valuation val _(T):TrarrR_{\mathbb{T}}: \mathbb{T} \rightarrow \mathbb{R} that assigns a real value to every template variable, such that Gamma^("val ")_(T)\Gamma^{\text {val }}{ }_{\mathbb{T}} becomes an inductively valid polynomial transition system. Here, Gamma^(val_(T))\Gamma^{v a l_{\mathrm{T}}} is the PTS obtained by taking the sketch Gamma\Gamma and replacing every appearance of each template variable t inTt \in \mathbb{T} by its corresponding value val_(T)(t)v a l_{\mathbb{T}}(t). Informally, our goal is to synthesize concrete values for each of the template variables so that the resulting program/PTS satisfies the programmer’s desired specification. TBSP。给定一个多项式过渡系统的草图 Gamma=(V,T,L,ℓ_(0),theta_(0),ℓ_(f),theta_(f),T,I)\Gamma=\left(\mathbb{V}, \mathbb{T}, \mathbb{L}, \ell_{0}, \theta_{0}, \ell_{f}, \theta_{f}, \mathcal{T}, \mathbb{I}\right) ,找到一个赋值 val _(T):TrarrR_{\mathbb{T}}: \mathbb{T} \rightarrow \mathbb{R} ,为每个模板变量分配一个实数值,使得 Gamma^("val ")_(T)\Gamma^{\text {val }}{ }_{\mathbb{T}} 成为一个归纳有效的多项式过渡系统。这里, Gamma^(val_(T))\Gamma^{v a l_{\mathrm{T}}} 是通过取草图 Gamma\Gamma 并将每个模板变量 t inTt \in \mathbb{T} 的每次出现替换为其对应的值 val_(T)(t)v a l_{\mathbb{T}}(t) 得到的 PTS。通俗地说,我们的目标是为每个模板变量合成具体的值,使得生成的程序/PTS 满足程序员期望的规范。
Boundedness. For technical reasons which will become evident in Section 3.2, we assume that our program variables V\mathbb{V} have bounded values. More specifically, we consider a bound M in(0,oo)M \in(0, \infty) and assume that no program variable ever takes a value larger than MM or smaller than -M-M. We call this the boundedness assumption. The boundedness assumption is necessary for our completeness 有界性。出于将在第 3.2 节中说明的技术原因,我们假设程序变量 V\mathbb{V} 的取值是有界的。更具体地说,我们考虑一个界限 M in(0,oo)M \in(0, \infty) ,并假设没有程序变量的取值会大于 MM 或小于 -M-M 。我们称之为有界性假设。有界性假设对于我们的完备性是必要的。
theorem (Theorem 3.16), but not for soundness. It is a merely theoretical assumption with no significant practical effect. In practice, we do not assume boundedness in our implementation in Section 5 and can successfully handle all the cases without this extra assumption. 定理(定理 3.16),但不适用于正确性。这只是一个纯理论的假设,对实际没有显著影响。在实践中,我们在第 5 节的实现中并未假设有界性,且能够成功处理所有情况而无需这个额外假设。
3 OUR ALGORITHM FOR TBSP 3 我们的 TBSP 算法
In this section, we provide an automated, sound and semi-complete algorithm for the TBSP problem as defined in Section 2. We assume that the input to our algorithm is either a sketch polynomial transition system (SPTS) or a sketch of a polynomial program, containing holes. In the latter case, we would first process the input and translate it to an SPTS. We start by providing a high-level overview of our algorithm (Section 3.1) and an illustration over the example of Figure 1. Then, we present our mathematical toolkit, i.e. Farkas’ Lemma, Handelman’s Theorem, Putinar’s Positivstellesatz and the Real Nullstellensatz in Section 3.2 and manipulate them to be usable for our application. We use this toolkit to fill in the details of our algorithm in Section 3.3. Finally, we provide soundness and semi-completeness theorems in Section 3.4. 本节中,我们提供一个针对第 2 节定义的 TBSP 问题的自动化、正确且半完备的算法。我们假设算法的输入要么是一个带有空洞的草图多项式转换系统(SPTS),要么是一个带有空洞的多项式程序草图。在后一种情况下,我们会先处理输入并将其转换为 SPTS。我们首先提供算法的高层次概述(第 3.1 节)并通过图 1 的示例进行说明。然后,在第 3.2 节中介绍我们的数学工具包,即 Farkas 引理、Handelman 定理、Putinar 的正定定理和实数 Nullstellensatz,并对其进行调整以适用于我们的应用。我们利用该工具包在第 3.3 节中详细阐述算法细节。最后,在第 3.4 节给出算法的正确性和半完备性定理。
3.1 An Illustration and Overview of the Algorithm 3.1 算法的示例说明与概述
Suppose that a sketch, i.e. a polynomial program with holes, is given as the input. As a running example, let us take Figure 1. Our algorithm fills in the holes using the following four steps: 假设输入是一个带有空洞的草图,即一个多项式程序。作为运行示例,我们以图 1 为例。我们的算法通过以下四个步骤填充空洞:
Step 1: Creating Templates and Translation to SPTS. For each hole in the sketch, the algorithm generates a template polynomial in which it introduces new template variables. Concretely, let the hole be of the form H=( bar(V),d)H=(\overline{\mathbb{V}}, d). This corresponds to a case in which the programmer desires the hole to be filled by a polynomial of degree at most dd over the set bar(V)subeV\overline{\mathbb{V}} \subseteq \mathbb{V}. The algorithm first generates all monomials m_(i)m_{i} of degree at most dd over bar(V)\overline{\mathbb{V}}. It then creates a template polynomial that includes all of these monomials and is of the form p_(H):=sum_(i)t_(i)*m_(i)p_{H}:=\sum_{i} t_{i} \cdot m_{i}, in which each t_(i)t_{i} is a newly generated template variable. It replaces the hole HH by the template polynomial p_(H)p_{H} and then translates the program to an SPTS. The translation from programs to transition systems is a standard procedure, i.e. a simple parsing exercise, and hence we skip it for brevity. At the end of this step, we have an SPTS Gamma=(V,T,L,ℓ_(0),theta_(0),ℓ_(f),theta_(f),T,I)\operatorname{SPTS} \Gamma=\left(\mathbb{V}, \mathbb{T}, \mathbb{L}, \ell_{0}, \theta_{0}, \ell_{f}, \theta_{f}, \mathcal{T}, \mathbb{I}\right). 步骤 1:创建模板并转换为 SPTS。对于草图中的每个空洞,算法生成一个模板多项式,其中引入新的模板变量。具体来说,设空洞的形式为 H=( bar(V),d)H=(\overline{\mathbb{V}}, d) 。这对应于程序员希望该空洞被填充为一个在集合 bar(V)subeV\overline{\mathbb{V}} \subseteq \mathbb{V} 上次数最多为 dd 的多项式的情况。算法首先生成所有在 bar(V)\overline{\mathbb{V}} 上次数最多为 dd 的单项式 m_(i)m_{i} 。然后它创建一个包含所有这些单项式的模板多项式,形式为 p_(H):=sum_(i)t_(i)*m_(i)p_{H}:=\sum_{i} t_{i} \cdot m_{i} ,其中每个 t_(i)t_{i} 都是新生成的模板变量。它用模板多项式 p_(H)p_{H} 替换空洞 HH ,然后将程序转换为 SPTS。从程序到转换系统的转换是一个标准过程,即一个简单的解析练习,因此我们为简洁起见省略此步骤。此步骤结束时,我们得到了一个 SPTS Gamma=(V,T,L,ℓ_(0),theta_(0),ℓ_(f),theta_(f),T,I)\operatorname{SPTS} \Gamma=\left(\mathbb{V}, \mathbb{T}, \mathbb{L}, \ell_{0}, \theta_{0}, \ell_{f}, \theta_{f}, \mathcal{T}, \mathbb{I}\right) 。
Example 3.1. Consider the sketch of Figure 1. The first hole in the invariant of line 5 should be filled by a polynomial of degree at most 2 over the variables {i,s}\{i, s\}. Hence, the algorithm generates the following template for this hole: 示例 3.1。考虑图 1 的草图。第 5 行不变式中的第一个空洞应由一个在变量 {i,s}\{i, s\} 上次数最多为 2 的多项式填充。因此,算法为该空洞生成以下模板:
Note that all the t_(i)t_{i} 's are new template variables whose concrete values have to be synthesized later. It then establishes a similar template for the second hole in line 5 : 注意,所有的 t_(i)t_{i} 都是新的模板变量,其具体值需要后续合成。然后,它为第 5 行的第二个空洞建立了类似的模板:
The third hole in line 5 and the hole in line 6 should be affine expressions over {i,n}\{i, n\}, so the algorithm generates: 第 5 行的第三个空洞和第 6 行的空洞应是关于 {i,n}\{i, n\} 的仿射表达式,因此算法生成:
{:[p_(3):=t_(12)+t_(13)*i+t_(14)*n","],[p_(4):=t_(15)+t_(16)*i+t_(17)*n.]:}\begin{aligned}
& p_{3}:=t_{12}+t_{13} \cdot i+t_{14} \cdot n, \\
& p_{4}:=t_{15}+t_{16} \cdot i+t_{17} \cdot n .
\end{aligned}
Finally, the last hole (line 9) should be filled by an affine expression over {i,s}\{i, s\}. So, we have: 最后,最后一个空洞(第 9 行)应由关于 {i,s}\{i, s\} 的仿射表达式填充。因此,我们有:
p_(5):=t_(18)+t_(19)*i+t_(20)*sp_{5}:=t_{18}+t_{19} \cdot i+t_{20} \cdot s
The algorithm first replaces each ii-th hole with its corresponding template polynomial p_(i)p_{i}. It then translates the program to a transition system, leading to the SPTS of Figure 4. 算法首先用对应的模板多项式 p_(i)p_{i} 替换每个第 ii 个空洞。然后,它将程序转换为一个转换系统,得到图 4 所示的 SPTS。
Step 2: Generating Entailment Constraints. Recall that our goal is to synthesize concrete real values for the template variables t_(i)inTt_{i} \in \mathbb{T} such that our SPTS becomes an inductively valid PTS. As 步骤 2:生成蕴含约束。回想一下,我们的目标是为模板变量 t_(i)inTt_{i} \in \mathbb{T} 合成具体的实数值,使得我们的 SPTS 成为归纳有效的 PTS。正如
such, it should satisfy the initiation, consecution and finalization constraints defined in Section 2. In this step, the algorithm considers every possible basic path pi\pi and symbolically computes its transition relation and its corresponding initiation/consecution/finalization constraint. Then, the algorithm translates the constraint into an equivalent system of constraints in the following standard form: 所述,它应满足第 2 节中定义的初始化、连续性和终结性约束。在这一步,算法考虑每一个可能的基本路径 pi\pi ,并符号化地计算其转移关系及其对应的初始化/连续性/终结性约束。然后,算法将该约束转换为以下标准形式的等价约束系统:
in which ff and each f_(i)f_{i} are symbolic polynomials over (VuuV^('),T)\left(\mathbb{V} \cup \mathbb{V}^{\prime}, \mathbb{T}\right) and each operator |><|,|><|_(i)\bowtie, \bowtie_{i} is either >=\geq or >>. 其中 ff 和每个 f_(i)f_{i} 都是关于 (VuuV^('),T)\left(\mathbb{V} \cup \mathbb{V}^{\prime}, \mathbb{T}\right) 的符号多项式,每个运算符 |><|,|><|_(i)\bowtie, \bowtie_{i} 是 >=\geq 或 >> 。
Example 3.2. Consider the SPTS and cutset of Figure 4. As discussed in Example 2.2, the basic paths in this SPTS are pi_(1)=(:tau_(1),tau_(2):)\pi_{1}=\left\langle\tau_{1}, \tau_{2}\right\rangle, pi_(2)=(:tau_(4):)\pi_{2}=\left\langle\tau_{4}\right\rangle, and pi_(3)=(:tau_(3),tau_(5),tau_(6):)\pi_{3}=\left\langle\tau_{3}, \tau_{5}, \tau_{6}\right\rangle. The algorithm symbolically computes the transition relation of each basic path: 示例 3.2。考虑图 4 中的 SPTS 和割集。如示例 2.2 中所述,该 SPTS 中的基本路径为 pi_(1)=(:tau_(1),tau_(2):)\pi_{1}=\left\langle\tau_{1}, \tau_{2}\right\rangle 、 pi_(2)=(:tau_(4):)\pi_{2}=\left\langle\tau_{4}\right\rangle 和 pi_(3)=(:tau_(3),tau_(5),tau_(6):)\pi_{3}=\left\langle\tau_{3}, \tau_{5}, \tau_{6}\right\rangle 。算法符号化地计算每条基本路径的转移关系:
It then has to symbolically compute the inductive validity constraints. For pi_(1)\pi_{1}, we have the following initiation constraint: 然后它必须符号化地计算归纳有效性约束。对于 pi_(1)\pi_{1} ,我们有以下启动约束:
" val "|==theta_(0)^^(val,val^('))|==rho_(pi_(1))=>val^(')|==I(6)^(').\text { val } \models \theta_{0} \wedge\left(v a l, v a l^{\prime}\right) \models \rho_{\pi_{1}} \Rightarrow v a l^{\prime} \models \mathbb{I}(6)^{\prime} .
The algorithm symbolically computes and expands this constraint and obtains: 算法符号化地计算并展开该约束,得到:
Note that this constraint should hold for any valuation of VuuV^(')\mathbb{V} \cup \mathbb{V}^{\prime}. At this point, since we know n^(')=nn^{\prime}=n and i^(')=s^(')=0i^{\prime}=s^{\prime}=0, we can further simplify the constraint to 注意该约束应对 VuuV^(')\mathbb{V} \cup \mathbb{V}^{\prime} 的任何赋值成立。此时,由于我们知道 n^(')=nn^{\prime}=n 和 i^(')=s^(')=0i^{\prime}=s^{\prime}=0 ,可以进一步简化该约束为
hence eliminating several variables and obtaining a much simpler but equivalent constraint. Our implementation in Section 5 applies such sound heuristics for simplifying the constraints. However, the constraint is still not in the standard form of (1) since there are several inequalities on the right-hand-side. The algorithm rewrites this constraint as the following equivalent set of constraints of the standard form (1): 从而消除若干变量,得到一个更简单但等价的约束。我们在第 5 节的实现中应用了此类合理的启发式方法来简化约束。然而,该约束仍未处于标准形式(1),因为右侧存在多个不等式。算法将该约束重写为以下等价的标准形式(1)约束集合:
{:[n >= 1=>t_(0) >= 0],[n >= 1=>t_(6) >= 0],[n >= 1=>t_(12)+t_(14)*n >= 0]:}\begin{gathered}
n \geq 1 \Rightarrow t_{0} \geq 0 \\
n \geq 1 \Rightarrow t_{6} \geq 0 \\
n \geq 1 \Rightarrow t_{12}+t_{14} \cdot n \geq 0
\end{gathered}
Let us now consider pi_(2)\pi_{2}. We need to generate a finalization constraint in this case. The algorithm symbolically computes 现在让我们考虑 pi_(2)\pi_{2} 。在这种情况下,我们需要生成一个终结约束。算法符号化地计算
and then expands it and rewrites it as an equivalent set of standard constraints just as in the previous case. Finally, for pi_(3)\pi_{3}, which starts and ends at the cutpoint 6 , the algorithm writes a consecution constraint: 然后将其展开并重写为一组等价的标准约束,就像前面的情况一样。最后,对于从切点 6 开始并结束的 pi_(3)\pi_{3} ,算法写出一个连续性约束:
As above, the constraint will be simplified and translated to an equivalent set of standard constraints. 如上所述,该约束将被简化并转换为一组等价的标准约束。
Step 3: Eliminating Program Variables and Reduction to QPQ P. We start by providing some intuition for this step. Let V={v_(1),dots,v_(m)}\mathbb{V}=\left\{v_{1}, \ldots, v_{m}\right\} be our program variables and T={t_(1),dots,t_(m^('))}\mathbb{T}=\left\{t_{1}, \ldots, t_{m^{\prime}}\right\} the template variables introduced in Step 1 above. By the end of the previous step, we have a set of standard constraints of form (1). Let the constraints be kappa_(1),kappa_(2),dots,kappa_(u)\kappa_{1}, \kappa_{2}, \ldots, \kappa_{u}. Our problem is now equivalent to finding concrete real values t_(i)^(**)inRt_{i}^{*} \in \mathbb{R} for each template variable t_(i)inTt_{i} \in \mathbb{T} such that the following formula is satisfied: 步骤 3:消除程序变量并归约到 QPQ P 。我们首先为这一步骤提供一些直观理解。设 V={v_(1),dots,v_(m)}\mathbb{V}=\left\{v_{1}, \ldots, v_{m}\right\} 为我们的程序变量, T={t_(1),dots,t_(m^('))}\mathbb{T}=\left\{t_{1}, \ldots, t_{m^{\prime}}\right\} 为在上述步骤 1 中引入的模板变量。到上一步结束时,我们已经有了一组形式为(1)的标准约束。设这些约束为 kappa_(1),kappa_(2),dots,kappa_(u)\kappa_{1}, \kappa_{2}, \ldots, \kappa_{u} 。我们的问题现在等价于为每个模板变量 t_(i)inTt_{i} \in \mathbb{T} 找到具体的实数值 t_(i)^(**)inRt_{i}^{*} \in \mathbb{R} ,使得以下公式成立:
AA" val "inR^(V)quad" val "|==(^^^_(j=1)^(u)kappa_(j)[t_(i)larrt_(i)^(**)]_(i=1)^(m^('))),\forall \text { val } \in \mathbb{R}^{\mathbb{V}} \quad \text { val } \vDash\left(\bigwedge_{j=1}^{u} \kappa_{j}\left[t_{i} \leftarrow t_{i}^{*}\right]_{i=1}^{m^{\prime}}\right),
where kappa_(j)[t_(i)larrt_(i)^(**)]_(i=1)^(m^('))\kappa_{j}\left[t_{i} \leftarrow t_{i}^{*}\right]_{i=1}^{m^{\prime}} is the formula kappa_(j)\kappa_{j} in which each t_(i)t_{i} is replaced by t_(i)^(**)t_{i}^{*}. This is not an easy problem in general (See Section 4), but the fact that all kappa_(i)\kappa_{i} constraints are in the standard form of (1) can be exploited for a reduction to quadratic programming (QP). This step requires mathematical details that will be presented in Section 3.2. At this point, we consider a simple sound algorithm that captures the main intuition of this step and then fill in the details to make it semi-complete in Section 3.3. 其中 kappa_(j)[t_(i)larrt_(i)^(**)]_(i=1)^(m^('))\kappa_{j}\left[t_{i} \leftarrow t_{i}^{*}\right]_{i=1}^{m^{\prime}} 是公式 kappa_(j)\kappa_{j} ,其中每个 t_(i)t_{i} 都被替换为 t_(i)^(**)t_{i}^{*} 。这通常不是一个简单的问题(参见第 4 节),但所有 kappa_(i)\kappa_{i} 约束都采用标准形式(1)的事实可以被利用来归约为二次规划(QP)。这一步需要数学细节,将在第 3.2 节中介绍。此时,我们考虑一个简单且健全的算法,它捕捉了这一步的主要直觉,然后在第 3.3 节中补充细节使其半完备。
Consider a standard constraint kappa_(i)\kappa_{i} of the following form: 考虑以下形式的标准约束 kappa_(i)\kappa_{i} :
As mentioned above, this constraint should hold over all valuations. So, intuitively, we would like to guarantee that whenever all polynomials f_(1),f_(2),dots,f_(r)f_{1}, f_{2}, \ldots, f_{r} are non-negative, then so is ff. A simple sound solution is to try to write ff as a combination of the f_(i)f_{i} 's in the following form: 如上所述,该约束应对所有赋值成立。因此,直观上,我们希望保证只要所有多项式 f_(1),f_(2),dots,f_(r)f_{1}, f_{2}, \ldots, f_{r} 非负,那么 ff 也非负。一个简单且健全的解决方案是尝试将 ff 写成以下形式的 f_(i)f_{i} 的组合:
where each lambda_(i)\lambda_{i} is a new non-negative real variable. We write Lambda\Lambda as a shorthand for {lambda_(0),dots,lambda_(r)}\left\{\lambda_{0}, \ldots, \lambda_{r}\right\}. This is clearly sound, since whenever the f_(i)f_{i} 's are non-negative at a given valuation, then so is every combination of them with non-negative coefficients. Indeed, we can go one step further and let each lambda_(i)\lambda_{i} be an always-non-negative polynomial, instead of a real constant, and the exact same argument will go through. As we will see, this idea can lead to a semi-complete algorithm. 其中每个 lambda_(i)\lambda_{i} 是一个新的非负实数变量。我们将 Lambda\Lambda 写作 {lambda_(0),dots,lambda_(r)}\left\{\lambda_{0}, \ldots, \lambda_{r}\right\} 的简写。这显然是合理的,因为只要在给定赋值下 f_(i)f_{i} 是非负的,那么它们与非负系数的任意组合也都是非负的。实际上,我们可以更进一步,让每个 lambda_(i)\lambda_{i} 都是一个始终非负的多项式,而不是一个实数常数,同样的论证依然成立。正如我们将看到的,这个想法可以导出一个半完备的算法。
We can now present Step 3 of the algorithm. In this step, the algorithm considers each standard constraint kappa_(i)\kappa_{i} and symbolically computes the equation (4) for it. Note that both sides of (4) are symbolic polynomials over ( V,Tuu Lambda\mathbb{V}, \mathbb{T} \cup \Lambda ). In particular, they are polynomials over V\mathbb{V}. However, two polynomials are equal if and only if they have equal coefficients for every monomial. Hence, the algorithm equates the corresponding coefficients on the left and right-hand sides of (4) and rewrites it as a system of quadratic equalities over Tuu Lambda\mathbb{T} \cup \Lambda. 现在我们可以介绍算法的第 3 步。在这一步中,算法考虑每个标准约束 kappa_(i)\kappa_{i} 并符号化地计算其对应的等式(4)。注意,(4) 的两边都是关于 ( V,Tuu Lambda\mathbb{V}, \mathbb{T} \cup \Lambda ) 的符号多项式。特别地,它们是关于 V\mathbb{V} 的多项式。然而,两个多项式相等当且仅当它们对每个单项式的系数相等。因此,算法将(4)左右两边对应的系数相等,并将其重写为关于 Tuu Lambda\mathbb{T} \cup \Lambda 的一组二次等式系统。
Example 3.3. Consider the standard constraint n-1 >= 0=>t_(12)+t_(14)*n >= 0n-1 \geq 0 \Rightarrow t_{12}+t_{14} \cdot n \geq 0 that was generated in Step 2 above (Example 3.2). The algorithm symbolically computes (4) and obtains 例 3.3. 考虑上面第 2 步中生成的标准约束 n-1 >= 0=>t_(12)+t_(14)*n >= 0n-1 \geq 0 \Rightarrow t_{12}+t_{14} \cdot n \geq 0 (例 3.2)。算法符号化地计算(4)并得到
Since both sides of this equality are polynomials over nn, in order for the equality to hold, they should have the same constant factor and the same coefficient for nn, so the algorithm obtains the following constraints: 由于该等式两边都是关于 nn 的多项式,为了使等式成立,它们应具有相同的常数项和 nn 的系数,因此算法得到以下约束条件:
This is a quadratic programming ( QP ) instance in which none of the program variables, e.g. nn, appear. The algorithm translates other standard constraints to QP in a similar manner and combines them conjunctively. 这是一个二次规划(QP)实例,其中没有任何程序变量,例如 nn 出现。算法以类似方式将其他标准约束转换为 QP,并将它们合取组合。
Step 4: Constraint Solving. The algorithm passes the QP instance generated in the previous step to an SMT solver or a numerical solver. If the solver fails to find a solution, then the algorithm fails, too. Otherwise, the solver provides values for all t_(i)t_{i} and lambda_(i)\lambda_{i} variables. The algorithm plugs the values found for t_(i)t_{i} 's back into the templates of Step 1, which successfully leads to an inductively valid PTS or equivalenty to a valid synthesized program that satisfies the desired specification. 步骤 4:约束求解。算法将上一步生成的 QP 实例传递给 SMT 求解器或数值求解器。如果求解器未能找到解,则算法也失败。否则,求解器会为所有 t_(i)t_{i} 和 lambda_(i)\lambda_{i} 变量提供数值。算法将为 t_(i)t_{i} 找到的数值代入步骤 1 的模板中,从而成功得到一个归纳有效的 PTS,或等价于满足期望规范的有效合成程序。
Example 3.4. Given the sketch of Figure 1 as input, the synthesized program of Figure 2 is obtained as one of the solutions of the QP instance in Step 4. However, the solution is not necessarily unique, and our algorithm might find a different solution based on the values found by the external solver. 示例 3.4. 以图 1 的草图作为输入,图 2 中的合成程序是步骤 4 中 QP 实例的一个解。然而,该解不一定是唯一的,我们的算法可能会根据外部求解器找到的值,得到不同的解。
3.2 Mathematical Toolkit 3.2 数学工具包
In Section 3.1 above, we provided an overview of our algorithm. However, the details of Step 3, i.e. the reduction to QP , were not presented since they depend on certain mathematical prerequisites. In this section, we provide the mathematical tools and theorems that are crucial for this step of the algorithm. We first recall some notation and classical definitions. Then, we present several theorems from polyhedral and real algebraic geometry. Finally, we obtain tailor-made versions of these theorems in a format that can be used in Step 3 of our algorithm above. We refer to [Bochnak et al. 2013; Hartshorne 2013] for a more detailed treatment of these theorems. 在上述第 3.1 节中,我们提供了算法的概述。然而,第 3 步的细节,即归约到 QP,并未展示,因为它们依赖于某些数学前提条件。在本节中,我们提供对该算法步骤至关重要的数学工具和定理。我们首先回顾一些符号和经典定义。然后,介绍多面体几何和实代数几何中的若干定理。最后,我们获得这些定理的定制版本,以便在上述算法的第 3 步中使用。关于这些定理的更详细论述,请参见 [Bochnak et al. 2013; Hartshorne 2013]。
Sums of Squares. A polynomial h inR[x_(1),dots,x_(n)]h \in \mathbb{R}\left[x_{1}, \ldots, x_{n}\right] is a sum of squares (SOS) iff there exist k >= 1k \geq 1 and polynomials g_(1),dots,g_(k)inR[x_(1),dots,x_(n)]g_{1}, \ldots, g_{k} \in \mathbb{R}\left[x_{1}, \ldots, x_{n}\right] such that h=sum_(i=1)^(k)g_(i)^(2)h=\sum_{i=1}^{k} g_{i}^{2}. 平方和。多项式 h inR[x_(1),dots,x_(n)]h \in \mathbb{R}\left[x_{1}, \ldots, x_{n}\right] 是平方和(SOS)当且仅当存在 k >= 1k \geq 1 和多项式 g_(1),dots,g_(k)inR[x_(1),dots,x_(n)]g_{1}, \ldots, g_{k} \in \mathbb{R}\left[x_{1}, \ldots, x_{n}\right] ,使得 h=sum_(i=1)^(k)g_(i)^(2)h=\sum_{i=1}^{k} g_{i}^{2} 。
Strong Positivity. Given a set X subeR^(n)X \subseteq \mathbb{R}^{n} and a polynomial g inR[x_(1),dots,x_(n)]g \in \mathbb{R}\left[x_{1}, \ldots, x_{n}\right], we say that gg is strongly positive over X if i n f_(x in X)g(x) > 0\inf _{x \in X} g(x)>0. We write this as X|==g≫0X \vDash g \gg 0. 强正性。给定集合 X subeR^(n)X \subseteq \mathbb{R}^{n} 和多项式 g inR[x_(1),dots,x_(n)]g \in \mathbb{R}\left[x_{1}, \ldots, x_{n}\right] ,如果 gg 在 X 上是强正的,当且仅当 i n f_(x in X)g(x) > 0\inf _{x \in X} g(x)>0 。我们将其记作 X|==g≫0X \vDash g \gg 0 。
Notation. Let Phi={g_(1)|><|_(1)0,dots,g_(k)|><|_(k)0}\Phi=\left\{g_{1} \bowtie_{1} 0, \ldots, g_{k} \bowtie_{k} 0\right\} be a set of polynomial inequalities where |><|_(i)in{ >= , > }\bowtie_{i} \in\{\geq,>\} and g_(i)inR[x_(1),dots,x_(n)]g_{i} \in \mathbb{R}\left[x_{1}, \ldots, x_{n}\right]. We define SAT(Phi)\operatorname{SAT}(\Phi) as the set of all real valuations val over the variables {x_(1),dots,x_(n)}\left\{x_{1}, \ldots, x_{n}\right\} that satisfy Phi\Phi. More formally, SAT(Phi)={:}\operatorname{SAT}(\Phi)=\left\{\right. val inR^(n)∣^^^_(i=1)^(k)\in \mathbb{R}^{n} \mid \bigwedge_{i=1}^{k} val {:|==(g_(i)|><|_(i)0)}\left.\vDash\left(g_{i} \bowtie_{i} 0\right)\right\}. 符号表示。设 Phi={g_(1)|><|_(1)0,dots,g_(k)|><|_(k)0}\Phi=\left\{g_{1} \bowtie_{1} 0, \ldots, g_{k} \bowtie_{k} 0\right\} 是一组多项式不等式,其中 |><|_(i)in{ >= , > }\bowtie_{i} \in\{\geq,>\} 和 g_(i)inR[x_(1),dots,x_(n)]g_{i} \in \mathbb{R}\left[x_{1}, \ldots, x_{n}\right] 。我们定义 SAT(Phi)\operatorname{SAT}(\Phi) 为所有实数赋值 val 的集合,这些赋值在变量 {x_(1),dots,x_(n)}\left\{x_{1}, \ldots, x_{n}\right\} 上满足 Phi\Phi 。更正式地, SAT(Phi)={:}\operatorname{SAT}(\Phi)=\left\{\right. val inR^(n)∣^^^_(i=1)^(k)\in \mathbb{R}^{n} \mid \bigwedge_{i=1}^{k} val {:|==(g_(i)|><|_(i)0)}\left.\vDash\left(g_{i} \bowtie_{i} 0\right)\right\} 。
Closure. Given a set X subeR^(n)X \subseteq \mathbb{R}^{n}, we define bar(X)\bar{X} to be the closure of XX with respect to the Euclidean topology of R^(n)\mathbb{R}^{n}. For a set Phi\Phi of polynomial inequalities, we define bar(Phi)\bar{\Phi} as the system of polynomial inequalities obtained from Phi\Phi by replacing every strict ineqaulity with its non-strict counterpart. 闭包。给定集合 X subeR^(n)X \subseteq \mathbb{R}^{n} ,我们定义 bar(X)\bar{X} 为 XX 关于 R^(n)\mathbb{R}^{n} 的欧几里得拓扑的闭包。对于一组多项式不等式 Phi\Phi ,我们定义 bar(Phi)\bar{\Phi} 为由 Phi\Phi 得到的多项式不等式系统,其中将每个严格不等式替换为其非严格对应式。
We are now ready to present the main mathematical theorems that will be used in our work. Our presentation follows that of [Goharshady 2020, Section 2.6], which also contains proofs of corollaries that are not proven here. 我们现在准备介绍将在本工作中使用的主要数学定理。我们的陈述遵循 [Goharshady 2020,第 2.6 节],该文献还包含此处未证明的推论证明。
Theorem 3.5 (Farkas’ Lemma [Farkas 1902]). Consider a set V={x_(1),dots,x_(r)}V=\left\{x_{1}, \ldots, x_{r}\right\} of real-valued variables and the following system Phi\Phi of equations over VV : 定理 3.5(Farkas 引理 [Farkas 1902])。考虑一组实值变量 V={x_(1),dots,x_(r)}V=\left\{x_{1}, \ldots, x_{r}\right\} 及以下关于 VV 的方程组 Phi\Phi :
if and only if psi\psi can be written as non-negative linear combination of the inequalities in Phi\Phi and the trivial inequality 1 >= 01 \geq 0, i.e. if there exist non-negative real numbers y_(0),dots,y_(m)y_{0}, \ldots, y_{m} such that 当且仅当 psi\psi 可以表示为 Phi\Phi 中不等式和平凡不等式 1 >= 01 \geq 0 的非负线性组合,即存在非负实数 y_(0),dots,y_(m)y_{0}, \ldots, y_{m} 使得
Moreover, Phi\Phi is unsatisfiable if and only if -1 >= 0-1 \geq 0 can be derived as above. 此外, Phi\Phi 不可满足当且仅当 -1 >= 0-1 \geq 0 可以如上推导得到。
The importance of Farkas’ Lemma for us is that if we have a standard constraint of form (1) and if the constraint includes only linear/affine inequalities, then we can use this lemma in Step 3 of our algorithm to reduce the standard constraint to QP, just as we did in Section 3.1. Moreover, Farkas’ Lemma guarantees that this approach is not only sound but also complete. A corner case that we have to consider is when Phi\Phi is itself unsatisfiable and thus Phi=>psi\Phi \Rightarrow \psi holds vacuously. Fortunately, Farkas’ Lemma also provides a criterion for unsatisfiability. In practice, we work with the following corollary of Theorem 3.5 which can also handle strict inequalities. Farkas 引理对我们来说的重要性在于,如果我们有一个形式为(1)的标准约束,并且该约束仅包含线性/仿射不等式,那么我们可以在算法的第 3 步中使用该引理,将标准约束简化为二次规划(QP),正如我们在第 3.1 节中所做的那样。此外,Farkas 引理保证了这种方法不仅是正确的,而且是完备的。我们必须考虑的一个特殊情况是当 Phi\Phi 本身不可满足,因此 Phi=>psi\Phi \Rightarrow \psi 在逻辑上成立。幸运的是,Farkas 引理还提供了不可满足性的判据。在实际操作中,我们使用定理 3.5 的以下推论,该推论也能处理严格不等式。
Corollary 3.6. Consider a set V={x_(1),dots,x_(r)}V=\left\{x_{1}, \ldots, x_{r}\right\} of real-valued variables and the following system of equations over VV : 推论 3.6。考虑一组实值变量 V={x_(1),dots,x_(r)}V=\left\{x_{1}, \ldots, x_{r}\right\} 及其上的以下方程组 VV :
where |><|_(i)in{ > , >= }\bowtie_{i} \in\{>, \geq\} for all 1 <= i <= m1 \leq i \leq m. When Phi\Phi is satisfiable, it entails a linear inequality 其中对于所有 1 <= i <= m1 \leq i \leq m , |><|_(i)in{ > , >= }\bowtie_{i} \in\{>, \geq\} 。当 Phi\Phi 可满足时,它蕴含一个线性不等式
with ⋈∈{ > , >= }\bowtie \in\{>, \geq\}, if and only if psi\psi can be written as non-negative linear combination of inequalities in Phi\Phi and the trivial inequality 1 > 01>0. Note that if psi\psi is strict, then at least one of the strict inequalities should appear with a non-zero coefficient in the linear combination. Moreover, Phi\Phi is unsatisfiable if and only if either -1 >= 0-1 \geq 0 or 0 > 00>0 can be derived as above. 当且仅当 psi\psi 可以表示为 Phi\Phi 中不等式和平凡不等式 1 > 01>0 的非负线性组合时,成立 ⋈∈{ > , >= }\bowtie \in\{>, \geq\} 。注意,如果 psi\psi 是严格不等式,则在线性组合中至少应有一个严格不等式的系数非零。此外,当且仅当可以如上推导出 -1 >= 0-1 \geq 0 或 0 > 00>0 时, Phi\Phi 是不可满足的。
We now consider extensions of Farkas’ Lemma which can help us handle non-linear standard constraints in Step 3. The first extension is Handelman’s theorem, which can be applied when the inequalities on the left hand side of (1) are linear/affine, but the right hand side is a polynomial of arbitrary degree. To present the theorem, we first need the concept of monoids. 我们现在考虑 Farkas 引理的扩展,这些扩展可以帮助我们在步骤 3 中处理非线性标准约束。第一个扩展是 Handelman 定理,当(1)左侧的不等式是线性/仿射的,而右侧是任意次数的多项式时,可以应用该定理。为了介绍该定理,我们首先需要单子(monoid)的概念。
Monoid. Consider a set V={x_(1),dotsx_(r)}V=\left\{x_{1}, \ldots x_{r}\right\} of real-valued variables and the following system of linear inequalities over VV : 单子。考虑一组实值变量 V={x_(1),dotsx_(r)}V=\left\{x_{1}, \ldots x_{r}\right\} 以及以下关于 VV 的线性不等式系统:
where |><|_(i)in{ > , >= }\bowtie_{i} \in\{>, \geq\} for all 1 <= i <= m1 \leq i \leq m. Let g_(i)g_{i} be the left hand side of the ii-th inequality, i.e. g_(i)(x_(1),dots,x_(r)):=a_(i,0)+a_(i,1)*x_(1)+dotsa_(i,r)*x_(r)g_{i}\left(x_{1}, \ldots, x_{r}\right):=a_{i, 0}+a_{i, 1} \cdot x_{1}+\ldots a_{i, r} \cdot x_{r}. The monoid of Phi\Phi is defined as: 其中对于所有 1 <= i <= m1 \leq i \leq m ,有 |><|_(i)in{ > , >= }\bowtie_{i} \in\{>, \geq\} 。令 g_(i)g_{i} 为第 ii 个不等式的左侧,即 g_(i)(x_(1),dots,x_(r)):=a_(i,0)+a_(i,1)*x_(1)+dotsa_(i,r)*x_(r)g_{i}\left(x_{1}, \ldots, x_{r}\right):=a_{i, 0}+a_{i, 1} \cdot x_{1}+\ldots a_{i, r} \cdot x_{r} 。 Phi\Phi 的单子定义为:
Monoid(Phi):={prod_(i=1)^(m)g_(i)^(k_(i))∣m inN^^AA ik_(i)inNuu{0}}\operatorname{Monoid}(\Phi):=\left\{\prod_{i=1}^{m} g_{i}^{k_{i}} \mid m \in \mathbb{N} \wedge \forall i k_{i} \in \mathbb{N} \cup\{0\}\right\}
In other words, the monoid contains all polynomials that can be obtained as a multiplication of the g_(i)g_{i} 's. Note that 1in Monoid(Phi)1 \in \operatorname{Monoid}(\Phi). We define Monoid_(d)(Phi)\operatorname{Monoid}_{d}(\Phi) as the subset of polynomials in Monoid(Phi)\operatorname{Monoid}(\Phi) of degree at most dd. 换句话说,单元包含所有可以通过乘法得到的 g_(i)g_{i} 的多项式。注意 1in Monoid(Phi)1 \in \operatorname{Monoid}(\Phi) 。我们定义 Monoid_(d)(Phi)\operatorname{Monoid}_{d}(\Phi) 为 Monoid(Phi)\operatorname{Monoid}(\Phi) 中次数最多为 dd 的多项式的子集。
Theorem 3.7 (Handelman’s Theorem [Handelman 1988]). Consider a set V={x_(1),dots,x_(r)}V=\left\{x_{1}, \ldots, x_{r}\right\} of real-valued variables and the following system of equations over VV : 定理 3.7(Handelman 定理 [Handelman 1988])。考虑一组实值变量 V={x_(1),dots,x_(r)}V=\left\{x_{1}, \ldots, x_{r}\right\} 及以下在 VV 上的方程组:
The intuition here is that if every inequality in Phi\Phi holds, then all the LHS expressions in Phi\Phi are non-negative and hence any multiplication h_(i)h_{i} of them is also non-negative. As in the case of Farkas’ Lemma, Handelman’s theorem shows that this approach is not only sound but also complete. We also need a variant that can handle strict inequalities in Phi\Phi. 这里的直觉是,如果 Phi\Phi 中的每个不等式都成立,那么 Phi\Phi 中所有左侧表达式都是非负的,因此它们的任意乘积 h_(i)h_{i} 也都是非负的。与 Farkas 引理的情况类似,Handelman 定理表明这种方法不仅是正确的,而且是完备的。我们还需要一个变体来处理 Phi\Phi 中的严格不等式。
Corollary 3.8. Consider a set V={x_(1),dots,x_(r)}V=\left\{x_{1}, \ldots, x_{r}\right\} of real-valued variables and the following system of equations over VV : 推论 3.8. 考虑一组实值变量 V={x_(1),dots,x_(r)}V=\left\{x_{1}, \ldots, x_{r}\right\} 以及以下在 VV 上的方程组:
in which |><|_(i)in{ > , >= }\bowtie_{i} \in\{>, \geq\} for all 1 <= i <= m1 \leq i \leq m. If Phi\Phi is satisfiable and SAT(Phi)\operatorname{SAT}(\Phi) is bounded, then Phi\Phi entails a strong polynomial inequality g≫0g \gg 0 if and only if there exist constants y_(0)in(0,oo)y_{0} \in(0, \infty), and y_(1),dots,y_(u)in[0,oo)y_{1}, \ldots, y_{u} \in[0, \infty), and polynomials h_(1),dots,h_(u)in Monoid(Phi)h_{1}, \ldots, h_{u} \in \operatorname{Monoid}(\Phi) such that: 其中对所有 1 <= i <= m1 \leq i \leq m , |><|_(i)in{ > , >= }\bowtie_{i} \in\{>, \geq\} 。如果 Phi\Phi 可满足且 SAT(Phi)\operatorname{SAT}(\Phi) 有界,则当且仅当存在常数 y_(0)in(0,oo)y_{0} \in(0, \infty) 和 y_(1),dots,y_(u)in[0,oo)y_{1}, \ldots, y_{u} \in[0, \infty) 以及多项式 h_(1),dots,h_(u)in Monoid(Phi)h_{1}, \ldots, h_{u} \in \operatorname{Monoid}(\Phi) 使得:
Corollary 3.8 above can handle a wider family of standard constraints than Corollary 3.6. However, it is also more expensive, since we now need to generate one new variable y_(i)y_{i} for every polynomial in Monoid _(d)(Phi)_{d}(\Phi) instead of Phi\Phi itself. Moreover, there is no bound dd in the theorem itself, so introducing dd would lead to semi-completeness instead of completeness, i.e. the approach would be complete only if a large enough value of dd is used. As such, in cases where both sides of (1) are linear, Corollary 3.6 is preferable. We now consider a more expressive theorem that can handle polynomials on boths sides of (1). 上述推论 3.8 能处理比推论 3.6 更广泛的标准约束族。然而,它的计算代价也更高,因为我们现在需要为 Monoid _(d)(Phi)_{d}(\Phi) 中的每个多项式生成一个新的变量 y_(i)y_{i} ,而不是仅为 Phi\Phi 本身生成。此外,定理本身中没有 dd 的界限,因此引入 dd 会导致半完备性而非完备性,即该方法只有在使用足够大的 dd 值时才是完备的。因此,在 (1) 两边均为线性的情况下,推论 3.6 更为合适。接下来我们考虑一个更具表达力的定理,它可以处理 (1) 两边的多项式。
Theorem 3.9 (Putinar’s Positivstellensatz [Putinar 1993]). Given a finite collection of polynomials {g,g_(1),dots,g_(k)}inR[x_(1),dots,x_(n)]\left\{g, g_{1}, \ldots, g_{k}\right\} \in \mathbb{R}\left[x_{1}, \ldots, x_{n}\right], let Phi\Phi be the set of inequalities defined as 定理 3.9(Putinar 的 Positivstellensatz [Putinar 1993])。给定有限集合的多项式 {g,g_(1),dots,g_(k)}inR[x_(1),dots,x_(n)]\left\{g, g_{1}, \ldots, g_{k}\right\} \in \mathbb{R}\left[x_{1}, \ldots, x_{n}\right] ,令 Phi\Phi 为定义如下的不等式集合:
If Phi\Phi entails the polynomial inequality g > 0g>0 and there exist some ii such that SAT(g_(i) >= 0)\operatorname{SAT}\left(g_{i} \geq 0\right) is compact, then there exist polynomials h_(0),dots,h_(k)inR[x_(1),dots,x_(n)]h_{0}, \ldots, h_{k} \in \mathbb{R}\left[x_{1}, \ldots, x_{n}\right] such that 如果 Phi\Phi 蕴含多项式不等式 g > 0g>0 ,且存在某些 ii 使得 SAT(g_(i) >= 0)\operatorname{SAT}\left(g_{i} \geq 0\right) 是紧致的,那么存在多项式 h_(0),dots,h_(k)inR[x_(1),dots,x_(n)]h_{0}, \ldots, h_{k} \in \mathbb{R}\left[x_{1}, \ldots, x_{n}\right] 使得
and every h_(i)h_{i} is a sum of squares. Moreover, Phi\Phi is unsatisfiable if and only if -1 > 0-1>0 can be obtained as above, i.e. with g=-1g=-1. 且每个 h_(i)h_{i} 都是平方和。此外, Phi\Phi 不可满足当且仅当 -1 > 0-1>0 可以如上获得,即满足 g=-1g=-1 。
As in the cases of Farkas and Handelman, we need a variant of of Theorem 3.9 that can handle strict inequalities in Phi\Phi. 与 Farkas 和 Handelman 的情况类似,我们需要定理 3.9 的一个变体,以处理 Phi\Phi 中的严格不等式。
Corollary 3.10. Consider a finite collection of polynomials {g,g_(1),dots,g_(k)}inR[x_(1),dots,x_(n)]\left\{g, g_{1}, \ldots, g_{k}\right\} \in \mathbb{R}\left[x_{1}, \ldots, x_{n}\right] and let 推论 3.10。考虑有限集合的多项式 {g,g_(1),dots,g_(k)}inR[x_(1),dots,x_(n)]\left\{g, g_{1}, \ldots, g_{k}\right\} \in \mathbb{R}\left[x_{1}, \ldots, x_{n}\right] ,并令
where |><|_(i)in{ > , >= }\bowtie_{i} \in\{>, \geq\} for all 1 <= i <= k1 \leq i \leq k. Assume that there exist some ii such that SAT(g_(i) >= 0)\operatorname{SAT}\left(g_{i} \geq 0\right) is compact or equivalently SAT(g_(i)|><|_(i)0)\operatorname{SAT}\left(g_{i} \bowtie_{i} 0\right) is bounded. If Phi\Phi is satisfiable, then it entails the strong polynomial inequality g≫0g \gg 0, iff there exists a constant y_(0)in(0,oo)y_{0} \in(0, \infty) and polynomials h_(0),dots,h_(k)inR[x_(1),dots,x_(n)]h_{0}, \ldots, h_{k} \in \mathbb{R}\left[x_{1}, \ldots, x_{n}\right] such that 其中对于所有的 1 <= i <= k1 \leq i \leq k , |><|_(i)in{ > , >= }\bowtie_{i} \in\{>, \geq\} 。假设存在一些 ii 使得 SAT(g_(i) >= 0)\operatorname{SAT}\left(g_{i} \geq 0\right) 是紧的,或者等价地 SAT(g_(i)|><|_(i)0)\operatorname{SAT}\left(g_{i} \bowtie_{i} 0\right) 是有界的。如果 Phi\Phi 是可满足的,那么它蕴含强多项式不等式 g≫0g \gg 0 ,当且仅当存在常数 y_(0)in(0,oo)y_{0} \in(0, \infty) 和多项式 h_(0),dots,h_(k)inR[x_(1),dots,x_(n)]h_{0}, \ldots, h_{k} \in \mathbb{R}\left[x_{1}, \ldots, x_{n}\right] 使得
and every h_(i)h_{i} is a sum of squares. 且每个 h_(i)h_{i} 都是平方和。
Trying to use the corollary above for handling standard constraints of form (1) in Step 3 of our algorithm leads to two problems: (i) we also need a criterion for unsatisfiability of Phi\Phi to handle the cases where Phi=>psi\Phi \Rightarrow \psi holds vacuously, and (ii) in our QP, we should somehow express the property that every h_(i)h_{i} is a sum of squares. We now show how each of these challenges can be handled. To handle (i), we need another classical theorem from real algebraic geometry. 尝试使用上述推论来处理我们算法第 3 步中形式为(1)的标准约束会导致两个问题:(i)我们还需要一个关于 Phi\Phi 不可满足的判据,以处理 Phi=>psi\Phi \Rightarrow \psi 空泛成立的情况;(ii)在我们的二次规划中,我们应以某种方式表达每个 h_(i)h_{i} 是平方和的性质。我们现在展示如何处理这两个挑战。为了解决(i),我们需要另一个来自实代数几何的经典定理。
Theorem 3.11 ([Bochnak et al. 2013, Corollary 4.1.8] the Real Nullstellensatz). Given polynomials g,g_(1),dots,g_(k)inR[x_(1),dots,x_(n)]g, g_{1}, \ldots, g_{k} \in \mathbb{R}\left[x_{1}, \ldots, x_{n}\right], exactly one of the following two statements holds: 定理 3.11([Bochnak 等,2013,第 4.1.8 推论] 实数 Nullstellensatz)。给定多项式 g,g_(1),dots,g_(k)inR[x_(1),dots,x_(n)]g, g_{1}, \ldots, g_{k} \in \mathbb{R}\left[x_{1}, \ldots, x_{n}\right] ,以下两种情况恰有其一成立:
There exists x inR^(n)x \in \mathbb{R}^{n}, such that g_(1)(x)=cdots=g_(k)(x)=0g_{1}(x)=\cdots=g_{k}(x)=0, but g(x)!=0g(x) \neq 0. 存在 x inR^(n)x \in \mathbb{R}^{n} ,使得 g_(1)(x)=cdots=g_(k)(x)=0g_{1}(x)=\cdots=g_{k}(x)=0 ,但 g(x)!=0g(x) \neq 0 。
There exists alpha inNuu{0}\alpha \in \mathbb{N} \cup\{0\} and polynomials h_(1),dots,h_(k)inR[x_(1),dots,x_(n)]h_{1}, \ldots, h_{k} \in \mathbb{R}\left[x_{1}, \ldots, x_{n}\right] such that sum_(i=1)^(k)h_(i)*g_(i)-h_(0)=\sum_{i=1}^{k} h_{i} \cdot g_{i}-h_{0}=g^(2*alpha)g^{2 \cdot \alpha} and h_(0)h_{0} is a sum of squares. 存在 alpha inNuu{0}\alpha \in \mathbb{N} \cup\{0\} 和多项式 h_(1),dots,h_(k)inR[x_(1),dots,x_(n)]h_{1}, \ldots, h_{k} \in \mathbb{R}\left[x_{1}, \ldots, x_{n}\right] ,使得 sum_(i=1)^(k)h_(i)*g_(i)-h_(0)=\sum_{i=1}^{k} h_{i} \cdot g_{i}-h_{0}=g^(2*alpha)g^{2 \cdot \alpha} 且 h_(0)h_{0} 是平方和。
We now combine the Real Nullstellensatz with Putinar’s Postivstellensatz to obtain a criterion for unsatisfiability of Phi\Phi. 我们现在将实数 Nullstellensatz 与 Putinar 的 Positivstellensatz 结合起来,以获得 Phi\Phi 不满足性的判据。
Theorem 3.12. Consider a finite collection of polynomials {g_(1),dots,g_(k)}inR[x_(1),dots,x_(n)]\left\{g_{1}, \ldots, g_{k}\right\} \in \mathbb{R}\left[x_{1}, \ldots, x_{n}\right] and the following system of inequalities: 定理 3.12。考虑有限集合的多项式 {g_(1),dots,g_(k)}inR[x_(1),dots,x_(n)]\left\{g_{1}, \ldots, g_{k}\right\} \in \mathbb{R}\left[x_{1}, \ldots, x_{n}\right] 及以下不等式系统:
where |><|_(i)in{ > , >= }\bowtie_{i} \in\{>, \geq\} for all 1 <= i <= k.Phi1 \leq i \leq k . \Phi is unsatisfiable if and only if at least one of the following statements holds: 当且仅当以下至少一条陈述成立时, |><|_(i)in{ > , >= }\bowtie_{i} \in\{>, \geq\} 对所有 1 <= i <= k.Phi1 \leq i \leq k . \Phi 不可满足:
There exist a constant y_(0)in(0,oo)y_{0} \in(0, \infty) and sum of square polynomials h_(0),dots,h_(k)inR[x_(1),dots,x_(n)]h_{0}, \ldots, h_{k} \in \mathbb{R}\left[x_{1}, \ldots, x_{n}\right] such that 存在一个常数 y_(0)in(0,oo)y_{0} \in(0, \infty) 和平方和多项式 h_(0),dots,h_(k)inR[x_(1),dots,x_(n)]h_{0}, \ldots, h_{k} \in \mathbb{R}\left[x_{1}, \ldots, x_{n}\right] ,使得
where h_(0)h_{0} is a sum of squares in R[x_(1),dots,x_(n)]\mathbb{R}\left[x_{1}, \ldots, x_{n}\right]. Note that w_(1),dots,w_(k)w_{1}, \ldots, w_{k} are new variables. 其中 h_(0)h_{0} 是 R[x_(1),dots,x_(n)]\mathbb{R}\left[x_{1}, \ldots, x_{n}\right] 中的平方和。注意 w_(1),dots,w_(k)w_{1}, \ldots, w_{k} 是新变量。
Proof. First we show that if any of the two equalities (5) or (6) holds then Phi\Phi is unsatisfiable. Suppose Phi\Phi is satisfiable and pick val in SAT(Phi)\in \operatorname{SAT}(\Phi). Then, the RHS of (5) is positive at val, whereas the LHS is negative. So, (5) cannot hold. Now define tilde(g)_(i)(x_(1),dots,x_(n),w_(1),dots,w_(k)):=g_(i)(x_(1),dots,x_(n))-w_(i)^(2)\tilde{g}_{i}\left(x_{1}, \ldots, x_{n}, w_{1}, \ldots, w_{k}\right):=g_{i}\left(x_{1}, \ldots, x_{n}\right)-w_{i}^{2}. Using this definition, we can rewrite (6) as w_(j)^(4*alpha)=sum_(i=1)^(m)h_(i)* tilde(g)_(i)-h_(0)w_{j}^{4 \cdot \alpha}=\sum_{i=1}^{m} h_{i} \cdot \tilde{g}_{i}-h_{0}. Moreover, g_(j)^(2*alpha)=( tilde(g)_(j)+w_(j)^(2))^(2*alpha)g_{j}^{2 \cdot \alpha}=\left(\tilde{g}_{j}+w_{j}^{2}\right)^{2 \cdot \alpha}. Expanding the right hand side using the binomial theorem, we get g_(j)^(2*alpha)=w_(j)^(4*alpha)+h_(j)^(')* tilde(g)_(j)g_{j}^{2 \cdot \alpha}=w_{j}^{4 \cdot \alpha}+h_{j}^{\prime} \cdot \tilde{g}_{j} for some h_(j)^(')inR[x_(1),dots,x_(n),w_(1),dots,w_(k)]h_{j}^{\prime} \in \mathbb{R}\left[x_{1}, \ldots, x_{n}, w_{1}, \ldots, w_{k}\right]. Now, substituting w_(j)^(4*alpha)(6)w_{j}^{4 \cdot \alpha}(6), we get 证明。首先我们证明如果两个等式(5)或(6)中的任意一个成立,则 Phi\Phi 不可满足。假设 Phi\Phi 是可满足的,并选取 val in SAT(Phi)\in \operatorname{SAT}(\Phi) 。那么,在 val 处,等式(5)的右侧为正,而左侧为负。因此,(5)不可能成立。现在定义 tilde(g)_(i)(x_(1),dots,x_(n),w_(1),dots,w_(k)):=g_(i)(x_(1),dots,x_(n))-w_(i)^(2)\tilde{g}_{i}\left(x_{1}, \ldots, x_{n}, w_{1}, \ldots, w_{k}\right):=g_{i}\left(x_{1}, \ldots, x_{n}\right)-w_{i}^{2} 。利用此定义,我们可以将(6)重写为 w_(j)^(4*alpha)=sum_(i=1)^(m)h_(i)* tilde(g)_(i)-h_(0)w_{j}^{4 \cdot \alpha}=\sum_{i=1}^{m} h_{i} \cdot \tilde{g}_{i}-h_{0} 。此外, g_(j)^(2*alpha)=( tilde(g)_(j)+w_(j)^(2))^(2*alpha)g_{j}^{2 \cdot \alpha}=\left(\tilde{g}_{j}+w_{j}^{2}\right)^{2 \cdot \alpha} 。利用二项式定理展开右侧,我们得到 g_(j)^(2*alpha)=w_(j)^(4*alpha)+h_(j)^(')* tilde(g)_(j)g_{j}^{2 \cdot \alpha}=w_{j}^{4 \cdot \alpha}+h_{j}^{\prime} \cdot \tilde{g}_{j} ,其中 h_(j)^(')inR[x_(1),dots,x_(n),w_(1),dots,w_(k)]h_{j}^{\prime} \in \mathbb{R}\left[x_{1}, \ldots, x_{n}, w_{1}, \ldots, w_{k}\right] 。现在,代入 w_(j)^(4*alpha)(6)w_{j}^{4 \cdot \alpha}(6) ,我们得到
Let us extend valv a l, which is a valuation of {v_(1),dots,v_(n)}\left\{v_{1}, \ldots, v_{n}\right\} to a valuation val^(')v a l^{\prime} over {v_(1),dots,v_(n),w_(1),dots,w_(k)}\left\{v_{1}, \ldots, v_{n}, w_{1}, \ldots, w_{k}\right\} such that val’ |== tilde(g)_(i)(v_(1),dots,v_(n),w_(1),dots,w_(k))=0\models \tilde{g}_{i}\left(v_{1}, \ldots, v_{n}, w_{1}, \ldots, w_{k}\right)=0 for all 1 <= i <= k1 \leq i \leq k. Note that such an extension is always possible. We get a contradiction by evaluating (7) on val’ as the LHS is positive, whereas the RHS is negative. 让我们将 valv a l ,即 {v_(1),dots,v_(n)}\left\{v_{1}, \ldots, v_{n}\right\} 的一个赋值,扩展为 {v_(1),dots,v_(n),w_(1),dots,w_(k)}\left\{v_{1}, \ldots, v_{n}, w_{1}, \ldots, w_{k}\right\} 上的赋值 val^(')v a l^{\prime} ,使得对于所有 1 <= i <= k1 \leq i \leq k ,val’ |== tilde(g)_(i)(v_(1),dots,v_(n),w_(1),dots,w_(k))=0\models \tilde{g}_{i}\left(v_{1}, \ldots, v_{n}, w_{1}, \ldots, w_{k}\right)=0 。注意,这样的扩展总是可能的。通过在 val’上计算(7),我们得到矛盾,因为左侧为正,而右侧为负。
We now prove the other side. Suppose Phi\Phi is unsatisfiable. We have two possibilities: either bar(Phi)\bar{\Phi} is also unsatisfiable or bar(Phi)\bar{\Phi} is satisfiable. Suppose bar(Phi)\bar{\Phi} is unsatisfiable, then using Theorem 3.9, bar(Phi)\bar{\Phi} entails -2 > 0-2>0 and we can write -2=h_(0)+sum_(i=1)^(k)h_(i)*g_(i)-2=h_{0}+\sum_{i=1}^{k} h_{i} \cdot g_{i} for sum of squares polynomials h_(0),dots,h_(k)inR[x_(1),dots,x_(n)]h_{0}, \ldots, h_{k} \in \mathbb{R}\left[x_{1}, \ldots, x_{n}\right]. Therefore, 现在我们证明反方向。假设 Phi\Phi 不可满足。我们有两种可能:要么 bar(Phi)\bar{\Phi} 也不可满足,要么 bar(Phi)\bar{\Phi} 是可满足的。假设 bar(Phi)\bar{\Phi} 不可满足,则利用定理 3.9, bar(Phi)\bar{\Phi} 蕴含 -2 > 0-2>0 ,我们可以将 -2=h_(0)+sum_(i=1)^(k)h_(i)*g_(i)-2=h_{0}+\sum_{i=1}^{k} h_{i} \cdot g_{i} 写成平方和多项式 h_(0),dots,h_(k)inR[x_(1),dots,x_(n)]h_{0}, \ldots, h_{k} \in \mathbb{R}\left[x_{1}, \ldots, x_{n}\right] 的形式。因此,
which fits into (5). Now we are left with the case when bar(Phi)\bar{\Phi} is satisfiable but Phi\Phi is unsatisfiable. We first reorder the inequalities in Phi\Phi such that the non-strict inequalities appear first in the order. Let jj be the smallest index for which Phi[1dots j]\Phi[1 \ldots j], i.e. the set of first jj inequalities in Phi\Phi, is unsatisfiable. By definition, Phi[1dots j-1]\Phi[1 \ldots j-1] is satisfiable and hence bar(SAT(Phi[1dots j-1]))=SAT( bar(Phi)[1dots j-1])\overline{\operatorname{SAT}(\Phi[1 \ldots j-1])}=\operatorname{SAT}(\bar{\Phi}[1 \ldots j-1]). We can 这符合(5)。现在我们剩下的情况是当 bar(Phi)\bar{\Phi} 可满足但 Phi\Phi 不可满足时。我们首先重新排列 Phi\Phi 中的不等式,使得非严格不等式先出现。令 jj 为满足 Phi[1dots j]\Phi[1 \ldots j] 的最小索引,即 Phi\Phi 中前 jj 个不等式的集合不可满足。根据定义, Phi[1dots j-1]\Phi[1 \ldots j-1] 是可满足的,因此 bar(SAT(Phi[1dots j-1]))=SAT( bar(Phi)[1dots j-1])\overline{\operatorname{SAT}(\Phi[1 \ldots j-1])}=\operatorname{SAT}(\bar{\Phi}[1 \ldots j-1]) 。我们可以
rewrite Phi[1dots j]=Phi[1dots j-1]^^(g_(j) > 0)\Phi[1 \ldots j]=\Phi[1 \ldots j-1] \wedge\left(g_{j}>0\right). As Phi[1dots j]\Phi[1 \ldots j] is unsatisfiable, we know that Phi[1dots j-1]\Phi[1 \ldots j-1] entails g_(j) <= 0g_{j} \leq 0. More precisely, this means SAT(Phi[1dots j-1])sube SAT(g_(j) <= 0)\operatorname{SAT}(\Phi[1 \ldots j-1]) \subseteq \operatorname{SAT}\left(g_{j} \leq 0\right). On taking closures on both sides we get SAT( bar(Phi)[1dots j-1])sube SAT(g_(j) <= 0)\operatorname{SAT}(\bar{\Phi}[1 \ldots j-1]) \subseteq \operatorname{SAT}\left(g_{j} \leq 0\right). This implies that bar(Phi)[1,dots j-1]\bar{\Phi}[1, \ldots j-1] entails g_(j) <= 0g_{j} \leq 0 and hence bar(Phi)[1dots j]\bar{\Phi}[1 \ldots j] entails g_(j)=0g_{j}=0. As defined above, tilde(g)_(i)(x_(1),dots,x_(n),w_(1),dots,w_(k))=g_(i)(x_(1),dots,x_(n))-w_(i)^(2)\tilde{g}_{i}\left(x_{1}, \ldots, x_{n}, w_{1}, \ldots, w_{k}\right)=g_{i}\left(x_{1}, \ldots, x_{n}\right)-w_{i}^{2}. Now, we will show that there is no valuation val^(**)v a l^{*} over the variables {x_(1),dots,x_(n),w_(1),dots,w_(k)}\left\{x_{1}, \ldots, x_{n}, w_{1}, \ldots, w_{k}\right\} such that for all 1 <= i <= j, tilde(g)_(i)(val^(**))=01 \leq i \leq j, \tilde{g}_{i}\left(v a l^{*}\right)=0 but g_(j)(val^(**))!=0g_{j}\left(v a l^{*}\right) \neq 0. Suppose there exist such a valuation val^(**)v a l^{*}. Let us define val to be the restriction of val* to {x_(1),dots,x_(n)}\left\{x_{1}, \ldots, x_{n}\right\}. For each 1 <= i <= j1 \leq i \leq j, we get g_(i)(val) >= 0g_{i}(v a l) \geq 0 as tilde(g_(j))(val^(**))=0\tilde{g_{j}}\left(v a l^{*}\right)=0. We also get g_(j)(val)=g_(j)(val^(**))!=0g_{j}(v a l)=g_{j}\left(v a l^{*}\right) \neq 0. Hence, we get a contradiction with the previous result that bar(Phi)[1dots j]\bar{\Phi}[1 \ldots j] entails g_(j)=0g_{j}=0. Applying the Real Nullstellensatz (Theorem 3.11) to tilde(g)_(i)\tilde{g}_{i} 's and g_(j)g_{j}, we have 重写 Phi[1dots j]=Phi[1dots j-1]^^(g_(j) > 0)\Phi[1 \ldots j]=\Phi[1 \ldots j-1] \wedge\left(g_{j}>0\right) 。由于 Phi[1dots j]\Phi[1 \ldots j] 不可满足,我们知道 Phi[1dots j-1]\Phi[1 \ldots j-1] 蕴含 g_(j) <= 0g_{j} \leq 0 。更准确地说,这意味着 SAT(Phi[1dots j-1])sube SAT(g_(j) <= 0)\operatorname{SAT}(\Phi[1 \ldots j-1]) \subseteq \operatorname{SAT}\left(g_{j} \leq 0\right) 。对两边取闭包,我们得到 SAT( bar(Phi)[1dots j-1])sube SAT(g_(j) <= 0)\operatorname{SAT}(\bar{\Phi}[1 \ldots j-1]) \subseteq \operatorname{SAT}\left(g_{j} \leq 0\right) 。这意味着 bar(Phi)[1,dots j-1]\bar{\Phi}[1, \ldots j-1] 蕴含 g_(j) <= 0g_{j} \leq 0 ,因此 bar(Phi)[1dots j]\bar{\Phi}[1 \ldots j] 蕴含 g_(j)=0g_{j}=0 。如上所定义, tilde(g)_(i)(x_(1),dots,x_(n),w_(1),dots,w_(k))=g_(i)(x_(1),dots,x_(n))-w_(i)^(2)\tilde{g}_{i}\left(x_{1}, \ldots, x_{n}, w_{1}, \ldots, w_{k}\right)=g_{i}\left(x_{1}, \ldots, x_{n}\right)-w_{i}^{2} 。现在,我们将证明不存在对变量 {x_(1),dots,x_(n),w_(1),dots,w_(k)}\left\{x_{1}, \ldots, x_{n}, w_{1}, \ldots, w_{k}\right\} 的赋值 val^(**)v a l^{*} ,使得对所有 1 <= i <= j, tilde(g)_(i)(val^(**))=01 \leq i \leq j, \tilde{g}_{i}\left(v a l^{*}\right)=0 都满足但 g_(j)(val^(**))!=0g_{j}\left(v a l^{*}\right) \neq 0 。假设存在这样的赋值 val^(**)v a l^{*} 。令 val 为 val*在 {x_(1),dots,x_(n)}\left\{x_{1}, \ldots, x_{n}\right\} 上的限制。对于每个 1 <= i <= j1 \leq i \leq j ,由于 tilde(g_(j))(val^(**))=0\tilde{g_{j}}\left(v a l^{*}\right)=0 ,我们得到 g_(i)(val) >= 0g_{i}(v a l) \geq 0 。我们还得到 g_(j)(val)=g_(j)(val^(**))!=0g_{j}(v a l)=g_{j}\left(v a l^{*}\right) \neq 0 。因此,我们与之前的结果 bar(Phi)[1dots j]\bar{\Phi}[1 \ldots j] 蕴含 g_(j)=0g_{j}=0 产生矛盾。将实数 Nullstellensatz 定理(定理 3.11)应用于 tilde(g)_(i)\tilde{g}_{i} 和 g_(j)g_{j} ,我们得到
where alpha\alpha is a non-negative integer and tilde(h)_(i)\tilde{h}_{i} 's and h_(0)h_{0} are sums of sqaures in R[x_(1),dots,x_(n),w_(1),dots,w_(k)]\mathbb{R}\left[x_{1}, \ldots, x_{n}, w_{1}, \ldots, w_{k}\right]. Using the definition of g_(j)= tilde(g_(j))+w_(j)^(2)g_{j}=\tilde{g_{j}}+w_{j}^{2} and the binomial theorem, we get g_(j)^(2*alpha)=w_(j)^(4*alpha)+h_(j)^(')* tilde(g_(j))g_{j}^{2 \cdot \alpha}=w_{j}^{4 \cdot \alpha}+h_{j}^{\prime} \cdot \tilde{g_{j}} for some h_(j)^(')inR[x_(1),dots,x_(n),w_(1),dots,w_(k)]h_{j}^{\prime} \in \mathbb{R}\left[x_{1}, \ldots, x_{n}, w_{1}, \ldots, w_{k}\right]. Therefore, we finally get the following expression: 其中 alpha\alpha 是一个非负整数, tilde(h)_(i)\tilde{h}_{i} 和 h_(0)h_{0} 是 R[x_(1),dots,x_(n),w_(1),dots,w_(k)]\mathbb{R}\left[x_{1}, \ldots, x_{n}, w_{1}, \ldots, w_{k}\right] 中的平方和。利用 g_(j)= tilde(g_(j))+w_(j)^(2)g_{j}=\tilde{g_{j}}+w_{j}^{2} 的定义和二项式定理,我们得到某个 h_(j)^(')inR[x_(1),dots,x_(n),w_(1),dots,w_(k)]h_{j}^{\prime} \in \mathbb{R}\left[x_{1}, \ldots, x_{n}, w_{1}, \ldots, w_{k}\right] 的 g_(j)^(2*alpha)=w_(j)^(4*alpha)+h_(j)^(')* tilde(g_(j))g_{j}^{2 \cdot \alpha}=w_{j}^{4 \cdot \alpha}+h_{j}^{\prime} \cdot \tilde{g_{j}} 。因此,我们最终得到以下表达式:
which fits into the format of (6), hence completing the proof. 该表达式符合公式 (6) 的格式,从而完成了证明。
Finally, we provide the needed theorems to check that a certain polynomial hh is a sum of squares using QP. 最后,我们提供了使用二次规划(QP)验证某个多项式 hh 是否为平方和所需的定理。
Theorem 3.13 ([Blekherman et al. 2012, Theorem 3.39]). Let vec(a)\vec{a} be the vector of all ((n+d)/(d))\binom{n+d}{d} monomials of degree less than or equal to dd over the variables {x_(1),dots,x_(n)}\left\{x_{1}, \ldots, x_{n}\right\}. A polynomial p inR[x_(1),dots,x_(n)]p \in \mathbb{R}\left[x_{1}, \ldots, x_{n}\right] of degree 2*d2 \cdot d is a sum of squares if and only if there exist a positive semidefinite matrix QQ of order ((n+d)/(d))\binom{n+d}{d} such that p=a^(T)*Q*ap=a^{T} \cdot Q \cdot a. 定理 3.13([Blekherman 等,2012,第 3.39 号定理])。设 vec(a)\vec{a} 是变量 {x_(1),dots,x_(n)}\left\{x_{1}, \ldots, x_{n}\right\} 上所有次数小于或等于 dd 的 ((n+d)/(d))\binom{n+d}{d} 单项式的向量。一个次数为 2*d2 \cdot d 的多项式 p inR[x_(1),dots,x_(n)]p \in \mathbb{R}\left[x_{1}, \ldots, x_{n}\right] 是平方和,当且仅当存在一个阶数为 ((n+d)/(d))\binom{n+d}{d} 的半正定矩阵 QQ ,使得 p=a^(T)*Q*ap=a^{T} \cdot Q \cdot a 。
Theorem 3.14 (Cholesky decomposition [Watkins 2004]). A symmetric square matrix QQ is positive semidefinite if and only if it has a Cholesky decomposition of the form Q=LL^(T)Q=L L^{T} where LL is a lower-triangular matrix with non-negative diagonal entries. 定理 3.14(Cholesky 分解 [Watkins 2004])。一个对称方阵 QQ 是半正定的,当且仅当它存在形如 Q=LL^(T)Q=L L^{T} 的 Cholesky 分解,其中 LL 是一个对角线元素非负的下三角矩阵。
Based on Theorems 3.13 and 3.14, a polynomial pp of degree 2*d2 \cdot d is a sum of squares if and only if it can be written as p=a^(T)*L*L^(T)*ap=a^{T} \cdot L \cdot L^{T} \cdot a such that diagonal entries of LL are non-negative. This representation provides us with a simple approach to generate a sum-of-squares polynomial of degree 2*d2 \cdot d with symbolic coefficients and encoding them in QP. We first generate a lower triangular matrix LL of order ((n+d)/(d))\binom{n+d}{d} by creating one fresh variable for each entry in the lower triangle and adding the extra condition that the entries on the diagonal must be non-negative. Then, we symbolically compute a^(T)*L*L^(T)*aa^{T} \cdot L \cdot L^{T} \cdot a. 基于定理 3.13 和 3.14,一个次数为 2*d2 \cdot d 的多项式 pp 是平方和当且仅当它可以写成 p=a^(T)*L*L^(T)*ap=a^{T} \cdot L \cdot L^{T} \cdot a ,且 LL 的对角线元素非负。这种表示为我们提供了一种简单的方法来生成具有符号系数的次数为 2*d2 \cdot d 的平方和多项式,并将其编码为二次规划(QP)。我们首先生成一个阶数为 ((n+d)/(d))\binom{n+d}{d} 的下三角矩阵 LL ,为下三角的每个元素创建一个新的变量,并添加额外条件,要求对角线上的元素必须非负。然后,我们符号计算 a^(T)*L*L^(T)*aa^{T} \cdot L \cdot L^{T} \cdot a 。
3.3 Details of Step 3 of the Algorithm 3.3 算法步骤 3 的详细说明
We now have all the necessary ingredients to provide a variant of Step 3 of the algorithm that preserves completeness. We assume a positive integer dd is given as part of the input. This dd serves as an upper-bound on the degrees of polynomials/templates that we use in Handelman’s theorem (the monoid) and the Stellensätze. Our approach is complete as long as a large enough dd is chosen. 我们现在拥有了提供算法步骤 3 变体所需的所有要素,该变体保持了完备性。我们假设一个正整数 dd 作为输入的一部分给出。该 dd 作为我们在 Handelman 定理(幺半群)和 Stellensätze 中使用的多项式/模板次数的上界。只要选择足够大的 dd ,我们的方法就是完备的。
Step 3: Eliminating Program Variables and Reduction to QP. Recall that at the end of Step 2, we have a finite set of standard constraints of form (1). In this step, the algorithm handles each standard constraint separately and reduces it to quadratic programming over template variables and newly-introduced variables, hence effectively eliminating the program variables and the quantification over them. Let f_(1)|><|_(1)0^^f_(2)|><|_(2)0^^dots^^f_(r)|><|_(r)0=>f|><|0f_{1} \bowtie_{1} 0 \wedge f_{2} \bowtie_{2} 0 \wedge \ldots \wedge f_{r} \bowtie_{r} 0 \Rightarrow f \bowtie 0 be one of the standard constraints. The algorithm considers three cases: (i) if all the inequalities on both sides of the constraint are affine, then it applies Farkas’ Lemma; (ii) if the LHS inequalities are affine but the 步骤 3:消除程序变量并归约为二次规划。回想在步骤 2 结束时,我们得到了一个有限的标准约束集合,形式如公式(1)。在这一步中,算法分别处理每个标准约束,并将其归约为关于模板变量和新引入变量的二次规划,从而有效地消除了程序变量及其上的量化。设 f_(1)|><|_(1)0^^f_(2)|><|_(2)0^^dots^^f_(r)|><|_(r)0=>f|><|0f_{1} \bowtie_{1} 0 \wedge f_{2} \bowtie_{2} 0 \wedge \ldots \wedge f_{r} \bowtie_{r} 0 \Rightarrow f \bowtie 0 为其中一个标准约束。算法考虑三种情况:(i)如果约束两边的所有不等式都是仿射的,则应用 Farkas 引理;(ii)如果左侧不等式是仿射的,但…
RHS is a higher-degree polynomial, then the algorithm applies Handelman’s theorem; and (iii) if the LHS contains higher-degree polynomials, the algorithm applies the Stellensätze and Theorem 3.12. Below, we define Phi:{f_(1)|><|_(1)0,f_(2)|><|_(2)0,dots,f_(r)|><|_(r)0}\Phi:\left\{f_{1} \bowtie_{1} 0, f_{2} \bowtie_{2} 0, \ldots, f_{r} \bowtie_{r} 0\right\} and psi:f|><|0\psi: f \bowtie 0. 如果右侧是高次多项式,则算法应用 Handelman 定理;(iii)如果左侧包含高次多项式,算法则应用 Stellensätze 和定理 3.12。下面,我们定义 Phi:{f_(1)|><|_(1)0,f_(2)|><|_(2)0,dots,f_(r)|><|_(r)0}\Phi:\left\{f_{1} \bowtie_{1} 0, f_{2} \bowtie_{2} 0, \ldots, f_{r} \bowtie_{r} 0\right\} 和 psi:f|><|0\psi: f \bowtie 0 。
Step 3.(i). Applying Farkas’ Lemma. Assuming all the constraints in Phi\Phi and psi\psi are affine, we can apply Corollary 3.6. Based on this corollary, we have to consider three cases disjunctively: 步骤 3.(i). 应用法尔卡斯引理。假设集合 Phi\Phi 和 psi\psi 中的所有约束都是仿射的,我们可以应用推论 3.6。基于该推论,我们必须析取地考虑三种情况:
(1) Phi\Phi is satisfiable and entails psi\psi : The algorithm creates new template variables y_(0),dots,y_(r)y_{0}, \ldots, y_{r} with the constraint y_(i) >= 0y_{i} \geq 0 for every ii. It then symbolically computes f=y_(0)+sum_(i=1)^(r)y_(i)*f_(i)f=y_{0}+\sum_{i=1}^{r} y_{i} \cdot f_{i}. The latter is a polynomial equality over V\mathbb{V}. So, the algorithm equates the coefficients of corresponding monomials on both sides, hence reducing this case to QP. Additionally, if psi\psi is a strict inequality, the algorithm adds the extra constraint sum_(|><|_(i)in{ > })y_(i) > 0\sum_{\bowtie_{i} \in\{>\}} y_{i}>0. (1) Phi\Phi 是可满足的且蕴含 psi\psi :算法为每个 ii 创建新的模板变量 y_(0),dots,y_(r)y_{0}, \ldots, y_{r} ,并附加约束 y_(i) >= 0y_{i} \geq 0 。然后它符号化地计算 f=y_(0)+sum_(i=1)^(r)y_(i)*f_(i)f=y_{0}+\sum_{i=1}^{r} y_{i} \cdot f_{i} 。后者是关于 V\mathbb{V} 的多项式等式。因此,算法将两边对应单项式的系数相等,从而将此情况归约为 QP。此外,如果 psi\psi 是严格不等式,算法会添加额外约束 sum_(|><|_(i)in{ > })y_(i) > 0\sum_{\bowtie_{i} \in\{>\}} y_{i}>0 。
(2) Phi\Phi is unsatisfiable and -1 >= 0-1 \geq 0 can be obtained: This is similar to the previous case, except that -1 should be written as y_(0)+sum_(i=1)^(r)y_(i)*f_(i)y_{0}+\sum_{i=1}^{r} y_{i} \cdot f_{i}. (2) Phi\Phi 是不可满足的且可以得到 -1 >= 0-1 \geq 0 :这与前一种情况类似,只是 -1 应写为 y_(0)+sum_(i=1)^(r)y_(i)*f_(i)y_{0}+\sum_{i=1}^{r} y_{i} \cdot f_{i} 。
(3) Phi\Phi is unsatisfiable and 0 > 00>0 can be obtained: This is also similar to the last two cases. We have 0=y_(0)+sum_(i=1)^(r)y_(i)*f_(i)0=y_{0}+\sum_{i=1}^{r} y_{i} \cdot f_{i} and sum_(|><|_(i)in{ > })y_(i) > 0\sum_{\bowtie_{i} \in\{>\}} y_{i}>0. (3) Phi\Phi 是不可满足的且可以得到 0 > 00>0 :这也与前两种情况类似。我们有 0=y_(0)+sum_(i=1)^(r)y_(i)*f_(i)0=y_{0}+\sum_{i=1}^{r} y_{i} \cdot f_{i} 和 sum_(|><|_(i)in{ > })y_(i) > 0\sum_{\bowtie_{i} \in\{>\}} y_{i}>0 。
Note that the template variables yy are freshly generated in each case above. Also, we have to consider cases (2) and (3) because Phi\Phi is unsatisfiable in these cases and hence the constraint Phi=>psi\Phi \Rightarrow \psi always holds vacuously. 注意,上述每种情况下模板变量 yy 都是新生成的。此外,我们必须考虑情况 (2) 和 (3),因为在这些情况下 Phi\Phi 是不可满足的,因此约束 Phi=>psi\Phi \Rightarrow \psi 总是虚假地成立。
Step 3.(ii). Applying Handelman’s Theorem. Assuming all constraints in Phi\Phi are linear but psi\psi is a higher-degree polynomial inequality, the algorithm applies Corollaries 3.6 and 3.8. Again, we have to consider the same three cases as in Step 3.(i): 步骤 3.(ii). 应用 Handelman 定理。假设 Phi\Phi 中的所有约束都是线性的,但 psi\psi 是高次多项式不等式,算法应用推论 3.6 和 3.8。同样,我们必须考虑与步骤 3.(i)中相同的三种情况:
(1) Phi\Phi is satisfiable and entails psi\psi : We apply Corollary 3.8. The algorithm first symbolically computes Monoid _(d)(Phi)={h_(1),h_(2),dots,h_(u)}_{d}(\Phi)=\left\{h_{1}, h_{2}, \ldots, h_{u}\right\}. It then generates new template variables y_(0),y_(1),dots,y_(u)y_{0}, y_{1}, \ldots, y_{u} and constrains them by setting y_(0),y_(1),y_(2),dots,y_(u) >= 0y_{0}, y_{1}, y_{2}, \ldots, y_{u} \geq 0. If psi\psi is a strict inequality, it further adds the constraint y_(0) > 0y_{0}>0. It then symbolically computes the equality (1) Phi\Phi 可满足且蕴含 psi\psi :我们应用推论 3.8。算法首先符号计算幺半群 _(d)(Phi)={h_(1),h_(2),dots,h_(u)}_{d}(\Phi)=\left\{h_{1}, h_{2}, \ldots, h_{u}\right\} 。然后生成新的模板变量 y_(0),y_(1),dots,y_(u)y_{0}, y_{1}, \ldots, y_{u} 并通过设置 y_(0),y_(1),y_(2),dots,y_(u) >= 0y_{0}, y_{1}, y_{2}, \ldots, y_{u} \geq 0 对其进行约束。如果 psi\psi 是严格不等式,则进一步添加约束 y_(0) > 0y_{0}>0 。接着符号计算等式
As usual, this is an equality whose both sides are polynomials over V\mathbb{V}. So, the algorithm equates the coefficients of corresponding monomials on the LHS and RHS, which reduces this case to QP. 和往常一样,这是一个两边都是关于 V\mathbb{V} 的多项式的等式。因此,算法将左右两边对应单项式的系数相等,从而将此情况归约为二次规划(QP)。
(2) Note that Phi\Phi consists of linear inequalities, so we can use Farkas’ Lemma to check if Phi\Phi is unsatisfiable. As such, this step is the same as case (2) of Step 3.(i). (2) 注意 Phi\Phi 由线性不等式组成,因此我们可以使用 Farkas 引理检查 Phi\Phi 是否不可满足。因此,这一步与步骤 3.(i)的情况(2)相同。
(3) This is the same as case (3) of Step 3.(i). (3) 这与步骤 3.(i)的情况(3)相同。
Step 3.(iii). Applying Stellensätze. If Phi\Phi includes polynomial inequalities of degree 2 or larger, then we have to apply Corollary 3.10 and Theorem 3.12. The algorithm considers three cases and combines them disjunctively: 步骤 3.(iii)。应用 Stellensätze。如果 Phi\Phi 包含二次或更高次的多项式不等式,则必须应用推论 3.10 和定理 3.12。算法考虑三种情况,并将它们用析取方式组合:
(1) Phi\Phi is satisfiable and entails psi\psi : In this case, we apply Corollary 3.10. The algorithm generates template sum-of-squares polynomials h_(0),dots,h_(r)h_{0}, \ldots, h_{r} of degree dd and adds QP constraints that ensure each h_(i)h_{i} is a sum of squares (See the end of Section 3.2). It also generates a non-negative fresh variable y_(0)y_{0}. If psi\psi is strict, the algorithm adds the constraint y_(0) > 0y_{0}>0. Finally, the algorithm symbolically computes (1) Phi\Phi 是可满足的并且蕴含 psi\psi :在这种情况下,我们应用推论 3.10。算法生成次数为 dd 的模板平方和多项式 h_(0),dots,h_(r)h_{0}, \ldots, h_{r} ,并添加 QP 约束以确保每个 h_(i)h_{i} 都是平方和(参见第 3.2 节末尾)。它还生成一个非负的新变量 y_(0)y_{0} 。如果 psi\psi 是严格的,算法会添加约束 y_(0) > 0y_{0}>0 。最后,算法符号计算
and equates the corresponding coefficients in the LHS and RHS to obtain QP constraints. 并将左右两边对应的系数相等,以获得 QP 约束。
(2) Phi\Phi is unsatisfiable due to the first condition of Theorem 3.12: This case is handled similary to case (1) above, except that we have -1=y_(0)+h_(0)+sum_(i=1)^(r)h_(i)*f_(i)-1=y_{0}+h_{0}+\sum_{i=1}^{r} h_{i} \cdot f_{i}. (2) 由于定理 3.12 的第一个条件, Phi\Phi 不可满足:此情况的处理方式与上述情况(1)类似,只是我们有 -1=y_(0)+h_(0)+sum_(i=1)^(r)h_(i)*f_(i)-1=y_{0}+h_{0}+\sum_{i=1}^{r} h_{i} \cdot f_{i} 。
(3) Phi\Phi is unsatisfiable due to the second condition of Theorem 3.12: The algorithm introduces rr new program variables w_(1),dots,w_(r)w_{1}, \ldots, w_{r}. It then generates a sum-of-squares template polynomial hh over V\mathbb{V} and arbitrary template polynomials h_(1),dots,h_(k)h_{1}, \ldots, h_{k} over Vuu{w_(1),dots,w_(r)}\mathbb{V} \cup\left\{w_{1}, \ldots, w_{r}\right\}. All h_(i)h_{i} 's are degree- dd (3) 由于定理 3.12 的第二个条件, Phi\Phi 不可满足:算法引入了 rr 个新的程序变量 w_(1),dots,w_(r)w_{1}, \ldots, w_{r} 。然后它生成了一个关于 V\mathbb{V} 的平方和模板多项式 hh 以及关于 Vuu{w_(1),dots,w_(r)}\mathbb{V} \cup\left\{w_{1}, \ldots, w_{r}\right\} 的任意模板多项式 h_(1),dots,h_(k)h_{1}, \ldots, h_{k} 。所有 h_(i)h_{i} 都是 dd 次
templates. Finally, for every index jj that corresponds to a strict inequality, i.e. |><|_(j)in{ > }\bowtie_{j} \in\{>\}, the algorithm symbolically computes 模板。最后,对于每个对应严格不等式的索引 jj ,即 |><|_(j)in{ > }\bowtie_{j} \in\{>\} ,算法符号计算
in which d^(')d^{\prime} is the largest multiple of 4 that does not exceed dd. Note that this is an equality between two polynomials over Vuu{w_(1),dots,w_(r)}\mathbb{V} \cup\left\{w_{1}, \ldots, w_{r}\right\}. As before, the algorithm equates the coefficients of corresponding monomials on both sides of the equality and reduces it to QP. 其中 d^(')d^{\prime} 是不超过 dd 的最大 4 的倍数。注意这是两个关于 Vuu{w_(1),dots,w_(r)}\mathbb{V} \cup\left\{w_{1}, \ldots, w_{r}\right\} 的多项式之间的等式。与之前一样,算法将等式两边对应单项式的系数相等,并将其化简为二次规划(QP)。
After the algorithm runs Step 3 as above, all standard constraints generated in Step 2 will be reduced to QP and can hence be passed to an external solver in Step 4, as illustrated in Section 3.1. 在算法执行上述第 3 步后,第 2 步中生成的所有标准约束将被化简为 QP,因此可以在第 4 步中传递给外部求解器,如第 3.1 节所示。
Degree bounds. We are using the same bound dd for the degree of the polynomials and templates in all cases above. This is not a requirement. One can fix different degree bounds for each case. 次数界限。我们在上述所有情况下对多项式和模板的次数都使用相同的界限 dd 。这并非必须。可以为每种情况设定不同的次数界限。
Handling Boundedness. To achieve completeness, we need the boundedness assumption, i.e. that for every variable v inVv \in \mathbb{V}, we always have -M <= v <= M-M \leq v \leq M. To model this in the algorithm, we can add the boundedness inequalities to the left-hand side of every standard constraint. Additionally, we can get a concrete value for MM as part of the input, or treat MM symbolically, i.e. as a template variable, and let the QP solver synthesize a value for it. 有界性处理。为了实现完备性,我们需要有界性假设,即对于每个变量 v inVv \in \mathbb{V} ,我们总有 -M <= v <= M-M \leq v \leq M 。为了在算法中建模这一点,我们可以将有界性不等式添加到每个标准约束的左侧。此外,我们可以将 MM 作为输入的一部分获得具体数值,或者将 MM 符号化处理,即作为模板变量,让 QP 求解器为其合成一个值。
3.4 Soundness and Completeness 3.4 正确性与完备性
We now prove that our algorithm is sound and semi-complete for TBSP. The soundness result needs no extra assumptions and can be obtained directly. The completeness on the other hand relies on several assumptions: (i) boundedness, (ii) having chosen a large enough degree bound dd, and (iii) having invariants and post-conditions that, when written in DNF form, consist only of strongly positive polynomial inequalities of the form g≫0g \gg 0. 我们现在证明我们的算法对于 TBSP 是正确且半完备的。正确性结果不需要额外假设,可以直接获得。另一方面,完备性依赖于几个假设:(i)有界性,(ii)选择了足够大的次数界限 dd ,以及(iii)不变式和后置条件在写成析取范式(DNF)时,仅包含形式为 g≫0g \gg 0 的强正多项式不等式。
Theorem 3.15 (Soundness). Given a sketch polynomial program or equivalently a sketch polynomial transition system (SPTS) of the form ( V,T,L,ℓ_(0),theta_(0),ℓ_(f),theta_(f),T,I\mathbb{V}, \mathbb{T}, \mathbb{L}, \ell_{0}, \theta_{0}, \ell_{f}, \theta_{f}, \mathcal{T}, \mathbb{I} ) together with a cutset CC as input, every concrete polynomial transition system (PTS) synthesized by the algorithm above is inductively valid. 定理 3.15(正确性)。给定一个草图多项式程序,或等价地,一个形式为( V,T,L,ℓ_(0),theta_(0),ℓ_(f),theta_(f),T,I\mathbb{V}, \mathbb{T}, \mathbb{L}, \ell_{0}, \theta_{0}, \ell_{f}, \theta_{f}, \mathcal{T}, \mathbb{I} )的草图多项式转换系统(SPTS)及其割集 CC 作为输入,上述算法合成的每个具体多项式转换系统(PTS)都是归纳有效的。
Proof. The standard constraints of form (1) generated in Step 2 are equivalent to the initiation, consecution and finalization constraints in the definition of inductive validity. The reduction from standard constraints to QP in Step 3 is also sound since, in every case, it either writes the RHS of the standard constraint as a combination of the LHS polynomials, hence proving that it holds, or otherwise proves that the LHS is unsatisfiable and thus the standard constraint holds vacuously. 证明。步骤 2 中生成的形式为(1)的标准约束等价于归纳有效性定义中的初始化、继承和终结约束。步骤 3 中从标准约束到 QP 的归约也是正确的,因为在每种情况下,它要么将标准约束的右侧写成左侧多项式的组合,从而证明其成立,要么证明左侧不可满足,因此标准约束在逻辑上成立。
Theorem 3.16 (Semi-completeness). Consider a solvable sketch polynomial transition system (SPTS) of the form ( V,T,L,ℓ_(0),theta_(0),ℓ_(f),theta_(f),T,I\mathbb{V}, \mathbb{T}, \mathbb{L}, \ell_{0}, \theta_{0}, \ell_{f}, \theta_{f}, \mathcal{T}, \mathbb{I} ), together with a cutset CC, that is given as input. Moreover, assume that: 定理 3.16(半完备性)。考虑一个可解的草图多项式转换系统(SPTS),形式为( V,T,L,ℓ_(0),theta_(0),ℓ_(f),theta_(f),T,I\mathbb{V}, \mathbb{T}, \mathbb{L}, \ell_{0}, \theta_{0}, \ell_{f}, \theta_{f}, \mathcal{T}, \mathbb{I} ),以及一个割集 CC ,作为输入给出。此外,假设:
(1) The boundedness assumption holds, i.e. there is a constant M in(0,oo)M \in(0, \infty) such that for every v inVv \in \mathbb{V}, we always have -M <= v <= M-M \leq v \leq M. (1)有界性假设成立,即存在常数 M in(0,oo)M \in(0, \infty) ,使得对于每个 v inVv \in \mathbb{V} ,总有 -M <= v <= M-M \leq v \leq M 。
(2) Every invariant I(ℓ)\mathbb{I}(\ell) and post-condition theta_(f)\theta_{f}, when written in disjunctive normal form, contains only strongly positive polynomial inequalities of the form g≫0g \gg 0. (2)每个不变式 I(ℓ)\mathbb{I}(\ell) 和后置条件 theta_(f)\theta_{f} ,当以析取范式表示时,仅包含形式为 g≫0g \gg 0 的强正多项式不等式。
Then, there exists a constant degree bound d inNd \in \mathbb{N}, for which the algorithm above is guaranteed to successfully synthesize an inductively valid polynomial transition system (PTS). 那么,存在一个常数次数界 d inNd \in \mathbb{N} ,对于该次数界,上述算法保证能够成功合成一个归纳有效的多项式过渡系统(PTS)。
Proof. Since our instance is solvable, there is a valuation val_(T)v a l_{\mathbb{T}} for the template variables that yields an inductively valid PTS. We prove that for large enough dd, the valuation val_(T)v a l_{\mathbb{T}} is obtained by one of the solutions of the QP instance solved in Step 4 of the algorithm. The proof is pretty straightforward since we just have to check that all steps of our algorithm are complete. Step 2 is complete since it simply rewrites the inductive validity constraints as an equivalent set of standard constraints. For Step 3, we prove completeness of each case separately. Step 3.(i) is complete due to 证明。由于我们的实例是可解的,存在一个模板变量的赋值 val_(T)v a l_{\mathbb{T}} ,使得得到一个归纳有效的 PTS。我们证明对于足够大的 dd ,赋值 val_(T)v a l_{\mathbb{T}} 是算法第 4 步中求解的 QP 实例的某个解所得到的。证明相当直接,因为我们只需检查算法的所有步骤都是完备的。第 2 步是完备的,因为它只是将归纳有效性约束重写为等价的一组标准约束。对于第 3 步,我们分别证明每种情况的完备性。第 3 步(i)的完备性是由于
Farkas’ Lemma (Corollary 3.6). In Step 3.(ii), if Phi\Phi is unsatisfiable, then the algorithm is complete based on Corollary 3.6. Otherwise, it is complete based on Corollary 3.8. However, since we are using a degree bound dd for the monoid, the completeness only holds if the chosen dd is large enough. Moreover, Corollary 3.8 requires strong positivity of gg, which corresponds to invariants and postconditions in our use-case, and boundedness of SAT(Phi)\operatorname{SAT}(\Phi), which is a direct consequence of our boundedness assumption. Finally, Step 3.(iii) is complete due to Corollary 3.10 and Theorem 3.12. These depend on dd, strong positivity and boundedness in the exact same manner as in the case of Step 3.(ii). Farkas 引理(推论 3.6)。在步骤 3.(ii)中,如果 Phi\Phi 不可满足,则算法基于推论 3.6 是完备的。否则,算法基于推论 3.8 是完备的。然而,由于我们对幺半群使用了次数界 dd ,完备性仅在所选的 dd 足够大时成立。此外,推论 3.8 要求 gg 的强正性,这对应于我们用例中的不变式和后置条件,以及 SAT(Phi)\operatorname{SAT}(\Phi) 的有界性,这是我们有界性假设的直接结果。最后,步骤 3.(iii)由于推论 3.10 和定理 3.12 而完备。这些依赖于 dd ,强正性和有界性,其方式与步骤 3.(ii)中的情况完全相同。
Limitations of Completeness. The main limitation in our completeness result is that it holds only if the degree bound dd chosen for the template polynomials is large enough. This is why we call it a semi-completeness theorem. In theory, it is possible to come up with adversarial instances in which the required degree is exponentially high [Mai and Magron 2022]. In practice, we rarely, if ever, need to use a higher degree than that of the polynomials that are already part of the input SPTS. The second limitation is boundedness. This limitation cannot be lifted since both Handelman’s Theorem and Putinar’s Positivstellensatz assume compactness, which is equivalent to being closed and bounded in R^(n)\mathbb{R}^{n}. Nevertheless, it does not have a significant practical effect and the algorithm remains sound even without this assumption. It is also noteworthy that the treatment of the linear/affine case using Farkas’ Lemma requires neither boundedness nor any specific value of dd and is always complete. Finally, strong positivity in the invariants and post-conditions is needed because Putinar’s Positivstellensatz and Theorem 3.12 can only provide a sound and complete characterization of strongly positive polynomials over a bounded semi-algebraic set X subeR^(n)X \subseteq R^{n} if we do not assume that XX itself is closed. In terms of the synthesis problem, this means that our algorithm is not guaranteed to be complete for inequalities of the form f > 0f>0 in the invariants/post-conditions for which the value of ff in the runs of the program can get arbitrarily close to 0 . However, this limitation is also not significant in practice because (i) our soundness does not depend on it, and (ii) f+epsilon≫0f+\epsilon \gg 0 holds for any constant epsilon > 0\epsilon>0. So, a small change (by any value epsilon > 0\epsilon>0 ) in the invariants/postconditions leads to an instance over which our completeness holds. 完备性的局限性。我们完备性结果的主要局限在于,它仅在为模板多项式选择的次数上界 dd 足够大时成立。这也是我们称之为半完备性定理的原因。理论上,确实可能出现需要指数级高次数的对抗性实例[Mai 和 Magron 2022]。但在实际中,我们几乎从未需要使用比输入 SPTS 中已有多项式次数更高的次数。第二个局限是有界性。该局限无法消除,因为 Handelman 定理和 Putinar 的 Positivstellensatz 都假设紧性,而紧性等价于在 R^(n)\mathbb{R}^{n} 中闭合且有界。然而,这在实际中影响不大,且即使没有该假设,算法仍然是正确的。值得注意的是,使用 Farkas 引理处理线性/仿射情况既不需要有界性,也不需要 dd 的任何特定值,并且始终是完备的。 最后,强正性在不变量和后置条件中是必要的,因为 Putinar 的 Positivstellensatz 和定理 3.12 只能在我们不假设 XX 本身是闭合的情况下,对有界半代数集上的强正多项式提供一个健全且完备的刻画 X subeR^(n)X \subseteq R^{n} 。就综合问题而言,这意味着我们的算法不能保证对形如 f > 0f>0 的不等式在不变量/后置条件中是完备的,其中程序运行中 ff 的值可以无限接近于 0。然而,这一限制在实际中也不显著,因为(i)我们的健全性不依赖于此,且(ii) f+epsilon≫0f+\epsilon \gg 0 对任意常数 epsilon > 0\epsilon>0 都成立。因此,在不变量/后置条件中进行一个小的改动(任意值 epsilon > 0\epsilon>0 )会导致一个我们的完备性成立的实例。
4 DECIDABILITY AND NP-HARDNESS 4 可判定性与 NP-难度
In this section, we study the decision variant of TBSP, in which we are given an SPTS of the form Gamma=(V,T,L,ℓ_(0),theta_(0),ℓ_(f),theta_(f),T,I)\Gamma=\left(\mathbb{V}, \mathbb{T}, \mathbb{L}, \ell_{0}, \theta_{0}, \ell_{f}, \theta_{f}, \mathcal{T}, \mathbb{I}\right) and should decide whether there exists a valuation val T:TrarrR\mathbb{T}: \mathbb{T} \rightarrow \mathbb{R} for the template variables under which Gamma\Gamma turns into an inductively valid PTS. 在本节中,我们研究 TBSP 的判定变体,其中给定一个形式为 Gamma=(V,T,L,ℓ_(0),theta_(0),ℓ_(f),theta_(f),T,I)\Gamma=\left(\mathbb{V}, \mathbb{T}, \mathbb{L}, \ell_{0}, \theta_{0}, \ell_{f}, \theta_{f}, \mathcal{T}, \mathbb{I}\right) 的 SPTS,应判定是否存在一个模板变量的赋值 val T:TrarrR\mathbb{T}: \mathbb{T} \rightarrow \mathbb{R} ,使得 Gamma\Gamma 变成一个归纳有效的 PTS。
Reduction to the First-order Theory of the Reals. Suppose V={v_(1),dots,v_(m)}\mathbb{V}=\left\{v_{1}, \ldots, v_{m}\right\} and T={t_(1),dots,t_(m^('))}\mathbb{T}=\left\{t_{1}, \ldots, t_{m^{\prime}}\right\}. Recall that Step 2 of our algorithm is sound and complete and reduces all the constraints to the form shown in Equation (2). However, in the synthesis algorithm, we are looking for a valuation to the template variables T\mathbb{T} that ensures (2). Hence, in the decision variant, we are interested in deciding the following first-order formula over the reals: 归约到实数的一阶理论。假设 V={v_(1),dots,v_(m)}\mathbb{V}=\left\{v_{1}, \ldots, v_{m}\right\} 和 T={t_(1),dots,t_(m^('))}\mathbb{T}=\left\{t_{1}, \ldots, t_{m^{\prime}}\right\} 。回顾我们算法的第 2 步是正确且完备的,并将所有约束归约为方程(2)所示的形式。然而,在综合算法中,我们正在寻找模板变量 T\mathbb{T} 的一个赋值,使得(2)成立。因此,在判定变体中,我们关注的是判定以下实数上的一阶公式:
It is well-known that the first-order theory of the reals is decidable and hence so is our problem. Specifically, one can apply Tarski’s quantifier elimination method [Tarski 1949] to (8). Note that while this proves decidability in theory, decision procedures and quantifier elimination on the firstorder theory of the reals are notoriously unscalable and since (8) contains a quantifier alternation, it is practically beyond the reach of all modern solvers, even for toy programs. 众所周知,实数的一阶理论是可判定的,因此我们的问题也是可判定的。具体来说,可以对(8)应用 Tarski 的量词消除方法[Tarski 1949]。注意,虽然这在理论上证明了可判定性,但实数一阶理论的判定过程和量词消除以其不可扩展性而著称,并且由于(8)包含量词交替,实际上即使是对于简单程序,所有现代求解器也难以处理。
NP-hardness. We prove our problem is strongly NP-hard, even for linear/affine transition systems, by providing a reduction from 3SAT. Consider a 3SAT instance ^^^_(i=1)^(m)vvv_(j=1)^(3)l_(i,j)\bigwedge_{i=1}^{m} \bigvee_{j=1}^{3} l_{i, j} over the boolean variables {x_(1),dots,x_(n)}\left\{x_{1}, \ldots, x_{n}\right\}, i.e. each literal l_(i,j)l_{i, j} is either an x_(k)x_{k} or a notx_(k)\neg x_{k}. We define the expression e(l_(i,j))e\left(l_{i, j}\right) as x_(k)x_{k} if l_(i,j)=x_(k)l_{i, j}=x_{k} and 1-x_(k)1-x_{k} if l_(i,j)=notx_(k)l_{i, j}=\neg x_{k}. To reduce this 3SAT instance to our problem, we let NP-难度。我们证明了即使对于线性/仿射转换系统,我们的问题也是强 NP-难的,方法是提供一个来自 3SAT 的归约。考虑一个布尔变量集合 {x_(1),dots,x_(n)}\left\{x_{1}, \ldots, x_{n}\right\} 上的 3SAT 实例 ^^^_(i=1)^(m)vvv_(j=1)^(3)l_(i,j)\bigwedge_{i=1}^{m} \bigvee_{j=1}^{3} l_{i, j} ,即每个文字 l_(i,j)l_{i, j} 要么是 x_(k)x_{k} ,要么是 notx_(k)\neg x_{k} 。我们定义表达式 e(l_(i,j))e\left(l_{i, j}\right) 为:如果 l_(i,j)=x_(k)l_{i, j}=x_{k} ,则为 x_(k)x_{k} ;如果 l_(i,j)=notx_(k)l_{i, j}=\neg x_{k} ,则为 1-x_(k)1-x_{k} 。为了将该 3SAT 实例归约到我们的问题,我们令 V={x_(1),dots,x_(n)}\mathbb{V}=\left\{x_{1}, \ldots, x_{n}\right\} and T={t_(1),dots,t_(n)}\mathbb{T}=\left\{t_{1}, \ldots, t_{n}\right\}. We then consider the sketch transition system corresponding to the following program: V={x_(1),dots,x_(n)}\mathbb{V}=\left\{x_{1}, \ldots, x_{n}\right\} 和 T={t_(1),dots,t_(n)}\mathbb{T}=\left\{t_{1}, \ldots, t_{n}\right\} 。然后我们考虑对应于以下程序的草图转换系统:
Note that the template variables are appearing in the pre-condition. It is easy to see that the synthesis instance has a solution if and only if the 3SAT instance is satisfiable. 注意模板变量出现在前置条件中。很容易看出,当且仅当 3SAT 实例可满足时,合成实例才有解。
5 IMPLEMENTATION AND EXPERIMENTAL RESULTS 5 实现与实验结果
In this section, we report on a prototype implementation of our algorithm and our experimental results. 本节中,我们报告了算法的原型实现及实验结果。
Implementation. We implemented our approach in Python and used SymPy [Meurer et al. 2017] for symbolic computations. We also used the Z3 SMT solver [Moura and Bjørner 2008] to handle the final QP instances. In all cases, we used quadratic templates for the holes and set the technical parameter (degree upper-bound) dd to 2 . 实现。我们用 Python 实现了该方法,并使用 SymPy [Meurer et al. 2017]进行符号计算。我们还使用了 Z3 SMT 求解器 [Moura and Bjørner 2008] 来处理最终的 QP 实例。在所有情况下,我们对空缺部分使用了二次模板,并将技术参数(次数上限) dd 设为 2。
Experimental Setting. All experimental results were obtained on an Intel i9-10980HK Processor (8 cores, 16 threads, 5.3GHz,16MB5.3 \mathrm{GHz}, 16 \mathrm{MB} Cache) with 32 GB of RAM running Microsoft Windows 10. 实验设置。所有实验结果均在配备 32 GB 内存、运行 Microsoft Windows 10 的 Intel i9-10980HK 处理器(8 核,16 线程, 5.3GHz,16MB5.3 \mathrm{GHz}, 16 \mathrm{MB} 缓存)上获得。
Heuristics. We used the following simple heuristics to speed up the solution of the QP instance by the SMT solver: 启发式方法。我们使用以下简单的启发式方法,通过 SMT 求解器加速 QP 实例的求解:
Simplifying Standard Constraints: We apply the simplification procedure illustrated in Example 3.2. Specifically, it is often the case that for some v_(1),v_(2)inVuuV^(')v_{1}, v_{2} \in \mathbb{V} \cup \mathbb{V}^{\prime}, the standard constraint contains v_(1)=v_(2)v_{1}=v_{2} on its left-hand side. In these cases, we merge v_(1)v_{1} and v_(2)v_{2} into a single variable. Similarly, if the left-hand side of a standard constraint has v_(1)=cv_{1}=c for a real constant cc, then we simply replace every occurrence of v_(1)v_{1} with cc. 简化标准约束:我们应用示例 3.2 中展示的简化过程。具体来说,通常情况下,对于某些 v_(1),v_(2)inVuuV^(')v_{1}, v_{2} \in \mathbb{V} \cup \mathbb{V}^{\prime} ,标准约束的左侧包含 v_(1)=v_(2)v_{1}=v_{2} 。在这些情况下,我们将 v_(1)v_{1} 和 v_(2)v_{2} 合并为一个变量。类似地,如果标准约束的左侧对于实数常数 cc 具有 v_(1)=cv_{1}=c ,那么我们直接将所有出现的 v_(1)v_{1} 替换为 cc 。
Strengthening the Constraints: Our algorithm introduces a large number of template variables, not only in Step 1, but also in Step 3, where each of the Stellensätze lead to the creation of new coefficient variables. Such new variables are created, for example, in the linear combinations appearing in Farkas/Handelman and the sum-of-squares template polynomials in Putinar. For most real-world cases, the vast majority of the template variables should be set to 0 in solutions to the QP. However, their inclusion makes the QP much larger and more complicated and can even lead to the failure of other heuristics used by the SMT solver. Hence, we use a process which is intuitively the opposite of abstraction-refinement. We start with a strengthened version of our QP instance and repeatedly make it weaker, but never weaker than the original instance, until the SMT solver finds a solution. Specifically, we first add additional constraints of the form t=0t=0 for every template variable tt. This strengthens the constraints but makes the problem easier for the SMT solver, since it can now simply plug in the 0 values and solve a lower-dimensional QP. Additionally, it would very likely lead to an unsatisfiable QP. However, Z3 can then provide us with an unsatisfiability core, i.e. a minimal subset of QP constraints that are unsatisfiable. If the core does not include any of our t=0t=0 constraints, 加强约束条件:我们的算法引入了大量的模板变量,不仅在步骤 1 中如此,在步骤 3 中也是如此,每个 Stellensätze 都会导致新的系数变量的产生。例如,这些新变量出现在 Farkas/Handelman 中的线性组合以及 Putinar 中的平方和模板多项式中。对于大多数实际情况,绝大多数模板变量在 QP 的解中应被设为 0。然而,它们的加入使得 QP 变得更大更复杂,甚至可能导致 SMT 求解器使用的其他启发式方法失败。因此,我们采用了一种直观上与抽象-细化相反的过程。我们从一个加强版的 QP 实例开始,反复使其变弱,但绝不比原始实例更弱,直到 SMT 求解器找到解。具体来说,我们首先为每个模板变量 tt 添加形式为 t=0t=0 的额外约束。这加强了约束条件,但使问题对 SMT 求解器更容易,因为它现在可以直接代入 0 值,求解一个低维的 QP。 此外,这很可能导致一个不可满足的 QP。然而,Z3 随后可以为我们提供一个不可满足核心,即一组不可满足的 QP 约束的最小子集。如果该核心不包含我们的任何 t=0t=0 约束,
@prog: ClosestCubeRoot
@real: a,x,s,r;
@pre: a }\geq0\mathrm{ ;
x=a;
r=1;
s = 3.25;
@invariant: x \geq0^-12\cdotr 2+4\cdots=1^4\cdotr}\mp@subsup{}{}{3}-6\cdot\mp@subsup{r}{}{2}+3\cdotr+4\cdotx-4\cdota=
while (x-s\geq0)
{
x= [x=-s];
s= [3]-s+6--}\mp@subsup{r}{]}{}
r=r+1;
}
@post: 4 \cdot r 3 + 6 \cdot r 2 + 3 \cdotr \geq 4 \cdota \geq 4 \cdot r 3 - 6 }\cdot\mp@subsup{r}{}{2}+3\cdotr-
@prog: SquareRootFloor
@prog: ClosestSquareRoot @real: a,su,t,n;
@real: a,x,r; @pre: n\geq0;
@pre: a }\geq1\mathrm{ ; }a=0\mathrm{ ;
x=0.5 \cdota; su=1;
r=0; t=1;
@invariant: a=[2-x+r---r]}\wedgex\geq0\mathrm{ @invariant: }\mp@subsup{a}{}{2}\leqn\wedget=2\cdota+1\wedgesu=(a+1\mp@subsup{)}{}{2
while (x z r) while (su \leqn)
{ {
x= [x-二-r];
r=r+1;
}
@post: r}\mp@subsup{}{}{2}-r\geqa-2\cdotr\wedge\mp@subsup{r}{}{2}-r\leqa
@post((a * a) <= n);
then we know that the original QP is also unsatisfiable. Otherwise, we simply remove all the t=0t=0 constraints in the core and repeat the same process. 那么我们就知道原始的 QP 也是不可满足的。否则,我们只需移除核心中所有的 t=0t=0 约束,然后重复相同的过程。
Experimental Results. We now illustrate several programs that we synthesized using our implementation. In each case, we show the completed program, in which the synthesized parts are boxed. Due to space limitations, some examples are relegated to Appendix A. Table 1 provides a summary of the runtimes of our algorithm over these examples. 实验结果。我们现在展示几个使用我们实现合成的程序。在每个案例中,我们展示了完整的程序,其中合成的部分用方框标出。由于篇幅限制,一些示例被放在附录 A 中。表 1 总结了我们算法在这些示例上的运行时间。
PositivityEnforcement: We are synthesizing an expression such that adding it to the given polynomial makes it positive for all possible inputs. PositivityEnforcement:我们正在合成一个表达式,使其与给定多项式相加后,对于所有可能的输入都为正。
SquareCompletion: We are synthesizing a number such that adding it to the given polynomial makes it always positive. 平方补全:我们正在合成一个数,使得将其加到给定多项式上后,该多项式始终为正。
SlidingBody: Consider the following Physics problem: An object is placed on an inclined plane of given length ll. The inclination is given in terms of the sine and cosine of its angle. The coefficients of static and kinetic friction are also known. We want to find whether the body will slide and, if so, find the time it will take for it to reach the bottom of the plane. A physics student can easily write a program template as shown in the example for solving this problem using the principles and equations from classical mechanics. For example, the student can use an if block to decide if the body will move or not. Then, inside the block, they can use an equation of motion that holds for the various parameters involved in the problem. Now, to find the time it takes to slide down, they can leave a program hole in the template. 滑动物体:考虑以下物理问题:一个物体被放置在长度为 ll 的倾斜平面上。倾斜角度以其角度的正弦和余弦表示。静摩擦系数和动摩擦系数也已知。我们想要判断物体是否会滑动,如果会,求出它滑到底部所需的时间。物理学生可以轻松地编写一个程序模板,如示例所示,利用经典力学的原理和方程来解决此问题。例如,学生可以使用 if 语句块来判断物体是否会移动。然后,在该语句块内,可以使用适用于问题中各种参数的运动方程。现在,为了求出滑到底部所需的时间,他们可以在模板中留一个程序空洞。
Table 1. The runtimes of the different steps of our algorithm in seconds. 表 1. 我们算法不同步骤的运行时间(秒)。
ArchimedesPrinciple: A cuboid with dimensions ( l,b,hl, b, h ) of density rho\rho is placed in a fluid of density rho^(')\rho^{\prime}. We want to determine whether the body will float, and if it floats, find the percentage of the volume of the body that will be outside the fluid. 阿基米德原理:一个尺寸为( l,b,hl, b, h )的长方体,密度为 rho\rho ,被放置在密度为 rho^(')\rho^{\prime} 的流体中。我们想确定该物体是否会浮起,如果浮起,求出物体体积中露出流体外的百分比。
ClosestCubeRoot[Rodríguez-Carbonell 2018]: Given a positive real number nn, we need to synthesize a program that computes the closest integer cube root of nn. 最接近的立方根[Rodríguez-Carbonell 2018]:给定一个正实数 nn ,我们需要合成一个程序来计算 nn 的最接近的整数立方根。
SquareRootFloor[Rodríguez-Carbonell 2018]: Given a positive real number nn, we need to synthesize a program that computes the floor of the square root of nn. 平方根下取整[Rodríguez-Carbonell 2018]:给定一个正实数 nn ,我们需要合成一个程序来计算 nn 的平方根的下取整值。
SquareRootApproximation[Rodríguez-Carbonell 2018]: Given a positive real number nn and an error threshold epsilon\epsilon, we need to synthesize a program that computes sqrtn\sqrt{n}. 平方根近似[Rodríguez-Carbonell 2018]:给定一个正实数 nn 和误差阈值 epsilon\epsilon ,我们需要合成一个程序来计算 sqrtn\sqrt{n} 。
ConsecutiveCubes[Rodríguez-Carbonell 2018]: We want to synthesize a program that computes the sum of first nn cubes. ConsecutiveCubes[Rodríguez-Carbonell 2018]:我们希望合成一个计算前 nn 个立方和的程序。
In summary, our algorithm is able to handle various polynomial synthesis problems, including examples from physics and [Rodríguez-Carbonell 2018] in a few seconds. Hence, not only is the algorithm semi-complete in theory, but it is also applicable in practice. 总之,我们的算法能够在几秒钟内处理各种多项式合成问题,包括物理学中的例子和[Rodríguez-Carbonell 2018]中的例子。因此,该算法不仅在理论上是半完备的,而且在实践中也是可行的。
ACKNOWLEDGMENTS 致谢
This section was removed to preserve anonymity. 为保持匿名性,本节内容已被删除。
REFERENCES 参考文献
Alessandro Abate, Cristina David, Pascal Kesseli, Daniel Kroening, and Elizabeth Polgreen. 2018. Counterexample guided inductive synthesis modulo theories. In CAV. 270-288. Alessandro Abate, Cristina David, Pascal Kesseli, Daniel Kroening, 和 Elizabeth Polgreen. 2018. 基于反例引导的模理论归纳综合。发表于 CAV。270-288。
Sheshansh Agrawal, Krishnendu Chatterjee, and Petr Novotnỳ. 2017. Lexicographic ranking supermartingales: an efficient approach to termination of probabilistic programs. In POPL. Sheshansh Agrawal, Krishnendu Chatterjee, 和 Petr Novotnỳ. 2017. 词典序排名超鞅:一种高效的概率程序终止性方法。发表于 POPL。
Rajeev Alur, Rastislav Bodik, Garvit Juniwal, Milo MK Martin, Mukund Raghothaman, Sanjit A Seshia, Rishabh Singh, Armando Solar-Lezama, Emina Torlak, and Abhishek Udupa. 2013. Syntax-Guided Synthesis. FMCAD (2013). Rajeev Alur, Rastislav Bodik, Garvit Juniwal, Milo MK Martin, Mukund Raghothaman, Sanjit A Seshia, Rishabh Singh, Armando Solar-Lezama, Emina Torlak, 和 Abhishek Udupa. 2013. 语法引导综合。发表于 FMCAD (2013)。
Rajeev Alur, Dana Fisman, Saswat Padhi, Andrew Reynolds, Rishabh Singh, and Abhishek Udupa. 2019. SyGuS-Comp: Syntax-guided Synthesis Competition. https://sygus.org/. Rajeev Alur、Dana Fisman、Saswat Padhi、Andrew Reynolds、Rishabh Singh 和 Abhishek Udupa。2019。SyGuS-Comp:基于语法指导的综合竞赛。https://sygus.org/。
Rajeev Alur, Rishabh Singh, Dana Fisman, and Armando Solar-Lezama. 2018. Search-based program synthesis. Commun. ACM 61, 12 (2018), 84-93. Rajeev Alur、Rishabh Singh、Dana Fisman 和 Armando Solar-Lezama。2018。基于搜索的程序综合。Commun. ACM 61, 12 (2018), 84-93。
Ali Asadi, Krishnendu Chatterjee, Hongfei Fu, Amir Kafshdar Goharshady, and Mohammad Mahdavi. 2021. Polynomial reachability witnesses via Stellensätze. In PLDI. 772-787. Ali Asadi、Krishnendu Chatterjee、Hongfei Fu、Amir Kafshdar Goharshady 和 Mohammad Mahdavi。2021。通过 Stellensätze 的多项式可达性证明。在 PLDI。772-787。
Grigoriy Blekherman, Pablo A Parrilo, and Rekha R Thomas. 2012. Semidefinite optimization and convex algebraic geometry. SIAM. Grigoriy Blekherman、Pablo A Parrilo 和 Rekha R Thomas。2012。半正定优化与凸代数几何。SIAM。
Jacek Bochnak, Michel Coste, and Marie-Françoise Roy. 2013. Real algebraic geometry. Vol. 36. Springer Science & Business Media. Jacek Bochnak、Michel Coste 和 Marie-Françoise Roy。2013 年。《实代数几何》。第 36 卷。Springer Science & Business Media。
Krishnendu Chatterjee, Hongfei Fu, and Amir Kafshdar Goharshady. 2016. Termination analysis of probabilistic programs through Positivstellensatz’s. In CAV. 3-22. Krishnendu Chatterjee、Hongfei Fu 和 Amir Kafshdar Goharshady。2016 年。通过 Positivstellensatz 进行概率程序的终止性分析。发表于 CAV,3-22 页。
Krishnendu Chatterjee, Hongfei Fu, Amir Kafshdar Goharshady, and Ehsan Kafshdar Goharshady. 2020b. Polynomial invariant generation for non-deterministic recursive programs. In PLDI. 672-687. Krishnendu Chatterjee、Hongfei Fu、Amir Kafshdar Goharshady 和 Ehsan Kafshdar Goharshady。2020 年 b。非确定性递归程序的多项式不变量生成。发表于 PLDI,672-687 页。
Krishnendu Chatterjee, Hongfei Fu, and Petr Novotnỳ. 2020a. Termination analysis of probabilistic programs with martingales. Foundations of Probabilistic Programming (2020), 221-258. Krishnendu Chatterjee、Hongfei Fu 和 Petr Novotnỳ。2020 年 a。利用鞅进行概率程序的终止性分析。《概率编程基础》(2020),221-258 页。
Alonzo Church. 1963. Application of recursive arithmetic to the problem of circuit synthesis. Fournal of Symbolic Logic 28, 4 (1963). 阿隆佐·丘奇。1963 年。递归算术在电路综合问题中的应用。《符号逻辑杂志》28 卷,第 4 期(1963 年)。
Michael A Colón, Sriram Sankaranarayanan, and Henny B Sipma. 2003. Linear invariant generation using non-linear constraint solving. In CAV. 420-432. 迈克尔·A·科隆,斯里拉姆·桑卡拉纳拉亚南,亨尼·B·西普马。2003 年。利用非线性约束求解的线性不变量生成。载于 CAV 会议。420-432 页。
Julius Farkas. 1902. Theory of simple inequalities. Journal for pure and applied mathematics (Crelles Journal) 1902, 124 (1902), 1-27. 尤利乌斯·法尔卡斯。1902 年。简单不等式理论。《纯粹与应用数学杂志》(克雷勒斯杂志)1902 年,124 期(1902 年),1-27 页。
Grigory Fedyukovich, Sumanth Prabhu, Kumar Madhukar, and Aarti Gupta. 2019. Quantified invariants via syntax-guided synthesis. In CAV. 259-277. 格里高利·费迪尤科维奇,苏曼斯·普拉布,库马尔·马杜卡尔,阿尔蒂·古普塔。2019 年。通过语法引导合成的量化不变量。载于 CAV 会议。259-277 页。
Yijun Feng, Lijun Zhang, David N Jansen, Naijun Zhan, and Bican Xia. 2017. Finding polynomial loop invariants for probabilistic programs. In ATVA. 400-416. 冯一军,张立军,David N Jansen,詹乃军,夏必灿。2017。为概率程序寻找多项式循环不变式。发表于 ATVA。400-416。
Amir Goharshady. 2020. Parameterized and algebro-geometric advances in static program analysis. Ph.D. Dissertation. Institute of Science and Technology Austria. Amir Goharshady。2020。静态程序分析中的参数化和代数几何进展。博士论文。奥地利科学技术研究院。
Cordell Green. 1981. Application of theorem proving to problem solving. In Readings in Artificial Intelligence. 202-222. Cordell Green。1981。定理证明在问题解决中的应用。发表于《人工智能读本》。202-222。
Sumit Gulwani. 2011. Automating string processing in spreadsheets using input-output examples. In POPL. 317-330. Sumit Gulwani。2011。使用输入输出示例自动化电子表格中的字符串处理。发表于 POPL。317-330。
Sumit Gulwani, William R Harris, and Rishabh Singh. 2012. Spreadsheet data manipulation using examples. Commun. ACM 55, 8 (2012), 97-105. Sumit Gulwani、William R Harris 和 Rishabh Singh。2012 年。使用示例进行电子表格数据操作。Commun. ACM 55, 8 (2012), 97-105。
Sumit Gulwani, Susmit Jha, Ashish Tiwari, and Ramarathnam Venkatesan. 2011. Synthesis of loop-free programs. In PLDI. 62-73. Sumit Gulwani、Susmit Jha、Ashish Tiwari 和 Ramarathnam Venkatesan。2011 年。无循环程序的合成。发表于 PLDI。62-73。
Sumit Gulwani, Oleksandr Polozov, and Rishabh Singh. 2017. Program synthesis. Foundations and Trends in Programming Languages 4, 1-2 (2017), 1-119. Sumit Gulwani、Oleksandr Polozov 和 Rishabh Singh。2017 年。程序合成。编程语言基础与趋势 4, 1-2 (2017), 1-119。
Zheng Guo, Michael James, David Justo, Jiaxiao Zhou, Ziteng Wang, Ranjit Jhala, and Nadia Polikarpova. 2019. Program synthesis by type-guided abstraction refinement. In POPL. 1-28. Zheng Guo、Michael James、David Justo、Jiaxiao Zhou、Ziteng Wang、Ranjit Jhala 和 Nadia Polikarpova。2019 年。基于类型引导的抽象精炼程序合成。发表于 POPL。1-28。
David Handelman. 1988. Representing polynomials by positive linear functions on compact convex polyhedra. Pacific F\mathcal{F}. Math. 132, 1 (1988), 35-62. David Handelman. 1988. 通过紧凑凸多面体上的正线性函数表示多项式。Pacific F\mathcal{F} . Math. 132, 1 (1988), 35-62.
Robin Hartshorne. 2013. Algebraic geometry. Vol. 52. Springer Science & Business Media. Robin Hartshorne. 2013. 代数几何。第 52 卷。Springer Science & Business Media.
Tristan Knoth, Di Wang, Nadia Polikarpova, and Jan Hoffmann. 2019. Resource-guided program synthesis. In PLDI. 253-268. Tristan Knoth, Di Wang, Nadia Polikarpova, 和 Jan Hoffmann. 2019. 资源引导的程序合成。发表于 PLDI。253-268.
Andrej Kolmogoroff. 1932. Zur deutung der intuitionistischen logik. Mathematische Zeitschrift 35, 1 (1932), 58-65. Andrej Kolmogoroff. 1932. 关于直觉主义逻辑的解释。Mathematische Zeitschrift 35, 1 (1932), 58-65.
John R Koza. 1994. Genetic programming as a means for programming computers by natural selection. Statistics and computing 4, 2 (1994), 87-112. John R Koza. 1994. 通过自然选择进行计算机编程的遗传编程方法。统计与计算 4, 2 (1994), 87-112。
Krzysztof Krawiec. 2016. Behavioral program synthesis with genetic programming. Vol. 618. Krzysztof Krawiec. 2016. 使用遗传编程的行为程序合成。卷 618。
Hongming Liu, Hongfei Fu, Zhiyong Yu, Jiaxin Song, and Guoqiang Li. 2022. Location-by-Location Linear Invariant Generation with Farkas’ Lemma. In OOPSLA. Hongming Liu, Hongfei Fu, Zhiyong Yu, Jiaxin Song, 和 Guoqiang Li. 2022. 基于 Farkas 引理的逐点线性不变量生成。发表于 OOPSLA。
Ngoc Hoang Anh Mai and Victor Magron. 2022. On the complexity of Putinar-Vasilescu’s Positivstellensatz. Fournal of Complexity (2022), 101663. Ngoc Hoang Anh Mai 和 Victor Magron. 2022. Putinar-Vasilescu 正值定理的复杂性研究。复杂性杂志 (2022), 101663。
Zohar Manna and Richard J Waldinger. 1971. Toward automatic program synthesis. Commun. ACM 14, 3 (1971), 151-165. Zohar Manna 和 Richard J Waldinger. 1971. 迈向自动程序综合。Commun. ACM 14, 3 (1971), 151-165。
Aaron Meurer, Christopher P Smith, Mateusz Paprocki, Ondřej Čertík, Sergey B Kirpichev, Matthew Rocklin, AMiT Kumar, Sergiu Ivanov, Jason K Moore, Sartaj Singh, et al. 2017. SymPy: symbolic computing in Python. Peerf Computer Science 3 (2017), e103. Aaron Meurer, Christopher P Smith, Mateusz Paprocki, Ondřej Čertík, Sergey B Kirpichev, Matthew Rocklin, AMiT Kumar, Sergiu Ivanov, Jason K Moore, Sartaj Singh 等. 2017. SymPy:Python 中的符号计算。Peerf Computer Science 3 (2017), e103。
Leonardo de Moura and Nikolaj Bjørner. 2008. Z3: An efficient SMT solver. In TACAS. 337-340. Leonardo de Moura 和 Nikolaj Bjørner. 2008. Z3:一种高效的 SMT 求解器。发表于 TACAS. 337-340。
Eike Neumann, Joël Ouaknine, and James Worrell. 2020. On ranking function synthesis and termination for polynomial programs. In CONCUR. Eike Neumann, Joël Ouaknine 和 James Worrell. 2020. 关于多项式程序的排序函数综合与终止性。发表于 CONCUR。
Amir Pnueli and Roni Rosner. 1989. On the synthesis of a reactive module. In POPL. 179-190. Amir Pnueli 和 Roni Rosner。1989 年。关于反应模块的综合。发表于 POPL,179-190 页。
Nadia Polikarpova, Ivan Kuraj, and Armando Solar-Lezama. 2016. Program synthesis from polymorphic refinement types. In PLDI. 522-538. Nadia Polikarpova、Ivan Kuraj 和 Armando Solar-Lezama。2016 年。基于多态细化类型的程序综合。发表于 PLDI,522-538 页。
Mathias Preiner, Aina Niemetz, and Armin Biere. 2017. Counterexample-guided model synthesis. In TACAS. 264-280. Mathias Preiner、Aina Niemetz 和 Armin Biere。2017 年。基于反例指导的模型综合。发表于 TACAS,264-280 页。
Mihai Putinar. 1993. Positive polynomials on compact semi-algebraic sets. Indiana University Mathematics Journal 42, 3 (1993), 969-984. Mihai Putinar。1993 年。紧致半代数集上的正多项式。Indiana University Mathematics Journal,42 卷,第 3 期(1993 年),969-984 页。
Andrew Reynolds, Morgan Deters, Viktor Kuncak, Cesare Tinelli, and Clark Barrett. 2015. Counterexample-guided quantifier instantiation for synthesis in SMT. In CAV. 198-216. Andrew Reynolds、Morgan Deters、Viktor Kuncak、Cesare Tinelli 和 Clark Barrett。2015 年。用于 SMT 合成的反例引导量词实例化。载于 CAV,198-216 页。
Henry Gordon Rice. 1953. Classes of recursively enumerable sets and their decision problems. Transactions of the American Mathematical society 74, 2 (1953), 358-366. Henry Gordon Rice。1953 年。递归可枚举集合的类别及其判定问题。美国数学学会会刊,74 卷,第 2 期(1953 年),358-366 页。
Enric Rodríguez-Carbonell. 2018. Some programs that need polynomial invariants in order to be verified. https://www.cs. upc.edu/~erodri/webpage/polynomial_invariants/list.html. Enric Rodríguez-Carbonell。2018 年。某些需要多项式不变量以进行验证的程序。https://www.cs.upc.edu/~erodri/webpage/polynomial_invariants/list.html。
Sriram Sankaranarayanan, Henny B Sipma, and Zohar Manna. 2004a. Constraint-based linear-relations analysis. In SAS. 53-68. Sriram Sankaranarayanan、Henny B Sipma 和 Zohar Manna。2004 年。基于约束的线性关系分析。载于 SAS,53-68 页。
Sriram Sankaranarayanan, Henny B Sipma, and Zohar Manna. 2004b. Non-linear loop invariant generation using Gröbner bases. In POPL. 318-329. Sriram Sankaranarayanan、Henny B Sipma 和 Zohar Manna。2004 年。使用 Gröbner 基生成非线性循环不变量。发表于 POPL。318-329。
David E Shaw, William R Swartout, and C Cordell Green. 1975. Inferring LISP Programs From Examples. In IFCAI. 260-267. David E Shaw、William R Swartout 和 C Cordell Green。1975 年。从示例推断 LISP 程序。发表于 IFCAI。260-267。
Xujie Si, Woosuk Lee, Richard Zhang, Aws Albarghouthi, Paraschos Koutris, and Mayur Naik. 2018. Syntax-guided synthesis of datalog programs. In ESEC/FSE. 515-527. Xujie Si、Woosuk Lee、Richard Zhang、Aws Albarghouthi、Paraschos Koutris 和 Mayur Naik。2018 年。基于语法指导的 datalog 程序合成。发表于 ESEC/FSE。515-527。
David Canfield Smith. 1975. Pygmalion: a creative programming environment. Stanford University. David Canfield Smith。1975 年。Pygmalion:一个创造性编程环境。斯坦福大学。
Dominik Sobania, Dirk Schweim, and Franz Rothlauf. 2022. A Comprehensive Survey on Program Synthesis with Evolutionary Algorithms. IEEE Transactions on Evolutionary Computation (2022). Dominik Sobania、Dirk Schweim 和 Franz Rothlauf。2022 年。使用进化算法进行程序合成的综合调查。《IEEE 进化计算汇刊》(2022 年)。
Armando Solar-Lezama. 2008. Program synthesis by sketching. University of California, Berkeley. Armando Solar-Lezama。2008 年。通过草图进行程序合成。加利福尼亚大学伯克利分校。
Armando Solar-Lezama. 2009. The sketching approach to program synthesis. In APLAS. 4-13. Armando Solar-Lezama。2009 年。程序合成的草图方法。载于 APLAS,页 4-13。
Saurabh Srivastava, Sumit Gulwani, and Jeffrey S Foster. 2010. From program verification to program synthesis. In POPL. 313-326. Saurabh Srivastava、Sumit Gulwani 和 Jeffrey S Foster。2010 年。从程序验证到程序合成。载于 POPL,页 313-326。
Saurabh Srivastava, Sumit Gulwani, and Jeffrey S Foster. 2013. Template-based program verification and program synthesis. International fournal on Software Tools for Technology Transfer 15, 5 (2013), 497-518. Saurabh Srivastava、Sumit Gulwani 和 Jeffrey S Foster。2013 年。基于模板的程序验证与程序合成。《国际软件工具技术转移杂志》15 卷,第 5 期(2013 年),497-518 页。
Toru Takisaka, Yuichiro Oyabu, Natsuki Urabe, and Ichiro Hasuo. 2018. Ranking and repulsing supermartingales for reachability in probabilistic programs. In ATVA. 476-493. Toru Takisaka、Yuichiro Oyabu、Natsuki Urabe 和 Ichiro Hasuo。2018 年。用于概率程序可达性的超鞅的排序与排斥。在 ATVA 会议论文集,476-493 页。
Alfred Tarski. 1949. A Decision Method for Elementary Algebra and Geometry. Fournal of Symbolic Logic 14, 3 (1949). Alfred Tarski。1949 年。初等代数与几何的决策方法。《符号逻辑杂志》14 卷,第 3 期(1949 年)。
Anne S Troelstra. 1977. Aspects of constructive mathematics. In Studies in Logic and the Foundations of Mathematics. Vol. 90. 973-1052. Anne S Troelstra。1977 年。构造数学的若干方面。收录于《逻辑与数学基础研究》卷 90,973-1052 页。
David S Watkins. 2004. Fundamentals of matrix computations. Vol. 64. John Wiley & Sons. David S Watkins. 2004. 矩阵计算基础。第 64 卷。约翰·威利父子公司。
Table 2. Comparison of our approach with previous synthesis methods. All times are in seconds. 表 2. 我们的方法与之前合成方法的比较。所有时间均以秒为单位。
COMPARISON WITH ROSETTE AND SKETCH 与 ROSETTE 和 SKETCH 的比较
Table 2 provides a comparison between our approach and the state-of-the-art synthesis tools Sketch and Rosette, as well as a direct encoding to SMT that was passed to Z3. The rest of this document contains the details of programs output by these tools. All experiments were run on the same machine as in our original submission with a time limit of 12 hours per instance. Note that Sketch is not sound for real variables and wrong answers are expected. However, in most cases Sketch’s output is just setting everything to 0 , which is wrong even for integer variables. 表 2 比较了我们的方法与最先进的综合工具 Sketch 和 Rosette,以及直接编码为 SMT 并传递给 Z3 的结果。本文其余部分包含这些工具输出程序的详细信息。所有实验均在与我们最初提交时相同的机器上运行,每个实例的时间限制为 12 小时。请注意,Sketch 对实数变量不保证正确性,预期会有错误答案。然而,在大多数情况下,Sketch 的输出只是将所有值设为 0,即使对于整数变量也是错误的。
A MORE EXAMPLES FROM SECTION 5 第 5 节的更多示例
@prog: PolynomialApproximation
@real \(t, x, e, g_{1}, g_{2}, n\);
@macro \(f_{1}=x^{3}\);
@macro \(f_{2}=x^{3}+x\);
@macro \(f_{3}=\underline{5}+\underline{x}+\underline{x}^{3}\);;
@pre: \(1 \geq 0\);
@prog: PositivityEnforcement
@prog: SquareCompletion \(t=0\);
@real: \(x, n\);
@real: \(x, n\);
\(e=5\);
@pre: \(x \leq 100\);
@pre: \(x \leq 100\);
if ( \(x \leq t\) )
\(x=n^{2}-5 \cdot n\);
\(x=n^{2}-5 \cdot n\);
\{
\(n=[5-\underline{n} \mathbf{+}-1] ;\)
\(n=\left\lfloor\frac{25}{4}\right\rfloor\);
\(x=x+n\);
\(x=x+n ;\)
@post: \(x \geq 0\);
@post: \(x \geq 0\);
else
\{
\(g_{2}=f_{3}-f_{2} ;\)
\(n=g_{2}\);
\}
@post: \(n \leq e\);
@prog: SlidingBody
@real: move, e, \(t, g, n u s, n u k, \sin , \cos , l\); @prog: ArchimedesPrinciple
@pre: \(t \geq 0 \wedge n u s \geq n u k ; \quad\) @real: fl, \(m, l, b, h, \rho, e, x\);
\(g=9.8 ; \quad\) @pre: \(x \geq 0 \wedge m \geq 0\);
nuk \(=0.2\); \(l=10\);
nus \(=0.3\); \(\quad b=5\);
\(\sin =0.5 ; \quad h=2\);
\(\cos =0.86 ; \quad \rho=2\);
\(l=10 ; \quad\) if ( \(m \leq \rho \cdot l \cdot b \cdot h\) )
if ( \(\sin \geq\) nus \(\cdot \cos\) ) \{
\(\{\quad f l=1\);
move \(=1\);
\(t=\left\lceil 21 \quad x=\left\lfloor\frac{1}{200}\right\rfloor\right.\);
\(e=t \cdot t \cdot g \cdot \sin -g \cdot n u k \cdot \cos -2 \cdot l ; \quad\}\)
\} else
else \{
\{
move \(=0\);
\(e=0\);
\(t=\left\lceil\frac{21}{2}-8.0056060865 \cdot\right.\) move \({ }_{1} ;\) \}
\}
\(e=0\);
\(f l=0\);
\(x=\left\lfloor\frac{\bar{f} l}{2 \underline{20}}\right\rfloor\);
\}
@post: \(e=0 \wedge t \geq 0\);
@prog: Cohendiv
@real: \(x, y, q, r, d d\);
@pre: \(x \geq 0 \wedge y \geq 1\);
\(q=0\);
\(r=x\);
@invariant: \(x=q \cdot y+r \wedge r \geq 0\)
while ( \(r \geq y\) )
\{
\(d=1\);
\(d d=y\);
@invariant: \(d d=y \cdot d \wedge x=q \cdot y+r\)
\(\wedge r \geq 0 \wedge r \geq y \cdot d\)
while( \(r \geq 2 \cdot d d\) )
\{
\(d=2 \cdot d ;\)
\(d d=[2]-\underline{d} d_{]} ;\)
\}
\(r=r-d d ;\)
\(q=[\overline{q+d}] ;\)
\}
@post: \(1 \geq 0\);
@prog: ClosestCubeRoot
@real: \(a, x, s, r\);
@pre: \(a \geq 0\);
\(x=a\);
\(r=1\);
\(\mathrm{s}=3.25 ;\)
@invariant: \(x \geq 0 \wedge-12 \cdot r^{2}+4 \cdot s=1 \wedge 4 \cdot r^{3}-6 \cdot r^{2}+3 \cdot r+4 \cdot x-4 \cdot a=1\)
while \((x-s \geq 0)\)
\{
\(x=\) Timed out;
\(s=\) Timed out];
\(r=r+1\);
\}
@post: \(4 \cdot r^{3}+6 \cdot r^{2}+3 \cdot r \geq 4 \cdot a \geq 4 \cdot r^{3}-6 \cdot r^{2}+3 \cdot r-1\)
@prog: SquareRootFloor
@prog: ClosestSquareRoot @real: a, su, \(t, n\);
@real: \(a, x, r\); @pre: \(n \geq 0\);
@pre: \(a \geq 1\); \(\quad a=0\);
\(x=0.5 \cdot a\); \(\quad\) su \(=1\);
\(r=0\); \(\quad t=1\);
@invariant: \(a=\left[2 \cdot \underline{x}+\underline{r}^{2}-\underline{-} r^{-} \wedge \wedge x \geq 0\right.\) @invariant: \(a^{2} \leq n \wedge t=2 \cdot a+1 \wedge s u=(a+1)^{2}\)
while \((x \geq r) \quad\) while \((s u \leq n)\)
\{
\(x=[\bar{x}=\bar{r}] ;\)
\(r=r+1\);
\}
@post: \(\left.r^{2}-r \geq a-2 \cdot r \wedge r^{2}-r \leq a \quad\right\}\)
@post((a * a) <= n);
@prog: SquareRootApproximation
@real: a,err, \(r, q, p\); @prog: ConsecutiveCubes
@pre: \(a \geq 1 \wedge e r r \geq 0\);
\(r=a-1\);
\(q=1\);
\(p=0.5\);
@invariant: \(p \geq 0 \wedge r \geq 0 \wedge a=q^{2}+2 \cdot r \cdot p\)
while ( \(2 \cdot p \cdot r \geq e r r\) )
\{
if \((2 \cdot r-2 \cdot q-p \geq 0)\)
\{
\(r=\) Timed out \(]\);
\(q=p+\) Timed out \(] ;\)
\(p=p / 2\);
\}
else
\{
\(r=\) Timed out \(]\);
\(p=p \cdot 0.5\);
\}
\}
@post: \(q^{2} \geq a-e r r \wedge q^{2} \leq a\)
@real: \(N, n, x, y, z, s\);
@pre: \(1 \geq 0\);
\(n=0\);
\(x=0\);
\(y=1\);
\(z=6\);
\(s=0\);
@invariant: \(z=6 \cdot n \wedge y=3 \cdot n^{2}+3 \cdot n+1 \wedge x=n^{3}\)
while ( \(n \leq N\) )
\{
if ( \(x=n^{3}\) )
\{
\(s=s+x ;\)
\}
\(n=n+1\);
\(x=\) Timed out \(] ;\)
\(y=\) Timed out ;
\(z=\) Limed out \({ }_{1}\);
\}
@post: \(1 \geq 0\);
@prog: PolynomialApproximation
@real t,x,e, g1, g2,n;
@macro f1 = x 3 ;
@macro f2 = x }\mp@subsup{}{}{3}+x\mathrm{ ;
@macro f3 = x x -0.5 - x 2 -0.5 - x +0.5;
@pre: 1 }\geq0\mathrm{ ;
@prog: PositivityEnforcement @prog: SquareCompletion t=0;
@real: x,n; @real: x,n; e=5;
@pre: x\leq100; @pre: x\leq100; if (x\leqt)
x = n}\mp@subsup{}{}{2}-5\cdotn\mathrm{ ;
n = Limed out];
x = x + n;
@post: x }\geq0\mathrm{ ;
x = n }\mp@subsup{}{}{2}-5\cdotn\mathrm{ ;
n = [6.25];
x = x + n;
@post: x \geq 0;
@prog: SlidingBody
@real: move,e,t,g,nus,nuk,sin,cos,l. @prog: ArchimedesPrinciple
g=9.8; @pre: x \geq0^m 0;
nuk = 0.2; l=10;
nus = 0.3. b=5;
sin=0.5; h=2;
cos = 0.86; o = 2;
l=10; if ( m\leq\rho\cdotl\cdotb\cdoth)
if (sin \geq nus · cos) {
{
move = 1;
t= Failed;
e=t\cdott\cdotg\cdotsin-g\cdotnuk\cdotcos-2\cdotl; }
} else
else {
{
move = 0;
e=0;
t = Failed;
}
@post: e=0^t }\mp@code{0;
fl=1;
x= [\frac{fl}{200}];
e=m-\rho\cdotl\cdotb\cdoth\cdotx;
}
{
e=0;
fl=0;
x= [ 京l}\mp@subsup{}{200}{200}]
}
@post: e=0^0\leqx\leq1;
@prog: Cohendiv
@real: x,y,q,r,dd;
@pre: x \geq0^y \geq1;
q=0;
r=x;
@invariant: x = q.y +r^r\geq0
while (r }ry\mathrm{ )
{
d=1;
dd = y;
@invariant: dd = y \cdotd ^ x = q.y +r
\wedger \geq0 ^ r \geqy d
while(r }\mp@code{2\cdotdd}\mathrm{ )
{
d=2\cdotd;
dd = [2--d d];
}
r=r-dd;
q= q+d];
}
@post: 1 }\geq0\mathrm{ ;
@prog: MannadivCarre
@real n, y,x,t;
@pre: n\geq0;
y=n;
x=0;
t=0;
@invariant: }\mp@subsup{x}{}{2}+2\cdott+y-n=
while(y.(y-1) \geq0)
{
if( t = x)
{
y= [y--1];
t=0;
x = x + 1;
}
else
{
y= y-2;
t=t+1;
}
}
@post: 1 }\geq0\mathrm{ ;
*Authors are ordered alphabetically. *作者按字母顺序排列。
Authors’ addresses: Amir Kafshdar Goharshady, Department of Computer Science and Engineering, Department of Mathematics, Hong Kong University of Science and Technology, Clear Water Bay, Kowloon, Hong Kong, goharshady@cse.ust.hk; S. Hitarth, Department of Computer Science and Engineering, Hong Kong University of Science and Technology, Clear Water Bay, Kowloon, Hong Kong, hsinghab@connect.ust.hk; Fatemeh Mohammadi, Department of Mathematics and Department of Computer Science, KU Leuven, Belgium, KU Leuven, Leuven, Belgium, fatemeh.mohammadi@kuleuven.be; Harshit Jitendra Motwani, Department of Mathematics: Algebra and Geometry, Ghent University, Ghent, Belgium, harshitjitendra.motwani@ugent.be. 作者地址:Amir Kafshdar Goharshady,香港科技大学计算机科学与工程系、数学系,香港九龙清水湾,goharshady@cse.ust.hk;S. Hitarth,香港科技大学计算机科学与工程系,香港九龙清水湾,hsinghab@connect.ust.hk;Fatemeh Mohammadi,比利时鲁汶大学数学系与计算机科学系,鲁汶,fatemeh.mohammadi@kuleuven.be;Harshit Jitendra Motwani,比利时根特大学数学系:代数与几何,根特,harshitjitendra.motwani@ugent.be。
^(1){ }^{1} Positivstellensatz is German for “positive locus theorem”. Its plural form is Positivstellensätze. ^(1){ }^{1} Positivstellensatz 是德语,意为“正点定理”。其复数形式为 Positivstellensätze。 ^(2){ }^{2} Nullstellensatz is German for “zero locus theorem”. ^(2){ }^{2} Nullstellensatz 是德语,意为“零点定理”。
^(3){ }^{3} Such invariants can be generated by our approach or [Chatterjee et al. 2020b; Sankaranarayanan et al. 2004b]. ^(3){ }^{3} 这样的不变量可以通过我们的方法或[Chatterjee et al. 2020b; Sankaranarayanan et al. 2004b]生成。