This paper was converted on www.awesomepapers.org from LaTeX by an anonymous user.
Want to know more? Visit the Converter page.

Program Synthesis for Polynomial System using Algebraic Geometry

Anonymous
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.

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.

Keywords:
program synthesis, sketching, syntax-guided synthesis

1 Introduction

An imperative program is a sequence of instructions in a programming language that manipulate the memory to solve a problem. The task of writing the program is usually done by a programmer who first comes up with a high-level idea for the algorithm, and then they implement their algorithm by writing a program. Synthesis makes the later part easier; given logical specification for the program, we can synthesize a program that satisfies those specifications. Syntax-Guided Synthesis problem (SyGuS) module theory TT is a general synthesis problem of a function ff given semantic constraint as a formula built from symbols in theory TT and ff, and syntactic constraint given as a (possibly infinite) set of expressions from TT specified using a context-free grammar.

In this paper, we focus on Syntax-Guided program synthesis problem module theory of Polynomial Arithmetic (over reals).

The treatment here generalises the methods for program synthesis used in [srivastava2013template] for linear programs to polynomial programs. Our main tools include the use of classical theorems from Real Algebraic Geoemtry [bochnak2013real] like Handelman’s Theorem (Thoerem 4.3), Putinar’s Positivstellensatz (Theorem 4.4) and Real Nullstellensatz (Theorem 4.5). We provide with a sound and semi-complete synthesis algorithm for polynomial programs.

Outline of the paper: In Section 2, we defined the notions of programs, semantics and templates. We also give a mathematically precise formulation of the problem in terms of constraint pairs. In Section 4.2, we presented classical theorems from Real Algebraic Geometry required for design of the synthesis algorithm. We also presented Theorem 4.6 which is a new mathematical contribution from this paper. In Section LABEL:synthesis_algo, we presented our synthesis algorithm along with proving it’s soundness and semi-completeness. Finally in Section LABEL:secion_proof_of_concept we presented a proof of our proposed concept by providing experimentation results on small programs.

2 Template-based Synthesis of Polynomial Programs

We consider program as a sequence of instructions, as in an imperative programming language. For instance, consider the following example program PP:

Example 1
@real: i,s,n;
@pre: n>=0;
i = 0;
while(i <= n, s >= i) {
s = s+1;
i = i+1;
}
@post: s >= n;

The program variables in the above example program are V={s,i,n}V=\{s,i,n\}, and we say that the program is defined over the variables VV. Note that we have the precondition and postcondition in our example program, which are polynomial assertion over the program variables. A program is said to be valid if every valuation of program variables that satisfies the pre condition, the valuation obtained after executing the program satisfies the post condition. The programmer sometimes may have a specification of a program via precondition and postcondition with partial implementation. We call such partial implementation as program template. The synthesis problem is to complete such partial implementation and generate a concrete valid program.

In this paper, we restrict ourselves to the so-called polynomial programs over a set of variables VV that can be generated from the following grammar:

P\displaystyle P :=(Φ,E,Φ)\displaystyle:=(\Phi,E,\Phi)
E\displaystyle E :=vP(V) if (Φ){E} else {E}while (Φ,Φ){E}E;E\displaystyle:=v\leftarrow P(V)\mid\texttt{ if }(\Phi)\;\{E\}\texttt{ else }\{E\}\mid\texttt{while }(\Phi,\Phi)\;\{E\}\mid E;E
Φ\displaystyle\Phi :=P(V)0(ΦΦ)¬Φ\displaystyle:=P(V)\geq 0\mid(\Phi\land\Phi)\mid\lnot\Phi

where P(V)P(V) denotes any polynomial expression over the variables VV with real coefficients. The semantics of each instruction are as usual except for while(ψ,ϕ,E)while(\psi,\phi,E) which is a while loop with guard ψ\psi for the block of code EE, and ϕ\phi is a loop invariant. In general, the loop invariant ϕ\phi should be strong enough for us to prove the correctness of the program with given precondition and postcondition.

Let the set of program variables be V={x1,x2,,xn}V=\{x_{1},x_{2},\ldots,x_{n}\}, νV\nu\in\mathbb{R}^{V} be any valuation of VV. Given a polynomial PP over VV and a valuation νV\nu\in\mathbb{R}^{V}, we denote P(ν)P(\nu) to be the evaluation of the polynomial PP on substituting each xVx\in V with ν(x)\nu(x). On executing an instruction EE, the valuation of the variables becomes ν=E(ν)\nu^{\prime}=E(\nu). We define the semantics of the program recursively in the Table 2.

Expression EE Final Valuation ν\nu^{\prime}
E1;E2E_{1};E_{2} ν=E2(E1(ν))\nu^{\prime}=E_{2}(E_{1}(\nu))
vP(V)v\leftarrow P(V) ν(v)=P(ν)\nu^{\prime}(v)=P(\nu) and xV{v}.ν(x)=ν(x)\forall x\in V\setminus\{v\}.\nu^{\prime}(x)=\nu(x)
if (ϕ){E1} else {E2}\texttt{if }(\phi)\;\{E_{1}\}\texttt{ else }\{E_{2}\} if νϕ\nu\models\phi then ν=E1(ν)\nu^{\prime}=E_{1}(\nu) else ν=E2(ν)\nu^{\prime}=E_{2}(\nu)
while (guard,inv){E}\texttt{while }(guard,inv)\;\{E\} if νguard\nu\models\textit{guard} and νinv\nu\models\textit{inv}, then ν=E(ν1)\nu^{\prime}=E(\nu_{1}) where ν1=E(ν)\nu_{1}=E(\nu) and ν1inv\nu_{1}\models\textit{inv} else ν=ν\nu^{\prime}=\nu
Example 2

Consider the following template TT, for example, whose one realization is the program PP from Example 1. The synthesis algorithm will replace the holes with suitable polynomials, if they exist, such that the resulting program satisfies the constraints given by pre-conditions and post-conditions.

@real: i,s,n;
@function f1 = [(i),1]
@function f2 = [(i),1]
@pre: n>=0;
i = 0;
s = 0;
while(i <= n, s >= f1) {
s = s+f2;
i = i+1;
}
@post: s >= n;

A template program basically specifies the intuition behind the final program and has holes at location where the program expects the synthesizer to fill in appropriate expressions. A hole could be thought of as a hint that programmer has provided to synthesis a correct program. In this example template program, we have two polynomial function symbols F={f1,f2}F=\{f_{1},f_{2}\}. [V,d][V^{\prime},d], called a program hole, represents a symbolic polynomial P over the variables VV^{\prime} with total degree dd\in\mathbb{N} and coefficients from the template variable set U={a1,a2,a3,a4}U=\{a_{1},a_{2},a_{3},a_{4}\}. Given a template program, our goal is to synthesize values for all the template variables such that the resulting program is valid.

In the following we formalize what we mean by partial implementation, or template. A template of the polynomial program over the variables VV and set of polynomial function symbol FF is defined using the following grammar:

E\displaystyle E :=E if (Φ){E} else {E}while (Φ,Φ){E}E;E\displaystyle:=E^{\prime}\mid\texttt{ if }(\Phi)\;\{E^{\prime}\}\texttt{ else }\{E\}\mid\texttt{while }(\Phi,\Phi)\;\{E^{\prime}\}\mid E;E
X\displaystyle X :=fP[V]f[V,d]ff+fff×f[σ](f)\displaystyle:=f\leftarrow P[V]\mid f\leftarrow[V^{\prime},d]\mid f\leftarrow f+f\mid f\leftarrow f\times f\mid[\sigma](f)
σ\displaystyle\sigma :=vP[V]σ,σ\displaystyle:=v\to P[V]\mid\sigma,\sigma
Φ\displaystyle\Phi :=P(V)0[V,d]0(ΦΦ)¬Φ\displaystyle:=P(V)\geq 0\mid[V^{\prime},d]\geq 0\mid(\Phi\land\Phi)\mid\lnot\Phi

The polynomial function symbols could be used by the programmer to specify either a concrete polynomial or a symbolic polynomial. The programmar can also evaluate a polynomial function symbol using a substitution map σ:[V][V]\sigma:\mathbb{R}[V]\to\mathbb{R}[V]. A substitution map that can be applied on polynomials and function symbols to obtain another polynomial expression.

Though this representation is programmer-friendly, to describe our algorithm succinctly we shall use an equivalent representation of programs and template programs. We provide with the notions of polynomial transition systems and symbolic polynomial transition systems which are respectively equivalent to polynomial programs and symbolic polynomial programs.

Example 3

In the figure 1, we graphically describe the symbolic polynomial transition system TSTS corresponding to the template program TT defined in Example 2. The location l0l_{0} and l4l_{4} are the inital and final location respectively. The set C={l2}C=\{l_{2}\} is the cutset.

Figure 1: The transition system for the template program defined in 2
Refer to caption

We will first define few terms that are useful, and then define polynomial variants of linear transitions system and linear control-flow graph that were defined in [colon2003linear].

Definition 1 (Symbolic Polynomial Assertions)

Given a set VV of program variables and UU of template variables, we define Ψ(U,V)\Psi(U,V) to be the set of finite boolean combination of polynomial inequalities over program variables with coefficients being real polynomials over template variables. More precisely, Ψ(U,V)\Psi(U,V) is the set of all possible finite boolean combinations of inequalities of the form f0f\geq 0 such that f([U])[V]f\in(\mathbb{R}[U])[V].

We can now define a polynomial transition system.

Definition 2 (Polynomial transition system)

A polynomial transition system is a tuple P=(V,L,l0,θ0,𝒯,lf,θf)P=(V,L,l_{0},\theta_{0},\mathcal{T},l_{f},\theta_{f}) that consists of a set of variables VV, a set of locations LL, an initial location l0l_{0}, an initial assertion θ0\theta_{0}, a final location lfl_{f}, a final assertion θf\theta_{f} and set of transitions 𝒯\mathcal{T}. Each transition τ𝒯\tau\in\mathcal{T} is a tuple (l,l,ρτ)(l,l^{\prime},\rho_{\tau}), where l,lLl,l^{\prime}\in L are the pre and post locations, and ρτ\rho_{\tau} is an polynomial assertion over VVV\cup V^{\prime}, where VV represents current-state variables and its primed version VV^{\prime} represents the next-state variables.

Symbolic polynomial transition system over the program variables VV and has the same structure as the polynomial transition system except that its assertions are allowed to be symbolic polynomial assertion from Ψ(U,VV)\Psi(U,V\cup V^{\prime}).

Definition 3 (Symbolic polynomial transition system)

. A symbolic polynomial transition system is a tuple T=(VU,L,l0,θ0,𝒯,lf,θf)T=(V\cup U,L,l_{0},\theta_{0},\mathcal{T},l_{f},\theta_{f}) that consists of a set of variables VV, a set of template variables UU, a set of locations LL, an initial location l0l_{0}, an initial symbolic polynomial assertion θ0\theta_{0}, a final location lfl_{f}, a final symbolic polynomial assertion θf\theta_{f} and set of transitions 𝒯\mathcal{T}. Each transition τ𝒯\tau\in\mathcal{T} is a tuple (l,l,ρτ)(l,l^{\prime},\rho_{\tau}), where l,lLl,l^{\prime}\in L are the pre and post locations, and ρτ\rho_{\tau} is a symbolic polynomial assertion over VVV\cup V^{\prime}, where VV represents current-state variables and its primed version VV^{\prime} represents the next-state variables. All the coefficients ofsymbolic polynomial assertions over VVV\cup V^{\prime} belong to the polynomial ring [U]\mathbb{R}[U].

A control-flow graph corresponds to the underlying structure of a given transition system.

Definition 4 (Control-flow graph)

Given a transition system P=(V,L,l0,θ0,𝒯,lf,θf)P=(V,L,l_{0},\theta_{0},\mathcal{T},l_{f},\theta_{f}), we define control-flow graph CFG(P)\emph{CFG}(P) with locations LL as the vertex set and transitions 𝒯\mathcal{T} as the edge set. More precisely we have an edge from ll to ll^{\prime} if and only if we have a transition τ=(l,l,ρτ)𝒯\tau=(l,l^{\prime},\rho_{\tau})\in\mathcal{T} for some ρτ\rho_{\tau}.

We shall now define the notion of cutset and basic path which would be help us in defining the inductive polynomial assertion map.

Definition 5 (Cutset)

Given a transition system P=(V,L,l0,θ0,𝒯,lf,θf)P=(V,L,l_{0},\theta_{0},\mathcal{T},l_{f},\theta_{f}), a subset of vertices of CFG(P)\emph{CFG}(P) is called a cutset CC if every cyclic path in CFG(P)\emph{CFG}(P) passes through some vertex in CC. An element of CC is called a cutpoint.

Definition 6 (Basic path)

Given a transition system P=(V,L,l0,θ0,𝒯,lf,θf)P=(V,L,l_{0},\theta_{0},\mathcal{T},l_{f},\theta_{f}), a path π\pi between two cutpoints ll and ll^{\prime} is called a basic path if it does not pass through any other cutpoint in CC.

Definition 7 (Inductive polynomial assertion map)

Given a transition system P=(V,L,l0,θ0,𝒯,lf,θf)P=(V,L,l_{0},\theta_{0},\mathcal{T},l_{f},\theta_{f}) with a cutset CC and an assertion ηC(l)\eta_{C}(l) for each cutpoint ll, we say that ηC\eta_{C} is an inductive polynomial assertion map for CC if it satisfies the following conditions for all cutpoints l,lCl,l^{\prime}\in C:

  • Initiation: For each basic path π\pi from l0l_{0} to ll, θ0ρπηC(l)\theta_{0}\wedge\rho_{\pi}\models\eta_{C}(l)^{\prime}.

  • Consecution: For each basic path π\pi from ll to ll^{\prime}, ηC(l)ρπηC(l)\eta_{C}(l)\wedge\rho_{\pi}\models\eta_{C}(l^{\prime})^{\prime}.

  • Finalization: For each basic path π\pi from ll to lfl_{f}, ηC(l)ρπθf\eta_{C}(l)\wedge\rho_{\pi}\models\theta_{f}

A inductive polynomial assertion map is said to be symbolic if it has one or more symbolic polynomial assertions. The definitions of control-flow graph, cutset and basic path also naturally extends to the symbolic polynomial transition system. Given a model M:UM:U\to\mathbb{R} of the template variables, let M(T)M(T) and M(ηC)M(\eta_{C}) denote the concrete polynomial transtion system and concrete inductive polynomial assertion map obtained by substituting the values of the template variables in the respective templates.

2.1 Problem Statement

Let TT be a symbolic polynomial transition system over the program variables V={x1,,xn}V=\{x_{1},\dots,x_{n}\} and the set of template variables U={c1,,cm}U=\{c_{1},\ldots,c_{m}\}, CC be a cutset of TT, and ηC\eta_{C} be the symbolic polynomial inductive assertion map.

The synthesis problem for the tuple (T,ηC)(T,\eta_{C}) is to find a valuation M:UM:U\to\mathbb{R} of template variables such that M(ηC)M(\eta_{C}) is valid inductive polynomial assertion map for the concrete transtion system TT.

3 Hardness

?? TODO: FILL THIS IN

4 Algorithms

4.1 Overview of our approach

The programmer first writes a template in the grammar defined at in the beginning of the section. In the pre-processing step, the algorithm first verifies the syntax of the program and substitute the program holes with symbolic polynomial of the specified degree. We call the program generated after the pre-processing step as symbolic polynomial program.

A constraint pair is a pair (α,β)(\alpha,\beta) where α={gii0i{,>}}\alpha=\{g_{i}\bowtie_{i}0\mid\bowtie_{i}\in\{\geq,>\}\} is a set of polynomial inequalities, and β\beta is an polynomial inequality of the form f0f\bowtie 0 with {,>}\bowtie\in\{\geq,>\}. We can reduce the correctness of the symbolic polynomial program TT to validity of a set of constraint pairs SS.

We will describe our approach to construct the constraint pairs with the following example.

Example 4

We are given the symbolic polynomial transition system TSTS as described in Example 1, the cutset C={l2}C=\{l_{2}\} and the symbolic polynomial assertion map ηC\eta_{C}. Say, ηC(l2)=a0s+a1i0\eta_{C}(l_{2})=a_{0}s+a_{1}i\geq 0. We will create three condition pairs corresponding to various restrictions on ηC\eta_{C} for it to be a valid inductive assertion map.

  1. 1.

    Initiation: There is only one basic path from the initial location l0l_{0} to l2l_{2}. We get the following constraint pair for the path π1:=l0l1l2\pi_{1}:=l_{0}\to l_{1}\to l_{2}:

    S1:=([n0>=0i0==0s0==0],[a0s0+a1i00])S_{1}:=([n_{0}>=0\land i_{0}==0\land s_{0}==0],[a_{0}s_{0}+a_{1}i_{0}\geq 0])
  2. 2.

    Consecution: There is one basic path π2:=l2l3l3\pi_{2}:=l_{2}\to l_{3}\to l_{3} from l2l_{2} to l2l_{2}. The constraint pair for the basic path π2\pi_{2} is:

    S2:=([i0<=n0s1==s0+(a0i0)+a1i1==i0+1],[a0s1+a1i10])S_{2}:=([i_{0}<=n_{0}\land s_{1}==s_{0}+(a_{0}i_{0})+a_{1}\land i_{1}==i_{0}+1],[a_{0}s_{1}+a_{1}i_{1}\geq 0])
  3. 3.

    Finalization: The path π3:=l2l4\pi_{3}:=l_{2}\to l_{4} is the only basic path from points of cutset CC to the final location l4l_{4}. For this path, we get the following constraint pair:

    S3:=([a0s1+a1i10,i1>n0],[s1>n0])S_{3}:=([a_{0}s_{1}+a_{1}i_{1}\geq 0,i_{1}>n_{0}],[s_{1}>n_{0}])

    For each basic path π\pi from ll to lfl_{f}, ηC(l)ρπθf\eta_{C}(l)\wedge\rho_{\pi}\models\theta_{f}

We get the three constraint pairs {S1,S2,S3}\{S_{1},S_{2},S_{3}\}.

Theorem 4.1

The number of constraint pairs generated using our approach is at most quadratic in the number of locations if the given cutset contains all the locations, i.e, C=LC=L. Moreover, if the cutset CLC\subset L, then the number of constraint pairs is linear in the to the number of basic paths between each pair of locations in the cutsets.

Proof

The proof follows directly from the construction.

4.2 Mathematical Toolkit

In Section LABEL:sec:algo:overview 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 [hartshorne2013algebraic, bochnak2013real] for a more detailed treatment of these theorems.

Sums of Squares

A polynomial h[x1,,xn]h\in\mathbb{R}[x_{1},\dots,x_{n}] is a sum of squares (SOS) iff there exist k1k\geq 1 and polynomials g1,,gk[x1,,xn]g_{1},\dots,g_{k}\in\mathbb{R}[x_{1},\dots,x_{n}] such that h=i=1kgi2.h=\sum_{i=1}^{k}g_{i}^{2}.

Strong Positivity

Given a set XnX\subseteq\mathbb{R}^{n} and a polynomial g[x1,,xn]g\in\mathbb{R}[x_{1},\dots,x_{n}], we say that gg is strongly positive over X if infxXg(x)>0\inf_{x\in X}g(x)>0. We write this as Xg0.X\models g\gg 0.

Notation

Let Φ={g110,,gkk0}\Phi=\{g_{1}\bowtie_{1}0,\dots,g_{k}\bowtie_{k}0\} be a set of polynomial inequalities where i{,>}\bowtie_{i}\in\{\geq,>\} and gi[x1,,xn]g_{i}\in\mathbb{R}[x_{1},\dots,x_{n}]. We define SAT(Φ)\textsl{SAT}(\Phi) as the set of all real valuations \val\val over the variables {x1,,xn}\{x_{1},\dots,x_{n}\} that satisfy Φ.\Phi. More formally, SAT(Φ)={\valn|i=1k\val(gii0)}.\textsl{SAT}(\Phi)=\{\val\in\mathbb{R}^{n}~{}|~{}\bigwedge_{i=1}^{k}\val\models(g_{i}\bowtie_{i}0)\}.

Closure

Given a set XnX\subseteq\mathbb{R}^{n}, we define X¯\overline{X} to be the closure of XX with respect to the Euclidean topology of n\mathbb{R}^{n}. For a set Φ\Phi of polynomial inequalities, we define Φ¯\overline{\Phi} as the system of polynomial inequalities obtained from Φ\Phi by replacing every strict ineqaulity with its non-strict counterpart.

We are now ready to present the main mathematical theorems that will be used in our work. Our presentation follows that of [goharshady2020parameterized, Section 2.6], which also contains proofs of corollaries that are not proven here.

Theorem 4.2 (Farkas’ Lemma [farkas1902theorie])

Consider a set V={x1,,xr}V=\{x_{1},\ldots,x_{r}\} of real-valued variables and the following system Φ\Phi of equations over VV:

Φ:={a1,0+a1,1x1++a1,rxr0am,0+am,1x1++am,rxr0.\Phi:=\begin{cases}a_{1,0}+a_{1,1}\cdot x_{1}+\ldots+a_{1,r}\cdot x_{r}\geq 0\\ \hfil\vdots\\ a_{m,0}+a_{m,1}\cdot x_{1}+\ldots+a_{m,r}\cdot x_{r}\geq 0\\ \end{cases}.

When Φ\Phi is satisfiable, it entails a linear inequality

ψ:=c0+c1x1++crxr0\psi:=c_{0}+c_{1}\cdot x_{1}+\dots+c_{r}\cdot x_{r}\geq 0

if and only if ψ\psi can be written as non-negative linear combination of the inequalities in Φ\Phi and the trivial inequality 10,1\geq 0, i.e. if there exist non-negative real numbers y0,,ymy_{0},\dots,y_{m} such that

c0=y0+i=1kyiai,0;c1=i=1kyiai,1;cr=i=1kyiai,r.\begin{matrix}c_{0}=y_{0}+\sum_{i=1}^{k}y_{i}\cdot a_{i,0};\\ c_{1}=\sum_{i=1}^{k}y_{i}\cdot a_{i,1};\\ \vdots\\ c_{r}=\sum_{i=1}^{k}y_{i}\cdot a_{i,r}.\end{matrix}

Moreover, Φ\Phi is unsatisfiable if and only if 10-1\geq 0 can be derived as above.

The importance of Farkas’ Lemma for us is that if we have a standard constraint of form (LABEL:eq:entailment-form) 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 LABEL:sec:algo:overview. 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 is itself unsatisfiable and thus Φψ\Phi\Rightarrow\psi holds vacuously. Fortunately, Farkas’ Lemma also provides a criterion for unsatisfiability. In practice, we work with the following corollary of Theorem 4.2 which can also handle strict inequalities.

Corollary 1

Consider a set V={x1,,xr}V=\{x_{1},\ldots,x_{r}\} of real-valued variables and the following system of equations over VV:

Φ:={a1,0+a1,1x1++a1,rxr10am,0+am,1x1++am,rxrm0\Phi:=\begin{cases}a_{1,0}+a_{1,1}\cdot x_{1}+\ldots+a_{1,r}\cdot x_{r}\bowtie_{1}0\\ \hfil\vdots\\ a_{m,0}+a_{m,1}\cdot x_{1}+\ldots+a_{m,r}\cdot x_{r}\bowtie_{m}0\\ \end{cases}

where i{>,}\bowtie_{i}\in\{>,\geq\} for all 1im1\leq i\leq m. When Φ\Phi is satisfiable, it entails a linear inequality

ψ:=c0+c1x1++crxr0\psi:=c_{0}+c_{1}\cdot x_{1}+\dots+c_{r}\cdot x_{r}\bowtie 0

with {>,}\bowtie\in\{>,\geq\}, if and only if ψ\psi can be written as non-negative linear combination of inequalities in Φ\Phi and the trivial inequality 1>01>0. Note that if ψ\psi is strict, then at least one of the strict inequalities should appear with a non-zero coefficient in the linear combination. Moreover, Φ\Phi is unsatisfiable if and only if either 10-1\geq 0 or 0>00>0 can be derived as above.

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 (LABEL:eq:entailment-form) 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.

Monoid

Consider a set V={x1,xr}V=\{x_{1},\dots x_{r}\} of real-valued variables and the following system of linear inequalities over VV:

Φ:={a1,0+a1,1x1++a1,rxr10am,0+am,1x1++am,rxrm0\Phi:=\begin{cases}a_{1,0}+a_{1,1}\cdot x_{1}+\ldots+a_{1,r}\cdot x_{r}\bowtie_{1}0\\ \hfil\vdots\\ a_{m,0}+a_{m,1}\cdot x_{1}+\ldots+a_{m,r}\cdot x_{r}\bowtie_{m}0\\ \end{cases}

where i{>,}\bowtie_{i}\in\{>,\geq\} for all 1im1\leq i\leq m. Let gig_{i} be the left hand side of the ii-th inequality, i.e. gi(x1,,xr):=ai,0+ai,1x1+ai,rxrg_{i}(x_{1},\dots,x_{r}):=a_{i,0}+a_{i,1}\cdot x_{1}+\dots a_{i,r}\cdot x_{r}. The monoid of Φ\Phi is defined as:

Monoid(Φ):={i=1mgikimiki{0}}.\textstyle\textsl{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 gig_{i}’s. Note that 1Monoid(Φ).1\in\textsl{Monoid}(\Phi). We define Monoidd(Φ)\textsl{Monoid}_{d}(\Phi) as the subset of polynomials in Monoid(Φ)\textsl{Monoid}(\Phi) of degree at most d.d.

Theorem 4.3 (Handelman’s Theorem [handelman1988representing])

Consider a set V={x1,,xr}V=\{x_{1},\dots,x_{r}\} of real-valued variables and the following system of equations over VV:

Φ:={a1,0+a1,1x1++a1,rxr0am,0+am,1x1++am,rxr0.\Phi:=\begin{cases}a_{1,0}+a_{1,1}\cdot x_{1}+\ldots+a_{1,r}\cdot x_{r}\geq 0\\ \hfil\vdots\\ a_{m,0}+a_{m,1}\cdot x_{1}+\ldots+a_{m,r}\cdot x_{r}\geq 0\\ \end{cases}.

If Φ\Phi is satisfiable, SAT(Φ)\textsl{SAT}(\Phi) is compact, and Φ\Phi entails a polynomial inequality g(x1,,xr)>0,g(x_{1},\dots,x_{r})>0, then there exist non-negative real numbers y1,yuy_{1},\dots y_{u} and polynomials h1,,huMonoid(Φ)h_{1},\dots,h_{u}\in\textsl{Monoid}(\Phi) such that:

g=i=1uyihi.\textstyle g=\sum_{i=1}^{u}y_{i}\cdot h_{i}.

The intuition here is that if every inequality in Φ\Phi holds, then all the LHS expressions in Φ\Phi are non-negative and hence any multiplication hih_{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.

Corollary 2

Consider a set V={x1,,xr}V=\{x_{1},\dots,x_{r}\} of real-valued variables and the following system of equations over VV:

Φ:={a1,0+a1,1x1++a1,rxr10am,0+am,1x1++am,rxrm0\Phi:=\begin{cases}a_{1,0}+a_{1,1}\cdot x_{1}+\ldots+a_{1,r}\cdot x_{r}\bowtie_{1}0\\ \hfil\vdots\\ a_{m,0}+a_{m,1}\cdot x_{1}+\ldots+a_{m,r}\cdot x_{r}\bowtie_{m}0\\ \end{cases}

in which i{>,}\bowtie_{i}\in\{>,\geq\} for all 1im1\leq i\leq m. If Φ\Phi is satisfiable and SAT(Φ)\textsl{SAT}(\Phi) is bounded, then Φ\Phi entails a strong polynomial inequality g0g\gg 0 if and only if there exist constants y0(0,),y_{0}\in(0,\infty), and y1,,yu[0,)y_{1},\dots,y_{u}\in[0,\infty), and polynomials h1,,huMonoid(Φ)h_{1},\dots,h_{u}\in\textsl{Monoid}(\Phi) such that:

g=y0+i=1uyihi.\textstyle g=y_{0}+\sum_{i=1}^{u}y_{i}\cdot h_{i}.

Corollary 2 above can handle a wider family of standard constraints than Corollary 1. However, it is also more expensive, since we now need to generate one new variable yiy_{i} for every polynomial in Monoidd(Φ)\textsl{Monoid}_{d}(\Phi) instead of Φ\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 (LABEL:eq:entailment-form) are linear, Corollary 1 is preferable. We now consider a more expressive theorem that can handle polynomials on boths sides of (LABEL:eq:entailment-form).

Theorem 4.4 (Putinar’s Positivstellensatz [putinar1993positive])

Given a finite collection of polynomials {g,g1,,gk}[x1,,xn]\{g,g_{1},\dots,g_{k}\}\in\mathbb{R}[x_{1},\dots,x_{n}], let Φ\Phi be the set of inequalities defined as

Φ:{g10,,gk0}.\Phi:\{g_{1}\geq 0,\dots,g_{k}\geq 0\}.

If Φ\Phi entails the polynomial inequality g>0g>0 and there exist some ii such that SAT(gi0)\textsl{SAT}(g_{i}\geq 0) is compact, then there exist polynomials h0,,hk[x1,,xn]h_{0},\dots,h_{k}\in\mathbb{R}[x_{1},\dots,x_{n}] such that

g=h0+i=1mhigi\textstyle g=h_{0}+\sum_{i=1}^{m}h_{i}\cdot g_{i}

and every hih_{i} is a sum of squares. Moreover, Φ\Phi is unsatisfiable if and only if 1>0-1>0 can be obtained as above, i.e. with g=1g=-1.

As in the cases of Farkas and Handelman, we need a variant of of Theorem 4.4 that can handle strict inequalities in Φ.\Phi.

Corollary 3

Consider a finite collection of polynomials {g,g1,,gk}[x1,,xn]\{g,g_{1},\dots,g_{k}\}\in\mathbb{R}[x_{1},\dots,x_{n}] and let

Φ:{g110,,gkk0}\Phi:\{g_{1}\bowtie_{1}0,\dots,g_{k}\bowtie_{k}0\}

where i{>,}\bowtie_{i}\in\{>,\geq\} for all 1ik1\leq i\leq k. Assume that there exist some ii such that SAT(gi0)\textsl{SAT}(g_{i}\geq 0) is compact or equivalently SAT(gii0)\textsl{SAT}(g_{i}\bowtie_{i}0) is bounded. If Φ\Phi is satisfiable, then it entails the strong polynomial inequality g0g\gg 0, iff there exists a constant y0(0,)y_{0}\in(0,\infty) and polynomials h0,,hk[x1,,xn]h_{0},\dots,h_{k}\in\mathbb{R}[x_{1},\dots,x_{n}] such that

g=y0+h0+i=1khigi,\textstyle g=y_{0}+h_{0}+\sum_{i=1}^{k}h_{i}\cdot g_{i},

and every hih_{i} is a sum of squares.

Trying to use the corollary above for handling standard constraints of form (LABEL:eq:entailment-form) in Step 3 of our algorithm leads to two problems: (i) we also need a criterion for unsatisfiability of Φ\Phi to handle the cases where Φψ\Phi\Rightarrow\psi holds vacuously, and (ii) in our QP, we should somehow express the property that every hih_{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.

Theorem 4.5 ([bochnak2013real, Corollary 4.1.8] the Real Nullstellensatz)

Given polynomials g,g1,,gk[x1,,xn]g,g_{1},\dots,g_{k}\in\mathbb{R}[x_{1},\dots,x_{n}], exactly one of the following two statements holds: {compactitem}

There exists xn,x\in\mathbb{R}^{n}, such that g1(x)==gk(x)=0g_{1}(x)=\dots=g_{k}(x)=0, but g(x)0g(x)\neq 0.

There exists α{0}\alpha\in\mathbb{N}\cup\{0\} and polynomials h1,,hk[x1,,xn]h_{1},\dots,h_{k}\in\mathbb{R}[x_{1},\dots,x_{n}] such that i=1khigih0=g2α\sum_{i=1}^{k}h_{i}\cdot g_{i}-h_{0}=g^{2\cdot\alpha} and h0h_{0} is a sum of squares.

We now combine the Real Nullstellensatz with Putinar’s Postivstellensatz to obtain a criterion for unsatisfiability of Φ.\Phi.

Theorem 4.6

Consider a finite collection of polynomials {g1,,gk}[x1,,xn]\{g_{1},\dots,g_{k}\}\in\mathbb{R}[x_{1},\dots,x_{n}] and the following system of inequalities:

Φ:{g110,,gkk0}\Phi:\{g_{1}\bowtie_{1}0,\dots,g_{k}\bowtie_{k}0\}

where i{>,}\bowtie_{i}\in\{>,\geq\} for all 1ik1\leq i\leq k. Φ\Phi is unsatisfiable if and only if at least one of the following statements holds: {compactitem}

There exist a constant y0(0,)y_{0}\in(0,\infty) and sum of square polynomials h0,,hk[x1,,xn]h_{0},\dots,h_{k}\in\mathbb{R}[x_{1},\dots,x_{n}] such that

1=y0+h0+i=1khigi.\textstyle-1=y_{0}+h_{0}+\sum_{i=1}^{k}h_{i}\cdot g_{i}. (1)

There exist α{0}\alpha\in\mathbb{N}\cup\{0\} and h0,h1,,hk[x1,,xn,w1,,wk]h_{0},h_{1},\dots,h_{k}\in\mathbb{R}[x_{1},\dots,x_{n},w_{1},\dots,w_{k}], such that for some 1jm1\leq j\leq m with j{>}\bowtie_{j}\in\{>\}, we have

wj4α=i=1mhi(giwi2)h0.\textstyle w_{j}^{4\cdot\alpha}=\sum_{i=1}^{m}h_{i}\cdot(g_{i}-w_{i}^{2})-h_{0}. (2)

where h0h_{0} is a sum of squares in [x1,,xn]\mathbb{R}[x_{1},\dots,x_{n}]. Note that w1,,wkw_{1},\dots,w_{k} are new variables.

Proof

First we show that if any of the two equalities (1) or (2) holds then Φ\Phi is unsatisfiable. Suppose Φ\Phi is satisfiable and pick \valSAT(Φ)\val\in\textsl{SAT}(\Phi). Then, the RHS of (1) is positive at \val,\val, whereas the LHS is negative. So, (1) cannot hold. Now define gi~(x1,,xn,w1,,wk):=gi(x1,,xn)wi2.\tilde{g_{i}}(x_{1},\dots,x_{n},w_{1},\dots,w_{k}):=g_{i}(x_{1},\dots,x_{n})-w_{i}^{2}. Using this definition, we can rewrite (2) as wj4.α=i=1mhigi~h0w_{j}^{4.\alpha}=\sum_{i=1}^{m}h_{i}\cdot\tilde{g_{i}}-h_{0}. Moreover, gj2α=(gj~+wj2)2α.g_{j}^{2\cdot\alpha}=(\tilde{g_{j}}+w_{j}^{2})^{2\cdot\alpha}. Expanding the right hand side using the binomial theorem, we get gj2α=wj4α+hjgj~g_{j}^{2\cdot\alpha}=w_{j}^{4\cdot\alpha}+h_{j}^{\prime}\cdot\tilde{g_{j}} for some hj[x1,,xn,w1,,wk]h_{j}^{\prime}\in\mathbb{R}[x_{1},\dots,x_{n},w_{1},\dots,w_{k}]. Now, substituting wj4αw_{j}^{4\cdot\alpha} (2), we get

gj2α=i=1mhigi~h0+hjgj~\textstyle g_{j}^{2\cdot\alpha}=\sum_{i=1}^{m}h_{i}\cdot\tilde{g_{i}}-h_{0}+h_{j}^{\prime}\cdot\tilde{g_{j}} (3)

Let us extend \val\val, which is a valuation of {v1,,vn}\{v_{1},\dots,v_{n}\} to a valuation \val\val^{\prime} over {v1,,vn,w1,,wk}\{v_{1},\dots,v_{n},w_{1},\dots,w_{k}\} such that \valgi~(v1,,vn,w1,,wk)=0\val^{\prime}\models\tilde{g_{i}}(v_{1},\dots,v_{n},w_{1},\dots,w_{k})=0 for all 1ik1\leq i\leq k. Note that such an extension is always possible. We get a contradiction by evaluating (3) on \val\val^{\prime} as the LHS is positive, whereas the RHS is negative.

We now prove the other side. Suppose Φ\Phi is unsatisfiable. We have two possibilities: either Φ¯\overline{\Phi} is also unsatisfiable or Φ¯\overline{\Phi} is satisfiable. Suppose Φ¯\overline{\Phi} is unsatisfiable, then using Theorem 4.4, Φ¯\overline{\Phi} entails 2>0-2>0 and we can write 2=h0+i=1khigi-2=h_{0}+\sum_{i=1}^{k}h_{i}\cdot g_{i} for sum of squares polynomials h0,,hk[x1,,xn]h_{0},\dots,h_{k}\in\mathbb{R}[x_{1},\dots,x_{n}]. Therefore,

1=1+h0+i=1khigi\textstyle-1=1+h_{0}+\sum_{i=1}^{k}h_{i}\cdot g_{i}

which fits into (1). Now we are left with the case when Φ¯\overline{\Phi} is satisfiable but Φ\Phi is unsatisfiable. We first reorder the inequalities in Φ\Phi such that the non-strict inequalities appear first in the order. Let jj be the smallest index for which Φ[1j]\Phi[1\dots j], i.e. the set of first jj inequalities in Φ\Phi, is unsatisfiable. By definition, Φ[1j1]\Phi[1\dots j-1] is satisfiable and hence SAT(Φ[1j1])¯=SAT(Φ¯[1j1])\overline{\textsl{SAT}(\Phi[1\dots j-1])}=\textsl{SAT}(\overline{\Phi}[1\dots j-1]). We can rewrite Φ[1j]=Φ[1j1](gj>0)\Phi[1\dots j]=\Phi[1\dots j-1]\wedge(g_{j}>0). As Φ[1j]\Phi[1\dots j] is unsatisfiable, we know that Φ[1j1]\Phi[1\dots j-1] entails gj0g_{j}\leq 0. More precisely, this means SAT(Φ[1j1])SAT(gj0)\textsl{SAT}(\Phi[1\dots j-1])\subseteq\textsl{SAT}(g_{j}\leq 0). On taking closures on both sides we get SAT(Φ¯[1j1])SAT(gj0)\emph{SAT}(\overline{\Phi}[1\dots j-1])\subseteq\emph{SAT}(g_{j}\leq 0). This implies that Φ¯[1,j1]\overline{\Phi}[1,\dots j-1] entails gj0g_{j}\leq 0 and hence Φ¯[1j]\overline{\Phi}[1\dots j] entails gj=0g_{j}=0. As defined above, gi~(x1,,xn,w1,,wk)=gi(x1,,xn)wi2\tilde{g_{i}}(x_{1},\dots,x_{n},w_{1},\dots,w_{k})=g_{i}(x_{1},\dots,x_{n})-w_{i}^{2}. Now, we will show that there is no valuation \val\val^{*} over the variables {x1,,xn,w1,,wk}\{x_{1},\dots,x_{n},w_{1},\dots,w_{k}\} such that for all 1ij1\leq i\leq j, gi~(\val)=0\tilde{g_{i}}(\val^{*})=0 but gj(\val)0g_{j}(\val^{*})\neq 0. Suppose there exist such a valuation \val\val^{*}. Let us define \val\val to be the restriction of \val\val^{*} to {x1,,xn}\{x_{1},\dots,x_{n}\}. For each 1ij1\leq i\leq j, we get gi(\val)0g_{i}(\val)\geq 0 as gj~(\val)=0\tilde{g_{j}}(\val^{*})=0. We also get gj(\val)=gj(\val)0g_{j}(\val)=g_{j}(\val^{*})\neq 0. Hence, we get a contradiction with the previous result that Φ¯[1j]\overline{\Phi}[1\dots j] entails gj=0g_{j}=0. Applying the Real Nullstellensatz (Theorem 4.5) to gi~\tilde{g_{i}}’s and gjg_{j}, we have

gj2α=i=1jhi~gi~h0\textstyle g_{j}^{2\cdot\alpha}=\sum_{i=1}^{j}\tilde{h_{i}}\cdot\tilde{g_{i}}-h_{0}

where α\alpha is a non-negative integer and hi~\tilde{h_{i}}’s and h0h_{0} are sums of sqaures in [x1,,xn,w1,,wk]\mathbb{R}[x_{1},\dots,x_{n},w_{1},\dots,w_{k}]. Using the definition of gj=gj~+wj2g_{j}=\tilde{g_{j}}+w_{j}^{2} and the binomial theorem, we get gj2α=wj4α+hjgj~g_{j}^{2\cdot\alpha}=w_{j}^{4\cdot\alpha}+h_{j}^{\prime}\cdot\tilde{g_{j}} for some hj[x1,,xn,w1,,wk]h_{j}^{\prime}\in\mathbb{R}[x_{1},\dots,x_{n},w_{1},\dots,w_{k}]. Therefore, we finally get the following expression:

wj4α=i=1jhi~(giwi2)hj(gjwj2)h0\textstyle w_{j}^{4\cdot\alpha}=\sum_{i=1}^{j}\tilde{h_{i}}\cdot(g_{i}-w_{i}^{2})-h_{j}^{\prime}\cdot(g_{j}-w_{j}^{2})-h_{0}

which fits into the format of (2), hence completing the proof.

Finally, we provide the needed theorems to check that a certain polynomial hh is a sum of squares using QP.

Theorem 4.7 ([blekherman2012semidefinite, Theorem 3.39])

Let a\vec{a} be the vector of all (n+dd)\binom{n+d}{d} monomials of degree less than or equal to dd over the variables {x1,,xn}.\{x_{1},\dots,x_{n}\}. A polynomial p[x1,,xn]p\in\mathbb{R}[x_{1},\dots,x_{n}] of degree 2d2\cdot d is a sum of squares if and only if there exist a positive semidefinite matrix QQ of order (n+dd)\binom{n+d}{d} such that p=aTQa.p=a^{T}\cdot Q\cdot a.

Theorem 4.8 (Cholesky decomposition [watkins2004fundamentals])

A symmetric square matrix QQ is positive semidefinite if and only if it has a Cholesky decomposition of the form Q=LLTQ=LL^{T} where LL is a lower-triangular matrix with non-negative diagonal entries.

Based on Theorems 4.7 and 4.8, a polynomial pp of degree 2d2\cdot d is a sum of squares if and only if it can be written as p=aTLLTap=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 2d2\cdot d with symbolic coefficients and encoding them in QP. We first generate a lower triangular matrix LL of order (n+dd)\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 aTLLTa.a^{T}\cdot L\cdot L^{T}\cdot a.

4.3 Details of Step 3 of the Algorithm

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.

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 (LABEL:eq:entailment-form). 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 f110f220frr0f0f_{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 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 4.6. Below, we define Φ:{f110,f220,,frr0}\Phi:\{f_{1}\bowtie_{1}0,f_{2}\bowtie_{2}0,\ldots,f_{r}\bowtie_{r}0\} and ψ:f0.\psi:f\bowtie 0.

Step 3.(i). Applying Farkas’ Lemma

Assuming all the constraints in Φ\Phi and ψ\psi are affine, we can apply Corollary 1. Based on this corollary, we have to consider three cases disjunctively: {compactenum}

Φ\Phi is satisfiable and entails ψ\psi: The algorithm creates new template variables y0,,yry_{0},\dots,y_{r} with the constraint yi0y_{i}\geq 0 for every ii. It then symbolically computes f=y0+i=1ryifi.f=y_{0}+\sum_{i=1}^{r}y_{i}\cdot f_{i}. The latter is a polynomial equality over \vars.\vars. So, the algorithm equates the coefficients of corresponding monomials on both sides, hence reducing this case to QP. Additionally, if ψ\psi is a strict inequality, the algorithm adds the extra constraint i{>}yi>0.\sum_{\bowtie_{i}\in\{>\}}y_{i}>0.

Φ\Phi is unsatisfiable and 10-1\geq 0 can be obtained: This is similar to the previous case, except that 1-1 should be written as y0+i=1ryifi.y_{0}+\sum_{i=1}^{r}y_{i}\cdot f_{i}.

Φ\Phi is unsatisfiable and 0>00>0 can be obtained: This is also similar to the last two cases. We have 0=y0+i=1ryifi0=y_{0}+\sum_{i=1}^{r}y_{i}\cdot f_{i} and i{>}yi>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 is unsatisfiable in these cases and hence the constraint Φψ\Phi\Rightarrow\psi always holds vacuously.

Step 3.(ii). Applying Handelman’s Theorem

Assuming all constraints in Φ\Phi are linear but ψ\psi is a higher-degree polynomial inequality, the algorithm applies Corollaries 1 and 2. Again, we have to consider the same three cases as in Step 3.(i): {compactenum}

Φ\Phi is satisfiable and entails ψ\psi: We apply Corollary 2. The algorithm first symbolically computes Monoidd(Φ)={h1,h2,,hu}.\textsl{Monoid}_{d}(\Phi)=\{h_{1},h_{2},\dots,h_{u}\}. It then generates new template variables y0,y1,,yuy_{0},y_{1},\dots,y_{u} and constrains them by setting y0,y1,y2,,yu0.y_{0},y_{1},y_{2},\dots,y_{u}\geq 0. If ψ\psi is a strict inequality, it further adds the constraint y0>0.y_{0}>0. It then symbolically computes the equality

f=y0+i=1uyihi.\textstyle f=y_{0}+\sum_{i=1}^{u}y_{i}\cdot h_{i}.

As usual, this is an equality whose both sides are polynomials over \vars.\vars. So, the algorithm equates the coefficients of corresponding monomials on the LHS and RHS, which reduces this case to QP.

Note that Φ\Phi consists of linear inequalities, so we can use Farkas’ Lemma to check if Φ\Phi is unsatisfiable. As such, this step is the same as case (2) of Step 3.(i).

This is the same as case (3) of Step 3.(i).

Step 3.(iii). Applying Stellensätze

If Φ\Phi includes polynomial inequalities of degree 22 or larger, then we have to apply Corollary 3 and Theorem 4.6. The algorithm considers three cases and combines them disjunctively: {compactenum}

Φ\Phi is satisfiable and entails ψ\psi: In this case, we apply Corollary 3. The algorithm generates template sum-of-squares polynomials h0,,hrh_{0},\ldots,h_{r} of degree dd and adds QP constraints that ensure each hih_{i} is a sum of squares (See the end of Section 4.2). It also generates a non-negative fresh variable y0y_{0}. If ψ\psi is strict, the algorithm adds the constraint y0>0.y_{0}>0. Finally, the algorithm symbolically computes

f=y0+h0+i=1rhifi;\textstyle f=y_{0}+h_{0}+\sum_{i=1}^{r}h_{i}\cdot f_{i};

and equates the corresponding coefficients in the LHS and RHS to obtain QP constraints.

Φ\Phi is unsatisfiable due to the first condition of Theorem 4.6: This case is handled similary to case (1) above, except that we have 1=y0+h0+i=1rhifi.-1=y_{0}+h_{0}+\sum_{i=1}^{r}h_{i}\cdot f_{i}.

Φ\Phi is unsatisfiable due to the second condition of Theorem 4.6: The algorithm introduces rr new program variables w1,,wr.w_{1},\dots,w_{r}. It then generates a sum-of-squares template polynomial hh over \vars\vars and arbitrary template polynomials h1,,hkh_{1},\dots,h_{k} over \vars{w1,,wr}.\vars\cup\{w_{1},\dots,w_{r}\}. All hih_{i}’s are degree-dd templates. Finally, for every index jj that corresponds to a strict inequality, i.e. j{>},\bowtie_{j}\in\{>\}, the algorithm symbolically computes

wjd=i=1rhi(fiwi2)h0,\textstyle w_{j}^{d^{\prime}}=\sum_{i=1}^{r}h_{i}\cdot(f_{i}-w_{i}^{2})-h_{0},

in which dd^{\prime} is the largest multiple of 44 that does not exceed dd. Note that this is an equality between two polynomials over \vars{w1,,wr}.\vars\cup\{w_{1},\dots,w_{r}\}. As before, the algorithm equates the coefficients of corresponding monomials on both sides of the equality and reduces it to 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 LABEL:sec:algo:overview.

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.

Handling Boundedness

To achieve completeness, we need the boundedness assumption, i.e. that for every variable v\vars,v\in\vars, we always have MvM.-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.

4.4 Soundness and Completeness

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 g0.g\gg 0.

Theorem 4.9 (Soundness)

Given a sketch polynomial program or equivalently a sketch polynomial transition system (SPTS) of the form (\vars,\tvars,\locs,\loc0,θ0,\locf,θf,\transitions,\invariant)(\vars,\tvars,\locs,\loc_{0},\theta_{0},\loc_{f},\theta_{f},\transitions,\invariant) together with a cutset \cutset\cutset as input, every concrete polynomial transition system (PTS) synthesized by the algorithm above is inductively valid.

Proof

The standard constraints of form (LABEL:eq:entailment-form) 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.

Theorem 4.10 (Semi-completeness)

Consider a solvable sketch polynomial transition system (SPTS) of the form (\vars,\tvars,\locs,\loc0,θ0,\locf,θf,\transitions,\invariant),(\vars,\tvars,\locs,\loc_{0},\theta_{0},\loc_{f},\theta_{f},\transitions,\invariant), together with a cutset \cutset,\cutset, that is given as input. Moreover, assume that: {compactenum}

The boundedness assumption holds, i.e. there is a constant M(0,)M\in(0,\infty) such that for every v\vars,v\in\vars, we always have MvM.-M\leq v\leq M.

Every invariant \invariant(\loc)\invariant(\loc) and post-condition θf,\theta_{f}, when written in disjunctive normal form, contains only strongly positive polynomial inequalities of the form g0.g\gg 0. Then, there exists a constant degree bound dd\in\mathbb{N}, for which the algorithm above is guaranteed to successfully synthesize an inductively valid polynomial transition system (PTS).

Proof

Since our instance is solvable, there is a valuation \tval\tval for the template variables that yields an inductively valid PTS. We prove that for large enough dd, the valuation \tval\tval 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 Farkas’ Lemma (Corollary 1). In Step 3.(ii), if Φ\Phi is unsatisfiable, then the algorithm is complete based on Corollary 1. Otherwise, it is complete based on Corollary 2. 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 2 requires strong positivity of gg, which corresponds to invariants and post-conditions in our use-case, and boundedness of SAT(Φ),\textsl{SAT}(\Phi), which is a direct consequence of our boundedness assumption. Finally, Step 3.(iii) is complete due to Corollary 3 and Theorem 4.6. These depend on dd, strong positivity and boundedness in the exact same manner as in the case of Step 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 [mai2022complexity]. 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 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 4.6 can only provide a sound and complete characterization of strongly positive polynomials over a bounded semi-algebraic set XRnX\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.0. However, this limitation is also not significant in practice because (i) our soundness does not depend on it, and (ii) f+ϵ0f+\epsilon\gg 0 holds for any constant ϵ>0.\epsilon>0. So, a small change (by any value ϵ>0\epsilon>0) in the invariants/postconditions leads to an instance over which our completeness holds.

References

  • [1]

5 Appendix

5.1 Examples used in Section LABEL:secion_proof_of_concept

These examples are motivated from the benchmarks provided in [rodriguez2018some].