Minimal representation of a polynomial as a linear combination of squares Given a polynomial of degree $2n$ over $\mathbb{Q}$, how to represent it as a linear combination (with rational coefficients) of squares of polynomials of degree at most $n$ over $\mathbb{Q}$ such that the number of polynomials is minimal?
In particular, when it is possible to represent a given polynomial of degree $2n$ as a linear combination of two squares of polynomials of degree at most $n$?
 A: Ok, here's how to write a polynomial $f$ of degree $2n$ as a linear combination of three squares. We can assume $f$ is monic, since everything can be scaled at the end. Now, complete squares, starting from the top degree term. So we can write $f = g^2 + h$, where $g$ is monic of degree $n$, and $h$ has degree at most $n-1$. Then write $h = \frac{1}{4}(h+1)^2 - \frac{1}{4}(h-1)^2$ to finish it off. Three squares is optimal: a little bit of work shows that $x^4 + x + 1$ cannot be written as a linear combination of two squares (the same holds for a generic quartic polynomial). I guess this doesn't fully answer your second question of how to characterize linear combinations of two squares of degree $n$.
A: Here is a comment relating the question to representations of sums of five squares of rational polynomials (sorry, too long for the comment field):
Suppose that $f$ is a linear combination of two squares of polynomials, i.e., $f=u^2-rv^2$ for some $r\in \mathbb{Q}$,
and $u,v\in \mathbb{Q}[x]$. If $r\le 0$, then $f$ need to be nonnegative. As $-r$ is the sum of four rational squares, we can write $f$ as the sum of five squares of rational polynomials. Conversely, if $f$ is nonnegative, then it is known that $f$ can be written as the sum of five squares of rational polynomials, $f=u_1^2+\cdots +u_5^2$. This is due to Pourchet, 1971,
"Sur la représentation en somme de carrés des polynômes à une indéterminée sur un corps de nombres alge ́briques". This result is best possible as far as the number of squares needed for such representations is concerned.
Edit: The result of Pourchet does not imply that $f$ may not be a linear combination of two squares of rational polynomials.
Consider the example $f(x)=x^2+x+4$. Since $4ac-b^2=15$ cannot be represented as a sum of three rational squares, the polynomial $f$ cannot be represented as the sum of squares of $4$ rational polynomials.
However,
$$
f(x)=x^2+x+4=\left( \\frac{x-7}{4}\right)^2+\frac{15}{16}(x+1)^2.
$$
If $r>0$, then $f$ must be reducible over $\mathbb{R}$, as $f=(u-\sqrt{r}v)(u+\sqrt{r}v)$ (see the comment of i707107).
A: If $f = u^2- r v^2$, then $f=(u-\sqrt{r}v)(u+\sqrt{r}v)$, so $f$ is reducible over $\mathbb Q(\sqrt{r})$.  This provides a strong condition on the Galois group of $f$ -  an index $2$ subgroup must act nontransitively on the roots. In other words, the Galois group must be a subgroup of the wreath product of $\mathbb Z/2$ and $S_n$.
Any polynomial with Galois group full$S_{2n}$, $n>1$, violates this condition.
On the other hand, a polynomial that does satisfy this Galois group condition can be written in this way. Over $\mathbb Q(\sqrt{r})$, it splits into two factors, say $a + b\sqrt{r}$ and $c+d\sqrt{r}$. But these two factors must be Galois conjugates, so $c=a $ and $d=-b$. So $f=a^2-r b^2$. (This is all up to a constant factor)
A: Somewhat related topic is the Waring problem for polynomials, namely to estimate the number 
$k(n)$ such that every polynomial $P(x)$ over $\mathbb{C}[x]$ can be represented as a sum
$P(x)=\sum_{k=1}^{k(n)}Q_k(x)^{n}.$ Clearly, $k(2)=2$ (just take $P(x)=1/4(P(x)+1)^2-1/4(P(x)-1)^2.$ This particular example shows that the number of polynomials needed to represent over $Q[x]$ can be larger than $k(n).$ In general, for $n\ge 3$ Newman and Slater ($1979$) proved the bound $k(n)\le n< k^2(n)-k(n).$    
