Feat: Polynoms can be differentiate!!!!

This commit is contained in:
2019-07-15 17:48:59 +02:00
parent 8389a319f0
commit 41385ec561
6 changed files with 123 additions and 0 deletions

View File

@@ -101,6 +101,24 @@ class Polynomial(Token):
tree = tree.map_on_leaf(replace_var)
return Expression(tree).simplify()
def differentiate(self):
""" Differentiate a polynome
:example:
>>> from ...core.MO.polynomial import MOpolynomial
>>> P = Polynomial(MOpolynomial('x', [1, 2, 3]))
>>> P
<Polynomial 3x^2 + 2x + 1>
>>> P.differentiate()
<Linear 2 + 6x>
>>> for s in P.differentiate().explain():
... print(s)
0 + 2 + 3 * 2x
2 + 3 * 2 * x
2 + 6x
"""
return Expression(self._mo.differentiate()).simplify()
@property
def roots(self):
""" Get roots of the Polynomial """
@@ -120,6 +138,8 @@ class Linear(Polynomial):
<MOnumber 2>
>>> P.b
<MOnumber 1>
>>> P.differentiate()
<Integer 2>
>>> P.roots
[<Fraction - 2 / 1>]
@@ -194,6 +214,8 @@ class Quadratic(Polynomial):
4 - 12 * 1
4 - 12
- 8
>>> P.differentiate()
<Linear 2 + 6x>
>>> P.roots
[]