TITLE: Hilbert's 17th Problem for smooth functions
QUESTION [11 upvotes]: Consider an open subset $U \subseteq \mathbb{R}^n$ and a smooth function $f\colon U \longrightarrow \mathbb{R}$ with $f(x) \ge 0$ for all $x \in U$.
It is then known (if I remember correctly: by Michor?) that $f = g^2$ with a function $g$ which can be shown to be twice differentiable but not $C^2$ in general. In particular, a smooth square root does not exist in general.
My question is whether $f$ can be represented as a sum of squares of smooth functions, i.e. the smooth version of Hilbert's problem 17, and if so, what is the minimal number of squares needed?

REPLY [4 votes]: Quoting from the introduction of Brumfiel's book Partially Ordered Rings and Semi-Algebraic Geometry (1979, CUP LMS Lecture Notes 37):

As a final remark on the birational interpretation of Artin's solution of Hilbert's 17th problem, consider a different category, that of smooth manifolds and smooth real valued functions.  Then Paul Cohen has shown me that (i) there exist nowhere negative smooth functions on any manifold which are not finite sums of squares of smooth functions (in fact, the zero set can be a single point) and (ii) given any nowhere negative smooth $f$, there are $h$, $g$, both smooth and $h$ not a zero divisor, such that $h^2f = g^2$.  The zero divisors are, of course, the smooth functions which vanish on some open set.

If the statement is correct ("on any manifold"), then there should be a counterexample on $\mathbb{R}$.  I would love to see how it is constructed!  But it does not seem to have been published, because in the 2005 paper ("Sommes de carrés de fonctions dérivables", Bull. Soc. Math. France, 133, 619–639) in which he proves (inter alia) that at least a $C^\infty$ function $f$ on $\mathbb{R}$ that is nonnegative can be written as $g^2 + h^2$ where $g$ and $h$ are $C^m$ for $m$ arbitrarily large but finite, Jean-Michel Bony mentions these counterexamples and asserts that, as far as he knows, they have not been published (he points to the aforementioned book, and also the book Real Algebraic Geometry by Bochnak, Coste and Roy, where a similar statement is attributed to P. Cohen and D. Epstein: see §6.6.4).