Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
When converging, take the intersection of old and new interval
Browse files Browse the repository at this point in the history
  • Loading branch information
jdemeyer committed Oct 7, 2015
1 parent eb61557 commit 7c689b6
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/sage/rings/polynomial/refine_root.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,20 @@ def refine_root(poly, deriv, root, field, long steps=10):
# nroot and root are exactly the same interval
raise ArithmeticError("cannot refine polynomial root (multiple roots?)")
else:
# Use Newton-Raphson to refine the root
# Use interval Newton-Raphson to refine the root
center = field(root.center())
nroot = center - poly(center) / slope

if converging or nroot in root:
if converging:
# If we are converging, make sure we never enlarge our
# interval again. This is in particular needed when the
# interval gets small to avoid oscillations.
nroot = nroot.intersection(root)
elif nroot in root:
# Once we are converging, assume that we keep converging.
converging = True

if converging:
if i == steps - 1:
# This is the last iteration
return nroot
Expand All @@ -225,9 +234,6 @@ def refine_root(poly, deriv, root, field, long steps=10):
# original diameter, then we have converged reasonably
# well.
return nroot
# Once we are converging, assume that we keep converging
# (to avoid small oscillations due to limited precision)
converging = True
else:
# If the new interval still isn't contained in the old
# after a while, try tripling the size of the region
Expand Down

0 comments on commit 7c689b6

Please sign in to comment.