本文整理汇总了Python中sympy.Add.as_ordered_terms方法的典型用法代码示例。如果您正苦于以下问题:Python Add.as_ordered_terms方法的具体用法?Python Add.as_ordered_terms怎么用?Python Add.as_ordered_terms使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.Add
的用法示例。
在下文中一共展示了Add.as_ordered_terms方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_as_ordered_terms
# 需要导入模块: from sympy import Add [as 别名]
# 或者: from sympy.Add import as_ordered_terms [as 别名]
def test_as_ordered_terms():
f, g = symbols("f,g", cls=Function)
assert x.as_ordered_terms() == [x]
assert (sin(x) ** 2 * cos(x) + sin(x) * cos(x) ** 2 + 1).as_ordered_terms() == [
sin(x) ** 2 * cos(x),
sin(x) * cos(x) ** 2,
1,
]
args = [f(1), f(2), f(3), f(1, 2, 3), g(1), g(2), g(3), g(1, 2, 3)]
expr = Add(*args)
assert expr.as_ordered_terms() == args
assert (1 + 4 * sqrt(3) * pi * x).as_ordered_terms() == [4 * pi * x * sqrt(3), 1]
assert (2 + 3 * I).as_ordered_terms() == [2, 3 * I]
assert (-2 + 3 * I).as_ordered_terms() == [-2, 3 * I]
assert (2 - 3 * I).as_ordered_terms() == [2, -3 * I]
assert (-2 - 3 * I).as_ordered_terms() == [-2, -3 * I]
assert (4 + 3 * I).as_ordered_terms() == [4, 3 * I]
assert (-4 + 3 * I).as_ordered_terms() == [-4, 3 * I]
assert (4 - 3 * I).as_ordered_terms() == [4, -3 * I]
assert (-4 - 3 * I).as_ordered_terms() == [-4, -3 * I]
f = x ** 2 * y ** 2 + x * y ** 4 + y + 2
assert f.as_ordered_terms(order="lex") == [x ** 2 * y ** 2, x * y ** 4, y, 2]
assert f.as_ordered_terms(order="grlex") == [x * y ** 4, x ** 2 * y ** 2, y, 2]
assert f.as_ordered_terms(order="rev-lex") == [2, y, x * y ** 4, x ** 2 * y ** 2]
assert f.as_ordered_terms(order="rev-grlex") == [2, y, x ** 2 * y ** 2, x * y ** 4]
示例2: test_as_ordered_terms
# 需要导入模块: from sympy import Add [as 别名]
# 或者: from sympy.Add import as_ordered_terms [as 别名]
def test_as_ordered_terms():
f, g = symbols('f,g', cls=Function)
assert x.as_ordered_terms() == [x]
assert (sin(x)**2*cos(x) + sin(x)*cos(x)**2 + 1).as_ordered_terms() == [sin(x)**2*cos(x), sin(x)*cos(x)**2, 1]
expr = Add(*[f(1), f(2), f(3), f(1, 2, 3), g(1), g(2), g(3), g(1, 2, 3)])
assert expr.as_ordered_terms() == \
[f(1), f(2), f(3), f(1, 2, 3), g(1), g(2), g(3), g(1, 2, 3)]
assert (1 + 4*sqrt(3)*pi*x).as_ordered_terms() == [4*pi*x*sqrt(3), 1]
示例3: test_as_ordered_terms
# 需要导入模块: from sympy import Add [as 别名]
# 或者: from sympy.Add import as_ordered_terms [as 别名]
def test_as_ordered_terms():
f, g = symbols('f,g', cls=Function)
assert x.as_ordered_terms() == [x]
assert (sin(x)**2*cos(x) + sin(x)*cos(x)**2 + 1).as_ordered_terms() == [sin(x)**2*cos(x), sin(x)*cos(x)**2, 1]
args = [f(1), f(2), f(3), f(1, 2, 3), g(1), g(2), g(3), g(1, 2, 3)]
expr = Add(*args)
assert expr.as_ordered_terms() == args
assert (1 + 4*sqrt(3)*pi*x).as_ordered_terms() == [4*pi*x*sqrt(3), 1]
assert ( 2 + 3*I).as_ordered_terms() == [ 2, 3*I]
assert (-2 + 3*I).as_ordered_terms() == [-2, 3*I]
assert ( 2 - 3*I).as_ordered_terms() == [ 2, -3*I]
assert (-2 - 3*I).as_ordered_terms() == [-2, -3*I]
assert ( 4 + 3*I).as_ordered_terms() == [ 4, 3*I]
assert (-4 + 3*I).as_ordered_terms() == [-4, 3*I]
assert ( 4 - 3*I).as_ordered_terms() == [ 4, -3*I]
assert (-4 - 3*I).as_ordered_terms() == [-4, -3*I]