Reputation: 1427
A long operation with sympy yielded the expression (1/x)^a / x^2
, which one would normally write as x^(-2-a)
. What is the right sequence of sympy operations that I can apply to arrive to the simplified form?
I have tried the following, and none of them seems to simplify the expression at all.
import sympy as sym
expr = sym.sympify("(1/x)^a / x^2")
print(sym.simplify(expr))
print(sym.expand_power_exp(expr))
print(sym.expand_power_base(expr, force=True))
print(sym.powsimp(expr, force=True))
print(sym.collect(expr, "x"))
print(sym.ratsimp(expr))
# prints (1/x)**a/x**2 every time
Upvotes: 1
Views: 71
Reputation: 13135
That simplification can only occurs when x
is positive.
from sympy import *
x = symbols("x", positive=True)
expr = sympify("(1/x)^a / x^2", locals={"x": x})
powsimp(expr)
Upvotes: 4