本文整理汇总了Python中mathics.core.expression.Expression.sort方法的典型用法代码示例。如果您正苦于以下问题:Python Expression.sort方法的具体用法?Python Expression.sort怎么用?Python Expression.sort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mathics.core.expression.Expression
的用法示例。
在下文中一共展示了Expression.sort方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: apply
# 需要导入模块: from mathics.core.expression import Expression [as 别名]
# 或者: from mathics.core.expression.Expression import sort [as 别名]
def apply(self, expr, evaluation):
'Variables[expr_]'
variables = set()
def find_vars(e):
if e.to_sympy().is_constant():
return
elif e.is_symbol():
variables.add(e)
elif (e.has_form('Plus', None) or
e.has_form('Times', None)):
for l in e.leaves:
find_vars(l)
elif e.has_form('Power', 2):
(a, b) = e.leaves # a^b
if not(a.to_sympy().is_constant()) and b.to_sympy().is_rational:
find_vars(a)
elif not(e.is_atom()):
variables.add(e)
exprs = expr.leaves if expr.has_form('List', None) else [expr]
for e in exprs:
find_vars(from_sympy(e.to_sympy().expand()))
variables = Expression('List', *variables)
variables.sort() # MMA doesn't do this
return variables
示例2: apply
# 需要导入模块: from mathics.core.expression import Expression [as 别名]
# 或者: from mathics.core.expression.Expression import sort [as 别名]
def apply(self, expr, evaluation):
'Variables[expr_]'
variables = find_all_vars(expr)
variables = Expression('List', *variables)
variables.sort() # MMA doesn't do this
return variables
示例3: apply
# 需要导入模块: from mathics.core.expression import Expression [as 别名]
# 或者: from mathics.core.expression.Expression import sort [as 别名]
def apply(self, expr, evaluation):
'Variables[expr_]'
variables = set()
def find_vars(e, e_sympy):
assert e_sympy is not None
if e_sympy.is_constant():
return
elif e.is_symbol():
variables.add(e)
elif (e.has_form('Plus', None) or
e.has_form('Times', None)):
for l in e.leaves:
l_sympy = l.to_sympy()
if l_sympy is not None:
find_vars(l, l_sympy)
elif e.has_form('Power', 2):
(a, b) = e.leaves # a^b
a_sympy, b_sympy = a.to_sympy(), b.to_sympy()
if a_sympy is None or b_sympy is None:
return
if not(a_sympy.is_constant()) and b_sympy.is_rational:
find_vars(a, a_sympy)
elif not(e.is_atom()):
variables.add(e)
exprs = expr.leaves if expr.has_form('List', None) else [expr]
for e in exprs:
e_sympy = e.to_sympy()
if e_sympy is not None:
find_vars(e, e_sympy)
variables = Expression('List', *variables)
variables.sort() # MMA doesn't do this
return variables