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