forked from sympy/sympy
/
polyerrors.py
178 lines (135 loc) · 4.46 KB
/
polyerrors.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
"""Definitions of common exceptions for `polys` module. """
from __future__ import print_function, division
from sympy.utilities import public
@public
class BasePolynomialError(Exception):
"""Base class for polynomial related exceptions. """
def new(self, *args):
raise NotImplementedError("abstract base class")
@public
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)
@public
class PolynomialDivisionFailed(BasePolynomialError):
def __init__(self, f, g, domain):
self.f = f
self.g = g
self.domain = domain
def __str__(self):
if self.domain.is_EX:
msg = "You may want to use a different simplification algorithm. Note " \
"that in general it's not possible to guarantee to detect zero " \
"in this domain."
elif not self.domain.is_Exact:
msg = "Your working precision or tolerance of computations may be set " \
"improperly. Adjust those parameters of the coefficient domain " \
"and try again."
else:
msg = "Zero detection is guaranteed in this coefficient domain. This " \
"may indicate a bug in SymPy or the domain is user defined and " \
"doesn't implement zero detection properly."
return "couldn't reduce degree in a polynomial division algorithm when " \
"dividing %s by %s. This can happen when it's not possible to " \
"detect zero in the coefficient domain. The domain of computation " \
"is %s. %s" % (self.f, self.g, self.domain, msg)
@public
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__)
@public
class HeuristicGCDFailed(BasePolynomialError):
pass
class ModularGCDFailed(BasePolynomialError):
pass
@public
class HomomorphismFailed(BasePolynomialError):
pass
@public
class IsomorphismFailed(BasePolynomialError):
pass
@public
class ExtraneousFactors(BasePolynomialError):
pass
@public
class EvaluationFailed(BasePolynomialError):
pass
@public
class RefinementFailed(BasePolynomialError):
pass
@public
class CoercionFailed(BasePolynomialError):
pass
@public
class NotInvertible(BasePolynomialError):
pass
@public
class NotReversible(BasePolynomialError):
pass
@public
class NotAlgebraic(BasePolynomialError):
pass
@public
class DomainError(BasePolynomialError):
pass
@public
class PolynomialError(BasePolynomialError):
pass
@public
class UnificationFailed(BasePolynomialError):
pass
@public
class GeneratorsError(BasePolynomialError):
pass
@public
class GeneratorsNeeded(GeneratorsError):
pass
@public
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])))
@public
class UnivariatePolynomialError(PolynomialError):
pass
@public
class MultivariatePolynomialError(PolynomialError):
pass
@public
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))
@public
class OptionError(BasePolynomialError):
pass
@public
class FlagError(OptionError):
pass