1 Introduction

1.1 The setting

Positive semidefinite matrices and operators come up in a large number of contexts throughout mathematics, physics and computer science, including the theory of operator algebras, computations with quantum states, or semidefinite relaxations of optimization problems. A problem that arises frequently in many of these contexts is determining whether a given matrix M or operator is positive semidefinite (psd). In certain applications—we describe two of them in Sects. 1.2 and 1.3M is of such a large dimension that it is impossible to express M in an orthonormal basis and store the result in a computer, let alone diagonalize it or compute determinants of principal minors. Instead, we assume that one can compute a few of the normalized moments \(\mathbf {tr}(M^k)\), where we define the normalized trace as

$$\begin{aligned} \mathbf {tr}(M) := s^{-1}\,\mathrm {tr}(M) , \end{aligned}$$

where s is the size of M. In this paper, we answer the following questions:

  1. (i)

    Given the first m normalized moments \(\mathbf {tr}(M^k)\) for \(k=1,\ldots ,m\) of a Hermitian operator M with \(\Vert M\Vert _\infty \le 1\), can one show that M is not psd?

  2. (ii)

    Given these moments and a \(p\in [1,\infty )\), can one optimally bound the distance of M to the psd cone from above and below in Schatten p-norm?

Since both the moments and the positive semidefiniteness of a Hermitian operator M are characterized by the distribution of eigenvalues—or more generally by the corresponding Borel measure on the spectrum of M—we are secretly concerned with a version of the truncated Hausdorff moment problem. In these terms, the above two questions become:

  1. (i)

    Given only the moments

    $$\begin{aligned} {\mathbb {E}}_\mu [x^k] := \int _{-1}^{+1} x^k \, d\mu \end{aligned}$$

    of a compactly supported Borel measure \(\mu \) on \([-1,1]\) for \(k=1,\ldots ,m\), can one show that \(\mu \) is not supported on [0, 1]?

  2. (ii)

    Given these moments and a \(p\in [1,\infty )\), can one optimally bound the p-Wasserstein distance [27] between \(\mu \) and the set of probability measures supported on [0, 1] from above and from below?

Given this connection with the moment problem, it should not come as a surprise that our methods also work in certain infinite-dimensional situations. While we focus on the matrix case in the main text, we sketch the extension to testing positivity of a Hermitian element in a von Neumann algebra equipped with a finite faithful trace in “Appendix A”.

Let us now motivate the assumption that we have access to a few moments of M. In the applications we have in mind, the space where M lives has a natural tensor product structure, with respect to which M can be expressed as

$$\begin{aligned} M=\sum _{j=1}^{r} A^{[1]}_j\otimes \cdots \otimes A^{[n]}_j , \end{aligned}$$
(1)

where each \(A^{[i]}_j\) is Hermitian and of reasonably small dimension.Footnote 1 Note that every M on a tensor product space can be written this way, for large enough r. In our example applications below, r is taken to be fixed and typically small, or not scaling with n. Thus, the naturally available operations are those that can be directly performed in terms of the local matrices \(A_j^{[i]}\). This includes taking powers of M and taking the trace, which gives us access to the moments of M:

$$\begin{aligned} \begin{aligned} \mathbf {tr}\left( M^k\right)&= \sum _{j_1,\ldots ,j_k=1}^{r} \mathbf {tr}\left( A_{j_1}^{[1]}\cdots A_{j_k}^{[1]}\right) \cdots \mathbf {tr}\left( A_{j_1}^{[n]}\cdots A_{j_k}^{[n]}\right) , \end{aligned} \end{aligned}$$
(2)

for \(k\in {\mathbb {N}}\) much smaller than the size of the matrix M, namely \(s\times s\).

1.2 Example application: tensor networks

Our first example application concerns quantum states of a many-body system, which are modelled by psd matrices on a Hilbert space \(\mathcal {H} = \mathcal {H}_1\otimes \mathcal {H}_2\otimes \ldots \otimes \mathcal {H}_n\), where \(\mathcal {H}_i\) is the Hilbert space associated to subsystem i. Typically, all \(\mathcal {H}_i\) are of the same finite dimension. Since the dimension of \(\mathcal {H}\) grows exponentially with n, physicists have attempted to develop a scalable description of quantum many-body systems, that is, one which grows only polynomially in n. This is the objective of the program of tensor networks [6, 19, 20, 26]. While this program has been very successful for pure states (i.e. psd matrices of rank 1), its success for mixed states has been more limited. One of the reasons for that is the positivity problem, which is the following. In the tensor network paradigm, it is natural to use a few matrices for each local Hilbert space \(\mathcal {H}_i\). For example, the state of the system in one spatial dimension (with periodic boundary conditions) is described by

$$\begin{aligned} M=\sum _{j_1, \ldots , j_{n}=1}^{r} A_{j_1,j_2} \otimes A_{j_2,j_3} \otimes \cdots \otimes A_{j_{n},j_1}, \end{aligned}$$
(3)

where each \(A_{j_{l},j_{l+1}}\) is a Hermitian matrix in \(\mathcal {H}_l\) [4, 25]. (In general, the local matrices \(A_{j_l,j_{l+1}}\) may also depend on the site l, but we do not consider this case for notational simplicity.) Now, while M must be psd to describe a quantum state, each of the local matrices \(A_{j_{l},j_{l+1}}\) need not be psd. While there is a way of imposing positivity in the local matrices (resulting in the ‘local purification form’), this generally comes at the price of a very large increase in the number of matrices, thus making the representation very inefficient [4].

Indeed, the hardness of deciding whether objects of the kind of (3) are psd has been studied. Specifically:

Problem 1

Given \( \{A_{j,j'} \in \mathrm {Her}_s \}_{j,j'=1}^{r}\) with \(s,r\ge 7\), let

$$\begin{aligned} M(n) := \sum _{j_1, \ldots , j_{n}=1}^{r} A_{j_1,j_2} \otimes A_{j_2,j_3} \otimes \cdots \otimes A_{j_{n},j_1}. \end{aligned}$$

Decide whether \(M(n) \ge 0\) for all n.

Proposition 1

[5] Problem 1 is undecidable.

This holds true even if all matrices \(A_{j,j'}\) are diagonal and their entries rational. Variants of this problem are also undecidable [14], and deciding whether it is psd for a finite number of system sizes and with open boundary conditions is NP-complete [14]. See also [28] for further perspectives on this problem.

1.3 Example application: free spectrahedra

Our second example application is in the area of convex optimization, where we find the same algebraic structures as the ones we have considered so far, albeit often studied from a different angle. Namely, given a tuple \((B_1,\ldots , B_{r})\) of Hermitian matrices, its associated spectrahedron [3] is defined as

$$\begin{aligned} \mathrm {S}(B_1,\ldots , B_{r}) = \left\{ (y_1, \ldots , y_{r}) \in {\mathbb {R}}^{r} \, \Bigg | \, \sum _{i=1}^{r} y_i B_i \geqslant 0\right\} , \end{aligned}$$

where \(\geqslant \) denotes positive semidefiniteness. Note that it is the intersection of an affine space with the set of psd matrices. Spectrahedra are precisely the feasible sets of semidefinite programimg (SDP). Characterizing which convex sets are spectrahedra is a main objective in the area of algebraic convexity [3], and has direct implications for the many applications of semidefinite programming.

Recently, a non-commutative generalization of spectrahedra has been proposed, called free spectrahedra [10], defined as

$$\begin{aligned} \mathrm {FS} (B_1,\ldots , B_{r}) = \bigcup _{s=1}^{\infty } \left\{ (A_1, \ldots , A_d) \in \mathrm {Her}_s^{r} \, \Bigg | \, \sum _{i=1}^{r} A_i \otimes B_i \geqslant 0\right\} . \end{aligned}$$
(4)

Thus, asking whether \(\sum _{i=1}^{r} A_i \otimes B_i\) is psd is equivalent to asking whether \((A_1,\ldots , A_{r})\) is in the free spectrahedron defined by \((B_1,\ldots , B_{r})\). This is again a problem of the form (1), with \(n=2\). Surprisingly, many things about standard spectrahedra can be learned by examining their free versions. For example, the inclusion test of spectrahedra proposed in [1] was fully understood in [11] as an inclusion test of free spectrahedra, opening the way to analyzing the exactness of the method (see [7] and the references therein). Also, two minimal matrix tuples defining the same spectrahedron are unitarily equivalent if and only if they define the same free spectrahedron [11]. So the different free spectrahedra over a standard spectrahedron characterize equivalence classes of its defining matrix tuples. Applying these results often means checking whether a free spectrahedron contains a certain matrix tuple, i.e. whether \(\sum _i A_i\otimes B_i\) is psd. Since the matrices might be of very large size, this is again a context in which our methods can be applied.

1.4 Related work

The methods we use to solve the problems described above are fairly standard: a combination of techniques used for moment problems combined with results on sums of squares representations of positive polynomials. One might therefore expect there to exist a substantial amount of literature on the problem which we solve in this work, but this does not seem to be the case.

There is only one work that we are aware of Lasserre [17] has investigated the smallest interval \([a_m,b_m]\) on which the support of a measure on \({\mathbb {R}}\) can be shown to be contained, given only its first m moments. One can think of this as providing a solution to the problems discussed above in the case \(p = \infty \). Lasserre found that the lower bound \(a_m\) and upper bound \(b_m\) are the optimal solutions of two simple semidefinite programs involving the moments.

1.5 Overview

The rest of this paper is structured as follows. In Sect. 2, we characterize the distance of a matrix to the psd cone. In Sect. 3, we provide upper and lower bounds to the distance to the psd cone by using a few moments of the matrix. In Sect. 4, we provide three methods to compute these bounds: the sos polynomial method, the Handelman method and the Chebyshev method. In Sect. 5 we analyse the numerical performance of these methods. Finally, in “Appendix A”, we will sketch the extension to von Neumann algebras.

2 The Distance to the psd Cone

We will start with some preliminaries (Sect. 2.1) and then define the negative part function and the distance to the psd cone (Sect. 2.2).

2.1 Preliminaries

Let us first fix some notation. For a matrix M, we denote its Hermitian conjugate by \(M^*\). \(\mathrm {Her}_s\) denotes the set of Hermitian matrices of size \(s\times s\). For \(M\in \mathrm {Her}_s\), \(M\geqslant 0\) denotes that M is psd, and \(M\leqslant 0\) that it is negative semidefinite (i.e. \(-M\geqslant 0\)).

We now state some basic facts about matrices and their norms. Consider \(M\in \mathrm {Her}_s\) and its spectral decomposition \(M = U^*DU\), where U is a unitary matrix, \(D=\text {diag}(\lambda _1,\ldots , \lambda _s)\), and \(\{\lambda _1,\ldots , \lambda _s\}=:\mathrm {sp}(M)\) is the spectrum of M (considered as a multiset). Any real-valued function f defined on \(\mathrm {sp}(M)\) can be defined on M by setting

$$\begin{aligned} f(M):=U^*f(D)\, U, \end{aligned}$$

where \(f(D)=\text {diag}(f(\lambda _1),\ldots , f(\lambda _s))\). For example, the absolute value \(\vert M\vert \) of M is defined this way. For \(p\in [1,\infty )\), we define the Schatten p-norm of M as

$$\begin{aligned} \Vert M\Vert _p := \left( \mathbf {tr}( | M|^p ) \right) ^{1/p}, \end{aligned}$$

where taking the normalized trace instead of the usual trace introduces an additional factor of \(s^{-1/p}\) with respect to the usual definition. This definition guarantees that \(\Vert I\Vert _p = 1\), where I is the identity matrix (of any size). The case \(p=2\) corresponds to the normalized Frobenius norm, and the case \(p=1\) to the normalized trace norm. Note also that if p is even, the norm is easier to compute, since in this case the absolute value is superfluous, so that \(\Vert M\Vert _p = \left( \mathbf {tr}(M^p) \right) ^{1/p}\), which is simply the pth root of the pth moment of M. The operator norm of M induced by the standard Euclidean norm on \({\mathbb {C}}^s\) is defined as

$$\begin{aligned} \Vert M\Vert _\infty := \max _{\lambda _i\in \mathrm {sp}(M)} |\lambda _i| . \end{aligned}$$

We have that \(\Vert M\Vert _\infty = \lim _{p\rightarrow \infty } \Vert M\Vert _p\).

Remark 1

In the following we will often assume that \(\Vert M\Vert _\infty \le 1\), i.e. that the spectrum of M lies in \([-1,1]\). This can clearly be achieved by a suitable scaling of M. Of course, since our main problem is that \(\mathrm {sp}(M)\) cannot be computed, we cannot simply scale by \(\Vert M\Vert _\infty \). But for \(1\le p\le q\le \infty \), we have

$$\begin{aligned} \Vert M\Vert _p\le \Vert M\Vert _q \le s^{\frac{1}{p}-\frac{1}{q}}\Vert M\Vert _p. \end{aligned}$$

So we can divide M by \(s^{1/p}\Vert M\Vert _p\) (for any \(p\in {\mathbb {N}}\)) in order to achieve \(\Vert M\Vert _\infty \le 1\). Moreover, since \(s^{\frac{1}{\log s}} = e\), the norm \(\Vert M\Vert _{\log s}\) is only a constant factor away from \(\Vert M\Vert _\infty \).Footnote 2

2.2 The negative part function and the distance to the psd cone

Given \(p\in {\mathbb {N}}\), let us define the negative part function\(f_{p}\) as

$$\begin{aligned} f_{p}(x) := {\left\{ \begin{array}{ll} 0 &{} x\ge 0\\ \vert x\vert ^p &{} x < 0. \end{array}\right. } \end{aligned}$$
(5)

So, for example, \(f_1(x)\) is the absolute value of the negative part of x. For \(M\in \mathrm {Her}_s\), we set

$$\begin{aligned} M_-:=f_{1}(M)\ \, \text{ and } \, M_+:=M+M_-, \end{aligned}$$

so that we obtain the natural definition \(M=M_+-M_-\), where both the positive part \(M_+\) and the negative part \(M_-\) are psd. (To define functions of matrices we follow the standard procedure [13]. Namely, if the matrix is diagonalisable, as in our case \(M = U D U^*\), then \(f(M) = U f(D) U^*\), where \(f(D) = \text {diag}(f(\lambda _1),f(\lambda _2),\ldots )\), where \(\{\lambda _i\}\) are the eigenvalues.)

Given a Hermitian matrix M of size s, we are interested in its distance to the cone of psd matrices of size s, \(\text {PSD}_s\), with respect to the Schatten p-norm, namely

$$\begin{aligned} d_p(M) := \inf _{N\in \text {PSD}_s} || M-N||_p . \end{aligned}$$
(6)

We now show that this is given by the negative part of M. That is, the best psd approximation to a Hermitian matrix is given by the positive part of this matrix.

Lemma 1

For \(p\in [1,\infty )\) and \(M\in \mathrm {Her}_s\), the matrix \(M_+\) is the point in the psd cone that is closest to M, with respect to any Schatten p-norm. That is,

$$\begin{aligned} d_p(M) = \Vert M_-\Vert _p = \mathbf {tr}(f_{p}(M))^{1/p} . \end{aligned}$$

Proof

Clearly \(M_+\geqslant 0\), so that the distance can at most be \(\Vert M_-\Vert _p\). Now, for any matrix \(A\in \mathrm {Her}_s\), denote by \(\sigma (A)\) the diagonal matrix with the eigenvalues of A on the diagonal, in decreasing order. It follows from [2] (IV.62) that

$$\begin{aligned} \Vert P-M\Vert _p \ge \Vert \sigma (P)-\sigma (M)\Vert _p \end{aligned}$$
(7)

holds for all \(P\in \mathrm {Her}_s\) and all p. If \(P\geqslant 0\), then clearly

$$\begin{aligned} \Vert P-M\Vert _p \ge \Vert \sigma (P)-\sigma (M)\Vert _p \ge \left( \frac{1}{s}\sum _{\lambda \in \mathrm {sp}(M), \lambda <0} \vert \lambda \vert ^p\right) ^{1/p}=\Vert M_-\Vert _p. \end{aligned}$$

This proves the claim.\(\quad \square \)

Remark 2

Note that \(\Vert \sigma (P)-\sigma (M)\Vert _p\) is precisely the p-Wasserstein distance [27] between the spectral measures \(s^{-1} \sum _i \delta _{\sigma (P)_{ii}}\) and \(s^{-1} \sum _i \delta _{\sigma (M)_{ii}}\) of P and M. So \(d_p(M)\) is in fact also the p-Wasserstein distance of the spectral measure of M to the cone of probability measures supported on \([0,\infty )\). \(\quad \square \)

3 Bounds on the Distance

We will now bound the negative part function \(f_p\) by polynomials (Sect. 3.1) and then show the asymptotic optimality of our bounds (Sect. 3.2).

3.1 Bounding the negative part function by polynomials

Clearly, M is psd if and only if its distance to the psd cone is zero, \(d_p(M) = 0\), and \(d_p(M)\) is a measure of how far M differs from being psd. Thus, ideally, we would like to compute \(d_p(M)\). Since we only have access to a few moments of M, we will use them to estimate \(d_p(M)\) as accurately as possible.

We start by showing that \(d_p(M)\) can be approximated arbitrarily well by the trace of polynomial expressions in M. For \(q\in {\mathbb {R}}[x]\), we write \(f_{p}\leqslant q\) if this holds pointwise on the interval \([-1,1].\)

Lemma 2

Suppose \(M\in \mathrm {Her}_s\) with \(\Vert M\Vert _\infty \le 1\) and \(p\in {\mathbb {N}}\). Then

$$\begin{aligned} d_p(M)^p = \inf _{f_{p}\leqslant q\in {\mathbb {R}}[x]}\mathbf {tr}( q(M) )= \sup _{f_{p}\geqslant q\in {\mathbb {R}}[x]}\mathbf {tr}( q(M) ). \end{aligned}$$

Proof

From \(f_{p}\leqslant q\) we obtain that \(f_{p}(M)\leqslant q(M)\), thus \(\mathbf {tr}(f_{p}(M))\le \mathbf {tr}(q(M))\) and finally

$$\begin{aligned} d_p(M)^p=\mathbf {tr}(f_{p}(M))\le \mathbf {tr}(q(M)). \end{aligned}$$

Conversely, by standard Weierstrass approximation for continuous functions on compact sets, for any \(\varepsilon >0\) there exists a polynomial \(q\in {\mathbb {R}}[x]\) with

$$\begin{aligned} f_{p}\leqslant q\leqslant f_{p}+\varepsilon . \end{aligned}$$

The same argument as above then shows

$$\begin{aligned} \mathbf {tr}(q(M))\le d_p(M)^p + \varepsilon . \end{aligned}$$

This proves the first equation, and the second follows in the same fashion. \(\quad \square \)

Thus, any polynomials \(q_1\) and \(q_2\) such that \(q_1\leqslant f_p\leqslant q_2\) give the bounds

$$\begin{aligned} \mathbf {tr}(q_1(M))\le d_p(M)^p\le \mathbf {tr}(q_2(M)). \end{aligned}$$

In particular, this means that if \(\mathbf {tr}(q_1(M))>0\) then M is not psd. The quality of the bounds depends on the quality of the approximation of \(f_p\) by \(q_1,q_2\) on \(\mathrm {sp}(M)\), or more generally on \([-1,1]\)—see Fig. 1 for an example.

Fig. 1
figure 1

Polynomials of degree 7 that approximate \(f_2\) from below and from above, together with the spectrum of M (black dots). The polynomials have been obtained with the Handelman method, to be described in Sect. 4.2

More generally, given a polynomial q which does not satisfy \(q\leqslant f_p\) or \(q\geqslant f_p\), what we can say is that

$$\begin{aligned} q - \Vert (q - f_p)_+ \Vert _\infty \leqslant f_p \leqslant q + \Vert (q - f_p)_- \Vert _\infty , \end{aligned}$$
(8)

where we use notation for positive and negative part as in the matrix case, and similarly \(\Vert g\Vert _\infty :=\sup _{x\in [-1,1]} | g(x)|\). Here, the function on the left hand side corresponds to shifting q by an additive constant until it is below \(f_p\), and similarly for the right hand side—see Fig. 2 for an example. This leads to the following result.

Fig. 2
figure 2

A polynomial q which approximates \(f_2\) but does not satisfy \(q\leqslant f_2\) or \(q\geqslant f_2\). The polynomial is a Chebyshev polynomial of degree 2, obtained with the Chebyshev method (Sect. 4.3). Then it is shifted up and down by \(|| q-f_2||_\infty \)

Theorem 1

Let \(M\in \mathrm {Her}_s\) with \(\Vert M\Vert _\infty \le 1\), \(p\in {\mathbb {N}}\), as well as \(q\in {\mathbb {R}}[x]\). Then

$$\begin{aligned} \qquad \mathbf {tr}(q(M)) - \Vert (q-f_p)_+ \Vert _\infty \,\le \, d_p(M)^p \,\le \, \mathbf {tr}(q(M)) +\Vert (q-f_p)_- \Vert _\infty . \end{aligned}$$
(9)

In particular:

  1. (i)

    If \(f_p\leqslant q\), then \(d_p(M)\le \mathbf {tr}(q(M))^{1/p}\).

  2. (ii)

    If \(\mathbf {tr}(q(M)) > \Vert (q-f_p)_+ \Vert _\infty \), then M is not psd.

  3. (iii)

    If \(q\leqslant f_p\) and \(\mathbf {tr}(q(M))>0\), then M is not psd.

Remark 3

We can also try to prove that a matrix is psd with the same approach, although this seems to be much harder in practice. Note the following: if for \(M\in \mathrm {Her}_s\) we find \(d_p(M)\le \varepsilon \), then \(d_\infty (M)\le s^{1/p} \varepsilon \), and therefore \(M+s^{1/p}\varepsilon I_s\geqslant 0\). So if we first replace M by

$$\begin{aligned} M_\varepsilon := M-s^{1/p}\varepsilon I_s, \end{aligned}$$

and then show that \(d_p(M_\varepsilon )\le \varepsilon \), then we have proven that \(M\geqslant 0\). By Theorem 1, this can be achieved by finding \(q\in {\mathbb {R}}[x]\) with

$$\begin{aligned} \mathbf {tr}(q(M_\varepsilon )) +\Vert (q-f_p)_- \Vert _\infty \le \varepsilon ^p. \end{aligned}$$
(10)

Note that the kth moment of \(M_\varepsilon \) can be computed from the moments of M of order \(\le k\). Further, if M is strictly positive definite, then this strategy does indeed work: there is \(\varepsilon >0\) with \(M_\varepsilon \geqslant 0\), i.e. \(d_p(M_\varepsilon )=0\). In view of Lemma 2, we can also find some q to make (10) hold, so that this method can indeed detect that M is psd. However, we might need to test for both very small \(\varepsilon \) and polynomials q of very high degree before obtaining a positive answer. \(\quad \square \)

3.2 Optimality of the bounds

We now show that given the first m moments of M, the best bounds to the distance to the psd cone which are independent of the size of M are given by a polynomial approximation. More precisely, given \(M\in \mathrm {Her}_s\) and \(p,m\in {\mathbb {N}}\), define

$$\begin{aligned} \begin{aligned} d_{p,m}^+(M)&:= \inf _{f_{p}\leqslant q,\, \deg (q)\le m}\mathbf {tr}( q(M) )^{1/p} \\ d_{p,m}^-(M)&:= \sup _{q\leqslant f_{p},\, \deg (q)\le m}\mathbf {tr}( q(M) )^{1/p} . \end{aligned} \end{aligned}$$
(11)

Clearly, these numbers depend only on the first m moments of M, and they lower and upper bound \(d_p(M)\),

$$\begin{aligned} 0\le d_{p,m}^-(M)\le d_p(M)\le d_{p,m}^+(M). \end{aligned}$$
(12)

We now show that these are the optimal upper and lower bounds to \(d_p(M)\) which can be obtained from the first m normalized moments of M and which are independent of the size of M. We thus call them asymptotically optimal.

The following result is a variation on a classical result from the theory of moment problems [15, Theorem 4.1(a)], for which we offer a self-contained proof.

Theorem 2

For any matrix \(M\in \mathrm {Her}_s\) with \(\Vert M\Vert _\infty \le 1\) and any \(m\in {\mathbb {N}}\),

  • For every \(\varepsilon > 0\), there are \(N_1,N_2\in \mathrm {Her}_{t}\) (for suitably large t) such that

    $$\begin{aligned} \vert \mathbf {tr}(M^k) - \mathbf {tr}(N_i^k)\vert \le \varepsilon \quad \text {for } k=1,\ldots , m , \end{aligned}$$

    and for which

    $$\begin{aligned} d_p(N_1)\ge d_{p,m}^+(M), \quad d_p(N_2) \le d_{p,m}^-(M). \end{aligned}$$
  • There are operators \(N_1\) and \(N_2\) in a finite von Neumann algebra \({\mathcal {N}}\) such that

    $$\begin{aligned} \mathbf {tr}(M^k) = \mathbf {tr}(N_i^k) \quad \text {for } k=1,\ldots , m , \end{aligned}$$

    and which saturate the bounds,

    $$\begin{aligned} d_p(N_1)=d_{p,m}^+(M) , \quad d_p(N_2) = d_{p,m}^-(M). \end{aligned}$$

Note that in the first case the moments are approximately reproduced but \(N_i\) has finite size — we will see an example thereof in Example 1. In the second case, the moments are exactly reproduced but the size of \(N_i\) may need to be infinite.

Proof

We only construct \(N_1\), since \(N_2\) is obtained similarly.

Consider the linear functional

$$\begin{aligned} \varphi :{\mathbb {R}}[x]_{\le m}&\rightarrow {\mathbb {R}}\\ q&\mapsto \mathbf {tr}(q(M)) \end{aligned}$$

on the space of polynomials of degree at most m, which clearly maps polynomials nonnegative on \([-1,1]\) to nonnegative numbers. Let us define the real vector space

$$\begin{aligned} V:=\{\,q+rf_p \mid q\in {\mathbb {R}}[x]_{\le m}, r\in {\mathbb {R}} \, \} . \end{aligned}$$

We extend \(\varphi \) to a linear functional \(\psi \) on V by setting

$$\begin{aligned} \psi (f_p):=\inf _{f_p\leqslant q\in {\mathbb {R}}[x]_{\le m}} \varphi (q). \end{aligned}$$

We claim that \(\psi \) still maps nonnegative functions in V to nonnegative numbers. So let \(h+rf_p\geqslant 0\) for some \(h\in {\mathbb {R}}[x]_{\le m}\) and \(r\in {\mathbb {R}}\). The case \(r = 0\) is clear, so assume \(r<0\). Then \(-\frac{1}{r}h\geqslant f_p\), and thus

$$\begin{aligned} \psi (h+rf_p)&= \varphi (h) + r \inf _{f_p\leqslant q} \varphi (q) \\&\ge \varphi (h) + r \varphi \left( -\frac{1}{r}h\right) \\&=\varphi (h)-\varphi (h)=0. \end{aligned}$$

If \(r>0\) instead, then \(f_p\leqslant q\) implies \(0\leqslant h+rf_p\leqslant h+rq\), and thus

$$\begin{aligned} \varphi (h)+r\varphi (q)=\varphi (h+rq)\ge 0. \end{aligned}$$

Passing to the infimum over these q proves the statement.

Since \({\mathbb {R}}[x]_{\le m}\) already contains an interior point of the convex cone of nonnegative continuous functions on \([-1,1]\) (such as the constant function 1), we can further extend \(\psi \) to a positive linear functional \(\varPsi \) on the whole of \({\mathcal {C}}([-1,1]),\) using the Riesz Extension Theorem [21]. By the Riesz Representation Theorem [23], there exists a positive measure \(\mu \) on \([-1,1]\) such that

$$\begin{aligned} \varPsi (f)=\int f\, d\mu \end{aligned}$$

for all \(f\in {\mathcal {C}}([-1,1])\). From \(\mu ([-1,1])=\int 1\, d\mu =\varPsi (1)=\varphi (1)=1\), we see that \(\mu \) is a probability measure. We now take \({\mathcal {N}} := L^\infty ([-1,+1],\mu )\), equipped with integration against \(\mu \) as a finite normalized trace, and define \(N_1\) to be the multiplication operator by the identity function, \(N_1 : f \mapsto xf\).

So for \(k=0,\ldots , m\), the kth moment of \(N_1\) is given by

$$\begin{aligned} \int x^kd\mu =\varPsi (x^k)=\varphi (x^k)=\mathbf {tr}(M^k), \end{aligned}$$

and we also have

$$\begin{aligned} d_p(N_1) = \int f_p\, d\mu = \varPsi (f_p) = \psi (f_p) = \inf _{f_p\leqslant q \in {\mathbb {R}}[x]_{\le m}}\varphi (q) = d^+_{p,m}(M)^p, \end{aligned}$$

which establishes the first claim.

Concerning the realization by finite-dimensional matrices, we use the well-known fact that each probability measure on \([-1,1]\) can be approximated arbitrarily well by uniform atomic measures with respect to the weak-\(^*\) topology. Concretely, we can approximate \(\mu \) by the uniform atomic measure \(\nu _t := \frac{1}{t}\cdot \sum _{i=1}^t \delta _{a_i}\), where the \(a_i\) are the right t-quantiles,

$$\begin{aligned} a_i := \inf \left\{ \, r \in [-1,1] \,\bigg |\, \mu ([r,1]) \ge \frac{i}{t} \,\right\} . \end{aligned}$$

This choice guarantees that the cumulative distribution function of \(\nu _t\) dominates the one of \(\mu _t\). Therefore the expectation value of \(\mu \) is not smaller than that of \(\nu _t\) on any monotonically nonincreasing function. In particular, we have

$$\begin{aligned} \int f_p \, d\nu _t \ge \int f_p \, d\mu . \end{aligned}$$

Furthermore, since \(\nu _t\) weak-\(^*\) convergesFootnote 3 to \(\mu \) as \(t\rightarrow \infty \), we can moreover choose t large enough such that

$$\begin{aligned} \left| \int x^k d\mu -\int x^k d\nu _t \right| \le \varepsilon \quad \text{ for } k=0,\ldots , m. \end{aligned}$$

For \(N_1 := \text {diag}(a_1,\ldots , a_t)\in \mathrm {Her}_t\), we then have \(\Vert N_1\Vert _\infty \le 1\) and

$$\begin{aligned} \mathbf {tr}(N_1^k)= \frac{1}{t}\sum _{i=1}^t a_i^k=\int x^kd\nu _t \end{aligned}$$

as well as

$$\begin{aligned} \int f_p\, d\nu _t=\frac{1}{t}\sum _{a_i<0}\vert a_i\vert ^p = \Vert {N_{1}}_-\Vert _p^p= d_p(N_1)^p, \end{aligned}$$

which gives the desired bounds. This altogether finishes the proof. \(\quad \square \)

Example 1

We show that \(\varepsilon = 0\) can in general not be achieved in the second part of Theorem 2. Taking \(m = 2\), let us consider the matrixFootnote 4

$$\begin{aligned} M = \text {diag}\left[ c + \sqrt{c(1-c)},\, c - \sqrt{c(1-c)}\right] , \end{aligned}$$

for \(c \in (0,1/2)\). Since the lower right entry is negative, M is not psd. Its first moment is c, the second moment is \(\frac{1}{2}\left( 2c^2 + 2c(1-c)\right) = c\), equal to the first moment. Looking for a probability measure \(\mu \) on [0, 1] with these moments, we must have \({\mathbb {E}}_\mu [x(1-x)] = 0\), which implies that \(\mu \) must be supported on \(\{0,1\}\) only. Since \(\mu = (1-c) \delta _0 + c \delta _1\) does indeed have these moments, we conclude that it is the unique measure on [0, 1] with these moments; and the fact that such a \(\mu \) exists implies \(d_{p,2}^-(M) = 0\), irrespectively of the value of p. However, as soon as c is irrational, the measure \((1-c)\delta _0 + c\delta _1\) is not of the form \(s^{-1}\sum _{i=1}^s \delta _{\lambda _i}\) for any finite sequence \((\lambda _1,\ldots ,\lambda _s)\). In particular, there is no psd matrix of finite size with the same moments as M, and \(\varepsilon = 0\) cannot be achieved in Theorem 2. By a standard compactness argument, this also implies that one must take \(t \rightarrow \infty \) as \(\varepsilon \rightarrow 0\) in the theorem. \(\quad \square \)

Remark 4

An interesting questionFootnote 5 is how close our bounds \(d_{p,m}^+(M)\) and \(d_{p,m}^-(M)\) are guaranteed to be to the actual value \(d_{p,m}(M)\). In the worst case, the actual value will coincide with one of the two bounds, in which case the other bound differs from the actual value by

$$\begin{aligned} d_{p,m}^+(M) - d_{p,m}^-(M) \le 12\frac{p}{m}, \end{aligned}$$

which follows from (29) and (26).

4 Algorithms

We now present our numerical methods to compute lower and upper bounds to the distance to the psd cone, in order of decreasing accuracy and complexity: the sos polynomial method (Sect. 4.1), the Handelman method (Sect. 4.2) and the Chebyshev method (Sect. 4.3). The sos polynomial method involves solving a semidefinite program, the Handelman method involves solving a linear program, and the Chebyshev method does not require any optimization. We will compare the numerical performance of three methods in Sect. 5.

Throughout, we fix nonzero \(p\in {\mathbb {N}}\).

4.1 The sos polynomial method

The sos polynomial method solves the optimization problems of Eq. (11) exactly,Footnote 6 and thereby computes \(d_{p,m}^+(M)\) and \(d_{p,m}^-(M)\). We start by explaining how to compute the upper bound \(d_{p,m}^+(M)\) via a semidefinite program.

To be able to talk about polynomials only, we first split the condition \(f_p\leqslant q\) into two parts:

$$\begin{aligned} 0\leqslant q(-x)-x^p\ \text{ and } \ 0\leqslant q(x),\ \text{ both } \text{ for } \text{ all } x\in [0,1]. \end{aligned}$$
(13)

Now note that any polynomial of the form

$$\begin{aligned} \sigma _0+\sigma _1x+\sigma _2(1-x)+\sigma _3x(1-x), \end{aligned}$$
(14)

where the \(\sigma _i\) are sums of squares of polynomials, is nonnegative on [0, 1]. In fact, the converse is true as well:

Theorem 3

[16, 18]. If \(q\in {\mathbb {R}}[x]_{\le m}\) is nonnegative on [0, 1], then there exist sums of squares \(\sigma _0,\sigma _1,\sigma _2,\sigma _3\in {\mathbb {R}}[x]\) such that

$$\begin{aligned} q(x)=\sigma _0+\sigma _1x+\sigma _2(1-x)+\sigma _3x(1-x) \end{aligned}$$

where the degree of each \(\sigma _i\) can be chosen such that each summand has degree at most \(\le m\).

So assume that we find such representations for both polynomials in (13),

$$\begin{aligned} q(-x)-x^p&= \sigma _0+\sigma _1x+\sigma _2(1-x)+\sigma _3x(1-x), \\ q(x)&= \tau _0+\tau _1x+\tau _2(1-x)+\tau _3x(1-x), \end{aligned}$$

with sums of squares (sos) \(\sigma _i,\tau _i\in {\mathbb {R}}[x]\). Then we have clearly ensured \(f_p\leqslant q\). This can be rewritten as

$$\begin{aligned} \begin{aligned} q(x)&= (-x)^p + {\tilde{\sigma }}_0 - {\tilde{\sigma }}_1 x + {\tilde{\sigma }}_2 (1+x) -{\tilde{\sigma }}_3 x (1+x) \\&= \tau _0+ \tau _1 x + \tau _2 (1-x) +\tau _3 x (1-x), \end{aligned} \end{aligned}$$
(15)

where the \({\tilde{\sigma }}_i (x) := \sigma _i(-x)\) are again sos.

Now assume that every term in (15) has degree \(\le m\). This imposes obvious degree bounds on the sums of squares \({\tilde{\sigma }}_i,\tau _i\), namely \(\deg ({\tilde{\sigma }}_0) \le m\), and \(\deg ({\tilde{\sigma }}_1), \deg ({\tilde{\sigma }}_2) \le m-1\) as well as \(\deg ({\tilde{\sigma }}_3) \le m-2\), and analogously for the \(\tau _i\), and note that every sos polynomial must have an even degree. It is easy to see that every sum of squares can be written as

$$\begin{aligned} \begin{aligned}&{\tilde{\sigma }}_i = (1,x,\ldots ,x^{l_i}) \, S_i\, (1,x,\ldots ,x^{l_i})^t, \quad S_i\ge 0\\&\tau _i = (1,x,\ldots ,x^{l_i}) \, T_i\, (1,x,\ldots ,x^{l_i})^t, \quad T_i\ge 0 \end{aligned} \end{aligned}$$
(16)

where \(l_i = \text {deg}({\tilde{\sigma }}_i)/2\) and similarly for \(\tau _i\). Writing each \(\sigma _i,{\tilde{\tau }}_i\) in such a way, using matrices with unknown entries, and then comparing coefficients with respect to x in (15), leads to the problem of finding psd matrices with certain linear constraints on the entries. Any solution to this problem will provide a polynomial \(q\in {\mathbb {R}}[x]_{\le m}\) with \(f_p\leqslant q.\) Among all of them, we want to minimize \(\mathbf {tr}(q(M))\), which is a linear function in the entries of the unknown matrices, having the moments of M as coefficients. Optimizing a linear function over an affine section of a cone of psd matrices is known as semidefinite programming, for which there exist efficient algorithms.

The derivation of the lower bound \(d_{p,m}^-(M)\) is entirely parallel, except for the fact that in (13) the two inequalities are reversed. This implies that

$$\begin{aligned} -q(-x)+x^p&= \sigma _0+\sigma _1x+\sigma _2(1-x)+\sigma _3x(1-x), \\ -q(x)&= \tau _0+\tau _1x+\tau _2(1-x)+\tau _3x(1-x), \end{aligned}$$

where \(\sigma _i,\tau _i\) are sos, and thus

$$\begin{aligned} \begin{aligned} q(x)&= ( -x)^p - {\tilde{\sigma }}_0 + {\tilde{\sigma }}_1 x - {\tilde{\sigma }}_2 (1+x) +{\tilde{\sigma }}_3 x (1+x) \\&= - \tau _0- \tau _1 x - \tau _2 (1-x) -\tau _3 x (1-x). \end{aligned} \end{aligned}$$
(17)

In summary, we have obtained:

Proposition 2

(Sos polynomial method). The sos polynomial method at level m computes the upper bound \(d_{p,m}^+(M)^p\) (defined in (11)) by solving the semidefinite program

$$\begin{aligned} \begin{aligned}&\min \, \mathbf {tr}(q(M)) \\&\mathrm {subject\, to\, \, Eq.\,} (15)\\&\quad \qquad \mathrm {and\, \, Eq.\,} (16) \end{aligned} \end{aligned}$$
(18)

It also computes the lower bound \(d_{p,m}^-(M)^p\) (defined in (11)) by solving the semidefinite program

$$\begin{aligned} \begin{aligned}&\max \, \mathbf {tr}(q(M)) \\&\mathrm {subject\, to\, \, Eq.\,} (17)\\&\quad \qquad \mathrm {and\, \, Eq.\,} (16) \end{aligned} \end{aligned}$$
(19)

As an example, Fig. 3 shows the sos polynomial approximation of degree 7 obtained for a matrix M with the indicated spectrum. We will discuss numerical results more systematically in Sect. 5.

Fig. 3
figure 3

Lower and upper sos polynomial approximation of degree 7 for \(p=2\) and for the matrix M whose spectrum is shown in black dots

Remark 5

For computational purposes, it may be better to use the ansatz

$$\begin{aligned} \sigma _0 +\sigma _1x(1-x) \end{aligned}$$
(20)

for a polynomial nonnegative on [0, 1], instead of (14). The advantage is that this reduces the number of sums of squares from 4 to 2. An analogue of Theorem 3 still holds [16], but with slightly weaker degree bounds: a degree m polynomial nonnegative on [0, 1] has a representation \(\sigma _0 +\sigma _1x(1-x)\) with \(\deg (\sigma _0)\le m+1\) and \(\deg (\sigma _1)\le m-1\) only.Footnote 7 So if we set up our optimization problem as above, but with the simpler representation (20) where we demand \(\deg (\sigma _0)\le m\) and \(\deg (\sigma _1)\le m-2\) (since moments of M are available only up to order m), then we will obtain a bound on \(d_p(M)\) which lies between \(d_{p,m}^+(M)^p\) and \(d_{p,m-1}^+(M)^p\). \(\quad \square \)

4.2 The Handelman method

The Handelman method relaxes the optimization of Eq. (11) by using another ansatz for nonnegative polynomials on [0, 1]. This results in a linear optimization problem, which can usually be solved much faster than a semidefinite problem.

We start by splitting the condition \(f_p\leqslant q\) as in (13). This time note that any polynomial of the form

$$\begin{aligned} \sum _{\alpha \in {\mathbb {N}}^2} b_\alpha x^{\alpha _1}(1-x)^{\alpha _2} \end{aligned}$$

with \(b_\alpha \ge 0\) (and only finitely many different from 0) is nonnegative on [0, 1]. So if we find coefficients \(b_\alpha , c_\alpha \ge 0\) with

$$\begin{aligned} q(-x)-x^p&= \sum _{\alpha \in {\mathbb {N}}^2} b_\alpha x^{\alpha _1}(1-x)^{\alpha _2}, \\ q(x)&= \sum _{\alpha \in {\mathbb {N}}^2} c_\alpha x^{\alpha _1}(1-x)^{\alpha _2}, \end{aligned}$$

then we can be sure to have \(f_p\leqslant q\). Assume that the degree of the polynomials is a priori bounded by m. Then comparing coefficients with respect to x yields a finite system of linear equations:

$$\begin{aligned} \begin{aligned} q(x)&= (-x)^p + \sum _{ |\alpha |\le m } b_\alpha (-x)^{\alpha _1}(1+x)^{\alpha _2} \\&= \sum _{ |\alpha |\le m } c_\alpha x^{\alpha _1}(1-x)^{\alpha _2}, \end{aligned} \end{aligned}$$
(21)

where \(|\alpha | = \alpha _1+\alpha _2\). We look for solutions under the constraint that \((b_\alpha ,c_\alpha )_{|\alpha |\le m}\), and among all these solutions, we look for the one that minimizes the quantity \(\mathbf {tr}(q(M))\). This is precisely a linear optimization problem, where information about our matrix M enters through the objective function.

The derivation of the lower bound of \(d_{p,m}^-(M)\) is analogous, except that in this case \(- q(-x)+x^p \) and \(-q(x)\) must be nonnegative polynomials on [0, 1]. This leads to

$$\begin{aligned} \begin{aligned} q(x)&= (-x)^p - \sum _{ |\alpha |\le m } b_\alpha (-x)^{\alpha _1}(1+x)^{\alpha _2} \\&= \sum _{ |\alpha |\le m } - c_\alpha x^{\alpha _1}(1-x)^{\alpha _2}, \end{aligned} \end{aligned}$$
(22)

In summary we have obtained:

Proposition 3

(Handelman method). The Handelman method at level m computes an upper bound of \(d_{p,m}^+(M)\) by solving the linear program

$$\begin{aligned} \begin{aligned}&\min \, \mathbf {tr}(q(M)) \\&\mathrm {subject\, to\, \, Eq.\,} (21)\\&\quad \qquad \mathrm {and\,} b_\alpha \ge 0, c_\alpha \ge 0 \end{aligned} \end{aligned}$$
(23)

It also computes a lower bound of \(d_{p,m}^-(M)\) by solving the linear program

$$\begin{aligned} \begin{aligned}&\max \, \mathbf {tr}(q(M)) \\&\mathrm {subject\, to\, \, Eq.\,} (22)\\&\quad \qquad \mathrm {and\,} b_\alpha \ge 0, c_\alpha \ge 0 \end{aligned} \end{aligned}$$
(24)

Note that linear optimization problems are easy to solve algorithmically (for example, interior point methods have polynomial complexity, but the simplex algorithm and its variants often work best in practice). See Fig. 1 above for upper and lower Handelman approximations of \(f_2\) for a given matrix M.

Although this method computes only a relaxation of \(d_{p,m}^+(M)\) (and analogously for \(d_{p,m}^-(M)\)), the following special case of Handelman’s Positivstellensatz for polytopes [9] ensures that these relaxations converge to the exact value \(d_p(M)\) in the limit \(m\rightarrow \infty \):

Theorem 4

(Handelman). If \(q\in {\mathbb {R}}[x]\) is strictly positive on [0, 1], then

$$\begin{aligned} q(x)=\sum _{\alpha \in {\mathbb {N}}^2} a_\alpha x^{\alpha _1}(1-x)^{\alpha _2} \end{aligned}$$

for certain \(a_\alpha \ge 0,\) only finitely many different from 0.

Note that this result leads directly to the standard solution of the Hausdorff moment problem in terms of complete monotonicity [24, Theorem 1.5]. We now have:

Corollary 1

Let \({\tilde{d}}_{p,m}^+(M)\) denote the pth root of the optimal value of the linear program described in Method 3. Then we have \(d_p(M)\le d_{p,m}^+(M)\le {\tilde{d}}_{p,m}^+(M)\), and

$$\begin{aligned} {\tilde{d}}_{p,m}^+(M){\mathop {\searrow }\limits ^{m\rightarrow \infty }} d_p(M). \end{aligned}$$

Proof

Every feasible point in the program leads to a polynomial \(q\in {\mathbb {R}}[x]_{\le m}\) with \(f_p\leqslant q\). This proves \(d_{p,m}^+(M)\le {\tilde{d}}_{p,m}^+(M)\). Now if \(q\in {\mathbb {R}}[x]\) fulfills \(f_p\leqslant q,\) then for any \(\varepsilon >0\) there is some \(m\in {\mathbb {N}},\) such that \(q+\varepsilon \) corresponds to a feasible point in the respective program, by Handelman’s theorem. This proves the claim. \(\quad \square \)

4.3 The Chebyshev method

The Chebyshev method chooses \(q_m\) as the Chebyshev polynomial of degree m that best approximates \(f_p\), and uses (9) to derive bounds on \(d_p(M)\). This has the advantage of not involving any optimization at all, i.e. one need only compute the Chebyshev polynomials \(q_m\) once, and the method can be applied to any matrix M.

Ideally, the best bounds of Eq. (9) are given by the polynomial q of degree m that minimizes \(||q_m-f_p||_\infty \), which we call \(q^*_m\). By Jackson’s theorem (see e.g. [22, Theorem 1.4]) we have that

$$\begin{aligned} \Vert f-q^*_m\Vert _\infty \le 6\, \omega (f,1/m). \end{aligned}$$
(25)

where \(\omega (f,\delta )\) denotes the modulus of continuity of a uniformly continuous function f, defined as

$$\begin{aligned} \omega (f,\delta ) = \sup _{\begin{array}{l}x_1,x_2\in [-1,1]\\ |x_1-x_2|\le \delta \end{array}} |f(x_1)-f(x_2)|. \end{aligned}$$

For the negative part function \(f_p\), we thus obtain that

$$\begin{aligned} \Vert f_p - q^*_m\Vert _{\infty }\le 6 \left( 1-\left( 1-m^{-1}\right) ^p\right) \le 6 \frac{p}{m}, \end{aligned}$$
(26)

where the second estimate is by Bernoulli’s inequality, which is tight up to an error of \(O(m^{-2})\).

However, it is in general not possible to find \(q_m^*\) (called the minimax approximation) analytically. Instead, Chebyshev polynomials provide a good proxy: they are close to the minimax approximation, and are straightforward to compute explicitly [22]. To obtain an analytical upper bound of the additional error, it is known [8] that the Chebyshev approximation \(q_m\) of a continuous function f satisfies that

$$\begin{aligned} \Vert q_m-f\Vert _\infty \le \, C \omega (f,1/m) \log m \, \end{aligned}$$

for some constant C. For our negative part function \(f_p\), it thus holds that

$$\begin{aligned} || q_m-f_p||_\infty \le C m^{-1} \log m . \end{aligned}$$
(27)

Numerically we can see the behaviour of \(||q_m-f_p||_\infty \) as a function of m and p in Fig. 4.

Fig. 4
figure 4

\(|| q_m-f_p||_\infty \) (obtained numerically) for the Chebyshev polynomial \(q_m\) of (28) as a function of m for several p

Let us now construct the Chebyshev interpolating polynomial of degree m, \(q_m\), explicitly. It interpolates \(f_p\) at the Chebyshev nodes

$$\begin{aligned} a_k=\cos (\pi (k+1/2)/(m+1)) \quad \text{ for } k=0,1,\ldots ,m, \end{aligned}$$

so that \(q_m\) is given by

$$\begin{aligned} q_m = \sum _{k=0}^m f_p(a_k) \ell _k , \end{aligned}$$

where the \(\ell _k\) are the Lagrange interpolation polynomials

$$\begin{aligned} \ell _k (x)=\frac{1}{\prod _{i\ne k}(a_k-a_i)} \prod _{\begin{subarray}{c} i\ne k \end{subarray}}(x-a_i). \end{aligned}$$

One can also express \(q_m\) in terms of the Chebyshev polynomials of the first kind, which are defined as \( t_k(x) = \cos (k\arccos (x))\) for \(|x|\le 1.\) In this basis, \(q_m\) takes the form

$$\begin{aligned} q_m = {\sum _{k=0}^m} c_k t_k -c_0/2, \qquad \text {with }\, c_k = \frac{2}{m+1}\sum _{j=0}^m f_p(a_j) t_k(a_j). \end{aligned}$$
(28)

In summary, we have obtained:

Proposition 4

(Chebyshev method). The Chebyshev method at level m computes the polynomial \(q_m\) of Eq. (28), which provides the following upper and lower bounds to \(d_p(M)\),

$$\begin{aligned} \begin{aligned}&d_p(M)^p \ge \mathbf {tr}(q_m(M)) - \Vert q_m-f_p \Vert _\infty \\&d_p(M)^p \le \mathbf {tr}(q_m(M)) +\Vert q_m-f_p \Vert _\infty . \end{aligned} \end{aligned}$$
(29)

Note that by minimizing \(\Vert q_m-f_p \Vert _\infty \) one minimises \(\Vert (q_m-f_p)_+ \Vert _\infty \) and \(\Vert (q_m-f_p)_- \Vert _\infty \) simultaneously. As an example, Fig. 5 shows two Chebyshev approximations of \(f_2\).

Fig. 5
figure 5

The Chebyshev approximation of degree 2 and 3 of \(f_2\)

5 Numerical Results and Examples

We now discuss the numerical performance of the three methods presented in Sect. 4. All computations were done with Mathematica on a standard computer with a 2.9 GHz processor and 16 GB RAM. Our Mathematica code is available with this paper.

Since all three methods take the vector of the first m normalized moments of a matrix M as input, we first study how long it takes to compute these moments for a matrix of the form (1). Specifically, we consider random local matrices \(A_j^{[i]}\) of size 2, a sum length of \(d=2\) and several values for the number n of tensor factors. Note that this is a natural scenario in the tensor network paradigm, where one could imagine having a numerical tensor of the form (1) and having to decide, or give necessary or sufficient conditions, on its positive semidefiniteness. Table 1 shows the average running time to compute the first m moments. Note that already for \(n=16\) we were not able to explicitly compute and store the matrix M, let alone decide its semidefiniteness on our computer.

Table 1 Average running time (in seconds) to compute the first m moments for n tensor factors for a matrix of the form of (1)

Now we study the running time of the three methods (with \(p=2\)) as a function of the number m of moments used (Table 2). Note that this does not include the computation of the moments, since they are part of the input. The moments have been produced from random instances of matrices of the form (1) with local matrices \(A_j^{[i]}\) of size 2, \(d=2\) and \(n=8\). Note that the running time includes the full setup of all problems, as provided in the attached Mathematica file. In particular, for the Chebyshev method this includes the computation of the Chebyshev polynomial (28) of degrees \(k=1,\ldots , m\) which interpolates \(f_p\). These, however, do not depend on the input, and thus could be computed in advance. The algorithm itself just has to compute the inner product of the coefficient vector and the moment vector, which can be done in almost no time.

Table 2 Average running time (in seconds) of the three methods, using the first m moments

To examine the qualitative performance of the three methods, we generated 10,000 random numbers uniformly in \([-\varepsilon , 1]\), for several small values of \(\varepsilon >0\), and took them as eigenvalues of our matrix M. Note that the corresponding spectral measure is a close approximation of the uniform Lebesgue measure on this interval. We then computed the corresponding normalized moments, and checked how many moments each method needed to produce a positive lower bound on the distance to the psd cone, i.e. to detect non-positivity. Note that the smaller \(\varepsilon \), the harder the task. Table 3 shows the average number of moments needed for each method, depending on \(\varepsilon \). For \(\varepsilon =1/16\), the Chebyshev algorithm did never provide positive bounds when using a number of moments that we could compute without running into numerical problems (for example when computing \(\Vert f_p-q_m\Vert _\infty \), which is needed in the algorithm).

Table 3 Average number of moments needed to detect non-positivity of a matrix with 10,000 random eigenvalues in the interval \([-\varepsilon , 1]\)

Let us summarize and compare the three methods. Concerning the running time, the Chebyshev method is clearly the best. In addition, as mentioned above, its running time can in practice be reduced to almost zero by computing the approximating polynomials beforehand. The Handelman method is also quite fast, in particular when compared to the sos polynomial method. On the other hand, the sos polynomial method needs significantly fewer moments than the other methods in order to produce the same qualitative results. Computing many moments can also require a lot of time, depending on the format of the matrix.

In order to compare both effects (running time versus number of moments needed), we conducted a final experiment. We produced random matrices again of the form (1) with local matrices of size 2, \(d=2\) and different values for the number n of tensor factors. For each method we first checked how many moments were needed to detect non-positivity, and then added the time to compute these moments to the actual running time of the method. Note that in practice one does not know in advance how many moments are needed to detect non-positivity. Interestingly, the Chebyshev method falls behind the other two by far, due to the large number of moments it needs. The comparison of the Handelman and the sos polynomial method is summarized in Table 4. Note that also the Handelman method did not produce any meaningful result in the case of a very large matrix.

Table 4 Total running time (in seconds) to detect non-positivity, involving the time to compute the moments and the running time of the algorithm, for n tensor factors

In summary, a general and clear decision between the three methods based on their performance cannot be made. They differ greatly in terms of running time and in terms of the moments needed to obtain meaningful results. However, the Chebyshev method seems to fall behind the other two in many relevant instances, at least for single matrices. If the matrices are not extremely large and the eigenvalues do not show an extreme behavior, the Handelman methods seems to perform best. The sos polynomial method can however solve some of these extreme cases in which the other two methods fail.

Files attached to this manuscript:

  • PSDBounds.nb: This Mathematica package contains the three functions sosApp, handelApp and chebyApp that provide the upper and lower bounds, together with the approximating polynomials corresponding to the sos polynomial method, Handelman method, and Chebyshev method, respectively.

  • TensorExample.nb: This Mathematica notebook provides some examples to illustrate the use of the above package, in particular for matrices of the form (1).