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

Commit

Permalink
Use sage_mantissa_exponent to get a cheaper log2
Browse files Browse the repository at this point in the history
  • Loading branch information
nbruin committed Jun 15, 2017
1 parent ce5097a commit 3285684
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/sage/schemes/riemann_surfaces/riemann_surface.py
Expand Up @@ -686,6 +686,7 @@ def _determine_new_w(self, z0, oldw, epsilon):
F = self._fastcall_f
dF = self._fastcall_dfdw
neww = []
prec = self._CC.prec()
# Iterate over all roots.
for i in range(len(oldw)):
delta = F(z0,oldw[i])/dF(z0,oldw[i])
Expand All @@ -703,7 +704,8 @@ def _determine_new_w(self, z0, oldw, epsilon):
Nnew_delta = new_delta.norm()
# If we found the root exactly, or if delta only affects half the digits and
# stops getting smaller, we decide that we have converged.
if (new_delta == 0) or (Nnew_delta>=Ndelta and Ndelta.log2() < wi.norm().log2()-wi.prec()):
if (new_delta == 0) or (Nnew_delta>=Ndelta and
Ndelta.sign_mantissa_exponent()[2]+prec < wi.norm().sign_mantissa_exponent()[2]):
neww.append(wi)
break
delta=new_delta
Expand Down Expand Up @@ -770,6 +772,7 @@ def _newton_iteration(self, z0, oldw, epsilon):
"""
F = self._fastcall_f
dF = self._fastcall_dfdw
prec = self._CC.prec()
delta = F(z0,oldw)/dF(z0,oldw)
Ndelta = delta.norm()
neww = oldw-delta
Expand All @@ -784,7 +787,8 @@ def _newton_iteration(self, z0, oldw, epsilon):
Nnew_delta = new_delta.norm()
# If we found the root exactly, or if delta only affects half the digits and
# stops getting smaller, we decide that we have converged.
if (new_delta == 0) or (Nnew_delta>=Ndelta and Ndelta.log2() < neww.norm().log2()-neww.prec()):
if (new_delta == 0) or (Nnew_delta>=Ndelta and
Ndelta.sign_mantissa_exponent()[2]+prec < neww.norm().sign_mantissa_exponent()[2]):
return neww
delta = new_delta
Ndelta = Nnew_delta
Expand Down

0 comments on commit 3285684

Please sign in to comment.