For a polynomial $f(x) = \sum\_{i=0}^dc\_ix^i \in \mathbb Z[x]$ of degree $d$, let


$$
H(f):=\max\limits\_{i=0,1,\ldots, d}\{|c\_i|\}
$$


denote the naive height. Further, define


$$
R(M, r, d) := \#\{f(x) \colon \text{$H(f) \leq M$, $\deg f = d$ and $f(x)$ has extactly $r$ real roots}\}.
$$


I wonder if anything is known about the quantity $R(M,r,d)$. More precisely, I am interested how it changes as $r$ and $d$ remain fixed and $M$ varies. Has this question been explored at all? I would be thankful for any references.



Proportion of polynomials of a fixed degree with a certain number of real roots
The quadratic case can be dealt with as follows. A quadratic polynomial $f(x) = ax^2 + bx + c \in \mathbb{Z}[x]$ has two distinct real roots if and only if $\Delta(f) = b^2 - 4ac > 0$, and a pair of complex conjugate roots if and only if $\Delta(f) < 0$. 


We now let $a,b,c$ vary in the box $[-X,X]^3$. We first pick a pair $(a,c) \in \mathbb{Z}^2 \cap [-X,X]^2$. If $ac < 0$, that is, if the pair $(a,c)$ lies in two of four quadrants, then $\Delta(f) > 0$; hence 100% of quadratic polynomials with $a,c$ coming from those two quadrants have two real roots. The remaining two quadrants are symmetric to each other, so we might as well consider only the positive quadrant. We can exploit symmetry once more to assume that $a \leq c$, and from density considerations we can carve out the 0-density sets corresponding to $a = 0$ and $a =c$; whence we assume $0 < a < c$. 


The count of triples $(a,b,c)$ satisfying $0 < a < c \leq X$ and $\Delta(f) < 0$ can be estimated by the triple integral


$$\displaystyle \int\_1^X \int\_1^c \int\_{-2\sqrt{ac}}^{2 \sqrt{ac}} db da dc = \frac{8}{9} X^3 + O(X^2).$$


Multiplying by 4 to account for the assumption that $a \leq c$ and $a,c > 0$ (and using standard geometry of numbers arguments), we see that the total number of negative discriminant quadratic polynomials of height at most $X$ is 


$$\displaystyle N^+(X) = \frac{32}{9} X^3 + O(X^2).$$


The number of positive discriminant forms is then 


$$\displaystyle N^{-}(X) = 8X^3 - \frac{32}{9} X^3 + O(X^2) = \frac{40}{9} X^3 + O(X^2).$$


One can do a similar (but much more difficult) argument for cubic polynomials (binary forms), by exploiting the fact that for a cubic binary form $g(x,y) \in \mathbb{Z}[x,y]$, its Hessian covariant $q\_g(x,y)$ (which is a quadratic form) has discriminant $-3\Delta(g)$; and hence the problem of counting cubic binary forms with three or one real linear factors is reduced to dealing with the Hessians. However, the inequalities involved are no longer linear in general, and hence the application of geometry of numbers methods will be more complicated. Cremona also worked out the exact conditions for quartic polynomials to have 0, 2, or 4 real roots in <https://homepages.warwick.ac.uk/~masgaj/papers/r34jcm.pdf>


I suspect the methods I used above become intractable very quickly with respect to the degree, so perhaps a different formulation is necessary to make progress.


Addendum: I should add that the answer to the question is known for degrees 3 and 4 if instead one counts $\operatorname{GL}\_2(\mathbb{Z})$-classes of binary forms (of degrees 3 and 4 respectively) with respect to an appropriate $\operatorname{GL}\_2(\mathbb{Z})$-invariant height. In particular, when $d = 3$ and we put the height as the discriminant, we have


\begin{align\*} N\_3(X)& = \# \{F = a\_3 x^3 + a\_2 x^2 y + a\_1 xy^2 + a\_0 y^3 \in \mathbb{Z}[x,y]: |\Delta(F)| \leq X\} \\
& = \frac{\pi^2}{18} X + O(X^{5/6}),
\end{align\*}
and $N\_3^{\pm}(X)$ (which counts the number of forms of bounded positive/negative discriminant, respectively) is given by


$$\displaystyle N\_3^+(X) = \frac{\pi^2}{72} X + O(X^{5/6}), N\_3^-(X) = \frac{\pi^2}{24} X + O(X^{5/6}).$$


The main term was first obtained by Davenport, and the error term as given was obtained by Shintani. Taniguchi and Thorne and Bhargava-Shankar-Tsimerman independently obtained a secondary main term of order $X^{5/6}$. If one includes this secondary term, then the error term is $O(X^{3/4+\varepsilon})$. 


For the degree 4 case, if we put the height as $H(F) = \max\{|I(F)|^3, J(F)^2/4\}$, as in Bhargava-Shankar (<http://annals.math.princeton.edu/2015/181-1/p03>), and put $N\_4^{(0)}(X), N\_4^{(1)}(X), N\_4^{(2)}(X)$ for the number of $\operatorname{GL}\_2(\mathbb{Z})$-classes of integral quartic forms of height at most $X$ with 0 pairs of complex conjugate linear factors, 1 pair of complex conjugate linear factors, and 2 pairs of complex conjugate linear factors respectively. They showed that


$$\displaystyle N\_4^{(0)}(X) = \frac{4 \zeta(2)}{135} X^{5/6} + O\_\varepsilon(X^{3/4 + \varepsilon}),$$
$$\displaystyle N\_4^{(1)}(X) = \frac{32 \zeta(2)}{135} X^{5/6} + O\_\varepsilon(X^{3/4 + \varepsilon}),$$
and
$$\displaystyle N\_4^{(2)}(X) = \frac{8 \zeta(2)}{135} X^{5/6} + O\_\varepsilon(X^{3/4 + \varepsilon}).$$


Sorting by a $\operatorname{GL}\_2(\mathbb{Z})$-invariant height is likely a more natural question and possibly easier than the original question. 


