From c044b8afdfbaa2e1a0872f4153177c0810abb13e Mon Sep 17 00:00:00 2001 From: cel34-bath Date: Fri, 2 Feb 2024 22:15:13 +0000 Subject: [PATCH 1/2] correction to RealRoots:-realRootIsolation Fixed oversight in realRootIsolation method that fails to perform bisection if the polynomial's leadCoefficient is negative. Lagrange bound was incorrectly implemented, failing to return a positive values whenever the lead coefficient was negative, and included the leading coefficient. This should now be correct (I have tested this but would appreciate another pair of eyes on this just in case). --- M2/Macaulay2/packages/RealRoots.m2 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/M2/Macaulay2/packages/RealRoots.m2 b/M2/Macaulay2/packages/RealRoots.m2 index a5d7e140be9..7e7453b1c8b 100644 --- a/M2/Macaulay2/packages/RealRoots.m2 +++ b/M2/Macaulay2/packages/RealRoots.m2 @@ -391,14 +391,14 @@ realRootIsolation (RingElement,A) := List => (f,r)->( if not isUnivariatePolynomial(f) then error "Error: Expected univariate polynomial"; R := ring f; - f = sub(f/gcd(f,diff(variable f,f)),R); + f = sub(f/gcd(f,diff(variable f,f)),R); --makes polynomial squarefree if (SturmCount(f)>0) then ( l := SturmSequence(f); --bound for real roots - C := (listForm f)/last; - M := (sum(C,abs))/(leadCoefficient f); + C := (listForm ((f-leadTerm(f))/leadCoefficient(f)))/last; --make the polynomial monic, and obtain list of coefficients of non-lead monomials. + M := max(1,sum(C,abs)); --obtains Lagrange bound. L := {{-M,M}}; midp := 0; From 15d28bb66e174f400d3ee53c77a29d1c02420c8e Mon Sep 17 00:00:00 2001 From: cel34-bath <91674047+cel34-bath@users.noreply.github.com> Date: Thu, 15 Feb 2024 00:33:40 +0000 Subject: [PATCH 2/2] Further improved bound and skipped bisection for isolated roots within interval size Combined the Lagrange and Cauchy bounds to return the smallest. realRootIsolation no longer bisects intervals when the root is isolated and the interval is below the required size (e.g. when two roots are very close together, the interval widths with be smaller, but the interval widths do not need to be smaller for the other roots). Final list is also sorted in case bisection stops in an interval after the first. Test also corrected (the new isolating intervals only look 'less nice' because the previous initial bounds happened to be divisible by 8). --- M2/Macaulay2/packages/RealRoots.m2 | 35 +++++++++++++++--------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/M2/Macaulay2/packages/RealRoots.m2 b/M2/Macaulay2/packages/RealRoots.m2 index 7e7453b1c8b..383ef531193 100644 --- a/M2/Macaulay2/packages/RealRoots.m2 +++ b/M2/Macaulay2/packages/RealRoots.m2 @@ -398,7 +398,7 @@ realRootIsolation (RingElement,A) := List => (f,r)->( --bound for real roots C := (listForm ((f-leadTerm(f))/leadCoefficient(f)))/last; --make the polynomial monic, and obtain list of coefficients of non-lead monomials. - M := max(1,sum(C,abs)); --obtains Lagrange bound. + M := min(1+max(apply(C,abs)),max(1,sum(C,abs))); --obtains Cauchy or Lagrange bound. L := {{-M,M}}; midp := 0; @@ -406,18 +406,23 @@ realRootIsolation (RingElement,A) := List => (f,r)->( while (max apply(L,I-> I#1-I#0) > r) or (max apply(L,I-> v#(I#0)-v#(I#1)) > 1) do ( for I in L do ( - midp = (sum I)/2; - v#midp = variations apply(l,g->signAt(g,midp)); - L = drop(L,1); - if (v#(I#0)-v#midp > 0) then ( - L = append(L,{I#0,midp}) - ); - if (v#midp-v#(I#1) > 0) then ( - L = append(L,{midp,I#1}) + if ((v#(I#0)-v#(I#1) == 1) and (I#1-I#0 <= r)) then ( + L = take(L,{1,#L})|{L#0}; -- skip bisection if root is identified and bound is within interval size. + ) + else ( + midp = (sum I)/2; + v#midp = variations apply(l,g->signAt(g,midp)); + L = drop(L,1); + if (v#(I#0)-v#midp > 0) then ( + L = append(L,{I#0,midp}) + ); + if (v#midp-v#(I#1) > 0) then ( + L = append(L,{midp,I#1}) + ); ) ) ); - L + sort L --list is ordered from smallest to largest interval, in case the while look stops after a larger interval ) else ( {} ) @@ -1033,7 +1038,7 @@ TEST /// TEST /// R = QQ[t]; f = (t-1)^2*(t+3)*(t+5)*(t-6); - assert(realRootIsolation(f,1/2) == {{-161/32, -299/64}, {-207/64, -23/8}, {23/32, 69/64}, {23/4, 391/64}}); + assert(realRootIsolation(f,1/2) == {{-1365/256,-637/128},{-819/256,-91/32},{91/128,273/256},{91/16,1547/256}}); /// TEST /// @@ -1073,10 +1078,4 @@ TEST /// -- assert(rationalUnivariateRepresentationresentation(I) == {Z^2 - (3/2)*Z - 9, x + y}); -- /// -end - - - - - - +end \ No newline at end of file