我想找到一种方法让sympy
solveset
函数返回一个表达式,我可以对其进行进一步的代数操作。如果做不到这一点,我想将solveset
输出转换为sympy
表达式,或者为了类似的目的使用替代函数。
# Writing an expression that I will later solve.
import sympy as sy
x, y = sy.symbols('x y')
exp1 = x + y*x + y**2
# This returns a core.syymbol.Symbol
exp2 = sy.solveset(exp1, x)
# This returns a sets.sets.FiniteSet
# Now trying to subtract a further expression results in an error.
exp2 - y
# AttributeError: 'Symbol' object has no attribute '_complement'