# Integrating a function over the interval formed by the largest two real roots of a cubic equation

Description of the problem: Suppose I have a depressed cubic equation $$-x^3+p^2x-q^2=0$$ under the condition (the local max is larger than zero and local min is less than zero)

$$-\frac{2}{3\sqrt 3} |p|^3

so that it has three real roots $$x_1(p,q) and over the interval $$(x_2(p,q),x_3(p,q))$$ formed by the largest two roots of it, the function $$-x^3+p^2x-q^2$$ has negative value.

Now I want to evaluate the integral:

$$I:=\int_{x_2}^{x_3}\frac{-x^3+p^2x-q^2}{x^4}~dx$$

and get a expression in terms of $$p,q$$ without the imaginary unit $$i$$.

My attempts and questions:

(1) The command

Reduce[-x^3 + p^2 x - q^2 == 0, x]


Only returns three roots (with imaginary unit $$i$$) and it is hard to tell which two are the largest.

(2) The condition $$-\frac{2}{3\sqrt 3} |p|^3 probably means nothing to Mathematica ? No matter it is satisfied or not, we always have imaginary expressions in $$x_2,x_3$$, and $$I$$ as well. How do we tell mathematica there is such a condition and "force" $$I$$ to be real?

Let's express $$p^2$$ and $$q^2$$ in terms of roots $$x_2$$ and $$x_3$$:

rel = SolveAlways[-(x - x1) (x - x2) (x - x3) == -x^3 + p2 x - q2, x] /.
{p2 -> p^2, q2 -> q^2} // Flatten

{p^2 -> x2^2 + x2 x3 + x3^2, q^2 -> x2 x3 (x2 + x3), x1 -> -x2 - x3}


Our assumptions imply that x1 < 0 < x2 < x3, since at x == 0 we have -x^3 + p^2 x - q^2 == -q^2 < 0 if q is real and x1 + x2 + x3 == 0 because coeficcient of x^2 vanishes. Moreover between x2 and x3 the polynomial is positive -x^3 + p^2 x - q^2 > 0 Now we can exploit Integrate supressing generating conditions

intg = Integrate[-((x - x1) (x - x2) (x - x3))/x^4, {x, x2, x3},
Assumptions -> x1 + x2 + x3 == 0 && x1 < 0 < x2 < x3,
GenerateConditions -> False]

-((x2 - x3) (x2 + x3) (x2^2 + x2 x3 + x3^2))/(6 x2^2 x3^2) + Log[x2] - Log[x3]


Comparing relations rel with intg we can rewrite it as

int = (x3 - x2)/(6 x3^3 x2^3) p^2 q^2 - Log[x3/x2];


indeed:

Simplify[ intg - int /. rel, 0 < x2 < x3]

0


Condition (2) means that there are three distinct roots, under our assumptions it means that the discriminant doesn't vanish:

Discriminant[x^3 - p^2 x + q^2, x]

4 p^6 - 27 q^4


The issue with apparently complex expressions for reals roots is called Casus irreducibilis