Coverage for /usr/lib/python3/dist-packages/sympy/polys/polyerrors.py: 75%
110 statements
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-14 15:55 +0200
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-14 15:55 +0200
1"""Definitions of common exceptions for `polys` module. """
4from sympy.utilities import public
6@public
7class BasePolynomialError(Exception):
8 """Base class for polynomial related exceptions. """
10 def new(self, *args):
11 raise NotImplementedError("abstract base class")
13@public
14class ExactQuotientFailed(BasePolynomialError):
16 def __init__(self, f, g, dom=None):
17 self.f, self.g, self.dom = f, g, dom
19 def __str__(self): # pragma: no cover
20 from sympy.printing.str import sstr
22 if self.dom is None:
23 return "%s does not divide %s" % (sstr(self.g), sstr(self.f))
24 else:
25 return "%s does not divide %s in %s" % (sstr(self.g), sstr(self.f), sstr(self.dom))
27 def new(self, f, g):
28 return self.__class__(f, g, self.dom)
30@public
31class PolynomialDivisionFailed(BasePolynomialError):
33 def __init__(self, f, g, domain):
34 self.f = f
35 self.g = g
36 self.domain = domain
38 def __str__(self):
39 if self.domain.is_EX:
40 msg = "You may want to use a different simplification algorithm. Note " \
41 "that in general it's not possible to guarantee to detect zero " \
42 "in this domain."
43 elif not self.domain.is_Exact:
44 msg = "Your working precision or tolerance of computations may be set " \
45 "improperly. Adjust those parameters of the coefficient domain " \
46 "and try again."
47 else:
48 msg = "Zero detection is guaranteed in this coefficient domain. This " \
49 "may indicate a bug in SymPy or the domain is user defined and " \
50 "doesn't implement zero detection properly."
52 return "couldn't reduce degree in a polynomial division algorithm when " \
53 "dividing %s by %s. This can happen when it's not possible to " \
54 "detect zero in the coefficient domain. The domain of computation " \
55 "is %s. %s" % (self.f, self.g, self.domain, msg)
57@public
58class OperationNotSupported(BasePolynomialError):
60 def __init__(self, poly, func):
61 self.poly = poly
62 self.func = func
64 def __str__(self): # pragma: no cover
65 return "`%s` operation not supported by %s representation" % (self.func, self.poly.rep.__class__.__name__)
67@public
68class HeuristicGCDFailed(BasePolynomialError):
69 pass
71class ModularGCDFailed(BasePolynomialError):
72 pass
74@public
75class HomomorphismFailed(BasePolynomialError):
76 pass
78@public
79class IsomorphismFailed(BasePolynomialError):
80 pass
82@public
83class ExtraneousFactors(BasePolynomialError):
84 pass
86@public
87class EvaluationFailed(BasePolynomialError):
88 pass
90@public
91class RefinementFailed(BasePolynomialError):
92 pass
94@public
95class CoercionFailed(BasePolynomialError):
96 pass
98@public
99class NotInvertible(BasePolynomialError):
100 pass
102@public
103class NotReversible(BasePolynomialError):
104 pass
106@public
107class NotAlgebraic(BasePolynomialError):
108 pass
110@public
111class DomainError(BasePolynomialError):
112 pass
114@public
115class PolynomialError(BasePolynomialError):
116 pass
118@public
119class UnificationFailed(BasePolynomialError):
120 pass
122@public
123class UnsolvableFactorError(BasePolynomialError):
124 """Raised if ``roots`` is called with strict=True and a polynomial
125 having a factor whose solutions are not expressible in radicals
126 is encountered."""
128@public
129class GeneratorsError(BasePolynomialError):
130 pass
132@public
133class GeneratorsNeeded(GeneratorsError):
134 pass
136@public
137class ComputationFailed(BasePolynomialError):
139 def __init__(self, func, nargs, exc):
140 self.func = func
141 self.nargs = nargs
142 self.exc = exc
144 def __str__(self):
145 return "%s(%s) failed without generators" % (self.func, ', '.join(map(str, self.exc.exprs[:self.nargs])))
147@public
148class UnivariatePolynomialError(PolynomialError):
149 pass
151@public
152class MultivariatePolynomialError(PolynomialError):
153 pass
155@public
156class PolificationFailed(PolynomialError):
158 def __init__(self, opt, origs, exprs, seq=False):
159 if not seq:
160 self.orig = origs
161 self.expr = exprs
162 self.origs = [origs]
163 self.exprs = [exprs]
164 else:
165 self.origs = origs
166 self.exprs = exprs
168 self.opt = opt
169 self.seq = seq
171 def __str__(self): # pragma: no cover
172 if not self.seq:
173 return "Cannot construct a polynomial from %s" % str(self.orig)
174 else:
175 return "Cannot construct polynomials from %s" % ', '.join(map(str, self.origs))
177@public
178class OptionError(BasePolynomialError):
179 pass
181@public
182class FlagError(OptionError):
183 pass