sympy preorder_traversal: 我想选择 ...tGreaterThan 元素

sympy preorder_traversal: i want to choice ...tGreaterThan element

2路?

① 我要选择 ...tGreaterThan 元素 ----> n > 6.1875

②我可以把它转成字符串,用正则表达式。

preorder_traversal < 走树 https://docs.sympy.org/latest/tutorial/manipulation.html#walking-the-tree

我试试

from sympy import *
var('n')
f=(99/16 < n) & (n < oo)
for arg in preorder_traversal(f):
    print("#",arg,"____",type(arg))
# (n > 6.1875) & (n < oo) ____ And
# n < oo ____ <class 'sympy.core.relational.StrictLessThan'>
# n ____ <class 'sympy.core.symbol.Symbol'>
# oo ____ <class 'sympy.core.numbers.Infinity'>
# n > 6.1875 ____ <class 'sympy.core.relational.StrictGreaterThan'>
# n ____ <class 'sympy.core.symbol.Symbol'>
# 6.18750000000000 ____ <class 'sympy.core.numbers.Float'>

参考)

只有日语

https://ja.whosebug.com/questions/74249/sympy%E3%81%AE1%E5%A4%89%E6%95%B0%E4%B8%8D%E7%AD%89%E5%BC%8F-inequality-solvers-%E3%81%AB%E3%81%A4%E3%81%84%E3%81%A6%E6%95%99%E3%81%88%E3%81%A6%E4%B8%8B%E3%81%95%E3%81%84

我不太确定你在要求什么,但如果你声明 n 是真实的(因此 finite)那么这将自动简化:

In [5]: n = symbols('n', real=True)

In [6]: f=(99/16 < n) & (n < oo)

In [7]: f
Out[7]: n > 6.1875