%mathpiper,def="RealRootsCount"

RealRootsCount(_p) <--
[
  Local(S);
  p:=SquareFree(Rationalize(p));
  S:=SturmSequence(p);
  SturmVariations(S,-Infinity)-SturmVariations(S,Infinity);
];

%/mathpiper



%mathpiper_docs,name="RealRootsCount",categories="User Functions;Solvers (Numeric)"
*CMD RealRootsCount --- return the number of real roots of a polynomial
*STD
*CALL
	RealRootsCount(p)

*PARMS

{p} - a polynomial in {x}

*DESC

Returns the number of real roots of a polynomial $ p $.
The polynomial must use the variable {x} and no other variables.

*E.G.

In> RealRootsCount(x^2-1)
Result: 2;
In> RealRootsCount(x^2+1)
Result: 0;

*SEE FindRealRoots, SquareFree, MinimumBound, MaximumBound, Factor
%/mathpiper_docs