Keywords

figure a
figure b

1 Introduction

Background. Craig interpolant is a fundamental concept in formal verification and automated theorem proving. It was introduced by William Craig in the 1950 s as a tool for reasoning about logical formulas and their satisfiability. Craig interpolation techniques possess excellent modularity and local reasoning capabilities, making them effective tools for enhancing the scalability of formal verification methods, like theorem proving [23, 35], model-checking [31], abstract interpretation [14, 32], program verification [19, 26] and so on.

Efficient generation of Craig interpolants is crucial in interpolation-based techniques, and therefore has garnered increasing attention. Formally, a formula I is called a Craig interpolant for two mutually exclusive formulae \(\phi \) and \(\psi \) in a background theory \(\mathcal {T}\), if it is defined on the common symbols of \(\phi \) and \(\psi \), implied by \(\phi \) in the theory \(\mathcal {T}\), and inconsistent with \(\psi \) in the theory \(\mathcal {T}\). Due to the diversity of background theories and their integration, researchers have been dedicated to developing efficient interpolation synthesis algorithms. Currently, numerous effective algorithms for automatic synthesis of interpolants have been proposed for various fragments of first-order logic, e.g., linear arithmetic [14], logic with arrays [15, 33], logic with sets [20], equality logic with uninterpreted functions (EUF) [5, 32], etc., and their combinations [22, 38, 43]. Moreover, D’Silva et al. [9] explored how to compare the strength of various interpolants.

However, interpolant generation for nonlinear arithmetic and its combination with the aforementioned theories is still in infancy, although nonlinear polynomial inequalities are quite common in software involving number theoretic functions as well as hybrid systems [44, 45]. In addition, when the formulas \(\phi \) and \(\psi \) are defined by polynomial inequalities, generating an interpolant is essentially equivalent to the mathematical problem of separating two disjoint semialgebraic sets, which has a long history and is a challenging mathematical problem [1].

In [7], Dai et al. attempted to generate interpolants for conjunctions of mutually contradictory nonlinear polynomial inequalities without unshared variables. They proposed an algorithm based on Stengle’s Positivstellensatz [41], which guarantees the existence of a witness and can be computed using semidefinite programming (SDP). While their algorithm is generally incomplete, it becomes complete when all variables are bounded, known as the Archimedean condition (see in Sect. 2.1).

In [10], Gan et al. introduced an algorithm for generating interpolants specifically for quadratic polynomial inequalities. Their approach is based on the insight that analyzing the solution space of concave quadratic polynomial inequalities can be achieved by linearizing them, using a generalization of Motzkin’s transposition theorem. Additionally, they discussed generating interpolants for a combination of the theory of quadratic concave polynomial inequalities and EUF using a hierarchical calculus proposed in [39] and employed in [38].

In [11], Gan et al. further extended the problem from the case of quadratic concave inequalities to the more general Archimedean case. To accomplish this, they utilized Putinar’s Positivstellensatz and proposed a Craig interpolation generation method based on SDP. This method allows to generate interpolants in a broader class of situations involving nonlinear polynomial inequalities. However, the Archimedean condition still imposes a limitation on the method, as it requires bounded domains.

In [4], Chen et al. proposed a counterexample-guided framework based on support vector machines for synthesizing nonlinear interpolants. Later in [27], Lin et al. combined this framework and deep learning for synthesizing neural interpolants. In [18], Jovanović and Dutertre also designed a counterexample-guided framework based on cylindrical algebraic decomposition (CAD) for synthesizing interpolants as boolean combinations of constraints. However, these approaches rely on quantifier elimination to ensure completeness and convergence, which terribly affects their efficiency due to its doubly exponential time complexity [8].

For theories including non-polynomial expressions, the general idea is to abstract non-polynomial expressions into polynomial or linear expressions. In [13], Gao and Zufferey presented an approach for extracting interpolants for nonlinear formulas that may contain transcendental functions and differential equations. They accomplished this by transforming proof traces from a \(\delta \)-decision procedure [12] based on interval constraint propagation (ICP) [3]. Like the Archimedean condition, \(\delta \)-decidability also imposes the restriction that variables are bounded (in a hyper-rectangle). A similar idea was also reported in [24]. In [6, 40], Srikanth et al. and Cimatti et al. proposed approaches to abstract nonlinear formulas into the theory of linear arithmetic with uninterpreted functions.

Contributions. In this paper, we consider how to synthesize an interpolant function \(h(\textbf{x})\) for two polynomial formulas \(\phi (\textbf{x},\textbf{y})\) and \(\psi (\textbf{x},\textbf{z})\) such that \(\phi (\textbf{x},\textbf{y})\models h(\textbf{x})>0\) and \(\psi (\textbf{x},\textbf{z})\models h(\textbf{x})<0\) without assuming the Archimedean condition, i.e., the variables in \(\phi \) and \(\psi \) can have an unbounded range of values. Here, uncommon variables of \(\phi \) and \(\psi \) are allowed, and the description of formulas may involve any polynomial of any degree. Hence the problem is more general than the ones discussed in [7, 10, 11], and is also more difficult as polynomial interpolants may not exist [1]. To address this problem, we first utilize homogenization techniques to elevate the descriptions of \(\phi \) and \(\psi \) to the homogeneous space. In this homogeneous space, we can impose the constraint that the variables lie on a unit sphere, thus reviving the Archimedean condition. Combining this idea with the work in [11], we can prove the existence of a semialgebraic function \(h(\textbf{x})=h_1(\textbf{x})+h_2(\textbf{x})\sqrt{\Vert \textbf{x}\Vert ^2+1}\) such that \(h(\textbf{x})>0\) serves as an interpolant, where \(h_1,h_2\) are polynomials (h becomes a polynomial when \(h_2=0\)). Furthermore, we provide sum-of-squares (SOS) programming procedures for finding such semialgebraic interpolants as well as polynomial interpolants. Under certain assumptions, we prove that the SOS procedures are sound and complete.

Organization. The rest of the paper is organized as follows. Preliminaries are introduced in Sect. 2. Section 3 proves the existence of an interpolant for two mutually contradictory polynomial formulas. Section 4 derives an SOS characterization for the interpolant. Section 5 presents an SDP-based method for computation and provides examples. Finally, Sect. 6, we conclude this paper and discuss some future works. Omitted proofs and portraits for examples can be found in the extended version [42].

2 Preliminaries

We first fix some basic notations. Let \(\mathbb {N}\) and \(\mathbb {R}\) be the sets of integers and real numbers, respectively. By convention, we use boldface letters to denote vectors. Fixing a vector of indeterminates \(\textbf{x}{:}{=}(x_1,\ldots ,x_r)\), let \(\mathbb {R}[\textbf{x}]\) denote the polynomial ring in variables \(\textbf{x}\) over real numbers. We use \(\mathrm {\Sigma }[\textbf{x}]{:}{=}\{\sum _{i=1}^m p_i^2\mid p_i\in \mathbb {R}[\textbf{x}], m\in \mathbb {N}\}\) to denote the set of SOS polynomials in variables \(\textbf{x}\). A basic semialgebraic set \(S\subseteq \mathbb R^r\) is of the form \(\{\textbf{x}\in \mathbb {R}^r \mid p_1(\textbf{x}) \triangleright 0, \dots , p_m(\textbf{x}) \triangleright 0\}\), where \(p_i(\textbf{x}) \in \mathbb {R}[\textbf{x}]\) and \(\triangleright \in \{\ge , >\}\) (each of the inequalities can be either strict or non-strict). A basic semialgebraic set is said to be closed if it is defined by non-strict inequalities. Semialgebraic sets are formed as unions of basic semialgebraic sets. i.e., \(T=\bigcup _{i=1}^{n} S_i\) is a semialgebraic set, where each \(S_i\) is a basic semialgebraic set. For any (semialgebraic) set \(S\subseteq \mathbb {R}^r\), let \(\mathrm cl(S)\) denote the closure of S. Let \(\bot \) and \(\top \) stand for false and true, respectively. For a vector \(\textbf{x}\in \mathbb {R}^r\), let \(\Vert \textbf{x}\Vert {:}{=}\sqrt{\sum _{i=1}^r x_i^2}\) denote the standard Euclidean norm.

In the following, we give a brief introduction on important notions used throughout the rest of this paper and then describe the problem of interest.

2.1 Quadratic Module

Definition 1

(Quadratic Module [30]). A subset \(\mathcal {M}\) of \(\mathbb {R}[\textbf{x}]\) is called a quadratic module if it contains 1 and is closed under addition and multiplication with squares, i.e.,

$$\begin{aligned} 1\in \mathcal {M}, \mathcal {M} + \mathcal {M} \subseteq \mathcal {M}, \text{ and } p^2 \mathcal {M} \subseteq \mathcal {M}~ \text{ for } \text{ all } p \in \mathbb {R}[\textbf{x}]. \end{aligned}$$

Definition 2

Let \(\overline{p}:=\{p_1,\ldots ,p_m\}\) be a finite subset of \(\mathbb {R}[\textbf{x}]\). The quadratic module \(\mathcal {M}_{\textbf{x}}( \overline{p})\), or simply \(\mathcal {M}(\overline{p})\), generated by \(\overline{p}\) is the smallest quadratic module containing all \(p_i\), i.e.,

$$\begin{aligned} \mathcal {M}_{\textbf{x}}(\overline{p}){:}{=}\{\sigma _0+\sum _{i=1}^m \sigma _i p_i \mid \sigma _0, \sigma _i \in \mathrm {\Sigma }[\textbf{x}]\}. \end{aligned}$$

Let S be a closed basic semialgebraic set described by \(\overline{p}\ge \boldsymbol{0}\), i.e.,

$$\begin{aligned} S {:}{=}\{\textbf{x}\in \mathbb {R}^r \mid p_1(\textbf{x}) \ge 0, \ldots , p_m (\textbf{x}) \ge 0\}. \end{aligned}$$
(1)

Since SOS polynomials are non-negative, it is easy to verify that the quadratic module \(\mathcal {M}(\overline{p})\) is a subset of polynomials that are nonnegative on S. In fact, under the so-called the Archimedean condition, the quadratic module \(\mathcal {M}(\overline{p})\) contains all polynomials that are strictly positive over S. Both the condition and the statement are formalized as follows.

Definition 3

(Archimedean [30]). Let \(\mathcal {M}\) be a quadratic module of \(\mathbb {R}[\textbf{x}]\). \(\mathcal {M}\) is said to be Archimedean if there exists some \(a>0\) such that \(a-\Vert \textbf{x}\Vert ^2 \in \mathcal {M}\). Furthermore, if \(\mathcal {M}(\overline{p})\) is Archimedean, we say that the semialgebraic set S as defined in Eq. (1) is of the Archimedean form.

Theorem 1

(Putinar’s Positivstellensatz [36]). Let \(\overline{p}{:}{=}\{p_1,\ldots ,p_m\}\) and S be defined in Eq. (1). Assume that the quadratic module \(\mathcal {M}(\overline{p})\) is Archimedean. If \(f(\textbf{x})> 0\) over S, then \(f\in \mathcal {M}(\overline{p})\).

The above theorem serves as a key result in real algebraic geometry, as it provides a simple characterization of polynomials that are locally positive on closed basic semialgebraic sets. Because of this, Theorem 1 is widely used in the field of polynomial optimization, referring to [25, 30] for an in-depth treatment of this topic.

Though powerful, Theorem 1 relies on the Archimedean condition. Note that the inclusion \(a-\Vert \textbf{x}\Vert ^2 \in \mathcal {M}\) implies that \(a-\Vert \textbf{x}\Vert ^2 \ge 0\) over S, deducing that S is contained in a ball with radius \(\sqrt{a}\). As a result, in case that the set S is unbounded, Theorem 1 is not directly applicable.

2.2 Homogenization

Let \(\textbf{x}=(x_1, \ldots ,x_r)\in \mathbb {R}^{r}\) be an r-tuple of variables and \(x_0\) a fresh variable. Suppose that \(f(\textbf{x})\in \mathbb {R}[\textbf{x}]\) is a polynomial of degree \(d_f\). We denote by \(\tilde{f}(x_0,\textbf{x})\in \mathbb {R}[x_0,\textbf{x}]\) the homogenization of \(f(\textbf{x})\) which is obtained by substituting \(\frac{x_1}{x_0}\) for \(x_1\), ..., \(\frac{x_r}{x_0}\) for \(x_r\) in \(f(\textbf{x})\) and then multiplying with \(x_0^{d_f}\), that is,

$$\begin{aligned} \tilde{f}(x_0,\textbf{x}){:}{=}x_0^{d_f} f(\frac{x_1}{x_0}, \ldots , \frac{x_r}{x_0}). \end{aligned}$$
(2)

For example, if \(f(\textbf{x})=x_1^3+2x_1x_2+3x_2+4\), then \(\tilde{f}(x_0,\textbf{x})=x_1^3+2x_0x_1x_2+3x_0^2x_2+4x_0^3\). In what follows, we always use the variable \(x_0\) as the homogenizing variable.

Let S be defined as in Eq. (1). We define the following set related to S by homogenizing polynomials in the description of S:

$$\begin{aligned} \tilde{S}^h{:}{=}\{(x_0,\textbf{x})\in \mathbb {R}^{r+1}\mid \tilde{p}_1(x_0, \textbf{x}) \ge 0 ,\ldots ,\tilde{p}_m (x_0, \textbf{x}) \ge 0,x_0>0, x_0^2+\Vert \textbf{x}\Vert ^2=1\}. \end{aligned}$$
(3)

Obviously, the following property holds.

Property 1

Let S be as in Eq. (1) and \(\tilde{S}^h\) be defined as above. Then, \(\textbf{x}\in S\) if and only if

$$\begin{aligned} \left( \frac{1}{\sqrt{1+\Vert \textbf{x}\Vert ^2}}, \frac{x_1}{\sqrt{1+\Vert \textbf{x}\Vert ^2}}, \ldots , \frac{x_r}{\sqrt{1+\Vert \textbf{x}\Vert ^2}}\right) \in \tilde{S}^h. \end{aligned}$$

Moreover, \((x_0, \textbf{x}) \in \tilde{S}^h\) if and only if \((\frac{x_1}{\sqrt{1-\Vert \textbf{x}\Vert ^2}}, \ldots , \frac{x_r}{\sqrt{1-\Vert \textbf{x}\Vert ^2}})\in S\).

Property 1 shows that there exists a one-to-one correspondence between points in \(S\in \mathbb {R}^n\) and those in \(\tilde{S}^h\in \mathbb {R}^{n+1}\).

We also define the set \(\tilde{S}\) by replacing \(x_0>0\) in Eq. (3) with \(x_0\ge 0\):

$$\begin{aligned} \tilde{S}{:}{=}\{ (x_0, \textbf{x})\in \mathbb {R}^{r+1}\mid \tilde{p}_1(x_0, \textbf{x}) \ge 0,\ldots ,\tilde{p}_m (x_0, \textbf{x}) \ge 0,x_0\ge 0, x_0^2 + \Vert \textbf{x}\Vert ^2=1\}. \end{aligned}$$
(4)

To capture the relation between \(\tilde{S}^h\) and \(\tilde{S}\), we introduce the following definition and a related useful lemma.

Definition 4

A closed basic semialgebraic set S is closed at \(\infty \) if \(\mathrm cl(\tilde{S}^h)=\tilde{S}\).

Lemma 1

([17]). Let \(f\in \mathbb {R}[\textbf{x}]\) and S be a closed basic semialgebraic set. Then \(f\ge 0\) on S if and only if \(\tilde{f}\ge 0\) on \(\mathrm cl(\tilde{S}^h)\). Moreover, assuming that S is closed at \(\infty \), then \(f\ge 0\) on S if and only if \(\tilde{f}\ge 0\) on \(\tilde{S}\).

Let us define

$$\begin{aligned} S^{(\infty )}&{:}{=}\{\textbf{x}\in \mathbb {R}^{r} \mid p_1^{(\infty )}(\textbf{x}) \ge 0,\ldots ,p_m^{(\infty )}(\textbf{x}) \ge 0, \Vert \textbf{x}\Vert ^2=1\}, \end{aligned}$$
(5)

where \(p^{(\infty )}(\textbf{x})\) denotes the highest degree homogeneous part of a polynomial \(p(\textbf{x})\in \mathbb {R}[\textbf{x}]\), e.g., if \(p=x_1^2+2x_1x_2+3x_2^2+4x_1+5x_2\), then \(p^{(\infty )}=x_1^2+2x_1x_2+3x_2^2\).

Property 2

Let \(\tilde{S}^h\), \(\tilde{S}\) and \(S^{(\infty )}\) be defined as above. If \(S^{(\infty )}\) is empty, then \(\tilde{S}^h=\tilde{S}\).

2.3 Problem Description

Given two formulas \(\phi \) and \(\psi \) in a first-order theory \(\mathcal {T}\) s.t. \(\phi \models \psi \), Craig showed that there always exists an interpolant I over the common symbols of \(\phi \) and \(\psi \) s.t. \(\phi \models I\) and \(I \models \psi \). In the context of verification, we slightly abuse the terminology following [32]: A reverse interpolant (as coined in [22]) I over the common symbols of \(\phi \) and \(\psi \) is defined as follows.

Definition 5

(Interpolant). Given two formulas \(\phi \) and \(\psi \) in a theory \(\mathcal {T}\) s.t. \(\phi \wedge \psi \models _{\mathcal {T}} \bot \), a formula I is an interpolant of \(\phi \) and \(\psi \) if (1) \(\phi \models _{\mathcal {T}} I\); (2) \(I \wedge \psi \models _{\mathcal {T}} \bot \); and (3) I only contains common symbols and free variables shared by \(\phi \) and \(\psi \).

The interpolant synthesis problem of interest in this paper is formulated as follows.

Problem 1

Let \(\phi (\textbf{x},\textbf{y})\) and \(\psi (\textbf{x},\textbf{z})\) be two polynomial formulas of the form

$$\begin{aligned} \phi (\textbf{x},\textbf{y}) &{:}{=}\bigvee _{k=1}^{K_\phi } \bigwedge _{i=1}^{m_k} f_{k,i}(\textbf{x},\textbf{y}) \ge 0,\end{aligned}$$
(6)
$$\begin{aligned} \psi (\textbf{x},\textbf{z}) &{:}{=}\bigvee _{k'=1}^{K_\psi } \bigwedge _{j=1}^{n_{k'}} g_{k',j}(\textbf{x},\textbf{z}) \ge 0, \end{aligned}$$
(7)

where \(\textbf{x}\in \mathbb {R}^{r_1}\), \(\textbf{y}\in \mathbb {R}^{r_2}\), \(\textbf{z}\in \mathbb {R}^{r_3}\) are variable vectors, \(r_1,r_2,r_3 \in \mathbb {N}\), and \(f_{k,i}, g_{k',j}\) are polynomials in the corresponding variables. We aim to find a function \(h(\textbf{x})\) such that \(h(\textbf{x})>0\) is an interpolant for \(\phi \) and \(\psi \), i.e.,

$$\begin{aligned} \phi (\textbf{x},\textbf{y}) \models h(\textbf{x})>0 \text { and } \psi (\textbf{x},\textbf{z}) \models h(\textbf{x})<0. \end{aligned}$$

Here \(h(\textbf{x})\) is called an interpolant function. Specifically, we are interested in two scenarios where

  1. 1.

    Polynomial interpolants: the function \(h(\textbf{x})\) is a polynomial in \(\mathbb {R}[\textbf{x}]\);

  2. 2.

    Semialgebraic interpolantsFootnote 1: the function \(h(\textbf{x})\) can be expressed as

    $$\begin{aligned} h(\textbf{x}) = h_1(\textbf{x}) + \sqrt{\Vert \textbf{x}\Vert ^2+1}\cdot h_2(\textbf{x}), \end{aligned}$$
    (8)

    with \(h_1(\textbf{x}), h_2(\textbf{x})\in \mathbb {R}[\textbf{x}]\).

Obviously, the second case degenerates to the first case when \(h_2(\textbf{x})=0\).

Remark 1

Like in [11, 12], we require \(\phi \) and \(\psi \) to be defined by non-strict polynomial inequalities, mainly for two reasons: (1) Theoretically, our approach relies on Theorem 1, which necessitates a closed underlying basic semialgebraic set. (2) Numerically, we employ numerical solvers incapable of distinguishing \(\ge \) from >. In the coming sections, we will see the significance of both closedness and closedness at \(\infty \) for the existence of interpolants.

3 Existence of Interpolant

In this section, we prove the existence of a semialgebraic interpolant function \(h(\textbf{x})\) of the form Eq. (8), under certain conditions on \(\phi \) and \(\psi \). In Sect. 3.1, we begin by focusing on the scenario where both \(\phi \) and \(\psi \) exclusively involve the variable \(\textbf{x}\). Subsequently, in Sect. 3.2, we expand our scope to the case where unshared variables, \(\textbf{y}\) and \(\textbf{z}\), emerge.

3.1 Interpolant Between \(\phi (\textbf{x})\) and \(\psi (\textbf{x})\)

In this part, we prove the existence of a semialgebraic interpolant function of the form in Eq. (8) that separates the two closed semialgebraic sets in \(\mathbb {R}^r\) corresponding to \(\phi (\textbf{x})\) and \(\psi (\textbf{x})\). The basic idea goes as follows: First, we consider the problem of finding a semialgebraic function \(h(\textbf{x})\) such that \(h(\textbf{x})=0\) separates two closed basic semialgebraic sets \(S_1\) and \(S_2\) in \(\mathbb {R}^{r}\). Using the homogenization technique, we prove that there exists a polynomial \(g\in \mathbb {R}[x_0, \textbf{x}]\) with \(g(x_0, \textbf{x})=0\) separating \(\tilde{S_1}\) and \(\tilde{S_2}\), and the existence of \(h(\textbf{x})\) is directly induced by that of g (see Proposition 2). After that, we extend the result to the case where \(S_1\) becomes a closed semialgebraic set (see Lemma 3) and when both \(S_1\) and \(S_2\) are closed semialgebraic sets (see Theorem 2).

We begin by recapping an existing result from [11].

Proposition 1

([11, Lemma 2]). Let \(S_1=\{\textbf{x}\in \mathbb {R}^{r} \mid p_1(\textbf{x}) \ge 0,\ldots ,p_m (\textbf{x}) \ge 0\}\), \(S_2=\{\textbf{x}\in \mathbb {R}^{r} \mid q_1(\textbf{x}) \ge 0,\ldots ,q_n (\textbf{x}) \ge 0\}\) be two closed basic semialgebraic sets of the Archimedean form. Assuming that \(S_1\cap S_2=\emptyset \), then there exists a polynomial \(h(\textbf{x})\in \mathbb {R}[\textbf{x}]\) such that

$$\begin{aligned} \forall \textbf{x}\in S_1.~h(\textbf{x})>0 \text { and } \forall \textbf{x}\in S_2.~-h(\textbf{x})>0. \end{aligned}$$
(9)

It is important to emphasize that the proof of Proposition 1 relies on Theorem 1 and hence is limited to the case where the sets \(S_1\) and \(S_2\) are of the Archimedean form. In the following Proposition 2, we show how to remove this restriction.

Proposition 2

Let \(S_1=\{\textbf{x}\in \mathbb {R}^{r} \mid p_1(\textbf{x}) \ge 0,\ldots ,p_m (\textbf{x}) \ge 0\}\), \(S_2=\{\textbf{x}\in \mathbb {R}^{r} \mid q_1(\textbf{x}) \ge 0,\ldots ,q_n (\textbf{x}) \ge 0\}\) be closed basic semialgebraic sets. Assuming that \(\tilde{S}_1\cap \tilde{S}_2=\emptyset \), then there exists a semialgebraic function \(h(\textbf{x})\) of the form in Eq. (8) such that

$$\begin{aligned} \forall \textbf{x}\in S_1.~h(\textbf{x})>0 \text { and }\forall \textbf{x}\in S_2.~ -h(\textbf{x})>0. \end{aligned}$$
(10)

Proof

By the definition of \(\tilde{S}\) in Eq. (4), we know that \(\tilde{S}_1\) and \(\tilde{S}_2\) are two basic semialgebraic sets of the Archimedean form (as \(1-x_0^2 - \Vert \textbf{x}\Vert ^2\) belongs to the corresponding quadratic modules). Since \(\tilde{S}_1\cap \tilde{S}_2=\emptyset \), by invoking Proposition 1, there exists a polynomial \(g\in \mathbb {R}[x_0, \textbf{x}]\) such that

$$\begin{aligned} \forall (x_0, \textbf{x})\in \tilde{S}_1.~g(x_0, \textbf{x})>0 \text { and }\forall (x_0,\textbf{x})\in \tilde{S}_2.~-g(x_0, \textbf{x})>0. \end{aligned}$$
(11)

Note that for any \(\textbf{x}\in S_1\) (resp. \(S_2\)), by Property 1 we have \((\frac{1}{\sqrt{\Vert \textbf{x}\Vert ^2+1}},\frac{\textbf{x}}{\sqrt{\Vert \textbf{x}\Vert ^2+1}})\in \tilde{S}_1\) (resp. \(\tilde{S}_2\)). Let

$$\begin{aligned} h(\textbf{x}){:}{=}(\sqrt{\Vert \textbf{x}\Vert ^2+1})^{\deg (g)} g(\frac{1}{\sqrt{\Vert \textbf{x}\Vert ^2+1}},\frac{\textbf{x}}{\sqrt{\Vert \textbf{x}\Vert ^2+1}}). \end{aligned}$$
(12)

Since \((\sqrt{\Vert \textbf{x}\Vert ^2+1})^{\deg (g)} \ge 1\), combining with Eq. (11), we have that \(h(\textbf{x})\) satisfies Eq. (10).

To see that \(h(\textbf{x})\) admits the form in Eq. (8), we expand the right-hand side of Eq. (12) and simplify the terms with power of \(\sqrt{\Vert \textbf{x}\Vert ^2+1}\) greater than or equal to 2. After simplification, we collect the terms with and without \(\sqrt{\Vert \textbf{x}\Vert ^2+1}\) into two groups so that \(h(\textbf{x})\) can be expressed as \(h_1(\textbf{x})+\sqrt{\Vert \textbf{x}\Vert ^2+1}\cdot h_2(\textbf{x})\) for \(h_1(\textbf{x}),h_2(\textbf{x})\in \mathbb {R}[\textbf{x}]\).   \(\square \)

In order to check whether the condition \(\tilde{S}_1\cap \tilde{S}_2=\emptyset \) in Proposition 2 holds, one can use the following lemma.

Lemma 2

Given two closed basic semialgebraic set \(S_1\) and \(S_2\), if \(S_1\cap S_2=\emptyset \) and \(S^{(\infty )}_1\cap S^{(\infty )}_2=\emptyset \), then \(\tilde{S}_1\cap \tilde{S}_2=\emptyset \).

Now, we extend the result in Proposition 2 to the case when \(S_1\) and \(S_2\) are two closed semialgebraic sets. A closed semialgebraic set, say T, is a union of some closed basic semialgebraic sets, i.e., \(T=\cup _{i=1}^a S_i\) with

$$\begin{aligned} S_i=\{\textbf{x}\in \mathbb {R}^r \mid p_{i1}(\textbf{x}) \ge 0,\ldots ,p_{im_i} (\textbf{x}) \ge 0\},\quad i=1,\ldots ,a, \end{aligned}$$

where \(p_{ik}(\textbf{x}) \in \mathbb {R}[\textbf{x}]\), \(m_i\in \mathbb {N}\), \(k=1,...,m_i\), \(i=1,\ldots ,a\). Mirroring the definition of \(S^{(\infty )}\) and \(\tilde{S}\), we define \(T^{(\infty )}{:}{=}\bigcup _{i=1}^a S_i^{(\infty )}\) and \(\tilde{T}{:}{=}\bigcup _{i=1}^a\tilde{S}_i\). In the following lemma, we deal with the case when \(S_1\) in Proposition 2 becomes a union of closed basic semialgebraic sets.

Lemma 3

Let \(T_1=\cup _{i=1}^aS_{i}\) be a closed semialgebraic set with \(S_i=\{\textbf{x}\in \mathbb {R}^{r} \mid p_{i1}(\textbf{x}) \ge 0,\ldots ,p_{im_i}(\textbf{x}) \ge 0\}\), and let \(T_2=\{\textbf{x}\in \mathbb {R}^{r} \mid q_1(\textbf{x}) \ge 0,\ldots ,q_n (\textbf{x}) \ge 0\}\) be a closed basic semialgebraic set. Assume that \(\tilde{T}_1\cap \tilde{T_2}=\emptyset \). Then there exists a polynomial \(g\in \mathbb {R}[x_0, \textbf{x}]\) such that

$$\begin{aligned} \forall (x_0,\textbf{x})\in \tilde{T}_1.~g(x_0,\textbf{x})>0 \text { and }\forall (x_0,\textbf{x})\in \tilde{T}_2.~-g(x_0,\textbf{x})>0. \end{aligned}$$
(13)

Then, we use Lemma 3 to prove the case where both sets are unions of closed basic semialgebraic sets.

Theorem 2

Let \(T_1=\cup _{i=1}^a S_{i}\) and \(T_2=\cup _{j=1}^b S'_{j}\) be closed semialgebraic sets, where \(S_i\) and \(S'_j\) are closed basic semialgebraic sets for \(i=1,\dots , a, j=1,\dots ,b\). Assume \(\tilde{T}_1\cap \tilde{T}_2=\emptyset \). Then there exists a semialgebraic function \(h(\textbf{x})\) of the form in Eq. (8) such that

$$\begin{aligned} \forall \textbf{x}\in T_1.~ h(\textbf{x})>0 \text { and }\forall \textbf{x}\in T_2.~ -h(\textbf{x})>0. \end{aligned}$$
(14)

Similarly to Lemma 2, the condition \(\tilde{T}_1\cap \tilde{T_2}=\emptyset \) can be verified by checking whether \(T_1\cap T_2=\emptyset \) and \(T^{(\infty )}_1\cap T^{(\infty )}_2=\emptyset \). As a direct inference of Theorem 2, we know that there exists a semialgebraic function \(h(\textbf{x})\) of the form in Eq. (8) such that \(h(\textbf{x})>0\) is an interpolant of \(\phi (\textbf{x})\) and \(\psi (\textbf{x})\).

3.2 Interpolant Between \(\phi (\textbf{x},\textbf{y})\) and \(\psi (\textbf{x},\textbf{z})\)

Let \(\phi (\textbf{x},\textbf{y})\) and \(\psi (\textbf{x},\textbf{z})\) be given in Problem 1. We denote by \(T_\phi \subseteq \mathbb {R}^{r_1+r_2}\) and \(T_\psi \subseteq \mathbb {R}^{r_1+r_3}\) the semialgebraic sets corresponding to \(\phi \) and \(\psi \), i.e.,

$$\begin{aligned} T_{\phi } &{:}{=}\bigcup _{k=1}^{K_\phi } S_k, \text { with }S_k{:}{=}\{(\textbf{x}, \textbf{y})\in \mathbb {R}^{r_1+r_2} \mid \bigwedge _{i=1}^{m_k} f_{k,i}(\textbf{x},\textbf{y}) \ge 0 \},\end{aligned}$$
(15)
$$\begin{aligned} T_{\psi } &{:}{=}\bigcup _{k'=1}^{K_\psi } S'_{k'}, \text { with }S'_{k'}{:}{=}\{(\textbf{x}, \textbf{z}) \in \mathbb {R}^{r_1+r_3}\mid \bigwedge _{j=1}^{n_{k'}} g_{k',j}(\textbf{x},\textbf{z}) \ge 0 \}. \end{aligned}$$
(16)

Since an interpolant contains only common symbols of \(\phi \) and \(\psi \), Problem 1 can be reduced to finding a function \(h(\textbf{x})\) such that \(h(\textbf{x})=0\) separates the two projection sets \(P_{\textbf{x}}(T_\phi ){:}{=}\{\textbf{x}\in \mathbb {R}^{r_1}\mid \exists \textbf{y}.~(\textbf{x},\textbf{y})\in T_{\phi }\}\) and \(P_{\textbf{x}}(T_\psi ){:}{=}\{\textbf{x}\in \mathbb {R}^{r_1} \mid \exists \textbf{z}.~(\textbf{x},\textbf{z})\in T_{\psi }\}\). We have the following theorem as a direct consequence of Theorem 2.

Theorem 3

Let \(\phi (\textbf{x},\textbf{y})\) and \(\psi (\textbf{x},\textbf{z})\) be defined in Problem 1, and let \(P_{\textbf{x}}(T_{\phi })\) and \(P_{\textbf{x}}(T_\psi )\) be defined above. Let \(T_1=\mathrm cl(P_{\textbf{x}}(T_{\phi }))\) and \(T_2=\mathrm cl(P_{\textbf{x}}(T_\psi ))\). Assume \(\tilde{T}_1\cap \tilde{T}_2=\emptyset \). Then there exists a semialgebraic function \(h(\textbf{x})\) of the form in Eq. (8) such that

$$\begin{aligned} \forall \textbf{x}\in P_{\textbf{x}}(T_{\phi }).~h(\textbf{x})>0 \text { and }\forall \textbf{x}\in P_{\textbf{x}}(T_{\psi }).~-h(\textbf{x})>0. \end{aligned}$$
(17)

As a consequence, \(h(\textbf{x})>0\) is a semialgebraic interpolant of \(\phi (\textbf{x},\textbf{y})\) and \(\psi (\textbf{x},\textbf{z})\).

Remark 2

Note that in Theorem 3, we need to consider the closures \(\mathrm cl(P_{\textbf{x}}(T_{\phi }))\) and \(\mathrm cl(P_{\textbf{x}}(T_\psi ))\) rather than \(P_{\textbf{x}}(T_{\phi })\) and \(P_{\textbf{x}}(T_\psi )\) themselves. The reason lies in that the projections of closed semialgebraic sets are not necessarily closed. For example, consider \(\phi (\textbf{x},\textbf{y}){:}{=}x_1x_2-1\ge 0\wedge x_2\ge 0\) with \(\textbf{x}=x_1\) and \(\textbf{y}=x_2\). Then \(P_{\textbf{x}}(T_{\phi }) = \{x_1\mid x_1>0\}\) is an open set.

4 Sum-of-Squares Formulation

In this section, we provide SOS characterizations for polynomial and semialgebraic interpolants. For simplicity, we will focus on the case where \(\phi \) and \(\psi \) are conjunctions of polynomial inequalities given by

$$\begin{aligned} \phi (\textbf{x},\textbf{y}) {:}{=}\bigwedge _{i=1}^m f_i(\textbf{x},\textbf{y}) \ge 0\text { and } \psi (\textbf{x},\textbf{z}) {:}{=}\bigwedge _{j=1}^n g_j(\textbf{x},\textbf{z}) \ge 0, \end{aligned}$$
(18)

where \(\textbf{x}\in \mathbb {R}^{r_1}\), \(\textbf{y}\in \mathbb {R}^{r_2}\), and \(\textbf{z}\in \mathbb {R}^{r_3}\). Extending to the general case is straightforward.

4.1 SOS Characterization for Polynomial Interpolants

In this part, we provide an SOS characterization for polynomial interpolants based on homogenization. We prove that the characterization is sound and weakly complete. Furthermore, we provide a concrete example to show that our new characterization is strictly more expressive than the one in [11].

Theorem 4

(Weak Completeness). Let \(\phi \), \(\psi \) be defined as in Eq. (18) and let \(S_\phi \), and \(S_\psi \) be the basic semialgebraic sets corresponding to \(\phi \) and \(\psi \). Let \(\tilde{f}_{m+1}= x_0\), \(\tilde{g}_{n+1}= x_0\), \(\tilde{f}_{m+2}= x_0^2+\Vert \textbf{x}\Vert ^2+\Vert \textbf{y}\Vert ^2-1\), and \(\tilde{g}_{n+2}= x_0^2+\Vert \textbf{x}\Vert ^2+\Vert \textbf{z}\Vert ^2-1\). If \(h(\textbf{x})\in \mathbb {R}[\textbf{x}]\) is a polynomial interpolant function of \(\phi \) and \(\psi \), then the homogenized polynomial \(\tilde{h}(x_0, \textbf{x})\) satisfies, for arbitrarily small \(\epsilon >0\),

$$\begin{aligned} \begin{aligned} \tilde{h}(x_0,\textbf{x}) + \epsilon &~=~\sigma _0+\sum _{i=1}^{m+2}\sigma _i\tilde{f}_i(x_0,\textbf{x},\textbf{y}), \\ -\tilde{h}(x_0,\textbf{x}) + \epsilon &~=~\tau _0+\sum _{j=1}^{n+2}\tau _j\tilde{g}_j(x_0,\textbf{x},\textbf{z}), \end{aligned} \end{aligned}$$
(19)

for some \(\sigma _i\in \mathrm {\Sigma }[x_0,\textbf{x},\textbf{y}]\), \(i=0,\ldots ,m+1\), \(\sigma _{m+2}\in \mathbb {R}[x_0,\textbf{x},\textbf{y}]\), \(\tau _i\in \mathrm {\Sigma }[x_0,\textbf{x},\textbf{z}]\), \(i=0,\ldots ,n+1\), \(\tau _{n+2}\in \mathbb {R}[x_0,\textbf{x},\textbf{z}]\).

Remark 3

In Eq. (19), we add a small quantity \(\epsilon >0\) to the left-hand sides in order to invoke Theorem 1. The ideal case is \(\epsilon =0\). Fortunately, in most practice circumstances, we can safely set \(\epsilon =0\) when the finite convergence property [34, Theorem 1.1] holds. Indeed, the finite convergence property is generically true and is violated only when h and \(S_{\phi }\) (or \(S_{\psi }\)) are of certain singular forms.

Theorem 5

(Soundness). Let \(\phi \) and \(\psi \) be defined as in Eq. (18). Suppose that \(h(\textbf{x})\) is a polynomial such that its homogenization \(\tilde{h}(x_0,\textbf{x})\) satisfies Eq. (19) with \(\epsilon =0\). Assume \(\phi \wedge h(\textbf{x})=0\models \bot \) and \(\psi \wedge h(\textbf{x})=0\models \bot \). Then \(h(\textbf{x})\) is an interpolant function of \(\phi \) and \(\psi \).

Now we compare our characterization Eq. (19) with [11, Theorem 5] which states that if \(S_{\phi }\) and \(S_\psi \) are of the Archimedean form, then a polynomial interpolant function \(h(\textbf{x})\) can be expressed as

$$\begin{aligned} \begin{aligned} h(\textbf{x}) - 1 &= \sigma _0 + \sum _{i=0}^{m} \sigma _i f_i(\textbf{x},\textbf{y}),\\ - h(\textbf{x}) - 1 &= \tau _0 + \sum _{j=0}^{n} \tau _j g_j(\textbf{x},\textbf{z}),\\ \end{aligned} \end{aligned}$$
(20)

for some \(\sigma _i \in \mathrm {\Sigma }[\textbf{x},\textbf{y}]\), \(i=0,\dots ,m\) and \(\tau _j\in \mathrm {\Sigma }[\textbf{x},\textbf{z}]\), \(j=0,\dots ,n\). Clearly, since Theorem 4 removes the restriction of the Archimedean condition, our characterization is strictly more expressive.

Let \(M(x_1,x_2){:}{=}x_1^4x_2^2+x_1^2x_2^4-3x_1^2x_2^2+1\) be the Motzkin polynomial. It is well known that \(M(x_1,x_2)\) is nonnegative but is not an SOS.

Proposition 3

The polynomial \(M(x_1,x_2)+1\) is positive but is not an SOS.

Example 1

Let \(\phi {:}{=}1\ge 0 (= \top )\) and \(\psi {:}{=}-1 \ge 0 (= \bot )\). By Proposition 3, the polynomial \(M(x_1,x_2)+1\) is an interpolant function of \(\phi \) and \(\psi \) but does not admit a representation as in Eq. (20), i.e., the program

$$\begin{aligned} \text {find} \quad &\sigma _0 \in \mathrm {\Sigma }[x_1,x_2]\\ \mathrm {s.t.} \quad & x_1^4x_2^2+x_1^2x_2^4-3x_1^2x_2^2+2 =\sigma _0 \end{aligned}$$

is not feasible. However, a numerical solution to the following program:

$$\begin{aligned} \text {find} \quad &\sigma _0, \sigma _1 \in \mathrm {\Sigma } [x_0,x_1,x_2], \sigma _2\in \mathbb {R}[x_0,x_1,x_2]\\ \mathrm {s.t.} \quad & x_1^4x_2^2 + x_1^2x_2^4 - 3x_1^2x_2^2x_0^2 + 2x_0^6= \sigma _0 + \sigma _1 x_0 + \sigma _2 (1-x_0^2-x_1^2-x_2^2). \end{aligned}$$

can be obtained by employing the Julia package TSSOS [28] and the SDP solver Mosek [2]. Therefore, the polynomial \(M(x_1,x_2)+1\) admits a representation as in Eq. (19) with \(\epsilon =0\).

4.2 SOS Characterization for Semialgebraic Interpolants

Let \(h(\textbf{x})\) be a semialgebraic interpolant function of the form in Eq. (8) and let w be a fresh variable. Though \(h(\textbf{x})\) is not a polynomial, it can be equivalently represented by a polynomial \(l(\textbf{x}, w)=h_1(\textbf{x})+w\cdot h_2(\textbf{x})\in \mathbb {R}[\textbf{x},w]\) with additional polynomial constraints \(w^2=1+\Vert \textbf{x}\Vert ^2\) and \(w\ge 0\). Adopting this idea, we have the following completeness theorem. The soundness result for the semialgebraic case is omitted, as it is essentially the same as Theorem 5.

Theorem 6

(Completeness). Let \(\phi \), \(\psi \) be defined as in Eq. (18) and let \(S_\phi \), and \(S_\psi \) be the basic semialgebraic sets corresponding to \(\phi \) and \(\psi \). Let \(S_1 = \mathrm cl(P_{\textbf{x}}(S_\phi ))\), \(S_2 = \mathrm cl(P_{\textbf{x}}(S_\psi ))\), \(\tilde{f}_{m+1}=\tilde{g}_{n+1}= x_0\), \(\tilde{f}_{m+2}=\tilde{g}_{m+2}=w\), \(\tilde{f}_{m+3}= x_0^2+\Vert \textbf{x}\Vert ^2+w^2+\Vert \textbf{y}\Vert ^2-1\), and \(\tilde{g}_{n+3}= x_0^2+\Vert \textbf{x}\Vert ^2+w^2+\Vert \textbf{z}\Vert ^2-1\), \(\tilde{f}_{m+4}=\tilde{g}_{n+4}= x_0^2+\Vert \textbf{x}\Vert ^2-w^2\). Assume that the following two conditions hold: (1) \(\tilde{S}_1\cap \tilde{S_2} = \emptyset \); (2) \(S_\phi \) and \(S_\psi \) are closed at \(\infty \). Then there exists a semialgebraic interpolant function \(h(\textbf{x})\) of the form in Eq. (8) such that the polynomial \(l(\textbf{x}, w)=h_1(\textbf{x})+w\cdot h_2(\textbf{x})\in \mathbb {R}[\textbf{x},w]\) satisfies, for arbitrarily small \(\epsilon >0\),

$$\begin{aligned} \begin{aligned} \tilde{l}(x_0, \textbf{x}, w) + \epsilon &~=~\sigma _0+\sum _{i=1}^{m+4}\sigma _i\tilde{f}_i(x_0,\textbf{x},\textbf{y}), \\ -\tilde{l}(x_0, \textbf{x}, w) + \epsilon &~=~\tau _0+\sum _{j=1}^{n+4}\tau _j\tilde{g}_j(x_0,\textbf{x},\textbf{z}), \end{aligned} \end{aligned}$$
(21)

for some \(\sigma _i\in \mathrm {\Sigma }[x_0,\textbf{x},\textbf{y},w]\), \(i=0,\ldots ,m+2\), \(\sigma _{m+3},\sigma _{m+4}\in \mathbb {R}[x_0,\textbf{x},\textbf{y},w]\), \(\tau _i\in \mathrm {\Sigma }[x_0,\textbf{x},\textbf{z},w]\), \(i=0,\ldots ,n+2\), \(\tau _{n+3},\tau _{n+4}\in \mathbb {R}[x_0,\textbf{x},\textbf{z},w]\).

We want to emphasize that Theorem 6 is a stronger result than Theorem 4, in the sense that Theorem 6 guarantees the existence of a semialgebraic interpolant (as per Theorem 3), which is not the case for polynomial interpolants in Theorem 4.

5 Synthesizing Interpolant via SOS Programming

In this section, we propose an SOS programming procedure to synthesize polynomial and semialgebraic interpolants. Concrete examples are provided to demonstrate the effectiveness and efficiency of our method. For all examples, existing approaches [7, 10, 12] are not applicable due to their restrictions on formulas, and the method in [11] also fails to produce interpolants of specified degrees.

Synthesizing Polynomial Interpolants: Let \(T_\phi \), \(T_\psi \), \(S_k\), and \(S_{k'}\) be defined as in Eq. (15) and Eq. (16). By treating \(S_k\) and \(S_k'\) respectively as \(S_\phi \) and \(S_\psi \) in Theorem 4, the problem of synthesizing a polynomial interpolant for \(\phi \) and \(\psi \) is reduced to solving the following SOS program:

$$\begin{aligned} \left\{ \begin{aligned}\text {find} \quad & h(\textbf{x})\\ \mathrm {s.t.} \quad &\tilde{h}(x_0,\textbf{x})=\sigma _{k,0}+\sum _{i=1}^{m_k+2} \sigma _{k,i} \tilde{f}_{k,i} \quad \text {for }k=1,\dots ,K_{\phi },\\ &-\tilde{h}(x_0,\textbf{x})=\tau _{k',0}+\sum _{j=1}^{n_{k'}+2} \tau _{k',j} \tilde{g}_{k',j} \quad \text {for }k'=1,\dots ,K_{\psi },\\ &\sigma _{k,0},...,\sigma _{k,m+1}\in \mathrm {\Sigma }[x_0,\textbf{x},\textbf{y}], \sigma _{k,m+2}\in \mathbb {R}[x_0,\textbf{x},\textbf{y}], \\ & \qquad \text {for }k=1,\dots ,K_{\phi },\\ &\tau _{k',0},...,\tau _{k',n+1}\in \mathrm {\Sigma }[x_0,\textbf{x},\textbf{z}], \tau _{k',n+2}\in \mathbb {R}[x_0,\textbf{x},\textbf{y}],\\ & \qquad \text {for }k=1,\dots ,K_{\psi }, \end{aligned} \right. \end{aligned}$$
(22)

where \(\tilde{f}_{k,m+1}=\tilde{g}_{k',n+1}=x_0\), \(\tilde{f}_{k,m+2} =x_0^2+\Vert \textbf{x}\Vert ^2+\Vert \textbf{y}\Vert ^2-1\), \(\tilde{g}_{k',n+2}=x_0^2+\Vert \textbf{x}\Vert ^2+\Vert \textbf{z}\Vert ^2-1\) for \(k=1,\dots ,K_{\phi }\) and \(k'=1,\dots ,K_{\psi }\).

As Theorem 5 suggests, a solution \(h(\textbf{x})\) to the above program only ensures that \(\phi \models h(\textbf{x})\ge 0\) and \(\psi \models -h(\textbf{x})\le 0\). Nevertheless, since numerical solvers are unable to distinguish \(\ge \) from >, the equalities are usually not attainable for a numerical solutionFootnote 2. Therefore, we can view the SOS program Eq. (22) as a sound approach for computing \(h(\textbf{x})\), while completeness follows from verifying the conditions discussed in Remark 3.

In practice, we solve the program Eq. (22) by solving a sequence of SDP relaxations which are obtained by restricting the highest degree of involved polynomials. Concretely speaking, suppose that we would like to find a polynomial interpolant function \(h(\textbf{x})\) of degree d, we set the template of \(h(\textbf{x})\) to be \(h(\textbf{x})= \sum _{|{\boldsymbol{\alpha }}|\le d} c_{{\boldsymbol{\alpha }}} \textbf{x}^{{\boldsymbol{\alpha }}}\), where \({\boldsymbol{\alpha }}=(\alpha _1, ..., \alpha _{r_1})\in \mathbb {N}^{r_1}\), \(|{\boldsymbol{\alpha }}|=\alpha _1+ \cdots \alpha _{r_1}\), and \(c_{{\boldsymbol{\alpha }}}\in \mathbb {R}\) are coefficients to be determined. Then, the homogenization of \(h(\textbf{x})\) is \(\tilde{h}(x_0,\textbf{x})= \sum _{|{\boldsymbol{\alpha }}|\le d} c_{{\boldsymbol{\alpha }}} x_0^{d-|{\boldsymbol{\alpha }}|} \textbf{x}^{{\boldsymbol{\alpha }}}\).

Given a relaxation order \(s\in \mathbb {N}\) with \(2s\ge d\), we set the degrees of the remaining unknown polynomials \(\sigma _i,\tau _j\) appropriately to ensure that the maximum degree of polynomials involved in Eq. (22) equals 2s. We refer to the resulting program as the s-th relaxation of Eq. (22), which can be translated into an SDP and can be numerically solved in polynomial time. If the s-th relaxation is solvable, it yields a solution \(h(\textbf{x})\) that serves as a polynomial interpolant function of \(\phi \) and \(\psi \). If it is not solvable, we then increase the relaxation order s to obtain a tighter relaxation, or alternatively, we can increase the degree d of \(h(\textbf{x})\) to search for interpolants of higher degree.

In the following, all experiments were conducted on a Mac lap-top with Apple M2 chip and 8GB memory. We use the Julia package TSSOS [28] to formulate SOS programs and rely on the SDP solver Mosek [2] to solve them. All numerical results are symbolically verified using Mathematica to be real interpolants.

Example 2

(adapted from [4]). Let \(\textbf{x}=(x,y)\) and \(\textbf{y}=\textbf{z}=\emptyset \), i.e., there is no uncommon variables. We define the following polynomials:

$$\begin{aligned} &f_1 = 11 - x^4 + 0.1y^4,\quad & f_2 = y^3,\\ &f_3 = 0.9025 - (x-1)^4 - y^4,\quad & f_4 = (x-1)^4 + y^4 - 0.09,\\ &f_5 = (x+1)^4 + y^4 - 1.1025,\quad & f_6 = 0.04 - (x+1)^4 - y^4,\\ &g_1 = 11 - x^4 + 0.1y^4,\quad & g_2 = -y^3,\\ &g_3 = 0.9025 - (x+1)^4 - y^4, \quad & g_4 = (x+1)^4 + y^4 - 0.09,\\ &g_5 = (x-1)^4 + y^4 - 1.1025, \quad & g_6 = 0.04 - (x-1)^4 - y^4. \end{aligned}$$

Let \(\phi \) and \(\psi \) be defined by

$$\begin{aligned} &\phi {:}{=}(f_1\ge 0 \wedge f_2\ge 0 \wedge f_4\ge 0\wedge f_5\ge 0) \vee (f_3\ge 0 \wedge f_4\ge 0 \wedge f_5\ge 0) \vee (f_6\ge 0),\\ &\psi {:}{=}(g_1\ge 0 \wedge g_2\ge 0 \wedge g_4 \ge 0 \wedge g_5\ge 0) \vee (g_3\ge 0 \wedge g_4\ge 0 \wedge g_5 \ge 0) \vee (g_6\ge 0). \end{aligned}$$

Set the degree of the polynomial interpolation function h(xy) to 7. It takes 0.16 s to solve the 4-th relaxation Eq. (22), yielding the solution

$$\begin{aligned} h(x,y) = - 0.00153942 y + 0.03053692x + \cdots + 0.06109453 x^6 y + 0.01643640 x^7, \end{aligned}$$

where the coefficients have been scaled so that the largest absolute value is 1.

Synthesizing Semialgebraic Interpolants: Similarly, the synthesis of a semialgebraic interpolant is reduced to solving the following SOS program:

$$\begin{aligned} \left\{ \begin{aligned} \text {find} \quad & h_1(\textbf{x}), h_2(\textbf{x})\\ \mathrm {s.t.} \quad & l(\textbf{x}, w) = h_1(\textbf{x})+w\cdot h_2(\textbf{x}),\\ &\tilde{l}(x_0,\textbf{x}, w)=\sigma _{k,0}+\sum _{i=1}^{m_k+4} \sigma _{k,i} \tilde{f}_{k,i} \quad \text {for }k=1,\dots ,K_{\phi },\\ &-\tilde{l}(x_0,\textbf{x}, w)=\tau _{k',0}+\sum _{j=1}^{n_{k'}+4} \tau _{k',j} \tilde{g}_{k',j} \quad \text {for }k'=1,\dots ,K_{\psi },\\ &\sigma _{k,0},...,\sigma _{k,m+2}\in \mathrm {\Sigma }[x_0,\textbf{x},\textbf{y}], \sigma _{k,m+3}, \sigma _{k,m+4}\in \mathbb {R}[x_0,\textbf{x},\textbf{y}], \\ & \qquad \text {for }k=1,\dots ,K_{\phi },\\ &\tau _{k',0},...,\tau _{k',n+2}\in \mathrm {\Sigma }[x_0,\textbf{x},\textbf{z}], \tau _{k',n+3}, \tau _{k',n+4}\in \mathbb {R}[x_0,\textbf{x},\textbf{y}],\\ & \qquad \text {for }k=1,\dots ,K_{\psi }, \end{aligned}\right. \end{aligned}$$
(23)

where \(\tilde{f}_{k,m+1}=\tilde{g}_{k',n+1}=x_0\), \(\tilde{f}_{k,m+2}=\tilde{g}_{k',n+2}=w\), \(\tilde{f}_{k,m+3} = x_0^2+\Vert \textbf{x}\Vert ^2+w^2+\Vert \textbf{y}\Vert ^2-1\), \(\tilde{g}_{k',n+3}= x_0^2+\Vert \textbf{x}\Vert ^2+w^2+\Vert \textbf{z}\Vert ^2-1\), \(\tilde{f}_{k,m+4} = \tilde{g}_{k',n+4}=x_0^2+\Vert \textbf{x}\Vert ^2-w^2\), for \(k=1,\dots ,K_{\phi }\) and \(k'=1,\dots ,K_{\psi }\).

By Theorem 6, if a feasible solution \((h_1, h_2)\) of Eq. (23) is found, then \(h(\textbf{x})=h_1(\textbf{x})+\sqrt{\Vert \textbf{x}\Vert ^2+1}\cdot h_2(\textbf{x})\) is a semialgebraic interpolant function for \(\phi \) and \(\psi \). In practice, w.l.o.g., we can assume that \(h_1\) and \(h_2\) are of the same degree d and solve SDP relaxations of Eq. (23). The soundness result is similar to that of Eq. (22), requiring that \(h(\textbf{x})=0\) is not attainable over \(T_{\phi }\) and \(T_{\psi }\).

Example 3

Let \(\textbf{x}=(x,y)\), \(\textbf{y}=\textbf{z}=\emptyset \). We define

$$\begin{aligned} \phi (x,y) &= 8xy-(x^2-y^3)^2\ge 0 \wedge x^2+y^2-1\ge 0,\\ \psi (x,y) &= -12.5xy-(x^2+y^2)^2\ge 0 \wedge x^2+y^2-1\ge 0. \end{aligned}$$

Let the degree of \(h_1(\textbf{x})\) and \(h_2(\textbf{x})\) to be 3, a solution to the 2-th relaxation of Eq. (23) is found in 0.02 s:

$$\begin{aligned} h_1 &= - 0.04402209 - 0.00093184 y + 0.01446436 x + \dots - 0.03703461 x^3,\\ h_2 &= 0.05644318 - 0.01305178 y + 0.02407258 x +\cdots + 0.23199837 x^2. \end{aligned}$$

As a comparison, solving Eq. (22) fails to produce a polynomial interpolant function of degree 3, but succeeds at degree 4.

Example 4

Let \(\textbf{x}=(x,y,z)\), \(\textbf{y}=\emptyset \), and \(\textbf{z}=(r,R)\). We define

$$\begin{aligned} \phi (x,y,z) & {:}{=}~ 1 + 0.1z^4 - x^4 - y^4 \ge 0 \wedge 10z^4 - x^4 - y^4 \ge 0,\\ \psi (x,y,z,r,R) & {:}{=}~ 4R^2(x^2+y^2) - (x^2+y^2+z^2+R^2-r^2)^2 \ge 0 \\ & \qquad \wedge 6\ge R\ge 4 \wedge 1\ge r\ge 0.5, \end{aligned}$$

where \(\exists r, \exists R.~\psi (x,y,z,r,R)\) describes the set of interior points of a 3-dimensional torus with unknown minor radius \(r\in [0.5,1]\) and major radius \(R\in [4,6]\). By solving Eq. (22) and Eq. (23), we obtain a polynomial interpolant

$$\begin{aligned} h_p(x,y,z) = 1.0 - 0.35507338 x^2 - 0.35507338 y^2 + 0.45264895 z^2, \end{aligned}$$

and a semialgebraic interpolant function with

$$\begin{aligned} h_1(x,y,z) &= 0.98004189 - 0.26291972 x^2 - 0.26291978 y^2 + 0.417581644 z^2,\\ h_2(x,y,z) &= 1.0 - 0.51670759 x^2 - 0.51670759 y^2 + 0.60569150 z^2. \end{aligned}$$

As a comparison, [11] fails to produce an interpolant of degree less than 4.

6 Conclusions and Future Work

In this paper, we have addressed the problem of synthesizing Craig interpolants for two general polynomial formulas. By combining the polynomial homogenization techniques with the approach from [11], we have presented a complete SOS characterization of semialgebraic (and polynomial) interpolants. Compared with existing works, our approach removes the restrictions on the form of formulas and is applicable to any polynomial formulas, especially when variables have unbound domains. Moreover, sparsity of polynomial formulas can be exploited to improve the scalability of our approach [16, 29].

Our Craig interpolation synthesis technique offers broad applicability in various verification tasks. It can be used as a sub-procedure, for example, in CEGAR-based model checking for identifying counterexamples [32], in bounded model checking for generating proofs [21], in program verification for squeezing invariants [26], and in SMT for reasoning about nonlinear arithmetic [18]. Compared with existing algorithms, our SDP-based algorithm is efficient and provides a relative completeness guarantee. However, the practical implementation is not a trivial undertaking, as it requires suitable strategies for storing numerical interpolants and taming numerical errors [37]. This remains an ongoing work of our research.