solve issue wit - and polynoms
This commit is contained in:
@@ -137,36 +137,52 @@ class Polynom(object):
|
||||
"""
|
||||
postfix = []
|
||||
for (i,a) in list(enumerate(self._coef))[::-1]:
|
||||
operator = op.add
|
||||
operator = [op.add]
|
||||
operator_sub1 = []
|
||||
if type(a) == Expression:
|
||||
# case coef is an arithmetic expression
|
||||
c = self.coef_postfix(a.postfix_tokens,i)
|
||||
if c != []:
|
||||
postfix.append(c)
|
||||
if len(postfix) > 1:
|
||||
postfix.append(operator)
|
||||
postfix += operator
|
||||
|
||||
elif type(a) == list:
|
||||
# case need to repeat the x^i
|
||||
for b in a:
|
||||
if len(postfix) > 0 and isNumber(b) and b < 0:
|
||||
b = -b
|
||||
operator = op.sub
|
||||
c = self.coef_postfix([b],i)
|
||||
if len(postfix) == 0 and isNumber(b) and b < 0:
|
||||
b = [-b]
|
||||
operator_sub1 = [op.sub1]
|
||||
elif len(postfix) > 0 and isNumber(b) and b < 0:
|
||||
b = [-b]
|
||||
operator = [op.sub]
|
||||
else:
|
||||
b = [b]
|
||||
c = self.coef_postfix(b,i)
|
||||
if c != []:
|
||||
postfix.append(c)
|
||||
if len(postfix) > 1:
|
||||
postfix.append(operator)
|
||||
postfix += operator_sub1
|
||||
postfix += operator
|
||||
postfix += operator_sub1
|
||||
|
||||
elif a != 0:
|
||||
if len(postfix) > 0 and a < 0:
|
||||
a = -a
|
||||
operator = op.sub
|
||||
c = self.coef_postfix([a],i)
|
||||
if len(postfix) == 0 and a < 0:
|
||||
a = [-a]
|
||||
operator_sub1 = [op.sub1]
|
||||
elif len(postfix) > 0 and a < 0:
|
||||
a = [-a]
|
||||
operator = [op.sub]
|
||||
else:
|
||||
a = [a]
|
||||
|
||||
c = self.coef_postfix(a,i)
|
||||
if c != []:
|
||||
postfix.append(c)
|
||||
if len(postfix) > 1:
|
||||
postfix.append(operator)
|
||||
postfix += operator_sub1
|
||||
postfix += operator
|
||||
postfix += operator_sub1
|
||||
|
||||
return flatten_list(postfix)
|
||||
|
||||
|
Reference in New Issue
Block a user