Reorder expression in descending negtive power of a variable using Sage or Sympy
Question:
I have an expression
1/24*(8*(l + 1)*l + 5*(2*E*(l + 1)*l + 3)/E - 6)/E
I want to reorder it to the form
a * E**1 + b * E**0 + c * E**(-1) + d * E**(-2) + ...
sympy.simplify()
gives me a close result.
from sympy import simplify
simplify(1/24*(8*(l + 1)*l + 5*(2*E*(l + 1)*l + 3)/E - 6)/E)
output
(6*E*l**2 + 6*E*l - 2*E + 5)/(8*E**2)
It didn’t combine 8*E**2
.
What I expect is
3/4*l**2*E**(-1) + 3/4*l*E**(-1) - 1/4*E**(-1) + 5/8*E**(-2)
Is this possible?
Answers:
Using expand
puts the terms in the order you wanted:
>>> expand((6*E*l**2 + 6*E*l - 2*E + 5)/(8*E**2))
3*l**2/(4*E) + 3*l/(4*E) - 1/(4*E) + 5/(8*E**2)
I have an expression
1/24*(8*(l + 1)*l + 5*(2*E*(l + 1)*l + 3)/E - 6)/E
I want to reorder it to the form
a * E**1 + b * E**0 + c * E**(-1) + d * E**(-2) + ...
sympy.simplify()
gives me a close result.
from sympy import simplify
simplify(1/24*(8*(l + 1)*l + 5*(2*E*(l + 1)*l + 3)/E - 6)/E)
output
(6*E*l**2 + 6*E*l - 2*E + 5)/(8*E**2)
It didn’t combine 8*E**2
.
What I expect is
3/4*l**2*E**(-1) + 3/4*l*E**(-1) - 1/4*E**(-1) + 5/8*E**(-2)
Is this possible?
Using expand
puts the terms in the order you wanted:
>>> expand((6*E*l**2 + 6*E*l - 2*E + 5)/(8*E**2))
3*l**2/(4*E) + 3*l/(4*E) - 1/(4*E) + 5/(8*E**2)