Lebesgue and gaussian measure of unions of basic semi-algebraic sets

Abstract: Given a finite Borel measure $\mu$ on R n and basic semi-algebraic sets $\Omega$\_i $\subset$ R n , i = 1,. .. , p, we provide a systematic numerical scheme to approximate as closely as desired $\mu$(\cup\_i $\Omega$\_i), when all moments of $\mu$ are available (and finite). More precisely , we provide a hierarchy of semidefinite programs whose associated sequence of optimal values is monotone and converges to the desired value from above. The same methodology applied to the complement R n \ (\cup\_i $\Omega$\_i) provides a monotone sequence that converges to the desired value from below. When $\mu$ is the Lebesgue measure we assume that $\Omega$ := \cup\_i $\Omega$\_i is compact and contained in a known box B  and in this case the complement is taken to be B \ $\Omega$. In fact, not only $\mu$($\Omega$) but also every finite vector of moments of $\mu$\_$\Omega$ (the restriction of $\mu$ on $\Omega$) can be approximated as closely as desired, and so permits to approximate the integral on $\Omega$ of any given polynomial.

\section*{Abstract}

Given a finite Borel measure $\mu$ on $\mathbb{R}^n$ and basic semi-algebraic sets $\mathbf{\Omega}_i\subset\mathbb{R}^n$, $i=1,\ldots,p$, we provide a systematic numerical scheme
to approximate as closely as desired $\mu(\bigcup_i\mathbf{\Omega}_i)$, when all moments of $\mu$ are available (and finite). More precisely, we provide a hierarchy
of semidefinite programs whose associated sequence of optimal values is monotone
and converges to the desired value from above. The same methodology applied to
the complement $\mathbb{R}^n\setminus (\bigcup_i\mathbf{\Omega}_i)$ provides a monotone sequence that converges to the desired value from below.
When $\mu$ is the Lebesgue measure we assume that $\mathbf{\Omega}:=\bigcup_i\mathbf{\Omega}_i$ is compact and contained in a known box $\mathbf{B}:=[-a,a]^n$ and in this case
the complement is taken to be $\mathbf{B}\setminus\mathbf{\Omega}$.
In fact, not only $\mu(\mathbf{\Omega})$ but also every finite vector of moments of $\mu_\mathbf{\Omega}$ (the restriction of $\mu$ on $\mathbf{\Omega}$)
can be approximated as closely as desired, and so permits to approximate the integral on $\mathbf{\Omega}$ of any given polynomial. \\
{\bf Keywords:} Lebesgue and Gaussian measure; semi-algebraic sets; moment problem and sums of squares; semidefinite programming; convex optimization\\
{\bf MSC:} 44A60 28A75 90C05 90C22

\section{Introduction}

Given a set $\mathbf{\Omega}\subset\mathbb{R}^n$ and a finite Borel measure $\mu$ on $\mathbb{R}^n$, computing $\mu(\mathbf{\Omega})$ is a very challenging problem.
In fact even approximating the Lebesgue volume of a convex body $\mathbf{\Omega}\subset\mathbb{R}^n$ (e.g. a polytope) is difficult; see e.g.
Bollob\'as \cite{Bollobas} and Dyer and Frieze \cite{dyer1}.
However, in the latter case some efficient (non deterministic) algorithms with probabilistic guarantees are available and for more details the interested reader is referred to
e.g. Dyer et al. \cite{dyer2}, Cousins and Vempala \cite{cousins1,cousins2} and the references therein.

In the non convex case no such algorithm is  available and one is left with approximating
$\mu(\mathbf{\Omega})$ with Monte Carlo (or Quasi-Monte-Carlo) type methods as described in e.g. Niederreiter \cite{niederreiter}. That is, one first generates a sample of $N$ points in $\mathbf{B}$ following the distribution
$\mu$ on $\mathbf{B}$ and then one {\it counts} the number $N_\mathbf{K}$ of points that fall into $\mathbf{\Omega}$. This realization of the random variable $N_\mathbf{K}/N$ provides an estimate of $\mu(\mathbf{\Omega})$ but by no means an upper bound or a lower bound on $\mu(\mathbf{\Omega})$. Of course this method is quite fast, especially is small dimension.

Yet, as $\mu(\mathbf{\Omega})$  is indeed very difficult to compute exactly, a less ambitious but still useful goal would be to provide {\it upper} and/or {\it lower bounds} on $\mu(\mathbf{\Omega})$.
Even better, a  converging sequence of upper (or lower) bounds would be highly desirable.
This is the strategy proposed in Henrion et al. \cite{sirev} when $\mathbf{\Omega}$ is a compact basic semi-algebraic set and $\mu$ is the Lebesgue measure.
In \cite{sirev} the authors have provided a (deterministic) numerical scheme which yields
a monotone sequence of upper bounds converging to $\mu(\mathbf{\Omega})$. It consists of solving a hierarchy of semidefinite programs of increasing size.
By repeating the procedure but now with the complement $\mathbf{B}\setminus\mathbf{\Omega}$, one also obtains a monotone sequence of
lower bounds converging to $\mu(\mathbf{\Omega})$. However, even on typical $2$ or $3$-dimensional examples, the convergence was rather slow and the authors proposed a slight modification which turned out to be much more efficient; the convergence was much faster but unfortunately not monotone anymore.

\subsection*{Contribution}
The purpose of this paper is to introduce a deterministic method to approximate (in principle as closely as desired)
the measure $\mu(\mathbf{\Omega})$ of the union  $\mathbf{\Omega}=\bigcup_i\mathbf{\Omega}_i$ of finitely many basic semi-algebraic set.
The finite Borel measure $\mu$ is any  measure whose all moments are finite, e.g., the Lebesgue measure
when $\mathbf{\Omega}$ is compact, the Gausssian measure $d\mu=\exp(-\Vert\mathbf{x}\Vert^2)d\mathbf{x}$ for non-compact set $\mathbf{\Omega}$.

The method is similar in spirit to the one in \cite{sirev} for a compact basic semi-algebraic set and the one in \cite{lass-gaussian}
for computing Gaussian measures of basic closed semi-algebraic sets (not necessarily compact), but with two important novelties.

$\bullet$ In contrast to \cite{sirev} and \cite{lass-gaussian}, we consider a finite {\it union} $\mathbf{\Omega}$ of (non disjoint) basic semi-algebraic sets, which complicates matters significantly.

$\bullet$ We include a technique to accelerate the convergence different from the one described in \cite{sirev}. Indeed
in contrast to \cite{sirev}, it has the highly desirable feature to maintain the {\it monotone} convergence to $\mu(\mathbf{\Omega})$ which is essential if one wishes to obtain upper and lower bounds. It consists of
using moments constraints coming from a particular application of Stokes' theorem.

 In fact this numerical scheme  allows to approximate  not only $\mu(\mathbf{\Omega})$ but also
any fixed finite sequence of moments of the measure $\mu_\mathbf{\Omega}$ (where $\mu_\mathbf{\Omega}$
is the restriction of $\mu$ to $\mathbf{\Omega}$).
\begin{rem}
{\rm One might invoke the inclusion-exclusion principle which states that
\begin{equation}
\label{toto}
\mu (\bigcup_{i=1}^p \mathbf{\Omega}_i) = \sum_{j=1}^p (-1)^{j+1} \sum_{1 \le i_1 < ... < i_j \le p} \mu (\mathbf{\Omega}_{i_1}\cap ... \cap \mathbf{\Omega}_{i_j}),
\end{equation}
so that in principle it suffices to compute (or approximate) $\mu (\mathbf{\Omega}_{i_1}\cap ... \cap \mathbf{\Omega}_{i_j})$ for all possible
intersections of the $\mathbf{\Omega}_j$'s, e.g.  by the approach of \cite{sirev} or \cite{lass-gaussian}. But this approach has two major drawbacks.
First there are possibly $2^p$ such sets  and secondly,
to compute an upper bound one has to compute an upper bound
for  such intersections with an odd number of elementary sets $\mathbf{\Omega}_{i_j}$, and a lower bound
for  such intersections with an even number of elementary sets. The latter lower bound in turn is obtained
by computing an upper bound for the complement. This makes the whole procedure tedious and complicated.
Finally, Bonferroni's inequalities also provide a (finite) sequence of upper and lower bounds on $\mu(\mathbf{\Omega})$
but computing those bounds involves sums similar to the right-hand-side of (\ref{toto}),
hence with the same drawbacks just mentioned. Our proposed technique is direct with no
partial computation on intersections of elementary sets $\mathbf{\Omega}_{i_j}$.
}\end{rem}

Of course, the technique described in this paper is computationally expensive. In particular, its applicability  is limited by the
performance of the state-of-the-art semidefinite solvers because the size of the semidefinite programs
increases fast with the rank in the hierarchy. Therefore it makes
its application limited to small dimensional problems ($n\leq 3,4$). For higher dimensions
only a few steps in the hierarchy can be implemented and therefore only upper and lower bounds (possibly crude) are expected.
But the reader should keep in mind that the problem is very difficult and to the best of our knowledge
we are not aware of an algorithm (at least at this level of generality) which provides certified upper and lower bounds
with such convergence properties (even for convex sets and in particular for non compact sets $\mathbf{\Omega}$). In our opinion
this methodology should be viewed as complementary to (rather than competing with) probabilistic methods.

\section{Notation, definitions and preliminary results}
\subsection{Notation and definitions}
Let $\mathbb{R}[\mathbf{x}]$ be the ring of polynomials in the variables $\mathbf{x}=(x_1,\ldots,x_n)$. Denote by $\mathbb{R}[\mathbf{x}]_d\subset\mathbb{R}[\mathbf{x}]$ the vector space of polynomials of degree at most $d$, which has dimension $s(d):=\binom{n+d}{d}$, with e.g., the usual canonical basis $(\mathbf{x}^\gamma)_{\gamma\in\mathbb{N}^n_d}$ of monomials, where $\mathbb{N}^n_d := \{\gamma\in\mathbb{N}^n \,:\, \vert\gamma\vert\leq d\}$, $\mathbb{N}$ is the set of natural numbers including $0$ and $\vert\gamma\vert := \sum_{i=1}^n\gamma_i$.
Also, denote by $\Sigma[\mathbf{x}]\subset\mathbb{R}[\mathbf{x}]$ (resp. $\Sigma[\mathbf{x}]_d\subset\mathbb{R}[\mathbf{x}]_{2d}$) the cone of sums of squares (s.o.s.) polynomials (resp. s.o.s. polynomials of degree at most $2d$).
If $f\in\mathbb{R}[\mathbf{x}]_d$, we write $f(\mathbf{x})=\sum_{\gamma\in\mathbb{N}^n_d}f_\gamma \mathbf{x}^\gamma$ in the canonical basis and denote by $\boldsymbol{f}=(f_\gamma)_\gamma\in\mathbb{R}^{s(d)}$ its vector of coefficients.
Finally, let $S^n$ denote the space of $n\times n$ real symmetric matrices, with inner product $\langle \mathbf{A},\mathbf{B}\rangle ={\rm trace}\,\mathbf{A}\mathbf{B}$. We use the notation $\mathbf{A}\succeq 0$ (resp. $\mathbf{A}\succ 0$) to denote that $\mathbf{A}$ is positive semidefinite (definite). With $g_0:=1$, the quadratic module $Q(g_1,\ldots,g_m)\subset\mathbb{R}[\mathbf{x}]$ generated by polynomials $g_1,\ldots,g_m$, is defined by:
\[
Q(g_1,\ldots,g_m)\,:=\,\left\{\sum_{j=0}^m\sigma_j\,g_j\::\:\sigma_j\in\Sigma[\mathbf{x}]\,\right\}.
\]
\begin{defn}[Archimedean assumption]
\label{definition-1}
The quadratic module $Q(g_1,\ldots,g_m)$ is {\it Archimedean} if there exists $M>0$ such that the quadratic polynomial
$\mathbf{x}\mapsto g_{m+1}:=M-\Vert\mathbf{x}\Vert^2$ belongs to $Q(g_1,\ldots,g_m)$. Notice that
$g_{m+1}\in Q(g_1,\ldots,g_m)$ is an {\it algebraic certificate} that the set $\mathbf{K}:=\{\mathbf{x}: g_j(\mathbf{x})\geq0,\:j=1,\ldots,m\}$ is compact.
\end{defn}
If the set  $\mathbf{K}:\{\mathbf{x}:g_j(\mathbf{x})\geq0,\:j=1,\ldots,m\}$ is compact  then $\Vert\mathbf{x}\Vert^2\leq M$ for some $M>0$,
and one may always include the redundant quadratic constraint $\theta(\mathbf{x}):=M-\Vert\mathbf{x}\Vert^2\geq0$ in the definition of $\mathbf{K}$ without changing $\mathbf{K}$.
Then the quadratic module $Q(g_1,\ldots,g_{m+1})$ is Archimidean.

\subsection*{Moment and localizing matrix}
With a real sequence $\mathbf{y}=(y_{\gamma})_{\gamma\in\mathbb{N}^n_d}$, one may associate the (Riesz) linear functional $L_{\mathbf{y}}:\mathbb{R}[\mathbf{x}]_d\to\mathbb{R}$ defined by
\[f\,\left(=\sum_\gamma f_\gamma\,\mathbf{x}^\gamma\right)\quad \mapsto L_{\mathbf{y}}(f)\,:=\,\sum_\gamma f_\gamma\,y_\gamma,\]
Denote by $\mathbf{M}_d(\mathbf{y})$ the {\it moment} matrix associated with $\mathbf{y}$, the real symmetric matrix with rows and columns indexed in the basis of monomials $(\mathbf{x}^\gamma)_{\gamma\in \mathbb{N}^n_{d}}$, and with entries:
\[
\mathbf{M}_d(\mathbf{y})(\alpha,\beta)\,:=\,L_{\mathbf{y}}(\mathbf{x}^{\alpha+\beta})\,=\,y_{\alpha+\beta},\qquad \forall\,\alpha,\beta\in\mathbb{N}^n_{d}.
\]
Next, given $g\in\mathbb{R}[\mathbf{x}]$, denote by $\mathbf{M}_d(g\,\mathbf{y})$ the {\it localizing} moment matrix associated with $\mathbf{y}$ and $g$, the real symmetric matrix with rows and columns indexed in the basis of monomials $(\mathbf{x}^\gamma)_{\gamma\in \mathbb{N}^n_{d}}$, and with entries:
\[
\mathbf{M}_d(g\,\mathbf{y})(\alpha,\beta)\,:=\,L_{\mathbf{y}}(g(\mathbf{x})\,\mathbf{x}^{\alpha+\beta})\,=\,\sum_{\gamma}g_\gamma\,y_{\alpha+\beta+\gamma},\qquad \forall\,\alpha,\beta\in\mathbb{N}^n_{d}.
\]
If $\mathbf{y}=(y_{\gamma})_{\gamma\in\mathbb{N}^n}$ is the sequence of moments of some Borel measure $\mu$ on $\mathbb{R}^n$ then $\mathbf{M}_d(\mathbf{y})\succeq0$ for all $d\in\mathbb{N}$.
However the converse is not true in general and it is related to the well-known fact that there are positive polynomials that are not sums of squares.
Similarly, if the support of $\mu$ is contained in $\{\mathbf{x}:g(\mathbf{x})\geq0\}$ then $\mathbf{M}_d(g\,\mathbf{y})\succeq0$ for all $d\in\mathbb{N}$.
For more details the interested reader is referred to e.g. \cite[Chapter 3]{lass-book-icp}.

Given a Borel set $\mathbf{\Omega}\subset\mathbb{R}^n$ let $\mathcal{M}(\mathbf{\Omega})$ be the space of finite {\it signed} Borel measures on $\mathbf{\Omega}$ and let
$\mathcal{M}(\mathbf{\Omega})_+\subset\mathcal{M}(\mathbf{\Omega})$ be the convex cone of finite Borel measures on $\mathbf{\Omega}$.

\subsection{The measure of a basic semi-algebraic set}
\label{sirev}
Let $\mathbf{B},\mathbf{K}\subset\mathbb{R}^n$ with $\mathbf{B}\supset\mathbf{K}$ and let $\mu$ be a finite Borel measure
whose support is $\mathbf{B}$.  (Typically $\mu$ is the Lebesgue measure on a box $\mathbf{B}$
and one wishes to compute the Lebesgue volume ${\rm vol}(\mathbf{K})$; alternatively $\mathbf{B}=\mathbb{R}^n$,
$\mu$ is the Gaussian measure $d\mu=\exp(-\Vert\mathbf{x}\Vert^2)d\mathbf{x}$
and one wishes to compute $\mu(\mathbf{K})$.)

\subsection*{An infinite-dimensional linear program $\mathbf{P}$}

Let $f\in\mathbb{R}[\mathbf{x}]$ be positive almost everywhere on $\mathbf{K}$ and consider the following infinite-dimensional \textbf{LP} problem :
\begin{center}
\begin{align}
\mathbf{P} : \quad f^*=\underset{\phi}{\mbox{sup  }} \Big \{\int_\mathbf{K} f\, d\phi : \lambda \le \mu; \mbox{ } \phi \in \mathcal{M}(\mathbf{K})_+ \Big \} \label{LPINF_P}
\end{align}
\end{center}
\begin{theorem}[\cite{sirev}]
\label{LPINF_THM}
The measure $\phi^*=\mu_\mathbf{K}$ (the restriction of $\mu$ to $\mathbf{K}$) is the unique optimal solution of $\mathbf{P}$. In particular, if $f(\mathbf{x})=1$ for all $\mathbf{x}$, then
$f^*=\mu(\mathbf{K})$.
\end{theorem}

\subsection*{Semidefinite relaxations}
Of course problem $\mathbf{P}$ in (\ref{LPINF_THM}) is infinite-dimensional and cannot be solved directly. However,
when $\mathbf{K}$ is a basic semi-algebraic set then Theorem \ref{LPINF_THM} can be further exploited.
So given $(g_j)_{j=1}^m\subset\mathbb{R}[\mathbf{x}]$, let $\mathbf{K}\subset\mathbb{R}^n$ be the basic semi-algebraic set
\begin{equation}
\label{setk}
\mathbf{K}\,=\,\{\,\mathbf{x}\in\mathbb{R}^n:\:g_j(\mathbf{x})\,\geq\,0,\quad j=1,\ldots,m\,\},
\end{equation}
assumed to nonempty and compact. Let $\mathbf{B}\supset\mathbf{K}$ and let $\mu$ be a finite Borel measure whose all moments
$\mathbf{z}=(z_\alpha)$ with
\[z_\alpha\,=\,\int_\mathbf{B}\mathbf{x}^\alpha\,d\mu(\mathbf{x}),\qquad\alpha\in\mathbb{N}^n,\]
are available in closed form or can be computed.

To approximate $f^*$ as closely as desired in \cite{sirev} the authors propose to solve the following hierarchy $(\mathbf{Q}_d)_{d\in\mathbb{N}}$ of
semidefinite programs\footnote{A semidefinite program (SDP) is a conic convex optimization problem
with a remarkable modeling power. It can be solved efficiently
(in time polynomial in its input size) up to arbitrary precision fixed in advance; see e.g. Anjos and Lasserre \cite{handbook}} indexed by $d\in\mathbb{N}$:

\begin{equation}
\label{primal-sdp}
\mathbf{Q}_d:\begin{array}{rl}
\rho_d=\displaystyle\sup_\mathbf{y} & \{\,L_{\mathbf{y}}(f): \\
\mbox{s.t.}& \mathbf{M}_d(\mathbf{y})\,\succeq0; \:\mathbf{M}_d(\mathbf{z}-\mathbf{y}) \succeq 0\\
& \mathbf{M}_{d-r_{j}}(g_{j}\,\mathbf{y}) \succeq 0, j = 1,\ldots,m\}.
\end{array}\end{equation}
Observe that $\mathbf{Q}_d$ is a relaxation of $P$, and so $\rho_d\geq\mu(\mathbf{K})$ for all $d$. In addition,
the sequence $(\rho_d)_{d\in\mathbb{N}}$ is monotone non increasing.
The dual of (\ref{primal-sdp})
is the semidefinite program:
\begin{equation}
\label{dual-sdp}
\mathbf{Q}^*_d:\quad \rho^*_d=\displaystyle\inf_{p\in\mathbb{R}[\mathbf{x}]_{2d}} \, \{\,\int_\mathbf{B} p\,d\mu:\: p-f\geq0\mbox{ on $\mathbf{K}$};\quad p\in\Sigma[\mathbf{x}]_d\,\},
\end{equation}
and by weak duality, $\rho_d\leq\rho^*_d\leq f^*$ for all $d$.

\begin{theorem}[\cite{sirev}]
Assume that $Q(g_1,\ldots,g_m)$ is Archimedean. Then $\rho_d\to f^*$ as $d\to\infty$. If $\mathbf{K}$ has nonempty interior then
$\rho^*_d=\rho_d$ and (\ref{dual-sdp}) has an optimal solution $p^*\in\mathbb{R}[\mathbf{x}]_{2d}$.
\end{theorem}
So when $f=1$, $(\rho_d)_{d\in\mathbb{N}}$ provides us with a monotone sequence of upper bounds on $f^*=\mu(\mathbf{K})$. Unfortunately
the convergence is rather slow as observed on several numerical examples. This is because
in the dual (\ref{dual-sdp}) the optimal solution $p^*\in\mathbb{R}[\mathbf{x}]_{2d}$ tries to approximate from above (in $L_1(\mathbf{B},\mu)$)
the discontinuous function $1_\mathbf{K}$, which implies an annoying Gibb's phenomenon\footnote{The Gibbs' phenomenon appears at a jump discontinuity when one approximates a piecewise $C^1$ function with a continuous function, e.g. by its Fourier series.}. To remedy this problem
the authors in \cite{sirev} propose to use a polynomial $f$, nonnegative on $\mathbf{K}$ and which vanishes on $\partial \mathbf{K}$.
In this case the convergence $\rho_d\to \int_\mathbf{K} f\,d\mu$ as $d\to\infty$ is still monotone and if
$\mathbf{y}^d=(y^d_\alpha)_{\alpha\in\mathbb{N}^n_{2d}}$ denotes an optimal solution of (\ref{primal-sdp}) then $y^d_0\to\mu(\mathbf{K})$ as $d\to\infty$.
However, while faster than with $f=1$, the latter convergence of $y^d_0$ to $\mu(\mathbf{K})$ is not monotone anymore, a rather annoying feature
which prevents from obtaining a non increasing sequence of upper bounds.

\section{Main result}

\subsection*{The context}
Let $\mathbf{B}\subset\mathbb{R}^n$ be a box, and for every $i=1,...,p$, let $\mathbf{\Omega}_i := \{\,\mathbf{x}\in\mathbb{R}^n :g_{ij}(x) \ge 0, j=1,\ldots,m_i\}$,
for some polynomials $(g_{ij})\subset\mathbb{R}[\mathbf{x}]$.
Assume that $\mathbf{B}$ has been chosen so as to satisfy:
\begin{align}
\mathbf{\Omega} := \bigcup_{i=1}^p \mathbf{\Omega}_i \subset \mathbf{B}.  \label{SEMIALGDEF}
\end{align}
The goal is to provide a numerical scheme to approximate as closely as desired the Lebesgue volume
$\mu(\mathbf{K})$. (We will see how to adapt the methodology to also approximate
as closely as desired $\mu(\mathbf{K})$ when $\mathbf{K}$ is not necessarily compact and $\mu$ is a Gaussian measure.)
One possible approach described below is to use the powerful inclusion-exclusion principle and/or
the associated Bonferroni inequalities.

\subsection{The inclusion-exclusion principle and Bonferroni Inequalities}
Let :
\[S_k \,:=\, \sum_{1 \le i_1 < ... < i_k \le p} \mu (\mathbf{\Omega}_{i_1}\cap ... \cap \mathbf{\Omega}_{i_k}),\quad k=1,\ldots,p.\]
By the inclusion-exclusion principle,

\begin{align*}
\mu (\bigcup_{k=1}^p \mathbf{\Omega}_k) = \sum_{k=1}^p (-1)^{k+1}S_k,
\end{align*}
which allows us to work with intersections of the $\mathbf{\Omega}_k$'s only. In addition, the Bonferroni inequalities state that

\begin{align*}
\mu (\bigcup_{i=1}^p \mathbf{\Omega}_i) &\le \sum_{j=1}^{2k+1} (-1)^{j+1}S_j &\forall 2k+1 \le p\\
& \ge \sum_{j=1}^{2k} (-1)^{j+1}S_j &\forall 2k \le p
\end{align*}
which provides sequences of (increasingly tighter) upper and lower bounds.\\

Therefore to compute $\mu(\mathbf{\Omega})$ we only have to compute the measure of the intersection
$\Theta_{i_1,\ldots,i_k}:=\displaystyle\bigcap_{j=1,\ldots,k}\mathbf{\Omega}_{i_j}$, for all $1 \le i_1 < ... < i_k \le p$.
Notice that there are $2^p$ such sets.
As each
$\Theta_{i_1,\ldots,i_k}\subset\mathbf{B}$ is a compact basic semi-algebraic set, one may apply the methodology described in \S\ref{sirev},
to obtain a sequence $(\rho^{(i_1,\ldots,i_k)}_d)_{d\in\mathbb{N}}$ which converges to $\mu(\Theta_{i_1,\ldots,i_k})$ as $d\to\infty$, and therefore
\[\lim_{d\to\infty}\left(\sum_{i=1}^p(-1)^{k+1}\sum_{1\leq i_1<\ldots<i_k\leq p}\rho_d^{i_1,\ldots,i_k}\right)\,=\,\mu(\mathbf{\Omega}).\]
Notice that the convergence is not monotone non increasing even if one solves (\ref{primal-sdp}) with $f=1$ because
we sum up negative and positive terms. To maintain the monotone convergence (when $f=1$)
it suffices to compute a lower bound on the complement $\mathbf{B}\setminus\Theta_{i_1,\ldots,i_k}$ when $k$ is even. However
as already mentioned the convergence is expected to be rather slow.

To accelerate the convergence one may use $f=\prod_{j=1}^k\prod_{\ell=1}^{m_{i_j}}g_{i_j\ell}$ when one solves (\ref{primal-sdp})
with $\mathbf{\Omega}=\Theta_{i_1,\ldots,i_k}$ as $f\geq0$ on $\Theta_{i_1,\ldots,i_k}$ and
$f=0$ on $\partial\Theta_{i_1,\ldots,i_k}$.
But then the convergence
\[\lim_{d\to\infty}\left(\sum_{i=1}^p(-1)^{k+1}\sum_{1\leq i_1<\ldots<i_k\leq p}y_{d,0}^{i_1,\ldots,i_k}\right)\,=\,\mu(\mathbf{\Omega}),\]
(where $\mathbf{y}^{i_1,\ldots,i_k}_d=y^{i_1,\ldots,i_k}_{d,\alpha}$ is an optimal solution of (\ref{primal-sdp}) with $\mathbf{\Omega}=\Theta_{i_1,\ldots,i_k}$) is not monotone anymore.

\subsection{A direct approach}

In this section we describe a direct approach with two distinguishing features:
\begin{itemize}
\item It does not use the inclusion-exclusion principle and the need to approximate
$\mu(\bigcap_{j=1}^k\mathbf{\Omega}_{i_j})$ for all $2^p$ such sets.
\item The convergence to $\mu(\mathbf{\Omega})$ (and also to $\mu(\mathbf{B}\setminus\mathbf{\Omega}))$ is monotone non increasing, that is, we
can compute two sequences $(\overline{\omega}_d)_{d\in\mathbb{N}}$ and $(\underline{\omega}_d)_{d\in\mathbb{N}}$ such that:
\[\underline{\omega}_d\,\leq\,\mu(\mathbf{\Omega})\,\leq\,\overline{\omega}_d,\quad d\in\mathbb{N};\quad
\mu(\mathbf{\Omega})\,=\,\lim_{d\to\infty}\underline{\omega}_d\,=\,\lim_{d\to\infty}\overline{\omega}_d.\]
\end{itemize}

Recall that any finite number of moments
\begin{center}
\begin{align*}
\mu_{\alpha} = \int_{\mathbb{B}} \textbf{x}^\alpha d\mu(\textbf{x}),\quad\alpha\in\mathbb{N}^n,
\end{align*}
\end{center}
are either available in closed-form or can be obtained numerically.

\subsection*{A multi infinite-dimensional linear program $\mathbf{Q}$}
As in \S \ref{sirev} we first introduce an infinite-dimensional \textbf{LP} problem $\mathbf{Q}$ whose unique optimal solution is the restriction of $\mu$ on $\mathbf{\Omega}$ (and whose dual has a clear interpretation).

Let $f\in\mathbb{R}[\mathbf{x}]$ be positive almost everywhere on $\mathbf{\Omega}$ and consider the following infinite-dimensional \textbf{LP} problem :

\begin{equation}
\label{LPINF_Q}
\mathbf{Q} : \quad f^*=\sup_{\phi_1,\ldots,\phi_p}
\Big \{\sum_{i=1}^p\int_{\mathbf{\Omega}_i} f d\phi_i : \sum_{i=1}^p \phi_i \le \mu; \mbox{ } \phi_i \in \mathcal{M}(\mathbf{\Omega}_i)_+,\:i=1,\ldots,p\Big \}.
\end{equation}

\begin{theorem} \label{OPTSOLQ}
Problem $\mathbf{Q}$ has an optimal solution $(\phi^*_1,\ldots,\phi^*_p)$ and
every optimal solution satisfies $\sum_{i=1}^p \phi^*_i = \mu_\mathbf{\Omega}$, where
$\mu_\mathbf{\Omega}$ is the restriction of $\mu$ to $\mathbf{\Omega}$.
\end{theorem}

\begin{proof}
We first prove that $\mathbf{Q}$ has an optimal solution. The set $\Delta_\mu:=\{\phi\in\mathcal{M}(\mathbb{R}^n)_+:\phi\leq\,\mu\}$
is weakly sequentially compact; see e.g. Dunford \& Schwartz \cite[Theorem 1, p. 305]{dunford}. Therefore let
$(\phi^k_1,\ldots,\phi^k_p)_{k\in\mathbb{N}}$ be a maximizing sequence of feasible solutions of $\mathbf{Q}$. There exists
a subsequence $(k_\ell)_{\ell\in\mathbb{N}}$ such that for every $i=1,\ldots,p$, $\phi^{k_\ell}_i\stackrel{w}{\to}\phi^*_i$ for some
$\phi^*_i\in\mathcal{M}(\mathbb{R}^n)_+$. The above weak convergence and $\displaystyle\int_{\mathbf{\Omega}_i^c}\,d\phi_i^{k_\ell}=0$ implies
$\displaystyle\int_{\mathbf{\Omega}_i^c}\,d\phi_i^*=0$, that is, $\phi^*_i\in\mathcal{M}(\mathbf{\Omega}_i)_+$ for all $i=1,\ldots,p$.
Weak convergence again implies $\sum_{i=1}\phi^*_i\leq\mu$ and so $(\phi^*_1,\ldots,\phi^*_p)$ is a feasible solution of $\mathbf{Q}$.
Finally weak convergence also implies
\[f^*\,=\,\lim_{\ell\to\infty}\sum_{i=1}^p\int f\,d\phi^{k_\ell}_i\,=\,\sum_{i=1}^p\lim_{\ell\to\infty}\int f\,d\phi^{k_\ell}_i\,=\,
\sum_{i=1}^p\int f\,d\phi^*_i,\]
which proves that $(\phi^*_1,\ldots,\phi^*_p)$ is an optimal solution of $\mathbf{Q}$.

We next prove that $f^*=\int  fd\mu_\mathbf{\Omega}$.
Indeed, firstly observe that for every feasible solution $(\phi_1,\ldots,\phi_p)$ of $\mathbf{Q}$,
$\sum_{i=1}^p\int f d\phi_i \le \int_\mathbf{\Omega} fd\mu= \int fd\mu_\mathbf{\Omega}$. On the other hand,
for every $i=1,\ldots,p$, denote by $\theta_i$ the measurable function defined on $\mathbf{\Omega}$ by :
\begin{center}
\begin{align*}
\mathbf{x}\mapsto \theta_i(\mathbf{x}) = \frac{1}{\vert\{j \in \{1,\ldots,p\} : \mathbf{x} \in \mathbf{\Omega}_j \}\vert} 1_{\mathbf{\Omega}_i}(\mathbf{x}),\qquad\mathbf{x}\in\mathbf{\Omega}.
\end{align*}
\end{center}
The (discontinuous) functions $(\theta_i)_{i=1,\ldots,p}$ form a {\it partition of unity} subordinate to the open cover $\bigcup_i{\rm int}(\mathbf{\Omega}_i)$.
For every $i=1,\ldots,p$, let $\phi^*_i\in\mathcal{M}(\mathbf{\Omega}_i)_+$ be the finite Borel measure defined by:
\begin{equation}
\label{phistar}
\phi^*_i(C) \,:=\,\int_C \theta_i(\mathbf{x})\,d\mu(\mathbf{x}),\qquad\forall C\in\mathcal{B}(\mathbb{R}^n).
\end{equation}
Hence, $\sum_{i=1}^p\phi^*_i(C)=\int_C\sum_{i=1}^p \theta_i(\mathbf{x})d\mu(\mathbf{x}) = \int_C 1_{\mathbf{\Omega}}(\mathbf{x})(\mathbf{x})d\mu(\mathbf{x}) = \mu_\mathbf{\Omega}(C) \le \mu(C)$. Therefore
$(\phi^*_1,\ldots,\phi^*_p)$ is a feasible solution of $\mathbf{Q}$ such that $\sum_{i=1}^p\phi^*_i=\mu_\mathbf{\Omega}$, and so
$\sum_{i=1}^p\int fd\phi^*_i=f^*$, i.e., $(\phi^*_1,\ldots,\phi^*_p)$ is an optimal solution of $\mathbf{Q}$.
In fact, {\it every} optimal solution $(\phi^*_1,\ldots,\phi^*_p)$ of $\mathbf{Q}$ satisfies
$\sum_{i=1}^p \int fd\phi^*_i=f^*$, and therefore $\phi^*:=\sum_{i=1}^p\phi^*_i\in\mathcal{M}(\mathbf{\Omega})_+$
is an optimal solution of $\sup_\phi\{\int fd\phi:\phi\leq\mu;\:\phi\in\mathcal{M}(\mathbf{\Omega})_+\}$. By Theorem \ref{LPINF_THM}
this solution $\phi^*$ is unique, which yields the desired result.
\end{proof}

\subsection*{A hierarchy of semidefinite relaxations}

Let $\mathbf{z} = (z_\alpha)_{\alpha\in\mathbb{N}^n}$ be the sequence of all moments of $\mu$
, that is,
\begin{equation}
\label{moments-mu}
z_\alpha\,:=\,\int \mathbf{x}^\alpha\,d\mu(\mathbf{x}),\quad \alpha\in\mathbb{N}^n.
\end{equation}
Let $\mathbf{B}\subset\mathbb{R}^n$ be a box and $\mathbf{\Omega}\subset\mathbf{B}$ be a compact semi-algebraic as in (\ref{SEMIALGDEF}).
With no loss of generality and possibly after scaling, we may and will assume that $\mathbf{B}\subset [-1,1]^n$
and $\mu$ is a probability measure. Therefore $\vert z_\alpha\vert\leq 1$ for all $\alpha\in\mathbb{N}^n$.

Let $r_{ij}= \lceil {\rm deg}(g_{ij})/2 \rceil$ and let $f\in \mathbb{R}[\mathbf{x}]$ be a given polynomial
positive almost everywhere on $\mathbf{\Omega}$ (and define $r_{00} := \lceil {\rm deg}(f)/2 \rceil$). For $d \ge d_0:=\mbox{max}_{i,j} r_{ij}$, consider the following
hierarchy of semidefinite programs $(\mathbf{Q}_d)$ indexed by $d\in\mathbb{N}$ :
\begin{equation}
\label{primal-newsdp}
\mathbf{Q}_d:\quad\begin{array}{rl}
\rho^f_d=\displaystyle\sup_{\mathbf{y}^1,\ldots,\mathbf{y}^d}&\Big \{\, \displaystyle\sum_{i=1}^p L_{\mathbf{y}^i}(f)\\
\mbox{s.t.}&\mathbf{M}_d(\mathbf{z} - \sum_{i=1}^p \mathbf{y}^i) \succeq 0;\:\mathbf{M}_d(\mathbf{y}^i)\succeq0,\quad i=1,\ldots,p\\
& \mathbf{M}_{d-r_{ij}}(g_{ij}\,\mathbf{y}^i) \succeq 0, \quad j=1,\ldots,m_i;\:i=1,\ldots,p\,\Big \}.
\end{array}
\end{equation}

Observe that $\rho^f_d\geq f^*$ for all $d\in\mathbb{N}$. Indeed, if $(\mathbf{z}^1,\ldots,\mathbf{z}^p)$
is the sequence of moments of an optimal solution $(\phi^*_1,\ldots,\phi^*_p)$ of  $\mathbf{Q}$ in (\ref{LPINF_Q})
then $(\mathbf{z}^1,\ldots,\mathbf{z}^p)$ is also a feasible solution of $\mathbf{Q}_d$.

\begin{theorem} \label{thm:SDP}
Consider the semidefinite programs $(\mathbf{Q}_d)$, $d\geq d_0$. Then :

\noindent
(i) $\mathbf{Q}_d$ has an optimal solution and the associated sequence of optimal values $(\rho^f_d)_{d\in\mathbb{N}}$ is monotone non increasing
and converges to $f^*$, that is:
\[\rho^f_d\,\downarrow\, f^*\,=\,\int_\mathbf{\Omega} f\,d\mu,\quad \mbox{as $d\rightarrow \infty$.}\]
\noindent
(ii) Let $(\mathbf{y}^{1,d},\ldots,\mathbf{y}^{p,d})$ be an optimal solution of $\mathbf{Q}_d$. Then for each $\alpha\in\mathbb{N}^n$:
\begin{equation}
\label{convergence}
\lim_{d\to\infty}\displaystyle \sum_{i=1}^py^{i,d}_\alpha \,=\, z^*_\alpha\,=\,\int_\mathbf{\Omega} \mathbf{x}^\alpha\,d\mu.\end{equation}
and in particular $\displaystyle\lim_{d\to\infty} \sum_{i=1}^py^{i,d}_0=\mu(\mathbf{\Omega})$.
\end{theorem}

\begin{proof}
For a sequence $\mathbf{y}= (y_\alpha)$, let $\tau_d(\mathbf{y}) = \max_{i=1,\ldots,n}L_{\mathbf{y}}(x_i^{2d})$ and recall
that if $\mathbf{M}_d(\mathbf{y})\succeq0$ then $\vert y_\alpha\vert\leq \max[y_0,\max_iL_\mathbf{y}(x_i^{2d})]$ for every $\alpha\in\mathbb{N}^n_{2d}$; see \cite[Proposition 3.6]{lass-book-icp}.
Next, observe that from $\mathbf{M}_d(\mathbf{z} -
\sum_{i=1}^p\mathbf{y}^{i,d}) \succeq 0$ and $\mathbf{M}_d(\mathbf{y}^i) \succeq 0$,
\[\mathbf{M}_d(\mathbf{z} - \mathbf{y}^{i,d}) \,\succeq\, \mathbf{M}_d(\sum_{j \neq i} \mathbf{y}^j) \succeq 0,\quad i=1,\ldots,n.\]
Hence the diagonal elements $z_{2\alpha} - y^{i,d}_{2\alpha}$ are all nonnegative which in turn implies
$\tau_d(\mathbf{y}^{i,d}) \le \tau_d(\mathbf{z})\leq 1$ for all $i=1,\ldots,n$.
As $z_0=1$ then  by \cite[Proposition 3.6 ]{lass-book-icp} $\vert y^{i,d}_{\alpha}\vert \le 1$
for every $\alpha \in \mathbb{N}^n_{2d}$, and so the feasible set of semidefinite program
$\mathbf{Q}_d$ is closed, bounded, hence compact, and therefore $\mathbf{Q}_d$ has an optimal solution.

Next, let $(\mathbf{y}^{1,d},\ldots,\mathbf{y}^{p,d})$ be an optimal solution of $\mathbf{Q}_d$ and by completing with zeros, make $(\mathbf{y}^{1,d},\ldots,\mathbf{y}^{p,d})$
an element of the unit ball of  $(\ell_\infty)^p$ (where
$\ell_\infty$ is the Banach space of bounded sequences, equipped with the sup-norm).
As $(\ell_\infty)^p$ is the topological dual of $(\ell_1)^p$, by the Banach-Alaoglu Theorem, there exists $(\mathbf{y}^{1,*},..,\mathbf{y}^{p,*}) \in (\ell_\infty)^p$ and a subsequence $\{d_k\}$ such that $(\mathbf{y}^{1,d_k},\ldots,\mathbf{y}^{p,d_k}) \rightarrow (\mathbf{y}^{1,*},\ldots,\mathbf{y}^{p,*})$ as
$k\rightarrow \infty$, for the weak $\star$ topology $\sigma((\ell_\infty)^p, (\ell_1)^p)$. In particular,
\begin{equation}
\label{CVS}
\lim_{k \to\infty}\, y_\alpha^{i,d_k}\, =\, y_\alpha^{i,*},\quad \forall \alpha \in \mathbb{N}^n, \forall i \in \{1,..,p\}.
\end{equation}
Next let $d\in \mathbb{N}$ be fixed arbitrary. From the pointwise convergence (\ref{CVS}) we also obtain $\mathbf{M}_d(\mathbf{y}^{i,*}) \succeq 0$ and $\mathbf{M}_d(\mathbf{z}-
\sum_{i=1}^p\mathbf{y}^{i,*}) \succeq 0$ for every $i=1,\ldots,p$. Similary, $\mathbf{M}_{d-r_{ij}}(g_{ij}\mathbf{y}^{i,*}) \succeq 0$ for every $i$ and $j$.
As $d$ was arbitrary, by Putinar's Positivistellensatz \cite{putinar}, $\mathbf{y}^{i,*}$ has a representing measure $\phi_i$ supported on
$\mathbf{\Omega}_i$ for all $i=1,\ldots,p$, and $\sum_{i=1}^p \phi_i \le \mu$.
In particular from (\ref{CVS}), as $k \to \infty$,
\[f^* \le\rho^f_{d_k} \,=\, \sum_{i=1}^p L_{\mathbf{y}^{i,d_k}}(f) \downarrow \sum_{i=1}^p L_{\mathbf{y}^{i,*}}(f) = \sum_{i=1}^p \int f\,d\phi_i.\]
Therefore $(\phi_1,\ldots,\phi_p)$ is admissible for problem $\mathbf{Q}$ with value $\sum_{i=1}^p \int fd\phi_i \ge f^*$, and so
$(\phi_1,\ldots,\phi_p)$ is an optimal solution of $\mathbf{Q}$.
Finally, by Theorem \ref{OPTSOLQ}, $\sum_{i=1}^p \phi_i = \mu_\mathbf{\Omega}$. And so for each $\alpha\in\mathbb{N}^n$:
\[\lim_{k\rightarrow \infty}\,\sum_{i=1}^py^{i,d_k}_\alpha\, = \,\sum_{i=1}^py^{i,*}_\alpha\, =\,  z^*_\alpha\,=\,\int_\mathbf{\Omega}\mathbf{x}^\alpha\,d\mu(\mathbf{x}).\]
As the converging subsequence $(d_k)_{k\in\mathbb{N}}$ was arbitrary, it follows that in fact the whole sequence $(\sum_{i=1}^py^{i,d}_\alpha)_d$
converges to $z_\alpha$, for all $\alpha\in\mathbb{N}^n$, that is, (\ref{convergence}) holds.
\end{proof}

\subsection*{The dual of $\mathbf{Q}_d$}
Let $g_{i0}(\mathbf{x})=1$ for all $\mathbf{x}\in\mathbb{R}^n$, $i=1,\ldots,p$. The dual of the semidefinite program $\mathbf{Q}_d$ is the semidefinite program:
\begin{equation}
\label{dual-newsdp}
\mathbf{Q}^*_d:\quad\begin{array}{rl}
(\rho^f _d)^*=\displaystyle\inf_{q,\sigma_{ij}}&\Big\{\displaystyle\int_\mathbf{B} q\,d\mu:\\
\mbox{s.t.}&q-f\,=\,\displaystyle\sum_{j=0}^{m_i}\sigma_{ij}\,g_{ij},\quad i=1,\ldots,p\\
&\sigma_{ij}\in\Sigma[\mathbf{x}]_{d-r_{ij}},\quad j=0,\ldots,m_i;\:i=1,\ldots,p\\
&q\in\Sigma[\mathbf{x}]_d\Big\}.
\end{array}
\end{equation}

\begin{prop}
\label{slater}
Assume that for every $i=1,\ldots,p$, both $\mathbf{\Omega}_i$ and $\mathbf{B}\setminus\mathbf{\Omega}_i$ have nonempty interior.
Then there is no duality gap between (\ref{primal-newsdp}) and its dual (\ref{dual-newsdp}), that is,
$\rho^f _d=(\rho^f _d)^*$
for all $d\geq d_0$. Moreover (\ref{dual-newsdp}) has an optimal solution $(q^*,(\sigma_{ij}^*)$.
\end{prop}

\begin{proof}
Let $(\phi^*_1,\ldots,\phi^*_p)$ be the measures defined in (\ref{phistar}) the proof of the Theorem \ref{OPTSOLQ} and let
$\mathbf{y}^i_d$ be the sequence of moments up to degree $d$ of $\phi^*_i$, $i=1,\ldots,p$.
As every  $\mathbf{\Omega}_i$ has nonempty interior, then clearly $\mathbf{M}_d(\mathbf{y}^i) \succ 0$ and $\mathbf{M}_{d-r_{ij}}(g_{ij}\mathbf{y}^i) \succ 0$ for every
$j= 1,\ldots,m_i$ and $i = 1,\ldots,p$. As $\mathbf{B}\setminus\mathbf{\Omega}$ also has nonempty interior then $\mathbf{M}_d(\mathbf{z} - \sum_{i=1}^p\mathbf{y}^i) \succ 0$.
Therefore Slater's condition holds for $\mathbf{Q}_d$. In addition, the set of admissible solution of $\mathbf{Q}_d^*$ is nonempty (set $q=f$ and $\sigma_{ij}=0$ for all $i,j$), and therefore
a standard result in conic convex optimization yields the desired result\footnote{In fact as the set of optimal solutions of (\ref{primal-newsdp})
is compact, the absence of a duality gap between (\ref{primal-newsdp}) and
(\ref{dual-newsdp}) also follows from \cite{strong} without the conditions ${\rm int}(\mathbf{\Omega}_i)\neq\emptyset$ and
${\rm int}(\mathbf{B}\setminus \mathbf{\Omega}_i)\neq\emptyset$.}.

\end{proof}

As in the case of a basic closed semi-algebraic set, when $f$ is the constant function $1$ the convergence
$\rho^f_d\to f^* =\mu(\mathbf{\Omega})$ is monotone non increasing, a highly desirable feature. However
in typical examples this convergence is rather slow. Again one may take for $f$
a function that is nonnegative on $\mathbf{\Omega}$ and which vanishes on $\partial\mathbf{\Omega}$. This accelerates the convergence
both $\rho^f_d\to f^*$ and $\sum_i y^{id}_0\to \mu(\mathbf{\Omega})$ as $d\to\infty$, but if by construction the former is monotone
non increasing,  the latter is not monotone anymore, a rather annoying feature if the goal is to obtain a
converging sequence of {\it upper bounds}. In the next section we describe a technique
that allows to accelerate significantly the convergence $\sum_i y^{id}_0\to \mu(\mathbf{\Omega})$ as $d\to\infty$, while maintaining
its monotone non increasing character.

\subsection{Convergence improvement using Stokes' formula}

In this section we show how to improve significantly the monotone non increasing
convergence of $\rho_d^1$ (i.e. $\rho^f_d$ with $f=1$) to $\mu(\mathbf{\Omega})$. To do this we will use Stokes' theorem for integration and in the sequel, to avoid technicalities we assume that $\mathbf{\Omega} \subset \mathbb{R}^n$ is the closure of its interior, i.e., $\mathbf{\Omega}=\overline{{\rm int}(\mathbf{\Omega})}$.
The basic idea is simple to express in informal terms.

\begin{center}
{\it Since we know in advance that  $(\phi^*_1,\ldots,\phi^*_p)$ in  (\ref{phistar}) is an optimal solution of problem $\mathbf{Q}$,
every additional information in terms of linear constraints on the moments of $\phi^*_i$
can be included in $\mathbf{Q}$ without changing its optimal value. BUT when included
in the relaxation $\mathbf{Q}_d$ it will provide useful additional constraints that restrict the feasible set of $\mathbf{Q}_d$ and so
 make its optimal value necessarily smaller.}
\end{center}

Suppose for the moment that $\mathbf{\Omega}$ is compact
with smooth boundary, and assume that the measure $\mu$ has a density $h$ with respect to Lebesgue measure $d\mathbf{x}$ of the form
$q(\mathbf{x})\exp(r(\mathbf{x}))1_{\mathbf{B}}(\mathbf{x})$ for some polynomial $r,q\in \mathbb{R}[\mathbf{x}]$.
Let $X$ be a given vector field and $f\in \mathbb{R}[\mathbf{x}]$. Then Stokes' theorem states:
\[\int_{\mathbf{\Omega}} {\rm Div}(X)\,f(\mathbf{x})\, h(\mathbf{x}) d\mathbf{x} + \int_{\mathbf{\Omega}} \langle X, \nabla (f(\mathbf{x})\,h(\mathbf{x}))\rangle d\mathbf{x} = \int_{\partial K}
\langle X,\vec{n}_\mathbf{x} \rangle f(\mathbf{x})h(\mathbf{x}) d\sigma(\mathbf{x}),\]
where $\vec{n}_\mathbf{x}$ is outward pointing normal at $\mathbf{x}\in\partial\mathbf{\Omega}$, and $\sigma$ is the
$(n-1)$-dimensional Hausdorff measure on $\partial\mathbf{\Omega}$. In particular if $f$ vanishes on $\partial\mathbf{\Omega}$
and $\mathbf{X}=e_k\in\mathbb{R}^n$ (where $e_k(j)=\delta_{k=j}$) Stokes' formula becomes
\begin{equation}
\label{stokes}
\int_{\mathbf{\Omega}} \frac{\partial}{\partial x_k}\,(f(\mathbf{x})\,h(\mathbf{x}))\, d\mathbf{x} = 0.
\end{equation}
To exploit (\ref{stokes}) in our particular context where $\mathbf{\Omega}$ is defined in (\ref{setk}),
let $g = \prod_{i=1}^p \prod_{j=1}^{m_i} g_{ij}$ and let $\mathbf{x}\mapsto f(\mathbf{x}) = \mathbf{x}^\alpha\,g(\mathbf{x})q(\mathbf{x})$
with $\alpha\in\mathbb{N}^n$ arbitrary. Then $f$ vanishes on $\partial\mathbf{\Omega}$ and
on $\partial \mathbf{\Omega}_{i_1,\ldots,i_s}:=\mathbf{\Omega}_{i_1}\cap\cdots\cap\mathbf{\Omega}_{i_s}$ for all $1\leq i_1<\ldots<i_s\leq p$, $s=1,\ldots,p$.
Hence by (\ref{stokes}):
\begin{eqnarray}
\label{stokes-alpha-1}
\int_{\mathbf{\Omega}} p_{\alpha,k} (\mathbf{x})\,\underbrace{q(\mathbf{x})\,\exp(r(\mathbf{x}))\,d\mathbf{x}}_{d\mu(\mathbf{x})}\,=\,0\\
\label{stokes-alpha-2}
\int_{\mathbf{\Omega}_{i_1,\ldots,i_s}} p_{\alpha,k} (\mathbf{x})\,\underbrace{q(\mathbf{x})\,\exp(r(\mathbf{x}))\,d\mathbf{x}}_{d\mu(\mathbf{x})}&=&0,
\end{eqnarray}
for all $1\leq i_1<\ldots<i_s\leq p$, $s=1,\ldots,p$, where
\[p_{\alpha,k} (\mathbf{x}) = q(\mathbf{x})\frac{\partial}{\partial_{x_k}} (\mathbf{x}^\alpha g(\mathbf{x})) + 2\mathbf{x}^\alpha g(\mathbf{x})\,\frac{\partial}{\partial_{x_k}}q(\mathbf{x}) + \mathbf{x}^\alpha g(\mathbf{x})q(\mathbf{x})\frac{\partial}{\partial_{x_k}} r(\mathbf{x}).\]
Recalling how $\phi^*_i$ is defined in (\ref{phistar}), it can be written as
\[\phi^*_i\,=\,\sum_{s=1}^p\sum_{1\leq i_1<\cdots<i_s\leq p}\phi^*_{i, i_1,\ldots,i_s},\]
where each $\phi^*_{i, i_1,\ldots,i_s}$ is supported on $\mathbf{\Omega}_i\cap\mathbf{\Omega}_{i_1,\ldots,i_s}$ and has a constant density w.r.t. $\mu$.
Therefore, for every $i=1,\ldots,p$:
\begin{equation}
\label{stokes-alpha-3}
\int_{\mathbf{\Omega}_i}p_{\alpha,k} (\mathbf{x})\,d\phi^*_i\,=\,0,\quad\forall \alpha\in\mathbb{N}^n;\:k=1,\ldots,n.
\end{equation}
Hence (\ref{stokes-alpha-3}) provides additional useful information
on the optimal solution $(\phi^*_1,\ldots,\phi^*_p)$ of $\mathbf{Q}$
defined in (\ref{phistar}). Namely it translates into
\[L_{\mathbf{y}^i}(p_{\alpha,k})\,=\,0,\quad\forall \alpha\in\mathbb{N}^n;\:k=1,\ldots,n;\: i=1,\ldots,p,\]
i.e., linear constraints on the moments of $\phi^*_i$, for every $i=1,\ldots,p$.

 Plugging this additional linear constraints
on the moments of $\phi^*_i$ into the relaxation $\mathbf{Q}_d$, yields the following new hierarchy
of SDP-relaxation $(\mathbf{Q}_d^{{\rm stokes}})_{d\geq d_0}$:
\begin{equation}
\label{primal-newsdp-stokes}
\begin{array}{rl}
\rho^{{\rm Stokes}}_d=\displaystyle\sup_{\mathbf{y}^1,\ldots,\mathbf{y}^d}&\Big \{\, \displaystyle\sum_{i=1}^p \mathbf{y}^i_0\\
\mbox{s.t.}&\mathbf{M}_d(\mathbf{z} - \sum_{i=1}^p \mathbf{y}^i) \succeq 0;\:\mathbf{M}_d(\mathbf{y}^i)\succeq0,\quad i=1,\ldots,p\\
& \mathbf{M}_{d-r_{ij}}(g_{ij}\,\mathbf{y}^i) \succeq 0, \quad j=1,\ldots,m_i;\:i=1,\ldots,p\\
&L_{\mathbf{y}^i}(p_{\alpha,k})\,=\,0,\quad k=1,\ldots,n;\:\vert\alpha\vert\leq 2d-{\rm deg}(p_{\alpha,k})\\
&i=1,\ldots,p\Big \}.
\end{array}
\end{equation}
By construction $\rho^1_d\geq\rho^{{\rm Stokes}}_d\geq\mu(\mathbf{\Omega})$ holds for every $d\geq d_0$,
and the analogue of Theorem \ref{thm:SDP} (with $f=1$) reads:

\begin{theorem} \label{thm:SDP-Stokes}
Consider the semidefinite programs $(\mathbf{Q}_d^{{\rm Stokes}})$, $d\geq d_0$, defined in (\ref{primal-newsdp-stokes}). Then :

\noindent
(i) $\mathbf{Q}_d^{{\rm Stokes}}$ has an optimal solution and the associated sequence of optimal values $(\rho^{{\rm Stokes}}_d)_{d\in\mathbb{N}}$ is monotone non increasing
and converges to $\mu(\mathbf{\Omega})$, that is:
\[\rho^{{\rm Stokes}}_d\,\downarrow\, \mu(\mathbf{\Omega}),\quad \mbox{as $d\rightarrow \infty$.}\]
\noindent
(ii) Let $(\mathbf{y}^{1,d},\ldots,\mathbf{y}^{p,d})$ be an optimal solution of $\mathbf{Q}^{{\rm Stokes}}_d$. Then for each $\alpha\in\mathbb{N}^n$:
\begin{equation}
\label{convergence-stokes}
\lim_{d\to\infty}\displaystyle \sum_{i=1}^py^{i,d}_\alpha \,=\, z^*_\alpha\,=\,\int_\mathbf{\Omega} \mathbf{x}^\alpha\,d\mu.\end{equation}
\end{theorem}
The proof being almost a verbatim copy of that of Theorem \ref{thm:SDP}, is omitted.

The important feature of Theorem \ref{thm:SDP-Stokes} is that we now have
the monotone non increasing convergence $\rho^{{\rm Stokes}}_d\downarrow\mu(\mathbf{\Omega})$
(compare with (\ref{convergence}) (with $\alpha=0$) in Theorem \ref{thm:SDP}).

\subsection{Gaussian measure of non compact sets $\mathbf{\Omega}$}

So far {\rm Theorem \ref{thm:SDP} and Theorem \ref{thm:SDP-Stokes} have been given for
$\mu$ supported on a box $\mathbf{B}$, and so only for sets $\mathbf{\Omega}$ in (\ref{SEMIALGDEF}) that are compact.

It turns out that for a Gaussian measure $\mu$ of (possibly non-compact) sets $\mathbf{\Omega}=\bigcup_i\mathbf{\Omega}_i$,
Theorem \ref{thm:SDP} (resp. Theorem \ref{thm:SDP-Stokes}) is still valid with exactly the same statement
and exactly the same semidefinite
relaxations (\ref{primal-newsdp}) (resp. (\ref{primal-newsdp-stokes})), except that now
 $\mathbf{z}=(z_\alpha)$ is the vector of moments of the Gaussian measure $\mu$ (instead of
 the moments of the Lebesgue measure on $\mathbf{B}$ previously).

However in the gaussian case the proof of Theorem \ref{thm:SDP}(i)-(ii) and Theorem \ref{thm:SDP-Stokes}(i)-(ii)
uses quite different arguments (some already used in \cite{lass-gaussian} for a basic semi-algebraic set). Indeed
as $\mathbf{\Omega}$ is not necessarily compact :

- The uniform bound $\sup_\alpha\vert\mathbf{z}_\alpha\vert\leq1$ is not valid any more for the relaxations $\mathbf{Q}_d$ and $\mathbf{Q}^{Stokes}_d$.

- One cannot invoke Putinar's Positivstellensatz \cite{putinar} any more.

- The standard version of Stokes' theorem where $\mathbf{\Omega}$ is compact cannot be invoked anymore either.

The new arguments that we need are the following:

$\bullet$ A crucial fact is that $\mu$ satisfies Carleman's condition
\begin{equation}
\label{carleman}
\sum_{k=1}^\infty \left(\int_{\mathbb{R}^n} x_i^{2k}\,d\mu(\mathbf{x})\right)^{-1/2k}\,=\,+\infty,\quad i=1,\ldots,n.\end{equation}
Then a sequence $\mathbf{y}=(y_\alpha)_{\alpha\in\mathbb{N}^n}$ such that $\mathbf{M}_d(\mathbf{y})\succeq0$ for all $d\in\mathbb{N}$, and
\[\sum_{k=1}^\infty L_\mathbf{y}(x_i^{2k})^{-1/2k}\,=\,+\infty,\quad i=1,\ldots,n,\]
has a unique representing measure $\phi$ on $\mathbb{R}^n$ which is moment determinate; see for instance \cite[Proposition 3.5, p. 60]{lass-book-icp}.

$\bullet$ If in addition $\mathbf{M}_d(h\,\mathbf{y})\succeq0$ for all $d\in\mathbb{N}$ (where $h\in\mathbb{R}[\mathbf{x}]$), and as $\phi$
satisfies (\ref{carleman}), then $h(\mathbf{x})\geq0$ for all $\mathbf{x}$ in the support of $\phi$; see Lasserre \cite{newlook}. This argument is used to show that $\phi$
is supported on $\mathbf{\Omega}$.

$\bullet$ To obtain a version of Stokes for  non-compact set $\mathbf{\Omega}$ with boundary $\partial\mathbf{\Omega}$, we invoke  a limiting argument
that uses (the standard) Stokes's theorem on the compact $\mathbf{\Omega}\cap \mathbf{B}(0,M)$ (where $\mathbf{B}(0,M)=\{\mathbf{x}:\Vert\mathbf{x}\Vert \leq M\}$).
Letting  $M\to\infty$ and using the Monotone and Bounded Convergence theorems yields the desired result.
For more details the reader is referred to \cite{lass-gaussian} where such arguments have been used in the case of a {\it basic} semi-algebraic set.

Finally it is worth emphasizing that this methodology also works for {\it any} measure $\mu$ that satisfies (\ref{carleman})
(and  whose moments are known or can be computed); an important spacial case is the exponential measure on the positive orthant $\mathbb{R}^n_+$.

\begin{rem}
{\rm As mentioned above, in \cite{lass-gaussian} the first author has already used Stokes' formula to accelerate the convergence
of a hierarchy of semidefinite relaxations to approximate the Gaussian measure $\mu(\mathbf{\Omega})$ of a {\it basic} semi-algebraic set
$\mathbf{\Omega}$, not necessarily compact.
The important and non trivial novelty here is that
(i) $\mathbf{\Omega}=\bigcup_{i=1}^p\mathbf{\Omega}_i$ is now a {\it union} of basic semi-algebraic sets,
and (ii) even if this complicates matters significantly,
we are still able to work with measures $\phi_i$, each supported on $\mathbf{\Omega}_i$ (a basic semi-algebraic set).
It turns out that $\mu(\mathbf{\Omega})=\sum_{i=1}^p\phi_i^*$ where is
each $\phi^*_i$ has a piecewise constant density w.r.t. $\mu$ (constant on each of the possible intersections
$\mathbf{\Omega}_i\cap \mathbf{\Omega}_{i_1,\ldots,i_p}$).
By using a family of polynomials that all vanish on the boundary of {\it each} $\mathbf{\Omega}_i\cap\mathbf{\Omega}_{i_1,\ldots,i_p}$, we
can exploit Stokes' Theorem on each piece and sum up to obtain a family of linear constraints on the moments of $\phi^*_i$.
}\end{rem}

\section{Numerical experiments and discussion}

For illustration purposes we have applied the methodology on a few (simple) examples.
We report some numerical experiments carried out in Matlab and GloptiPoly3 \cite{gloptipoly}, a software package for manipulating and solving generalized problems of moments. The SDP problems were solved with SeDuMi 1.1R3.

\subsection{Lebesgue volume of a union of two ellipsoids}

We first consider a simple example of two ellipsoids in $\mathbb{R}^2$ where the exact value
$\mu(\mathbf{\Omega})$ can be computed exactly so that we can compare with our upper bounds. So we want to compute the Lebesgue measure of
$\mathbf{\Omega} = \mathbf{\Omega}_1 \cup \mathbf{\Omega}_2$ with $\mathbf{\Omega}_1 = \{(x_1,x_2) \in \mathbb{R}^2 : \frac{x_1^2}{4} + x_2^2 \le 1\}$ and $\mathbf{\Omega}_2 = \{(x_1,x_2) \in \mathbb{R}^2 :
\frac{x_2^2}{4} + x_1^2 \le 1\}$. In this example  we take $\mathbf{B}:=[-2,2]^2$.

\begin{figure}[htb]
\centering
\includegraphics[width=0.65\columnwidth]{vol1}
\caption{$n=2$: Lebesgue measure of a union of 2 ellipsoids
\label{fig:vol1} }
\end{figure}

The results are displayed in  the Figure~\ref{fig:vol1} with:  in \textbf{orange} the approximation of the Lebesgue volume
$\mu(\mathbf{\Omega})$ without using Stokes' formulas, in \textbf{red} the approximation when using Stokes' formulas and in \textbf{blue} the
exact value of $\mu(\mathbf{\Omega})$.\\

We next consider a union of two ellipsoids in dimension $n=3$. Let $\mathbf{\Omega}_1 = \{\mathbf{x}\in \mathbb{R}^3 : x_1^2 + 4x_2^2 + 4x_3^2\le 1\}$, $\mathbf{\Omega}_2 = \{\mathbf{x}\in \mathbb{R}^3 : x_2^2 + 4x_1^2 + 4x_3^2\le 1\}$, $\mathbf{\Omega}=\mathbf{\Omega}_1\cup\mathbf{\Omega}_2$ and $\mathbf{B} = [-1,1]^3$.
Results are displayed in Figure~\ref{fig:vol2}.
In both examples one can check that the convergence is much faster when using  Stokes' formula.

\begin{figure}[htb]
\centering
\includegraphics[width=0.65\columnwidth]{vol2}
\caption{$n=3$: Lebesgue measure of a union of 2 ellipsoids \label{fig:vol2} }
\end{figure}

\subsection{Lebesgue measure a union of three ellipsoids}

We next  consider a union of three ellipsoid in dimension $n=2$, with:
\[\mathbf{\Omega}_1 = \{\mathbf{x} \in \mathbb{R}^2 : (x_1,x_2).\left[\begin{array}{cc}
\frac{16}{9} & 0\\
0 & 4
\end{array}\right]\left(\begin{array}{c}
x_1\\
x_2
\end{array}\right) \le 1\},\]
\[\mathbf{\Omega}_2 = \{(x_1,x_2) \in \mathbb{R}^2 : \frac{1}{9}(x_1-0.1,x_2-0.1).\left[\begin{array}{cc}
31 & 5\sqrt{3}\\
5\sqrt{3} & 21
\end{array}\right]\left(\begin{array}{c}
x_1-0.1\\
x_2-0.1
\end{array}\right) \le 1\},\]
\[\mathbf{\Omega}_3 = \{(x_1,x_2) \in \mathbb{R}^2 : \frac{1}{9}(x_1+0.1,x_2-0.1).\left[\begin{array}{cc}
31 & -5\sqrt{3}\\
-5\sqrt{3} & 21
\end{array}\right]\left(\begin{array}{c}
x_1+0.1\\
x_2-0.1
\end{array}\right) \le 1\},\]
and $\mathbf{B} = [-1,1]^2$. In Figure \ref{fig:vol3} we also compare our results with those obtained
when using \textit{Bonferroni} inequalities.
In \textbf{red} the upper bounds obtained by solving $\textbf{Q}^{Stokes}$, in \textbf{orange} the lower bounds
obtained by solving $\textbf{Q}^{Stokes}$ for the complement, and in \textbf{blue} the upper bounds obtained by using Bonferroni inequalities. (For a fair comparison, for each relaxation in Bonferroni case we also use appropriate Stokes' constraints.)
\begin{figure}[htb]
\centering
\includegraphics[width=0.65\columnwidth]{vol3}
\caption{$n=2$: Lebesgue measure of a union of 3 ellipsoids \label{fig:vol3} }
\end{figure}

\subsection{Examples for the Gaussian measure}

In this section we consider the Gaussian measure $d\mu = \exp(-\frac{\left\|\textbf{x}\right\|^2}{\sigma^2})d\textbf{x}$
with variance $\sigma^2 = 0.8$. For each example we have computed two upper-bounds and two lower-bounds for $\mu(\mathbf{\Omega})$. The first
(resp. second) upper-bound $\overline{\rho}_d$ (resp. $\overline{\rho}^{Stokes}_d$)
is obtained by  solving the semidefinite relaxation
$\textbf{Q}_d$ (resp. $\textbf{Q}^{Stokes}_d$). Similary, the lower-bounds $\underline{\rho}_d$ (resp. $\underline{\rho}^{Stokes}_d$) are obtained from  upper bounds
for the complement $\mathbb{R}^n\setminus\mathbf{\Omega}$. The respective relative error-gap
are denoted by $\epsilon_d= \frac{\overline{\rho}_d - \underline{\rho}_d}{\overline{\rho}_d}$ and
$\epsilon^{Stokes}_d = \frac{\overline{\rho}^{Stokes}_d - \underline{\rho}^{Stokes}_d}{\overline{\rho}^{Stokes}_d}$.

\begin{ex}
\label{ex-gauss-1}
{\rm
In this example $\mathbf{\Omega} $ is the union of two ellipsoids.
Let $\mathbf{\Omega} := \mathbf{\Omega}_1 \cup \mathbf{\Omega}_2$ with $\mathbf{\Omega}_1 = \{\textbf{x} \in \mathbb{R}^2 : (\textbf{x} - \textbf{u})^T \textbf{A}_1 (\textbf{x} - \textbf{u}) \le 1\}$ and $\mathbf{\Omega}_2 = \{\textbf{x} \in \mathbb{R}^2 : (\textbf{x} - \textbf{v})^T \textbf{A}_2 (\textbf{x} - \textbf{v}) \le 1\}$ for the values
\[
\begin{array}{ccccc}
\textbf{u} = &(0,0), &(0.1,0.5), &(0.5,0.5)
\end{array}
\]
$\textbf{v} = (1,0)$, \[\textbf{A}_1 = \left[\begin{array}{cc}
1 & 0\\
0 & \frac{1}{4}
\end{array}
\right]
\mbox{ and } \textbf{A}_2 = \left[\begin{array}{cc}
\frac{1}{4} & 0\\
0 & 1
\end{array}
\right]\]
In this case $\rho:=\mu(\mathbf{\Omega}$ can be computed exactly and so
we have displayed the values of the relative errors denoted by $\epsilon_d = \frac{\overline{\rho}_d - \underline{\rho}}{\overline{\rho}}$
and $\epsilon^{Stokes}_d = \frac{\overline{\rho}^{Stokes}_d - \underline{\rho}}{\overline{\rho}}$ respectively, depending on whether or not we have used Stokes' formula. As one can see in Table \ref{tbl:1} for  a reasonable value $d=10$
the relative error (when using Stokes' formula) is quite good. The respective behaviors are displayed in Figure \ref{gauss-1}.

\begin{table}[h]
\bgroup
\def\arraystretch{1.5
\begin{tabular}{|l|c|c|c|}
\hline
& $\textbf{u} = (0,0)$ & $\textbf{u} = (0.1,0.5)$ & $\textbf{u} = (0.5,0.5)$\\
\hline
$\overline{\rho}_{10}$ & $1.9649$ & $1.9554$ & $1.9484$\\
\hline
$\underline{\rho}_{10}$ & $1.6129$ & $1.5752$ & $1.5369$\\
\hline
$\epsilon_{10}$ & $18\%$ & $19\%$ & $21\%$ \\
\hline
$\overline{\rho}^{Stokes}_{10}$ & $1.8571$ & $1.8308$ & $1.8156$\\
\hline
$\underline{\rho}^{Stokes}_{10}$ & $1.7948$ & $1.7746$ & $1.7618$\\
\hline
$\epsilon^{Stokes}_{10}$ & $3\%$ & $3\%$ & $3\%$ \\
\hline
\end{tabular}
\egroup
\caption{Example \ref{ex-gauss-1}: Values of $\overline{\rho}_{10}$, $\underline{\rho}_{10}$, $\overline{\rho}_{10}^{Stokes}$, $\underline{\rho}_{10}^{Stokes}$, $\epsilon_{10}$ and $\epsilon_{10}^{Stokes}$ \label{tbl:1}}
\end{table}
\begin{figure}[h]
\centering
\includegraphics[width=0.65\linewidth]{vol9}
\caption{Example \ref{ex-gauss-1}: Relative errors $\epsilon_d$ (\textbf{blue}) and $\epsilon_d^{Stokes}$ (\textbf{red})
\label{gauss-1}}
\end{figure}
}\end{ex}
\newpage

\begin{ex}
\label{ex-gauss-2}
{\rm
Consider $\mathbf{\Omega} = \mathbf{\Omega}_1 \cup \mathbf{\Omega}_2$ with $\mathbf{\Omega}_1 = \{\textbf{x} \in \mathbb{R}^2 : (\textbf{x} - \textbf{u})^T \textbf{A}_1 (\textbf{x} - \textbf{u}) \le 1\}$ and $\mathbf{\Omega}_2 = \{\textbf{x} \in \mathbb{R}^2 : (\textbf{x} - \textbf{v})^T \textbf{A}_2 (\textbf{x} - \textbf{v}) \le 1\}$ for the values

$
\textbf{u} = (0,0),
$
$\textbf{v} = (-2,0)$, \[\textbf{A}_1 = \left[\begin{array}{cc}
\frac{1}{16} & 0\\
0 & 1
\end{array}
\right]
\mbox{ and } \textbf{A}_2 = \left[\begin{array}{cc}
\frac{1}{4} & \frac{1}{2}\\
\frac{1}{2} & -1
\end{array}
\right]\]
In this case $\mathbf{\Omega}$ is not a compact set as it is unbounded. The results for $d=9$ displayed in Table \ref{tbl:ex2}
show that a good value is already obtained when using Stokes' formula. The respective behaviors of $\epsilon_d$ and $\epsilon^{Stokes}_d$
displayed in Figure \ref{fig:ex2} also show that using Stokes' formula yields a significant improvement.
\begin{table}[h]
\bgroup
\def\arraystretch{1.5
\begin{tabular}{|c|c|c|c|c|c|}
\hline
$\overline{\rho}_{9}$ & $\underline{\rho}_{9}$ & $\epsilon_{9}$ & $\overline{\rho}^{Stokes}_{9}$ & $\underline{\rho}^{Stokes}_{9}$ & $\epsilon^{Stokes}_{9}$\\
\hline
$2.0038$ & $1.8252$ & $8.9\%$ & $1.9347$ & $1.9019$ & $1.7\%$\\
\hline
\end{tabular}
\egroup
\caption{Example \ref{ex-gauss-2}: Bounds and relative gap for $d=9$\label{tbl:ex2}}
\end{table}

\begin{figure}[ht]
\includegraphics[width=0.65\columnwidth]{vol11}
\caption{Example \ref{ex-gauss-2}: Relative error $\epsilon_d$ (\textbf{blue}) and $\epsilon^{Stokes}_d$
(\textbf{red}) \label{fig:ex2} }
\end{figure}
}\end{ex}

\begin{ex}
\label{ex-gauss-3}
{\rm Consider $\mathbf{\Omega} = \mathbf{\Omega}_1 \cup \mathbf{\Omega}_2$ with $\mathbf{\Omega}_1 = \{\textbf{x} \in \mathbb{R}^2 : (\textbf{x} - \textbf{u})^T \textbf{A}_1 (\textbf{x} - \textbf{u}) \le 1\}$ and $\mathbf{\Omega}_2 = \{\textbf{x} \in \mathbb{R}^2 : (\textbf{x} - \textbf{v})^T \textbf{A}_2 (\textbf{x} - \textbf{v}) \le 1\}$ for the values

$
\textbf{u} = (0,0),
$
$\textbf{v} = (-2,0)$, \[\textbf{A}_1 = \left[\begin{array}{cc}
-\frac{1}{16} & 0\\
0 & 1
\end{array}
\right]
\mbox{ and } \textbf{A}_2 = \left[\begin{array}{cc}
\frac{1}{4} & \frac{1}{2}\\
\frac{1}{2} & -1
\end{array}
\right]\]
Again $\mathbf{\Omega}$ is not compact. The results in Table \ref{tbl:ex3} and the respective behaviors of $\epsilon_d$ and $\epsilon^{Stokes}_d$
displayed in Figure \ref{fig:ex3} confirm that using Stokes' formula yields a significant improvement.
\begin{table}[h]
\bgroup
\def\arraystretch{1.5
\begin{tabular}{|c|c|c|c|c|c|}
\hline
$\overline{\rho}_{9}$ & $\underline{\rho}_{9}$ & $\epsilon_{9}$ & $\overline{\rho}^{Stokes}_{9}$ & $\underline{\rho}^{Stokes}_{9}$ & $\epsilon^{Stokes}_{9}$\\
\hline
$2.0046$ & $1.8342$ & $8\%$ & $1.9542$ & $1.9083$ & $2\%$\\
\hline
\end{tabular}
\egroup
\caption{Example \ref{ex-gauss-3}: Bounds and relative gap for $d=9$ \label{tbl:ex3}}
\end{table}

\begin{figure}[ht]
\includegraphics[width=0.65\columnwidth]{vol10}
\caption{ Example \ref{ex-gauss-3}: Relative errors $\epsilon^{Stokes}_d$ (\textbf{red}) and
$\epsilon_d$ (\textbf{blue})\label{fig:ex3}}
\end{figure}
}\end{ex}

\begin{ex}
\label{ex-gauss-4}
{\rm We next consider an example in dimension $n=3$. Let $\mathbf{\Omega}_1 = \{\textbf{x} \in \mathbb{R}^3 : (\textbf{x} - \textbf{u})^T \textbf{A}_1 (\textbf{x} - \textbf{u}) \le 1\}$ and $\mathbf{\Omega}_2 = \{\textbf{x} \in \mathbb{R}^2 : (\textbf{x} - \textbf{v})^T \textbf{A}_2 (\textbf{x} - \textbf{v}) \le 1\}$ for the values

$
\textbf{u} = (0,0,0),
$
$\textbf{v} = (-2,0,-1)$, \[\textbf{A}_1 = \left[\begin{array}{ccc}
-\frac{1}{16} & 0 & 0\\
0 & 1 & 0\\
0 & 0 & \frac{1}{4}
\end{array}
\right]
\mbox{ and } \textbf{A}_2 = \left[\begin{array}{ccc}
\frac{1}{4} & \frac{1}{2} & 0\\
\frac{1}{2} & -1 & 0\\
\frac{1}{4} & \frac{1}{4} & \frac{1}{2}
\end{array}
\right]\]

Results for $d=6$ are displayed in Table \ref{tbl:ex4} and the relative errors $\epsilon_d$ and $\epsilon^{Stokes}_d$  are displayed in  Figure \ref{fig:ex4}.
The quality of results is comparable to that in Examples \ref{ex-gauss-2} and \ref{ex-gauss-3} for $d=6$.
\begin{table}[h]
\bgroup
\def\arraystretch{1.5
\begin{tabular}{|c|c|c|c|c|c|}
\hline
$\overline{\rho}_{6}$ & $\underline{\rho}_{6}$ & $\epsilon_{6}$ & $\overline{\rho}^{Stokes}_{6}$ & $\underline{\rho}^{Stokes}_{6}$ & $\epsilon^{Stokes}_{6}$\\
\hline
$2.8222$ & $2.3123$ & $18\%$ & $2.6856$ & $2.5360$ & $5.6\%$\\
\hline
\end{tabular}
\egroup
\caption{Example \ref{ex-gauss-4}: Bounds and relative gap for $d=6$\label{tbl:ex4}}
\end{table}

\begin{figure}[ht]
\includegraphics[width=0.65\columnwidth]{vol12}
\caption{Example \ref{ex-gauss-4}:  Relative error  $\epsilon^{Stokes}_d$ ({\bf red}) and $\epsilon_d$ ({\bf blue}) \label{fig:ex4}}
\end{figure}
}
\end{ex}

\begin{ex}
\label{ex-gauss-5}
{\rm
Still in dimension $n=3$, let  $\mathbf{\Omega} = \mathbf{\Omega}_1 \cup \mathbf{\Omega}_2$ with $\mathbf{\Omega}_1 = \{\textbf{x} \in \mathbb{R}^3 : \textbf{x}^Te \le 1\}$ and $\mathbf{\Omega}_2 = \{\textbf{x} \in \mathbb{R}^3 : \textbf{x} ^T \textbf{A} \textbf{x}\ \le 1\}$, where
$e = (1,1,1)$ and \[\textbf{A} = \left[\begin{array}{ccc}
\frac{1}{4} & \frac{1}{2} & 0\\
\frac{1}{2} & -1 & 0\\
\frac{1}{4} & \frac{1}{4} & \frac{1}{2}
\end{array}
\right].\]
The relative errors $\epsilon_d$ and $\epsilon^{Stokes}_d$  are displayed in  Figure \ref{fig:ex5}.
\begin{table}[h]
\bgroup
\def\arraystretch{1.5
\begin{tabular}{|c|c|c|c|c|c|}
\hline
$\overline{\rho}_{7}$ & $\underline{\rho}_{7}$ & $\epsilon_{7}$ & $\overline{\rho}^{Stokes}_{7}$ & $\underline{\rho}^{Stokes}_{7}$ & $\epsilon^{Stokes}_{7}$\\
\hline
$2.8143$ & $2.3494$ & $17\%$ & $2.6887$ & $2.5338$ & $6\%$\\
\hline
\end{tabular}
\egroup
\caption{Example \ref{ex-gauss-5}: Bounds and relative gaps for $d=7$
\label{tbl:ex5}}
\end{table}

\begin{figure}[ht]
\includegraphics[width=0.65\columnwidth]{vol13}
\caption{Example \ref{ex-gauss-5}:  Relative error $\epsilon^{Stokes}_d$ ({\bf red}) and $\epsilon_d$ ({\bf blue}) \label{fig:ex5}}
\end{figure}
}\end{ex}

One can see that in all examples quite good approximations are obtained with relatively few moments (up to order $2d\leq 18$ for $n=2$ and
$2d\leq 14$ for $n=3$) provided that
we use the hierarchy (\ref{primal-newsdp-stokes}) with the additional  moments constraints induced by Stokes' formula. The convergence
of the hierarchy (\ref{primal-newsdp}) (without those Stokes constraints) is indeed much slower.

For all the examples that we have treated,
the (crucial) moment and localizing matrices involved in (\ref{primal-newsdp}) and in (\ref{primal-newsdp-stokes})
have been expressed
in the canonical basis $(\mathbf{x}^\alpha)_{\alpha\in\mathbb{N}^n}$ of monomials for
simplicity and easyness of implementation of the SDP relaxations. But this choice is in fact
the worst from a numerical point of view (numerical stability and robustness) which prevented us from
solving (\ref{primal-newsdp}) and (\ref{primal-newsdp-stokes}) for $d\geq 7$ when $n=3$. It is very likely that
the basis of orthonormal polynomials w.r.t. $\mu$ (Legendre for the Lebesgue measure $\mu$ on $[-1,1]$ and
Hermite for the Gaussian measure $\mu$) is a much better (and recommended) choice. Such a more sophisticated implementation was beyond the scope of this paper.

\section*{Conclusion}

In this paper we have provided a numerical scheme to approximate as closely as desired the measure
$\mu(\mathbf{\Omega})$ of a finite {\it union} $\mathbf{\Omega}=\cup_{i=1}^p\mathbf{\Omega}_i$ of basic semi-algebraic sets (the case of a single basic semi-algebraic set was treated in \cite{lass-gaussian})).
Surprisingly, even though the case of a union of semi-algebraic sets complicates matters significantly we are still able to adapt the methodology developed in \cite{lass-gaussian}
and provide a monotone non-increasing (resp. non-decreasing) sequence of upper (resp. lower)  bounds that converges to $\mu(\mathbf{\Omega})$ as the number of moments considered increases. In addition we are also able to use additional moment constraints induced by an appropriate application of Stokes' Theorem
which permits to improve significantly the convergence. In fact those additional moment constraints are crucial to obtain good bounds rapidly as they
permit strongly attenuate a Gibbs' phenomenon that otherwise appears.

Our current implementation could be significantly
improved by using a basis for polynomials more appropriate than the usual canonical basis of monomials
(the worst choice from a numerical stability point of view). For instance in doing so it should
be possible to implement step $d=8,9$ of the hierarchy in dimension $n=3$, and step $d=7$ for $n=4$. As the convergence
seems to be fast, each additional step of the hierarchy can yield a significant improvement.

The methodology was presented for the Lebesgue measure
$\mu$ when $\mathbf{\Omega}$ is compact and the Gaussian measure for non-compact sets $\mathbf{\Omega}$, but in fact and remarkably, the same methodology works for any measure
$\mu$ that satisfies Carleman's condition and provided that all its moments are available (or can be computed easily).

Of course the methodology proposed in this paper  is computationally expensive, especially when compared with Monte-Carlo type methods.
But the latter provide only an estimate of $\mu(\mathbf{\Omega})$
and by no means an upper or lower bound on $\mu(\mathbf{\Omega})$ and therefore these two types of methods should be seen as complementary rather than
competing.
In its present form it is also limited to small dimension problems (typically $n\leq 3,4$)
because since each upper (or lower) bound requires to solve a semidefinite program whose size increases fast in the hierarchy, one is
limited by the current efficiency of state-of-the-art semidefinite solvers. However to the best of our knowledge this is the first method that
provides a sequence of  upper and lower bounds with strong asymptotic guarantees, at least at this level of generality.

\subsection*{Acknowledgement}
Research  funded by by the European Research Council
(ERC) under the European Union's Horizon 2020 research and innovation program
(grant agreement ERC-ADG 666981 TAMING)"


Polynomial approximation avoiding values in sets II

Abstract: We prove some results on when functions on compact sets $K \subset \mathbb C$ can be approximated by polynomials avoiding values in given sets. We also prove some higher dimensional analogues. In particular we prove that a continuous function from a compact set $K \subset \mathbb R^n$ without interior points to $\mathbb R^n$ can be uniformly approximated by a polynomial mapping avoiding values in any given countable set $A \subset \mathbb R^n$, giving a real $n$-dimensional analogue of a recent version of Lavrentiev's theorem of Andersson and Rousu. We also prove the same result for infinite dimensional Banach spaces.

\section{Introduction}
In \cite{AndRos}, \cite{Rousu} the following version of Lavrent\'ev's theorem was proved
 \begin{thm} \label{TH1}
  Let $A \subset \C $ be any countable set, let $K \subset \C$ be  a compact set with connected complement and without interior points, and let $f$ be a continuous function on $K$. Then  given any $\varepsilon>0$ there exists some polynomial $p$ such that $p(z) \not \in A$ if $z \in K$ and such that
  \[
    \max_{z \in K} \abs{f(z)-p(z)}<\varepsilon.
  \]
 \end{thm}
 Lavrentiev's theorem \cite{Lavrentiev} is the special case where $A=\emptyset$ and Theorem \ref{TH1}  also generalize  \cite[Theorem 1]{Andersson}\footnote{A result which has applications to the Riemann zeta-function.} where it was proved for $A=\{0\}$.
 Examples of sets $K \subset \C$ with positive two dimensional Lebesgue measure where the result holds true can be given by e.g. $[0,1]+i S$ where $S \subset[0,1]$ is a fat Cantor set. In the case when the compact set $K$ has  measure zero\footnote{in which case it automatically has an empty interior} we prove this in a simpler way than in \cite{AndRos},\cite{Rousu} as a consequence of the fact that the difference set\footnote{where the difference set   $A-B=\{a-b: a \in A, b \in B\}$ here adheres to standard terminology in additive combinatorics.}   $p(K)-A$ must then also have measure zero so that its complement $(p(K)-A)^\complement$ is dense in $\C$. The general idea  will also allow us to generalize this result to higher dimensions, and also allow a sharper result when the set $K$ does not have full dimension. Finally we will adapt the method of \cite{AndRos}, \cite{Rousu} which together with the observation that if $p:\R^n \to \R^n$ is a polynomial mapping then the fact that $K$ is a compact set without interior points implies that the image $p(K)$  is also a compact set without interior points. This will allow us to prove a real $n-$dimensional analogue of Theorem \ref{TH1}.

 \section{Sumsets, translates of sets avoiding sets and polynomial approximation}
 \subsection{Some notation}
We use the following standard notation for sumsets, difference sets and sums of an element and a set
 $$A \pm B=\{a \pm b: a \in A, b \in B\} , \qquad c \pm A=\{c \pm a: a \in A\},$$
 where $c$ lies in some vector space and $A,B$ are subsets of said vector space.
\subsection{A Lebesgue measure argument}
In this and the next subsection we give some conditions (Propositions \ref{prop1}, \ref{prop2}) on when translates of sets avoids sets each of which gives a corresponding result on polynomial approximation avoiding sets (Theorems \ref{TH2}, \ref{TH3}). These Propositions in turn are direct consequences of some elementary results on sumsets (or difference sets),  Lemmas  \ref{lem1},\ref{lem2}.
 \begin{lem} \label{lem1} Let $A,K \subset \R^n$, where $A$ is countable and $K$ has $n$-dimensional Lebesgue measure 0. Then the Lebesgue measure of $A\pm K$ is also 0.
 \end{lem}
\begin{proof}
 Let $A=\{a_j\}_{j=1}^\infty$ . Then
 $$A\pm K=\bigcup_{j=1}^\infty (a_j\pm K),$$ and by the subadditivity and the translation invariance of the $n$-dimensional Lebesgue measure $\mu$ we have that
 $$\mu(A \pm K)=\mu\p{\bigcup_{j=1}^\infty (a_j\pm K)}   \leq   \sum_{j=1}^\infty \mu(a_j \pm K)=\sum_{j=1}^\infty 0 =0. $$
 \end{proof}
Our first Proposition which will give a simple proof of a special case of Theorem \ref{TH1} now follows as a direct consequence of Lemma \ref{lem1}.
\begin{prop} \label{prop1}
  Let $\varepsilon>0$, let $K \subset \R^n$ have $n$-dimensional Lebesgue measure 0 and let $A \subset \R^n$ be countable. Then for almost all    $\xi \in \R^n$ such that $|\xi|<\varepsilon$ then $(\xi +K) \cap A=\emptyset$.
 \end{prop}
\begin{proof}
By Lemma \ref{lem1} the difference set  $A-K$ has measure zero and thus also its subset $(A-K)\cap B_{\varepsilon}^\circ(0)$ also has measure zero. This means that for almost all  $|\xi|<\varepsilon$ then  $ \xi \not \in (A-K)$, which in other words means that $(\xi+K)\cap A=\emptyset$.
 \end{proof}
 Since $\C$  may be identified by $\R^2$
 we are thus ready to prove the following special case of Theorem \ref{TH1}.
\begin{thm} \label{TH2}
  Let $A \subset \C $ be any countable set, let $K \subset \C$ be  a compact set with connected complement and with measure 0, and let $f$ be a continuous function on $K$. Then  given any $\varepsilon>0$ there exists some polynomial $p$ such that $p(z) \not \in A$ if $z \in K$ and such that
  \[
    \max_{z \in K} \abs{f(z)-p(z)}<\varepsilon.
  \]
 \end{thm}
 \begin{proof}
 Since $K$ has measure zero it has no interior points and
 by Lavrientiev's theorem there exist some polynomial $q$ such that
\begin{gather} \label{a}
    \max_{z \in K} \abs{f(z)-q(z)}<\frac{\varepsilon} 2.
  \end{gather}
  Since $K$ has measure zero and $q$ is a polynomial, then also $q(K)$ has measure zero.
By Proposition \ref{prop1}  we have that there exists some $\xi \in \C$ with
 \begin{gather}
 \label{a2}
\abs{\xi}<\frac {\varepsilon} 2,
\end{gather}
such that $(q(K)+\xi) \cap A=\emptyset$, which in other words means that $p(z):=q(z)+\xi$ does not attain values in  $A$ for $z \in K$. Our conclusion follows from \eqref{a}, \eqref{a2} and the triangle inequality.
\end{proof}
\subsection{A Hausdorff dimension argument}
 We now replace the Lebesgue measure with the Hausdorff and upper box counting dimension. The following holds true
    \begin{lem}  \label{lem2}
       Suppose that $A,K \in \R^n$. Then
        \begin{gather} \label{aa1}
          \dim_H(A \pm K) \leq \dim_{H}(A)+\overline{\dim}_{B}(K)
        \end{gather}
         where $\dim_H$ and $\overline{\dim}_B$ denotes the Hausdorff dimension and upper box counting dimension\footnote{which coincides with the box/Minkowski dimension when it is defined \cite[Chapter 3.1]{falconer}} respectively.
         \end{lem}
         \begin{proof}
         From \cite[Product formula 7.3, p.99]{falconer} it follows that
         \begin{gather} \label{a1} \dim_H(A \times K)  \leq \dim_{H}(A)+\overline{\dim}_{B}(K). \end{gather}
         Now let $f:\R^{2n} \to \R^n$ be given by $f(x,y)=x\pm y$ when $x,y \in  \R^n$. It is clear that $f(A\times K)=A\pm K$ and that  $f$ is Lipschitz. Thus by \cite[Corollary 2.4]{falconer}
         \begin{gather} \label{aa2} \dim_H(A  \pm K) \leq \dim_H(A \times K).
          \end{gather}
         Our conclusion follows from the inequalities \eqref{a1} and \eqref{aa2}.
       \end{proof}
 \begin{prop} \label{prop2}
  Let $\varepsilon>0$, let $K,A \in \R^n$ and let $\overline{\dim}_B (K)+\dim_H( A)<n$ or $\dim_H(K)+\overline{\dim}_B (A)<n$. Then for almost all $\xi \in \R^n$ such that $|\xi|<\varepsilon$ then $(\xi +K) \cap A=\emptyset$.
 \end{prop}
 \begin{proof}
By Lemma \ref{lem2} the difference set  $A-K$ has dimension strictly less than $n$ and thus its $n$-dimensional Lebesgue measure is zero. It follows that also its subset $(A-K)\cap B_{\varepsilon}^\circ(0)$ has measure zero. This means that for almost all  $|\xi|<\varepsilon$ then  $ \xi \not \in (A-K)$, which in other words means that $(\xi+K)\cap A=\emptyset$.
\end{proof}
In a similar way
 to how Proposition \ref{prop1} implies Theorem \ref{TH2}, Proposition \ref{prop2} implies the following result.
 \begin{thm} \label{TH3}
  Let $K \subset \C$ be a compact set with connected complement and let $f$ be a continuous function on  $K$ and let $A \subset \C $ be a set such that
  \begin{gather*} \dim_H(A)+\overline{\dim}_B(K)<2, \\ \intertext{or} \overline{\dim}_B(A)+\dim_H(K)<2.
  \end{gather*}
   Then  given any $\varepsilon>0$ there exists some polynomial $p$ such that $p(z) \not \in A$ if $z \in K$ and such that
  \[
    \max_{z \in K} \abs{f(z)-p(z)}<\varepsilon.
  \]
 \end{thm}
  \begin{proof}
 Since $K$ does not have full dimension in $\C$ it has no interior points and
 by Lavrientiev's theorem there exist some polynomial $q$ such that
\begin{gather} \label{a9}
    \max_{z \in K} \abs{f(z)-q(z)}<\frac{\varepsilon} 2.
  \end{gather}
  Since a polynomial $q:\C \to \C$ is Lipschitz we have that $\dim_H(q(K)) \leq \dim_H(K)$ and  $\overline{\dim}_B(q(K)) \leq \overline{\dim}_B(K)$.
By Proposition \ref{prop2}  we have that there exists some $\xi \in \C$ with
 \begin{gather}
 \label{a10}
\abs{\xi}<\frac {\varepsilon} 2,
\end{gather}
such that $(q(K)+\xi) \cap A=\emptyset$, which in other words means that $p(z):=q(z)+\xi$ does not attain values in  $A$ for $z \in K$. Our conclusion follows from \eqref{a9}, \eqref{a10} and the triangle inequality.
\end{proof}
\subsection{A without interior points argument}
 It may be of some interest to prove a proposition on translates of sets avoiding sets corresponding to Theorem \ref{TH1}. We will do this and also show how this gives a new proof of Theorem \ref{TH1}.  Indeed we may use the methods of \cite{AndRos}, \cite{Rousu} to prove the following proposition which we may as well state and prove for a general Banach space $\mathcal B$.
  \begin{prop} \label{prop3}
  Let $\mathcal B$ be a Banach space, $\varepsilon>0, K \subset   \mathcal B$ be a compact set without interior points and let $A \subset \mathcal B$ be countable. Then for any $\varepsilon>0$ there exists some  $\xi \in \mathcal B$ with $\norm{\xi}<\varepsilon$ such that $(\xi +K) \cap A=\emptyset$.
  \end{prop}
  We will be able to use Proposition \ref{prop3} to give a new proof of Theorem \ref{TH1}.

  \begin{proof} (We follow the proof of \cite[Lemma 2]{AndRos} with suitable modifications.)
 Let $A=\{a_j \}_{j=1}^\infty$, let $\xi_0:=0$ and let  $0<\varepsilon_0 <\varepsilon$.
    For $j=1, 2, \ldots$ there is, since $K$ is a compact set without interior points some $\xi_j \in \mathcal B$  such that
\begin{gather}\label{neq_a}
     \delta_j:= d(K+\xi_j,a_j)>0,
    \end{gather}
    and such that \begin{equation} \label{appr}
\norm{\xi_j-\xi_{j-1}}<\frac{\varepsilon_{j-1}}{2},
\end{equation}
where $\varepsilon_j>0$ for $j\geq 1$ is definied recursively so that
\begin{equation} \label{epsj}
    \varepsilon_j < \min \left(\delta_j,\frac{\varepsilon_{j-1}} 2 \right).
\end{equation}
By  the inequalities \eqref{appr}, \eqref{epsj}, and the triangle inequality we find if $0 \leq k <l$ that
\begin{gather}\label{Cauchy}
\begin{split}
\norm{\xi_l-\xi_k}&\leq \norm{\xi_l-\xi_{l-1}}+ \cdots +\norm{\xi_{k+1}-\xi_{k}}
\\
&<\frac{\varepsilon_{l-1}}{2}
+\cdots+\frac{\varepsilon_k}{2}<\sum_{j=1}^{l-k}\frac{\varepsilon_k}{2^j}<\sum_{j=1}^{\infty}\frac{\varepsilon_k}{2^j}=\varepsilon_k.
\end{split}
\end{gather}
 By \eqref{epsj} and \eqref{Cauchy} it follows that  $\{\xi_j\}_{j=1}^\infty$ is a Cauchy-sequence in $\mathcal B$ and converges to an element   \begin{gather} \label{p} \xi:=\lim_{j \to \infty} \xi_j.
 \end{gather}
 By the definition \eqref{p} the inequality \eqref{Cauchy} implies that \begin{equation}\label{pj-p}
    \norm{\xi-\xi_j}\leq \varepsilon_j.
\end{equation}
For  $\xi$ definied by \eqref{p}, the inequalites \eqref{neq_a},  \eqref{epsj}, \eqref{pj-p}  and the triangle inequality gives us
\begin{equation} \label{yy}
    d(K+\xi,a_j) \geq d(K+\xi_j,a_j)-\norm{\xi-\xi_j} \geq \delta_j-\varepsilon_j>0,
\end{equation} for all $a_j\in A.$
  The conclusion  follows by \eqref{pj-p} and \eqref{yy}, by recalling that $ \xi_0=0$ and $0<\varepsilon_0<\varepsilon$.
 \end{proof}
   In order to give another proof of Theorem \ref{TH1} we need the following Lemma
  \begin{lem} \label{LE3}
    Let $K \subset \C$ be a compact set without interior points and let $p$ be a polynomial. Then $p(K)$ is also a compact set without interior points.
  \end{lem}
  We might as well prove the following more general lemma in order to obtain a higher dimensional analogue of Theorem \ref{TH1} (by identifying $\C$ with $\R^2$ Lemma \ref{LE3} is a direct consequence of Lemma \ref{LE4}).
  \begin{lem} \label{LE4}
    Let $K \subset \R^n$ be a compact set without interior points and let $p$ be a polynomial mapping $p:\R^n \to \R^n$. Then $p(K)$ is also a compact set without interior points.
  \end{lem}

  \begin{proof}
  Since $p$ is continuous and $K$ is compact it is clear that $p(K)$ is compact. It remains to show that $p(K)$ is nowhere dense, which since $p(K)$ is compact is equivalent to the fact that $p(K)$ has no interior points.
    The result is  true if $p(z)=Az+b,$  where $b \in \R^n$ and $A$ is a non-invertible $n\times n$ matrix. In such a case $p$ maps $\R^n$ onto an affine subspace $E \subset \R^n$ of dimension at most $n-1$. Since $E$ does not have full dimension, also $p(K) \subset E$ does not have full dimension and is thus  nowhere dense.
        Now let $p$ be a polynomial mapping $p:\R^n \to \R^n$ that is not of such type. The mapping $p$ is locally invertible whenever the Jacobian determinant $\det(J_p(z))$ of $p(z)$ is non-zero.  Let $A=\{z \in K:\det(J_p(z))=0\}$ and $p(A)=B$. It is clear that $B$ is a closed set and since $p(z)$ is not of the form $Az+b$  its Jacobian determinant is a non-zero polynomial and its zero set $C \subset \R^n$ will be a real variety of dimension at most $n-1$. Since  $p$ is a polynomial mapping which is Lipschitz, also $p(C)$ and $B=p(A) \subset p(C)$ will have Hausdorff dimension at most $n-1$ and thus be nowhere dense. Let us now assume that $p(K)$ is not nowhere dense, i.e.  there exist som open set $D \subset p(K)$. Since $B$ is a nowhere dense set, we may choose some $w \in D \setminus B$ (we remark that since $D$ is open and $B$ closed, then $D\setminus B$ is open).  Let us now  consider the equation $p(z)=w$.
         If   the equation has infinitely many roots for $z \in K$, it must have some limit point $z_0 \in K$  (since $K$ is compact) such that $p(z_0)=w$  by continuity. At such a point $z_0$ the function is not locally invertible and thus $\det(J_p(z_0))=0$ which implies that $w \in B$ contradicting our assumption that $w \in D \setminus B$. Thus we know that the equation $p(z)=w$ has  $m$ distinct roots\footnote{where by Bezouts theorem $m$ is bounded from above by $d_1 \cdots d_n$, where $d_j$ is the degree of the polynomial $p_j$ where $p=(p_1,\ldots,p_n)$} for each $j=1,\ldots,m$ and that $\det(J_p(z_j)) \neq 0$ for $j=1,\ldots,m$.  By the inverse function theorem the polynomial mapping $p$ gives homeomorphisms $f_j$ between a small neighborhood of $z_j$  for each $j=1,\ldots,m$ and a  small neighborhood of $w$. Let $\varepsilon>0$ be sufficiently small such that  $\mathcal O=B_{\varepsilon}(w)$ is a subset of $D \setminus B$ as well as all these small neighborhoods of $w$. Let $E_j=f_j^{-1}(\mathcal O)$.   It is clear that
      $$\mathcal O  \cap p(K)= \bigcup_{j=1}^m f_j(E_j \cap K)$$ is a finite union of nowhere dense sets (``nowhere dense'' is a topological property that is preserved by homeomorphisms) and thus  nowhere dense\footnote{For a proof see Proposition 7.1 in \url{https://www.ucl.ac.uk/~ucahad0/3103_handout_7.pdf}-}. This contradicts our assumption that $\mathcal O \subset D \subset p(K)$, so $p(K)$ is nowhere dense.
      \end{proof}
  \begin{rem}
    By replacing our argument for why the set of critical values of $p$ has measure zero by Sard's theorem, Lemma \ref{LE4} hold also for $\mathcal C^1$ functions.
  \end{rem}

   \noindent {\em{Proof of Theorem  \ref{TH1}.}}
    Since $K \subset \C$ is a compact set with connected complement without interior points, Lavrentiev's theorem gives us a polynomial $q$ such that
    \begin{gather} \label{a12}
    \max_{z \in K} \abs{f(z)-q(z)}<\frac{\varepsilon} 2.
  \end{gather}
  By Lemma \ref{LE3} we have that $q(K)$ is a compact set without interior points.
By Proposition \ref{prop3}  (with $\mathcal B=\C$), we have that there exists some $\xi \in \C$ with
 \begin{gather}
 \label{a21}
\abs{\xi}<\frac {\varepsilon} 2,
\end{gather}
such that $(q(K)+\xi) \cap A=\emptyset$, which in other words means that $p(z):=q(z)+\xi$ does not attain values in  $A$ for $z \in K$. Our conclusion follows from \eqref{a12}, \eqref{a21} and the triangle inequality. \qed

\section{Higher dimensional results}

\subsection{Finite dimensional results}
  One advantage with our approach is that it readily generalizes to several variables, by using higher dimensional analogues of the one variable approximation theorems (Weierstrass theorem, Lavrentiev's theorem).  By the $n$-dimensional version of the Weierstrass approximation theorem\footnote{which is an easy consequence of the Stone Weierstrass theorem, see e.g. \cite{mst} } we may prove
  \begin{thm} \label{TH4}
  Let $A \subset \R^n $ be any countable set, let $K \subset \R^n$ be  a compact set without interior points, and let $f:K \to \R^n$ be a continuous function. Then  given any $\varepsilon>0$ there exists some polynomial mapping $p$ such that $p(x) \not \in A$ if $x \in K$ and such that
  \[
    \max_{\vvx \in K} \norm{f(\vvx)-p(\vvx)}<\varepsilon.
  \]
 \end{thm}
 We remark that we will use Proposition \ref{prop3} in the proof. If we instead use Proposition \ref{prop1} (which have a somewhat simpler proof) we obtain the slightly weaker version where we have to assume that $K$ has Lebesgue measure zero.
\begin{proof} (We follow the proof of Theorem \ref{TH2}) By the multivariate Weierstrass theorem we may find a polynomial mapping $q: \R^n \to \R^n$ such that
\begin{gather} \label{aaa1} \max_{\vvx \in K}\norm{q(\vvx)-f (\vvx)}<\frac {\varepsilon} 2.
\end{gather}
 Since $K \subset \R^n$ is a compact set without interior points and $q:\R^n \to \R^n$ is a polynomial map, then by Lemma \ref{LE4} also $q(K)$ is a compact set without interior points. By Proposition \ref{prop3}  we have that there exists some $\xi \in \R^n$ with
 \begin{gather}
 \label{aaa2}
\norm{\xi}<\frac {\varepsilon} 2,
\end{gather}
such that $(q(K)+\xi) \cap A=\emptyset$, which in other words means that $p(\vvx):=q(\vvx)+\xi$ does not attain values in  $A$ for $\vvx \in K$. Our conclusion follows from \eqref{aaa1}, \eqref{aaa2} and the triangle inequality.
 \end{proof}

  \begin{thm} \label{TH5}
  Let  $K \subset \R^n$  and let $A \subset \R^m$. Furthermore assume that
   \begin{gather}
     \overline{\dim}_{B}(K)+\dim_{H}(A)<m, \\ \intertext{or}
      \dim_{H}(K)+\overline{\dim_{B}}(A)<m.
        \end{gather}
        Then given any continuous function $f:K \to \R^m$ and any $\varepsilon>0$ there exists some polynomial mapping $p$ such that $p(x) \not \in A$ if $x \in K$ and such that
  \[
    \max_{\vvx \in K} \norm{f(\vvx)-p(\vvx)}<\varepsilon.
  \]
  \end{thm}
  \begin{proof}
  (We follow the proof of Theorem \ref{TH4}) By the multivariate Weierstrass theorem we may find a polynomial mapping $q: \R^n \to \R^m$ such that
\begin{gather} \label{aaaa1} \max_{\vvx \in K}\norm{q(\vvx)-f (\vvx)}<\frac {\varepsilon} 2
\end{gather}
   Since a polynomial map $q:\R^n \to \R^m$  is Lipschitz we have that $\dim_H(q(K)) \leq \dim_H(K)$ and $\overline{\dim}_B(q(K)) \leq \overline{\dim}_B(K)$. Thus by Proposition \ref{prop2} we have that  for some $\xi \in \R^m$ with
   \begin{gather} \label{aaaa2} \norm{\xi}<\frac \varepsilon 2 \end{gather} that $(q(K)+\xi) \cap A=\emptyset$, which in other words means that $p(\vvx):=q(\vvx)+\xi$ does not attain values in  $A$ for $\vvx \in K$. Our conclusion follows from \eqref{aaaa1}, \eqref{aaaa2} and the triangle inequality.
 \end{proof}

In several complex variables Lavrentiev's theorem may be generalised to a result of Harvey-Wells\footnote{This  is a sharper version of a result of Hörmander-Wermer \cite{HWe}, see discussion in \cite[section 8.]{Levenberg}.}
 \cite{HW} that if $E$  is a {\em totally real\footnote{For the definition see \cite[p.115]{Levenberg}.}}  submanifold of class $C^1$ in an open set in $\C^n$ then for any compact $K \subset E$ where $K$ is polynomially convex then any function $f$ continuous on $K$ may be uniformly approximated by polynomials on $K$. We remark that just like the classical Weierstrass theorem is a special case of the Lavrentiev theorem (since an interval $[a,b] \in \R$ is a compact set with connected complement and without interior points in $\C$), the multivariate Weierstrass theorem is a special case of the Harvey-Wells theorem (since $\R^n$ is a totally real manifold in $\C^{n}$ and any compact set $K \subset \R^n$ is polynomially convex).

\begin{thm} \label{TH6}
 Let $E \subset \C^n$ be a totally real manifold of class $\mathcal C^1$ and let  $K \subset E$ be a compact set that is polynomially convex. Then for any continuous function $f:K \to \C^m$ and any set $A \subset \C^m$ with $\overline{\dim}_B (K) +\dim_H (A)<2m$ or ${\dim}_H(K)  +\overline{\dim}_B (A)<2m$
there exists some polynomial mapping $p$ such that \[
    \max_{z \in K} \abs{f(z)-p(z)}<\varepsilon.
  \] and such that $p(z) \not \in A$ if $z \in K$.
\end{thm}
\begin{proof}
  (We follow the proof of Theorem \ref{TH5}) By the Harvey-Wells theorem we may find a polynomial map $q: \C^n \to \C^m$ such that
\begin{gather} \label{aaaaa1} \max_{\vvx \in K}\norm{q(\vvx)-f (\vvx)}<\frac {\varepsilon} 2.
\end{gather}
Thus by identifying $\C^m$ with $\R^{2m}$ and by Proposition \ref{prop2} we have that  for some $\xi \in \C^m$ with
   \begin{gather} \label{aaaaa2} \norm{\xi}<\frac \varepsilon 2 \end{gather} that $(q(K)+\xi) \cap A=\emptyset$, which in other words means that $p(\vvx):=q(\vvx)+\xi$ does not attain values in  $A$ for $\vvx \in K$. Our conclusion follows from \eqref{aaaaa1}, \eqref{aaaaa2} and the triangle inequality.
 \end{proof}

 Since $E \subset \C^n$ is a totally real manifold of class $\mathcal C^1$ in particular means that $\dim_H (E)=\overline{\dim}_B(E) \leq n $,  a sufficient condition in Theorem \ref{TH6} is that $\dim_H A<2m-n$. We obtain the following Corollary.

\begin{cor} \label{cor}
 Let $E \subset \C^n$ be a totally real manifold of class $\mathcal C^1$ and let  $K \subset E$ be a compact set that is polynomially convex. Then for any continuous function $f:K \to \C^m$ and any set $A \subset \C^m$ with $\dim_H (A)<2m-n$
there exists some polynomial function $p$ such that \[
    \max_{z \in K} \abs{f(z)-p(z)}<\varepsilon.
  \] and such that $p(z) \not \in A$ if $z \in K$.
\end{cor}

\subsection{Infinite dimensional results}
It is well known that Weierstrass theorem on approximation of continuous functions on compact sets by polynomials generalizes from $\R^n$ to infinite dimensional real Banach spaces  \cite{ww}.  Since compact sets in infinite-dimensional Banach spaces are always without interior points the analogue of Lemma \ref{LE4} become trivial.
We are thus ready to prove our main approximation theorem on Banach spaces wich is a natural analogue of Theorem \ref{TH1} and Theorem \ref{TH6}.

\begin{thm}  \label{TH7}
 Let $\mathcal B$ be an infinite dimensional real Banach space, let $A \subset \mathcal B$ be a countable set, let $K \subset \mathcal B$ be a compact set and let $f:K \to  \mathcal B$ be a continuous function.
  Then for any $\varepsilon>0$  there exists some polynomial mapping $p:K \to \mathcal B$ such that
 \begin{gather*}
   \max_{x \in K} \norm{f(x)-p(x)}<\varepsilon,
 \end{gather*}
 and such that $p(x) \not \in  A$ if $x \in K$.
   \end{thm}

   \begin{proof}
  (We follow the proof of Theorem \ref{TH5}) By the Weierstrass approximation theorem for real Banach spaces \cite[Theorem 2.5]{ww} we may find a continuous polynomial map $q: \mathcal B \to \mathcal B$ such that
\begin{gather} \label{kk1} \max_{\vvx \in K}\norm{q(\vvx)-f (\vvx)}<\frac {\varepsilon} 2.
\end{gather}
Since $K$ is compact and  $q$ is continuous, also $q(K)$ is compact.
Since $\mathcal B$ is infinite dimensional and any compact set in an infinite dimensional Banach space is a compact set without interior points, it follows that $q(K)$ is a compact set without interior points. By  Proposition \ref{prop3} we have that  for some $\xi \in \mathcal B$ with
   \begin{gather} \label{kk2} \norm{\xi}<\frac \varepsilon 2 \end{gather} that $(q(K)+\xi) \cap A=\emptyset$, which in other words means that $p(\vvx):=q(\vvx)+\xi$ does not attain values in  $A$ for $\vvx \in K$. Our conclusion follows from \eqref{kk1}, \eqref{kk2} and the triangle inequality.
 \end{proof}

\bibliographystyle{plain}

Classical Analysis and ODEs (math.CA); Complex Variables (math.CV)