英文:
Simplify (1/x)^a / x^2 in sympy
问题
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 at the simplified form?
我已尝试了以下操作,但似乎都没有简化表达式。
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))
# 每次都打印出 (1/x)**a/x**2
英文:
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
答案1
得分: 4
那种简化只能发生在x
为正数时。
from sympy import *
x = symbols("x", positive=True)
expr = sympify("(1/x)^a / x^2", locals={"x": x})
powsimp(expr)
英文:
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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论