Skip to content

Commit

Permalink
Improved stability of point_on_variety with arbitrary precision compl…
Browse files Browse the repository at this point in the history
…ex floats (retrying on NoConvergence and AssertionError, the latter sometimes being triggered by an innacurate Grobner basis computation); fixed issue in Polynomial with parsing of arbitrary precision complex floats where the imaginary part is written in scientific notation (was failing to include 'e+' or 'e-' in the pattern matching).
  • Loading branch information
GDeLaurentis committed Oct 14, 2024
1 parent 4d2560b commit cd87416
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion syngular/polynomial.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def reduce(self):
@staticmethod
def __rstr__(polynomial, field):
polynomial = polynomial.replace(" ", "").replace("+-", "-")
polynomial = re.sub(r"(\+|\-)I\*{0,1}([\d\.]+)", r"\1\2j", polynomial) # format complex nbrs
polynomial = re.sub(r"(\+|\-)I\*{0,1}([\d\.e\+\-]+)", r"\1\2j", polynomial) # format complex nbrs
parentheses = [(("(", ), (")", )), (("{", ), ("}", )), (("[", "⟨", "<", ), ("]", "⟩", ">"))]
lopen_parentheses = [parenthesis[0] for parenthesis in parentheses]
lclos_parentheses = [parenthesis[1] for parenthesis in parentheses]
Expand Down
8 changes: 5 additions & 3 deletions syngular/variety.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from copy import copy, deepcopy
from pyadic import ModP

from mpmath.libmp.libhyper import NoConvergence

from .tools import RootNotInFieldError, RootPrecisionError
from .field import Field
from .polynomial import Monomial, Polynomial
Expand All @@ -32,10 +34,10 @@ def wrapper(self, field, base_point={}, directions=None, valuations=tuple(), ind
res = func(self, field, base_point=base_point, directions=directions, valuations=valuations,
indepSetNbr=indepSetNbr, seed=seed, verbose=verbose)
break
except (RootNotInFieldError, RootPrecisionError) as e:
except (RootNotInFieldError, RootPrecisionError, NoConvergence, AssertionError) as e:
if try_nbr != max_tries - 1:
if verbose:
print(f"Caught {type(e).__name__}, retrying...")
print(f"Caught {type(e).__name__} at try number {try_nbr}, retrying...")
if seed is not None: # maintain pseudo-randomness, but change seed, else retring has no effect.
random.seed(seed)
seed += random.randint(10 ** 5, 10**6)
Expand Down Expand Up @@ -157,7 +159,7 @@ def point_on_variety(self, field, base_point={}, directions=None, valuations=tup
if prime is None and oSemiNumericalIdeal.groebner_basis == ['1']:
raise RootPrecisionError
if not oSemiNumericalIdeal.dim == 0:
raise Exception("The dimension of the semi-numerical ideal was not zero.")
raise AssertionError("The dimension of the semi-numerical ideal was not zero.")

root_dicts = lex_groebner_solve(oSemiNumericalIdeal.groebner_basis, prime=prime)
check_solutions(oSemiNumericalIdeal.groebner_basis, root_dicts, field) # they may be stricter then wanted for mpc.
Expand Down

0 comments on commit cd87416

Please sign in to comment.