From 20cae3e0a5a27d209c04f1bb2731b6accff69be9 Mon Sep 17 00:00:00 2001 From: Benjamin Bertrand Date: Wed, 9 Mar 2016 10:56:00 +0300 Subject: [PATCH] adapt abstract_polynom to new init --- pymath/calculus/abstract_polynom.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/pymath/calculus/abstract_polynom.py b/pymath/calculus/abstract_polynom.py index f976f39..57fc0a3 100644 --- a/pymath/calculus/abstract_polynom.py +++ b/pymath/calculus/abstract_polynom.py @@ -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