From f4c5d245e43db577ca492462d543ddc8d10de2f8 Mon Sep 17 00:00:00 2001 From: Jonathan Rampersad Date: Fri, 31 Oct 2025 11:17:29 -0400 Subject: [PATCH] fix(ga): Derivative of a constant now returns 0 instead of a throwing an error --- src/polysolve/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/polysolve/__init__.py b/src/polysolve/__init__.py index 0f624a0..30f00eb 100644 --- a/src/polysolve/__init__.py +++ b/src/polysolve/__init__.py @@ -265,7 +265,9 @@ class Function: """ self._check_initialized() 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) @@ -681,7 +683,7 @@ class Function: def _multiply_by_scalar(self, scalar: Union[int, float]) -> 'Function': """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: result_func = Function(0)