If a polynomial $P$ has only real roots, so does $P'-2xP$
Let $P$ be a polynomial such that all of the roots of $P$ are real. Prove that all the roots of $P'-2xP$ are also real. I know a proof for this fact but it is very computational and messy. Is there an elegant solution?
Let $g(x)=P(x)e^{-x^2}$. Then $$g'(x)=P'(x)\cdot e^{-x^2}+P(x)\cdot (-2x)e^{-x^2}= (P'(x)-2xP(x))e^{-x^2}. $$ We may consider $g$ to be extended to the infinities per $g(\pm\infty)=0$ because the exponential function outweighs the polynomial factor.
First assume that the roots of $P$ are distinct. Then $g$ has $n+2$ distinct zeroes, namely the $n$ zeroes of $P$ and $\pm\infty$. Between any two consecutive of these, Rolle gives us a zero of $g'$, hence a root of $P'-2xP$. This gives us $n+1$ distinct real roots, and as this corresponds to the degree, the claim follows.
You may contemplate how to make the Rolle argument rigorous when $x=\pm\infty$ is involved, and what to look out for when $P$ has roots of higher multiplicity. For the latter, I suggest to add a tiny "perturbation" to $P$ that splits multiple roots up into separate roots, and let the perturbation tend to $0$.
May assume that $P$ has $n$ distinct roots $a_1< \ldots < a_n$, otherwise the multiple roots are also roots of the new equation. The equation is equivalent to $\frac{P'(x)}{P(x)} = 2 x$, that is $$\sum_{i=1}^n \frac{1}{x-a_i} = 2x$$ On each interval $(a_i, a_{i+1})$ the LHS decreases from $+\infty$ to $-\infty$, while the RHS increases between two finite values. Therefore, the equality is achieved exactly once in each $(a_i, a_{i+1})$. Now, on the interval $(a_{n}, \infty)$, LHS decreases from $+\infty$ to $0$, while RHS increases from a finite value to $+ \infty$. So we have exactly one root in $(a_{n}, \infty)$. Similarly in $(-\infty, a_1)$. We conclude that the equation has exactly $n+1$ solutions. Note that we can substitute $2 x$ with any continuous increasing function with infinite limits. The case of a constant is also interesting. The picture for $P(x)=(x+1)(x-1)(x-2)$ is below.
Note: @Hagen von Eitzen: 's method works for any functions $P(x)$, since $(e^{-L(x)}P(x))' = e^{-L(x)}( P'(x) - l(x) P(x))$, so we do get a root ( an odd number) between two (consecutive) roots of $P(x)$. If $e^{-L(x)}P(x)$ is $0$ at $\pm \infty$ $ we do get extra roots.
Does our method work for functions $P(x)$ that are not polynomial? Say $a$, $b$ are consecutive simple roots of $P(x)$. Then $P'(a)$, $P'(b)$ are of opposite value so on the interval $(a,b)$ the function $\frac{P'(x)}{P(x)}$ ranges from $+\infty$ to $-\infty$. At $\pm \infty$ it's about the behaviour of $\frac{P'(x)}{P(x)}$. The method seems to still work.
$\bf{Added:}$ Say we are want to show that $(x-\alpha) P'(x) + \lambda P(x)=0$ has all roots real ( $\lambda> 0$ or $\lambda < -n$) (Laguerre). Consider the derivative of $|x-\alpha|^{\lambda} P(x)$. Or we can do the analysis with $\frac{P'(x)}{P(x)}$.