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?

Comparing terms of degrees $0$, $2$, $4$ and $6$ in a Talyor series around $0$, we see that $a_i=b_i=c_i=0$ and $z^6 + x^4 y^2 + x^2 y^4 − 3x^2 y^2 z^2 = \sum d_i(x,y,z)^2$. It is well known (see e.g. Wikipedia) that the left hand side is not a sum of squares of cubics.

@David: First of all, thanks a lot. That solves the (interesting) cases of dimension $\ge 3$. I guess there are similar examples for $n = 2$. But what happens in $n=1$? Here the Taylor expansion argument won't work (if I'm correct: Hilbert's problem is OK for polynomials in $1$ variable, right?) to produce a counter-example. Are there any other? The problem I have is that already in one dimension, the zeros of a smooth function can cluster in a rather nasty way... (?)
–
Stefan WaldmannFeb 2 '11 at 13:03

I don't know what happens in $n=1$ and $n=2$. My guess would be that the answer is "yes" in those low dimensions, and that the key will be some sort of partition of unity argument. But I don't have an actual proof.
–
David SpeyerFeb 2 '11 at 14:21

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).