postfix in postfix change + to -

This commit is contained in:
Lafrite 2014-12-20 17:42:31 +01:00
parent 096e025302
commit dbe382f892

View File

@ -137,25 +137,38 @@ class Polynom(object):
""" """
postfix = [] postfix = []
for (i,a) in list(enumerate(self._coef))[::-1]: for (i,a) in list(enumerate(self._coef))[::-1]:
operator = op.add
if type(a) == Expression: if type(a) == Expression:
# case coef is an arithmetic expression # case coef is an arithmetic expression
c = self.coef_postfix(a.postfix_tokens,i) c = self.coef_postfix(a.postfix_tokens,i)
if c != []: if c != []:
postfix.append(c) postfix.append(c)
if len(postfix) > 1:
postfix.append(operator)
elif type(a) == list: elif type(a) == list:
# case need to repeat the x^i # case need to repeat the x^i
for b in a: for b in a:
if isNumber(b) and b < 0:
b = -b
operator = op.sub
c = self.coef_postfix([b],i) c = self.coef_postfix([b],i)
if c != []: if c != []:
postfix.append(c) postfix.append(c)
if len(postfix) > 1:
postfix.append(operator)
elif a != 0: elif a != 0:
if a < 0:
a = -a
operator = op.sub
c = self.coef_postfix([a],i) c = self.coef_postfix([a],i)
if c != []: if c != []:
postfix.append(c) postfix.append(c)
if len(postfix) > 1:
postfix.append(operator)
return flatten_list(self.postfix_add(postfix)) return flatten_list(postfix)
def conv2poly(self, other): def conv2poly(self, other):
"""Convert anything number into a polynom""" """Convert anything number into a polynom"""