Connection
Base URL, credentials and a reachable server.
Keep widely separated coefficient scales beside the proposed root calculation and examine rejection paths together with the polynomial residuals.
Base URL, credentials and a reachable server.
A model available through the configured endpoint.
Context limits and tool support are determined by the model and server.
from math import isfinite, sqrt, copysign
def real_roots(a, b, c):
original = (a, b, c)
if not all(type(v) in (int, float) and isfinite(v) for v in original) or a == 0:
raise ValueError("finite quadratic coefficients")
if c == 0:
other = -b / a
if not isfinite(other) or (b != 0 and other == 0):
raise ValueError("unrepresentable root")
return [0.0] if b == 0 else sorted((0.0, other))
scale = max(map(abs, original))
a, b, c = (v / scale for v in original)
if any(v != 0 and s == 0 for v, s in zip(original, (a,b,c))):
raise ValueError("coefficient underflow")
d = b*b - 4*a*c
if d < 0: return []
if d == 0: roots = [-b / (2*a)]
else:
q = -0.5 * (b + copysign(sqrt(d), b))
if q == 0: raise ValueError("root underflow")
roots = sorted((q/a, c/q))
if not all(map(isfinite, roots)) or (original[2] != 0 and 0 in roots):
raise ValueError("unrepresentable roots")
return roots