From 05d7d43b393d388280b11a611533d9c28c52455c Mon Sep 17 00:00:00 2001 From: Benjamin Bertrand Date: Tue, 22 Mar 2016 11:21:39 +0300 Subject: [PATCH] add __truediv__ for AbstractPolynom --- pymath/calculus/abstract_polynom.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/pymath/calculus/abstract_polynom.py b/pymath/calculus/abstract_polynom.py index 4ca2c3a..3fb525d 100644 --- a/pymath/calculus/abstract_polynom.py +++ b/pymath/calculus/abstract_polynom.py @@ -653,6 +653,35 @@ class AbstractPolynom(Explicable): return o_poly.__mul__(self) + def __truediv__(self, other): + r""" Overload / + + >>> P = AbstractPolynom([1, 2, 4]) + >>> P / 2 + < AbstractPolynom x [< Fraction 1 / 2>, 1, 2]> + >>> for i in (P/2).explain(): + ... print(i) + ( 4 x^{ 2 } + 2 x + 1 ) \times 2 + \frac{ 4 }{ 2 } x^{ 2 } + \frac{ 2 }{ 2 } x + \frac{ 1 }{ 2 } + 2 x^{ 2 } + x + \frac{ 1 }{ 2 } + + + """ + ans_coefs = [Expression([c, other, op.div]) if c != 0 + else 0 + for c in self._coef + ] + + ans = AbstractPolynom(ans_coefs, letter=self._letter) + ini_step = [Step( + self.postfix_tokens + + [other, op.mul] + )] + + ans = ans.simplify() + ans.this_append_before(ini_step) + return ans + @power_cache def __pow__(self, power): r""" Overload **