简化 (1/x)^a / x^2 在 sympy 中的表达式。

huangapple go评论63阅读模式
英文:

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)

huangapple
  • 本文由 发表于 2023年7月17日 20:25:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/76704439.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定