Feat: Polynomial are displayed in nicer order!
This commit is contained in:
@@ -84,19 +84,20 @@ x^7
|
||||
>>> e = Expression.from_str("1+2x^2+3x+4+5x")
|
||||
>>> e_simplified = e.simplify()
|
||||
>>> e_simplified
|
||||
<Quadratic 5 + 2x^2 + 8x>
|
||||
<Quadratic 2x^2 + 8x + 5>
|
||||
>>> for s in e_simplified.explain():
|
||||
... print(s)
|
||||
1 + 2x^2 + 3x + 4 + 5x
|
||||
1 + 2x^2 + 3x + 4 + 5x
|
||||
1 + 4 + 2x^2 + 3x + 5x
|
||||
5 + 2x^2 + (3 + 5) * x
|
||||
5 + 2x^2 + 8x
|
||||
2x^2 + 3x + 1 + 4 + 5x
|
||||
2x^2 + 3x + 5x + 1 + 4
|
||||
2x^2 + (3 + 5) * x + 5
|
||||
2x^2 + 8x + 5
|
||||
|
||||
|
||||
>>> e = Expression.from_str("(2x+3)^2")
|
||||
>>> e_simplified = e.simplify()
|
||||
>>> e_simplified
|
||||
<Quadratic 12x + 4x^2 + 9>
|
||||
<Quadratic 4x^2 + 12x + 9>
|
||||
>>> for s in e_simplified.explain():
|
||||
... print(s)
|
||||
(2x + 3)^2
|
||||
@@ -105,7 +106,8 @@ x^7
|
||||
2 * 2 * x^(1 + 1) + 3 * 2 * x + 3 * 2 * x + 9
|
||||
6x + 6x + 4x^2 + 9
|
||||
(6 + 6) * x + 4x^2 + 9
|
||||
12x + 4x^2 + 9
|
||||
4x^2 + 12x + 9
|
||||
|
||||
|
||||
"""
|
||||
|
||||
|
@@ -104,7 +104,7 @@ class Expression(object):
|
||||
<Linear 2x + 1>
|
||||
>>> e = Expression.from_str("2x + 1 + 5x^2")
|
||||
>>> e
|
||||
<Quadratic 2x + 1 + 5x^2>
|
||||
<Quadratic 5x^2 + 2x + 1>
|
||||
>>> e = Expression.from_str("2x + 1 + 5x")
|
||||
>>> e
|
||||
<Exp: 2x + 1 + 5x>
|
||||
@@ -468,7 +468,7 @@ class Expression(object):
|
||||
>>> f("u_n")
|
||||
<Exp: 3u_n^2 + 2u_n + 1>
|
||||
>>> f(f)
|
||||
<Polynomial 36x^2 + 16x + 6 + 36x^3 + 27x^4>
|
||||
<Polynomial 27x^4 + 36x^3 + 36x^2 + 16x + 6>
|
||||
"""
|
||||
tree = self._tree
|
||||
variable = (set(tree.get_leafs(extract_variable)) - {None}).pop()
|
||||
|
@@ -104,12 +104,12 @@ class Polynomial(Token):
|
||||
>>> P
|
||||
<Polynomial 3x^2 + 2x + 1>
|
||||
>>> P.differentiate()
|
||||
<Linear 2 + 6x>
|
||||
<Linear 6x + 2>
|
||||
>>> for s in P.differentiate().explain():
|
||||
... print(s)
|
||||
0 + 2 + 3 * 2x
|
||||
2 + 3 * 2 * x
|
||||
2 + 6x
|
||||
6x + 2
|
||||
"""
|
||||
return Expression(self._mo.differentiate()).simplify()
|
||||
|
||||
@@ -212,7 +212,7 @@ class Quadratic(Polynomial):
|
||||
4 - 12
|
||||
- 8
|
||||
>>> P.differentiate()
|
||||
<Linear 2 + 6x>
|
||||
<Linear 6x + 2>
|
||||
>>> P.roots
|
||||
[]
|
||||
|
||||
|
@@ -174,7 +174,7 @@ class Token(object):
|
||||
>>> a = Integer(3)
|
||||
>>> c = a - "x"
|
||||
>>> c
|
||||
<Linear 3 - x>
|
||||
<Linear - x + 3>
|
||||
"""
|
||||
return self._operate(other, "-")
|
||||
|
||||
|
Reference in New Issue
Block a user