From f62f572fb3928122a7681462ca73e11a9d2a241c Mon Sep 17 00:00:00 2001 From: Benjamin Bertrand Date: Sun, 13 Mar 2016 17:48:40 +0300 Subject: [PATCH] 2var poly ok for results but bad with explain --- pymath/calculus/abstract_polynom.py | 30 ++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/pymath/calculus/abstract_polynom.py b/pymath/calculus/abstract_polynom.py index 03eb601..b6a1ac0 100644 --- a/pymath/calculus/abstract_polynom.py +++ b/pymath/calculus/abstract_polynom.py @@ -292,7 +292,8 @@ class AbstractPolynom(Explicable): """ if (isNumber(other) and not isPolynom(other)) or \ (isPolynom(other) and self._letter != other._letter): - ans = self.__class__([other], letter=self._letter) + #ans = self.__class__([other], letter=self._letter) + ans = AbstractPolynom([other], letter=self._letter) ans.steal_history(other) return ans elif isPolynom(other): @@ -326,6 +327,23 @@ class AbstractPolynom(Explicable): 6 x^{ 2 } + 12 x + 3 >>> Q.steps [< Step [6, 'x', 2, ^, *, 3, 'x', *, +, 4, 'x', *, +, 5, 'x', *, +, 1, +, 2, +]>, < Step [6, 'x', 2, ^, *, 3, 4, +, 5, +, 'x', *, +, 1, 2, +, +]>, < Step [6, 'x', 2, ^, *, 7, 5, +, 'x', *, +, 3, +]>, < Step [6, 'x', 2, ^, *, 12, 'x', *, +, 3, +]>] + >>> P = AbstractPolynom([1,2]) + >>> Q = AbstractPolynom([P,3], 'y') + >>> Q + < AbstractPolynom y [< AbstractPolynom x [1, 2]>, 3]> + >>> Q = Q.reduce() + >>> for i in Q.explain(): + ... print(i) + 3 y + 2 x + 1 + >>> P = AbstractPolynom([1,2]) + >>> Q = AbstractPolynom([[P,1],3], 'y') + >>> Q + < AbstractPolynom y [[< AbstractPolynom x [1, 2]>, 1], 3]> + >>> Q = Q.reduce() + >>> for i in Q.explain(): + ... print(i) + 3 y + 2 x + 1 + 1 + 3 y + 2 x + 2 """ # TODO: Il manque le ini_step |jeu. mars 10 12:39:40 EAT 2016 @@ -426,6 +444,16 @@ class AbstractPolynom(Explicable): 3 x^{ 2 } + 7 x + 5 >>> R.steps [< Step [3, 'x', 2, ^, *, 2, 'x', *, +, 1, +, 5, 'x', *, 4, +, +]>, < Step [3, 'x', 2, ^, *, 2, 'x', *, +, 5, 'x', *, +, 1, +, 4, +]>, < Step [3, 'x', 2, ^, *, 2, 5, +, 'x', *, +, 1, 4, +, +]>, < Step [3, 'x', 2, ^, *, 7, 'x', *, +, 5, +]>] + >>> Q = AbstractPolynom([4,5], letter = 'y') + >>> R = P+Q + >>> R + < AbstractPolynom x [< AbstractPolynom y [5, 5]>, 2, 3]> + >>> for i in R.explain(): + ... print(i) + 3 x^{ 2 } + 2 x + 1 + 5 y + 4 + 3 x^{ 2 } + 2 x + 5 y + 1 + 4 + 3 x^{ 2 } + 2 x + 5 y + 5 + """ o_poly = self.conv2poly(other)