Source code for sympy.polys.polyerrors

"""Definitions of common exceptions for `polys` module. """


[docs]class BasePolynomialError(Exception): """Base class for polynomial related exceptions. """ def new(self, *args): raise NotImplementedError("abstract base class")
[docs]class ExactQuotientFailed(BasePolynomialError): def __init__(self, f, g, dom=None): self.f, self.g, self.dom = f, g, dom def __str__(self): # pragma: no cover from sympy.printing.str import sstr if self.dom is None: return "%s does not divide %s" % (sstr(self.g), sstr(self.f)) else: return "%s does not divide %s in %s" % (sstr(self.g), sstr(self.f), sstr(self.dom)) def new(self, f, g): return self.__class__(f, g, self.dom)
[docs]class OperationNotSupported(BasePolynomialError): def __init__(self, poly, func): self.poly = poly self.func = func def __str__(self): # pragma: no cover return "`%s` operation not supported by %s representation" % (self.func, self.poly.rep.__class__.__name__)
[docs]class HeuristicGCDFailed(BasePolynomialError): pass
[docs]class HomomorphismFailed(BasePolynomialError): pass
[docs]class IsomorphismFailed(BasePolynomialError): pass
[docs]class ExtraneousFactors(BasePolynomialError): pass
[docs]class EvaluationFailed(BasePolynomialError): pass
[docs]class RefinementFailed(BasePolynomialError): pass
[docs]class CoercionFailed(BasePolynomialError): pass
[docs]class NotInvertible(BasePolynomialError): pass
[docs]class NotReversible(BasePolynomialError): pass
[docs]class NotAlgebraic(BasePolynomialError): pass
[docs]class DomainError(BasePolynomialError): pass
[docs]class PolynomialError(BasePolynomialError): pass
[docs]class UnificationFailed(BasePolynomialError): pass
[docs]class GeneratorsError(BasePolynomialError): pass
[docs]class GeneratorsNeeded(GeneratorsError): pass
[docs]class ComputationFailed(BasePolynomialError): def __init__(self, func, nargs, exc): self.func = func self.nargs = nargs self.exc = exc def __str__(self): return "%s(%s) failed without generators" % (self.func, ', '.join(map(str, self.exc.exprs[:self.nargs])))
[docs]class UnivariatePolynomialError(PolynomialError): pass
[docs]class MultivariatePolynomialError(PolynomialError): pass
[docs]class PolificationFailed(PolynomialError): def __init__(self, opt, origs, exprs, seq=False): if not seq: self.orig = origs self.expr = exprs self.origs = [origs] self.exprs = [exprs] else: self.origs = origs self.exprs = exprs self.opt = opt self.seq = seq def __str__(self): # pragma: no cover if not self.seq: return "can't construct a polynomial from %s" % str(self.orig) else: return "can't construct polynomials from %s" % ', '.join(map(str, self.origs))
[docs]class OptionError(BasePolynomialError): pass
[docs]class FlagError(OptionError): pass