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'>
参考)
只有日语
我不太确定你在要求什么,但如果你声明 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
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'>
参考)
只有日语
我不太确定你在要求什么,但如果你声明 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