add __truediv__ for AbstractPolynom

This commit is contained in:
Benjamin Bertrand 2016-03-22 11:21:39 +03:00
parent f648e94a37
commit 05d7d43b39
1 changed files with 29 additions and 0 deletions

View File

@ -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 **