How many linear functions in $\mathbb{Q}[x]$ are needed to write $px^2+q$ as a sum of squares? Consider the quadratic polynomial $px^2+q$ for positive integers $p,q$. What is 
the smallest $n$ such that $$px^2+q=\sum_{k=1}^n (a_k x+b_k)^2$$ where $\{a_k\},\{b_k\}$ are rational?
One can prove a simple upper bound: If the integers $p,q$ may be respectively decomposed in rational squares as $$p=\sum_{k=1}^{n_p} a_k^2,\qquad q=\sum_{k=1}^{n_q} b_k^2,$$ then one has the trivial decomposition $$px^2+q = \sum_{k=1}^{n_p} (a_k x)^2 +\sum_{k=1}^{n_q} (b)_k^2.$$ Hence if $p,q$ respectively can be written as sums of $n_p,n_q$ rational squares then $px^2+q$ can be written as a sum of $n=n_p+n_q$ squares of linear functions with rational coefficents.
The case of $(p,q)=(1,7)$ recently appeared on this site as Find the minimum $n$ such that $x^2+7=\sum_{k=1}^n f_k(x)^2$ where $f_k(x)\in \mathbb{Q}[x]$. Since $7=1^2+1^2+1^2+2^2$ and $1=1^2$, the argument above establishes that the minimum $n$ is at most $n_p+n_q=4+1=5$. The nontrivial part is to rule out any smaller examples, with Mindlack's answer proving that $n>4$ in that example. However, his answer makes critical use of the fact that $7$ cannot be written as a sum of three rational squares. It is therefore interesting whether $n=n_p+n_q$ is generically the smallest such $n$ or if can be improved further for certain choices of $p,q$.
 A: A complete answer can be given as follows. I will first state the results and then I will give some explanations or references.
$px^2 + q = \sum_{i=1}^n (a_k x + b_k)^2$ for rational numbers $a_k, b_k$ if and
only if the two-dimensional quadratic form $<p,q>$ is a subform of $n<1>$, where
$n<1>$ stands for the quadratic form $y_1^2 + \cdots + y_n^2$ and $<p,q>$ stands for the quadratic form $p x_1^2 + q x_2^2$.
It can be shown that $<p,q>$ is always a subform of $5<1>$.
In addition, as already noted in a comment, it can be shown that $<p,q>$ is a subform of $4<1>$ if and only if $pq$ is a sum of three rational squares.
Next, $<p,q>$ is a subform of $<1,1,1>$ if and only if $<p,q,pq>$ is rationally
equivalent to $<1,1,1>$.
Finally, $<p,q>$ is equivalent to $<1,1>$ if and only if $pq$ is a rational square and $p$ is a sum of two rational squares.
For the first statement, let $\vec{a} = (a_1, \ldots, a_n)$ and
$\vec{b} = (b_1, \ldots, b_n)$.  Then the equation
$px^2 + q = \sum_{i=1}^n (a_k x + b_k)^2$ is equivalent to the vector equations
$\vec{a} \cdot \vec{a} = p$, $\vec{a} \cdot \vec{b} = 0$, and
$\vec{b} \cdot \vec{b} = q$.  Since $\vec{a}, \vec{b}$ must be linearly independent, this is equivalent to knowing that
$<p,q>$ is equivalent to a subform of $n<1>$.
It is not easy to prove that $<p,q>$ is always a subform of $5<1>$, but it easy to give a proof assuming the truth of the Hasse-Minkowski Theorem.
Since $p$ is a sum of four squares, one shows that
$5<1>$ is equivalent to $<p, r,s,t,u>$ for rational numbers $r,s,t,u$.
The Hasse-Minkowski Theorem implies that $<r,s,t,u>$ is equivalent to
$<q,c,d,e>$ for rational numbers $c,d,e$.  Thus $<p,q>$ is a subform of $5<1>$.
(This result for $5<1>$ was first proved by Landau in 1919 without using the Hasse-Minkowski theorem.  He had to work harder.)
Using a bit of quadratic form theory that can be found in Lam's textbook on quadratic forms, we can argue that $<p,q>$ is a subform of $4<1>$ if and only if
$<p,q>$ is a subform of $4<p>$ if and only if $<q>$ is a subform of $<p,p,p>$ if
and only if $<pq>$ is a subform of $<1,1,1>$ if and only if
$pq$ is a sum of $3$ rational squares.
The remaining two statements are easier to prove using basic results from Lam's book.
