当前位置: 首页>>代码示例>>Python>>正文


Python Expression.sort方法代码示例

本文整理汇总了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
开发者ID:Averroes,项目名称:Mathics,代码行数:30,代码来源:algebra.py

示例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
开发者ID:Piruzzolo,项目名称:Mathics,代码行数:10,代码来源:algebra.py

示例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
开发者ID:sn6uv,项目名称:Mathics,代码行数:38,代码来源:algebra.py


注:本文中的mathics.core.expression.Expression.sort方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。