Compare commits

..

2 Commits

Author SHA1 Message Date
f4c5d245e4 fix(ga): Derivative of a constant now returns 0 instead of a throwing an error
All checks were successful
Run Python Tests / test (3.12) (pull_request) Successful in 24s
Run Python Tests / test (3.10) (pull_request) Successful in 30s
Run Python Tests / test (3.8) (pull_request) Successful in 22s
Publish Python Package to PyPI / deploy (push) Successful in 20s
2025-10-31 11:17:29 -04:00
b7ea6c2e23 Added root_precision warning 2025-10-31 11:08:02 -04:00
2 changed files with 14 additions and 3 deletions

View File

@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
[project] [project]
# --- Core Metadata --- # --- Core Metadata ---
name = "polysolve" name = "polysolve"
version = "0.6.0" version = "0.6.1"
authors = [ authors = [
{ name="Jonathan Rampersad", email="jonathan@jono-rams.work" }, { name="Jonathan Rampersad", email="jonathan@jono-rams.work" },
] ]

View File

@@ -133,6 +133,15 @@ class GA_Options:
raise ValueError( raise ValueError(
f"blend_alpha cannot be negative, but got {self.blend_alpha}" f"blend_alpha cannot be negative, but got {self.blend_alpha}"
) )
if self.root_precision > 15:
warnings.warn(
f"root_precision={self.root_precision} is greater than 15. "
"This demands an accuracy that is likely impossible for standard "
"64-bit floats (float64), which are limited to 15-16 significant digits. "
"The solver may fail to find any roots.",
UserWarning,
stacklevel=2
)
def _get_cauchy_bound(coeffs: np.ndarray) -> float: def _get_cauchy_bound(coeffs: np.ndarray) -> float:
""" """
@@ -256,7 +265,9 @@ class Function:
""" """
self._check_initialized() self._check_initialized()
if self._largest_exponent == 0: if self._largest_exponent == 0:
raise ValueError("Cannot differentiate a constant (Function of degree 0).") diff_func = Function(0)
diff_func.set_coeffs([0])
return diff_func
derivative_coefficients = np.polyder(self.coefficients) derivative_coefficients = np.polyder(self.coefficients)
@@ -672,7 +683,7 @@ class Function:
def _multiply_by_scalar(self, scalar: Union[int, float]) -> 'Function': def _multiply_by_scalar(self, scalar: Union[int, float]) -> 'Function':
"""Helper method to multiply the function by a scalar constant.""" """Helper method to multiply the function by a scalar constant."""
self._check_initialized() # It's good practice to check here too self._check_initialized()
if scalar == 0: if scalar == 0:
result_func = Function(0) result_func = Function(0)