Analytic approximations of smooth vector fields Let $M$ be the set of smooth divergence-free vector fields $u$ on $\mathbb{R}^3$ with
$$|\partial_x^{\alpha} u(x)| \leq C_{\alpha K}(1+|x|)^{-K}$$
on $\mathbb{R}^3$ for any $\alpha,K$.
Further, we consider the subset of analytic functions $M_0 \subset M$. The question is now, whether for each $u \in M$ and $\varepsilon >0$, there is an $v \in M_0$, such that
$$|u(x)-v(x)| < \varepsilon$$ for each $x \in \mathbb{R}^3$.
As a second question consider $M$ to be the set of smooth divergence-free vector fields $u$ on $\mathbb{R}^3$ with
$$u(x+e_j) = u(x)$$
for all $x \in \mathbb{R}^3$ and $1 \leq j \leq 3$.
Again, consider the subset of analytic functions $M_0 \subset M$. The question here is now again, whether for each $u \in M$ and $\varepsilon >0$, there is an $v \in M_0$, such that
$$|u(x)-v(x)| < \varepsilon$$ for each $x \in \mathbb{R}^3$.
These questions are fairly similar to the Stone-Weierstrass theorem, but it seems it is not possible to derive it directly from it.
 A: I believe the most natural approach to this particular question is via Fourier analysis. In the periodic case we have the series
$$u(x)=\sum_{k\in\mathbb{Z}^3}u_k e^{2\pi i (k,x)},$$
and the condition $\nabla\cdot u=0$ simply means $(u_k,k)=0$.
Taking
$$v(x)=\sum_{|k|<K}u_k e^{2\pi i (k,x)}$$
for sufficiently large $K>0$ we can approximate $u$ as close as we want because the Fourier series of a smooth function converges uniformly and very quickly. Obviously, a polynomial $v(x)$ is analytic.
The same trick works in the first case too  except the Fourier series has to be replaced  by the Fourier integral, and the fact that $v$ is  analytic may be a little less obvious (but still true).
A: Here is how to derive both results from the Stone-Weierstras theorem. As you say, it's not direct, but not a long way either. Recall these simple applications of the S-W theorem, to be used in PB1 resp. in PB2

*

*The algebra $A$ of rapidly decreasing real analytic functions on $\mathbb{R}^3$ is uniformly dense in the space of continuous functions vanishing at infinity on $\mathbb{R}^3$. This follows from the S-W theorem applied to the one-point compactification  $\mathbb{R}^3\cup\{\infty\}$, the $3$-sphere. To check that the above algebra separates points it is sufficient to consider the function $\exp(-\|x\|^2)$ and its translates.


*The algebra $A$ of $\mathbb{Z}^3$-periodic real analytic functions on $\mathbb{R}^3$ is uniformly dense in the space of $\mathbb{Z}^3$-periodic continuous functions on $\mathbb{R}^3$. This follows from the S-W theorem applied to the quotient $\mathbb{R}^3/\mathbb{Z}^3$, the $3$-torus. To check that the above algebra separates points it is sufficient to consider the functions $\sin(2\pi x_1)$, $\sin(2\pi x_2)$, $\sin(2\pi x_3)$ and their translates.
Now, given $u\in M$ and $\epsilon>0$, we find $w_i\in A$, such that $\|u_i-w_i\|_{\infty}\le\epsilon$ (for $i=1,..,3$). To define a divergence-free approximation $v=(v_1,v_2,v_3)\in M_0$, we may then take $v_1:=w_1$, $v_2=w_2$ and for all $(x,y,z)\in\mathbb{R}^3$
$$v_3(x,y,z):=w_3(x,y,0)-\int_0^z\big\{\partial_1w_1(x,y,s)+\partial_2w_2(x,y,s)\big\}ds.$$
It is easy to check that, both in problem 1 and 2, $v_3\in A$, that ${\rm div\, } v=0$, and that $v$ is still uniformly close to $u$.
