This question is about decomposing real polynomials which are positive on some subset of $\mathbf{R}$.
Level 1:
Let $P \in \mathbf{R}[X]$ such that $P(x) \geq 0$ for all $x \in \mathbf{R}$.
Let us consider $\mathcal{S} = \{ A^2+B^2 \textrm{ | } (A, B) \in \mathbf{R}[X]^2 \}$. $\mathcal{S}$ is stable by multiplication. Indeed, $(A^2+B^2)(C^2+D^2) = (AD-BC)^2+(AC+BD)^2$. By considering the irreducible factors of $P$, we can show they all belong to $\mathcal{S}$, so $P$ itself belongs to $\mathcal{S}$.
So there exists $(A, B) \in \mathbf{R}[X]^2$ such that $P = A^2+B^2$.
Level 2:
Let $P \in \mathbf{R}[X]$ such that $P(x) \geq 0$ for all $x \in \mathbf{R}_+$.
Now, let's take $\mathcal{S} = \{ A^2+ X B^2 \textrm{ | } (A, B) \in \mathbf{R}[X]^2 \}$. $\mathcal{S}$ is still stable by multiplication because $(A^2+XB^2)(C^2+XD^2) = (AC+XBD)^2 + X(AD-BC)^2$. By considering the irreducible factors of $P$, we can show they all belong to $\mathcal{S}$, so $P$ itself belongs to $\mathcal{S}$.
So there exists $(A, B) \in \mathbf{R}[X]^2$ such that $ P = A^2 + X B^2 $.
Level 3:
Let $P \in \mathbf{R}[X]$ such that $P(x) \geq 0$ for all $x \in [-1, 1]$.
I am trying to find an expression of $P$ of the same kind as above. But I do not know which set $\mathcal{S}$ to consider. Any clue?
My try:
I have looked at the $A^2-XB^2$ and $XA^2+XB^2$ but no one seems to be suitable.
This is Lukacks theorem (see Szego Orthogonal Polynomials preliminaries for example - if you are in the USA, the Amazon Look Inside covers that) which is based on Feijer's well-known theorem about non-negative trigonometric polynomials as squares of absolute values of regular polynomials of the same degree.
If $P(x) \ge 0, -1 \le x \le 1$ then:
if $\deg P$ is even, $P(x)=A^2(x)+(1-x^2)B^2(x)$, $A,B$ real polynomials s.t. each term on RHS has degree at most the degree of $P$
if $\deg P$ is odd, $P(x)=(1+x)C^2(x)+(1-x)D^2(x)$, $C,D$ real polynomials s.t. each term on RHS has degree at most the degree of $P$