By the fundamental theorem of algebra a real nonconstant polynomial $Q$ has factorisation into real prime factors $$Q=g_1^{k_1}g_2^{k_2}\cdots g_l^{k_l}$$ The prime factors $g_j$, all distinct, are first degree polynomials or second degree polynomials without real roots. The exponents are positive integers. The polynomial $Q$ is called square-free if all the exponents $k_j$ equal 1.
Exercise:
Let $\psi$ be square-free polynomial of degree $d$ and $P$ have degree less than $2d$ and no prime factor in common with $\psi$. Show that the integral $\int\frac{P}{\psi^2}$ is rational if and only if $\psi$ divides $P'\psi'-P\psi''.$
My sratch work:
I have noticed that $$(\frac{P}{\psi'})'=\frac{P'\psi'-P\psi''}{(\psi')^2}$$ So I decided use this pattern in the given integral bu using integration by parts :$$\int\frac{P}{\psi^2}=\int(\frac{P}{\psi'})(\frac{1}{\psi^2}\psi')=\frac{P}{\psi'}(\frac{-1}{\psi})+\int\frac{1}{\psi}\frac{P'\psi'-P\psi''}{(\psi')^2}$$ Meanwhile the first sum in the right is rational we should care about the rightside integral. Lets consider $$\int\frac{1}{\psi}\frac{P'\psi'-P\psi''}{(\psi')^2}=\frac{A}{B}$$ Where A and B are polynomials. So we get $$\frac{1}{\psi}\frac{P'\psi'-P\psi''}{(\psi')^2}=\frac{A'B-B'A}{B^2} $$but how judge after I couldn't proceed.
Maybe, another approach is using Hermite-Ostragradski method of integration. In this case the integral becomes $$\int \frac{P}{\psi^2}=\frac{P_1}{\psi}+\int \frac{P_2}{\psi}$$ The integral on the right hand side is transcendental function since the denominator $\psi$ is square free and the numerator has lower degree than the denominator. In order integral to be rational the rightside integral should be equal $0$. So we get an equality $$\int \frac{P}{\psi^2}=\frac{P_1}{\psi}$$ and diferrentiate both side :$$\frac{P}{\psi^2}=\frac{P_1'\psi-P_1\psi'}{\psi^2}$$ However I am still unable to proceed further. Could anybody help me please.
You just need to combine the two approaches in your answer!
Let $\psi Q=P'\psi'-P\psi''$. Your first approach gives $$\int\frac P{\psi^2}=-\frac P{\psi\psi'}+\int\frac Q{\psi'^2}$$ and your second approach gives $$\int\frac P{\psi^2}=\frac{P_1}\psi$$ where upon differentiation, $P_1$ satisfies $P_1'\psi=P_1\psi'+P$.
Therefore, $$\frac{P_1}\psi=-\frac P{\psi\psi'}+\int\frac Q{\psi'^2}\iff\int\frac Q{\psi'^2}=\frac{P_1\psi'+P}{\psi\psi'}=\frac{P_1'}{\psi'}$$ and differentiating both sides yields $Q=P_1''\psi'-P_1'\psi''$ which is a polynomial.