adapt abstract_polynom to new init

This commit is contained in:
Benjamin Bertrand 2016-03-09 10:56:00 +03:00
parent 19069a41f7
commit 20cae3e0a5
1 changed files with 10 additions and 9 deletions

View File

@ -56,8 +56,6 @@ class AbstractPolynom(Explicable):
>>> AbstractPolynom([1, 2, 3], name = "Q").name
'Q'
"""
super(AbstractPolynom, self).__init__()
try:
# Remove 0 at the end of the coefs
while coefs[-1] == 0:
@ -78,6 +76,9 @@ class AbstractPolynom(Explicable):
self.mainOp = op.add
self._isPolynom = 1
pstf_tokens = self.compute_postfix_tokens()
super(AbstractPolynom, self).__init__(pstf_tokens)
def feed_coef(self, l_coef):
"""Feed coef of the polynom. Manage differently whether it's a number or an expression
@ -166,8 +167,7 @@ class AbstractPolynom(Explicable):
return ans
@property
def postfix_tokens(self):
def compute_postfix_tokens(self):
"""Return the postfix form of the polynom
:returns: the postfix list of polynom's tokens
@ -204,10 +204,9 @@ class AbstractPolynom(Explicable):
[2, 3, +, 'x', *, 1, +]
"""
if self == 0:
if not [i for i in self._coef if i!= 0]:
return [0]
# TODO: Faudrait factoriser un peu tout ça..! |dim. déc. 21 16:02:34
# CET 2014
postfix = []
for (i, a) in list(enumerate(self._coef))[::-1]:
operator = [op.add]
@ -288,8 +287,10 @@ class AbstractPolynom(Explicable):
elif isPolynom(other):
return other
else:
raise ValueError(type(other) +
" can't be converted into a polynom")
raise ValueError(
type(other) +
" can't be converted into a polynom"
)
def reduce(self):
"""Compute coefficients which have same degree