Counting roots of oscillatory functions Consider the functions $f_m : [0,1] \to \mathbb{R}$ defined by

$f_m(x) = \displaystyle\sum_{n=1}^{m} \frac{\sin(nx)}{1+\sin^2(n)}$

for every natural number $m$. My task is to find the number of roots of this function for every $m$. After some thought, I think it behaves similarly to the function $g_m(x) = \sum_{n=1}^{m}\sin(nx) = \frac{\sin{(m+1)x/2}}{\sin{(x/2)}}\sin{(mx/2)}$ which has roots $x= 2k\pi/m$, $0 \le k \le m/2\pi$ and $x = 2l\pi/(m+1), 0 \le l \le (m+1)/2k\pi$. This gives $\left\lfloor \frac{m}{2\pi}\right\rfloor+\left\lfloor \frac{m+1}{2\pi}\right \rfloor+1$ roots in the interval $[0,1]$ for the function $g_m$.
This did match the number of roots of $f_m$ for some values of $m$, however, inconsistencies were noticed for values of $m$ near $31$. Roots of $g_m$ tell us that the number of roots must keep increasing as $m$ increases, which doesn't seem to be true for $f_m$. The number of roots decreased from $9$ to $8$ from $m=30$ to $31$, and $11$ to $9$ from $m=32$ to $33$. Any hints on how to proceed with this problem? We perhaps require an appropriate correction term with $g_m$.
 A: $$\sin(nx) = \sin(x) U_{n-1}(\cos(x))$$
where $U_k$ are the Chebyshev polynomials of the second kind.
So (besides $0$) you're asking for the number of roots of the polynomial
$$ P_m(t) = \sum_{n=1}^m \frac{U_{n-1}(t)}{1+\sin^2(1) U_{n-1}(\cos(1))^2}$$
in the interval $[0, \cos(1)]$.
But because of the involvement of the transcendental constant $\cos(1)$, I doubt that
you'll get a "closed form" for the number of roots.
A: This is not an answer but it may be helpful. There is a known formula for the number of roots of a function $f$ in the interval $[a,b]$, namely:
$$
N(a,b) = \int_a^b  \delta (f(x) ) \vert f'(x) \vert dx \, , 
$$
where $\delta$ is Dirac's delta. As it is I'm not sure that this formula is easier to deal with than explicitly counting the roots (with some numerical algorithm). For example you can thing of approximating the Dirac delta with a peaked Gaussian and estimate the integral.
You can also look at this question which is of similar nature though your function is periodic.
