SymPy simplify relational (inequality) expression

给你一囗甜甜゛ 提交于 2019-12-08 03:04:22

问题


Why doesn't the following simplification work, or how could it be fixed:

>>> x = Symbol('x', real=True)
>>> y = Symbol('y', real=True)
>>> simplify(x - 1 < y - 1)
x - 1 < y - 1

But this works:

>>> simplify(x - 1 - (y - 1) < 0)
x - y < 0

Can somehow the first expression be simplified to x < y?

Thanks


回答1:


You could solve for x:

import sympy as sy
x, y = sy.symbols('x,y', real=True)
print(sy.solve(x - 1 < y - 1, x))

yields

x < y

x, y, z = sy.symbols('x,y,z', real=True)
print(sy.solve(x - 1 < y*z - 1, x))

yields

x < y*z


来源:https://stackoverflow.com/questions/27825581/sympy-simplify-relational-inequality-expression

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!