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


Python Q.even方法代码示例

本文整理汇总了Python中sympy.Q.even方法的典型用法代码示例。如果您正苦于以下问题:Python Q.even方法的具体用法?Python Q.even怎么用?Python Q.even使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sympy.Q的用法示例。


在下文中一共展示了Q.even方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_pow

# 需要导入模块: from sympy import Q [as 别名]
# 或者: from sympy.Q import even [as 别名]
def test_pow():
    assert refine((-1) ** x, Q.even(x)) == 1
    assert refine((-1) ** x, Q.odd(x)) == -1
    assert refine((-2) ** x, Q.even(x)) == 2 ** x

    # nested powers
    assert refine(sqrt(x ** 2)) != Abs(x)
    assert refine(sqrt(x ** 2), Q.complex(x)) != Abs(x)
    assert refine(sqrt(x ** 2), Q.real(x)) == Abs(x)
    assert refine(sqrt(x ** 2), Q.positive(x)) == x
    assert refine((x ** 3) ** (S(1) / 3)) != x

    assert refine((x ** 3) ** (S(1) / 3), Q.real(x)) != x
    assert refine((x ** 3) ** (S(1) / 3), Q.positive(x)) == x

    assert refine(sqrt(1 / x), Q.real(x)) != 1 / sqrt(x)
    assert refine(sqrt(1 / x), Q.positive(x)) == 1 / sqrt(x)

    # powers of (-1)
    assert refine((-1) ** (x + y), Q.even(x)) == (-1) ** y
    assert refine((-1) ** (x + y + z), Q.odd(x) & Q.odd(z)) == (-1) ** y
    assert refine((-1) ** (x + y + 1), Q.odd(x)) == (-1) ** y
    assert refine((-1) ** (x + y + 2), Q.odd(x)) == (-1) ** (y + 1)
    assert refine((-1) ** (x + 3)) == (-1) ** (x + 1)

    assert refine((-1) ** ((-1) ** x / 2 - S.Half), Q.integer(x)) == (-1) ** x
    assert refine((-1) ** ((-1) ** x / 2 + S.Half), Q.integer(x)) == (-1) ** (x + 1)
    assert refine((-1) ** ((-1) ** x / 2 + 5 * S.Half), Q.integer(x)) == (-1) ** (x + 1)
    assert refine((-1) ** ((-1) ** x / 2 - 7 * S.Half), Q.integer(x)) == (-1) ** (x + 1)
    assert refine((-1) ** ((-1) ** x / 2 - 9 * S.Half), Q.integer(x)) == (-1) ** x

    # powers of Abs
    assert refine(Abs(x) ** 2, Q.real(x)) == x ** 2
    assert refine(Abs(x) ** 3, Q.real(x)) == Abs(x) ** 3
    assert refine(Abs(x) ** 2) == Abs(x) ** 2
开发者ID:neitzke,项目名称:sympy,代码行数:37,代码来源:test_refine.py

示例2: test_pow

# 需要导入模块: from sympy import Q [as 别名]
# 或者: from sympy.Q import even [as 别名]
def test_pow():
    x, y, z = symbols('x,y,z')
    assert refine((-1)**x, Q.even(x)) == 1
    assert refine((-1)**x, Q.odd(x)) == -1
    assert refine((-2)**x, Q.even(x)) == 2**x

    # nested powers
    assert refine(sqrt(x**2)) != Abs(x)
    assert refine(sqrt(x**2), Q.complex(x)) != Abs(x)
    assert refine(sqrt(x**2), Q.real(x)) == Abs(x)
    assert refine(sqrt(x**2), Q.positive(x)) == x
    assert refine((x**3)**(S(1)/3)) != x

    assert refine((x**3)**(S(1)/3), Q.real(x)) != x
    assert refine((x**3)**(S(1)/3), Q.positive(x)) == x

    assert refine(sqrt(1/x), Q.real(x)) != 1/sqrt(x)
    assert refine(sqrt(1/x), Q.positive(x)) == 1/sqrt(x)

    # powers of (-1)
    assert refine((-1)**(x+y), Q.even(x)) == (-1)**y
    assert refine((-1)**(x+y+z), Q.odd(x) & Q.odd(z))==(-1)**y
    assert refine((-1)**(x+y+1), Q.odd(x))==(-1)**y
    assert refine((-1)**(x+y+2), Q.odd(x))==(-1)**(y+1)
    assert refine((-1)**(x+3)) == (-1)**(x+1)
开发者ID:101man,项目名称:sympy,代码行数:27,代码来源:test_refine.py

示例3: test_pow2

# 需要导入模块: from sympy import Q [as 别名]
# 或者: from sympy.Q import even [as 别名]
def test_pow2():
    # powers of (-1)
    assert refine((-1)**(x + y), Q.even(x)) == (-1)**y
    assert refine((-1)**(x + y + z), Q.odd(x) & Q.odd(z)) == (-1)**y
    assert refine((-1)**(x + y + 1), Q.odd(x)) == (-1)**y
    assert refine((-1)**(x + y + 2), Q.odd(x)) == (-1)**(y + 1)
    assert refine((-1)**(x + 3)) == (-1)**(x + 1)
开发者ID:KonstantinTogoi,项目名称:sympy,代码行数:9,代码来源:test_refine.py

示例4: test_pow1

# 需要导入模块: from sympy import Q [as 别名]
# 或者: from sympy.Q import even [as 别名]
def test_pow1():
    assert refine((-1)**x, Q.even(x)) == 1
    assert refine((-1)**x, Q.odd(x)) == -1
    assert refine((-2)**x, Q.even(x)) == 2**x

    # nested powers
    assert refine(sqrt(x**2)) != Abs(x)
    assert refine(sqrt(x**2), Q.complex(x)) != Abs(x)
    assert refine(sqrt(x**2), Q.real(x)) == Abs(x)
    assert refine(sqrt(x**2), Q.positive(x)) == x
    assert refine((x**3)**(S(1)/3)) != x

    assert refine((x**3)**(S(1)/3), Q.real(x)) != x
    assert refine((x**3)**(S(1)/3), Q.positive(x)) == x

    assert refine(sqrt(1/x), Q.real(x)) != 1/sqrt(x)
    assert refine(sqrt(1/x), Q.positive(x)) == 1/sqrt(x)
开发者ID:KonstantinTogoi,项目名称:sympy,代码行数:19,代码来源:test_refine.py

示例5: test_pow

# 需要导入模块: from sympy import Q [as 别名]
# 或者: from sympy.Q import even [as 别名]
def test_pow():
    x = Symbol('x', even=True)
    assert refine((-1)**x) == 1
    x = Symbol('x', odd=True)
    assert refine((-1)**x) == -1
    x = Symbol('x', even=True)
    assert refine((-2)**x) == 2**x

    # nested powers
    x = Symbol('x')
    assert refine(sqrt(x**2)) != Abs(x)
    x = Symbol('x', complex=True)
    assert refine(sqrt(x**2)) != Abs(x)
    x = Symbol('x', real=True)
    assert refine(sqrt(x**2)) == Abs(x)
    p = Symbol('p', positive=True)
    assert refine(sqrt(p**2)) == p
    x = Symbol('x')
    assert refine((x**3)**(S(1)/3)) != x
    x = Symbol('x', real=True)
    assert refine((x**3)**(S(1)/3)) != x
    x = Symbol('x', positive=True)
    assert refine((x**3)**(S(1)/3)) == x
    x = Symbol('x', real=True)
    assert refine(sqrt(1/x)) != 1/sqrt(x)
    x = Symbol('x', positive=True)
    assert refine(sqrt(1/x)) == 1/sqrt(x)

    # powers of (-1)
    x = Symbol('x', even=True)
    assert refine((-1)**(x + y), Q.even(x)) == (-1)**y
    x = Symbol('x', odd=True)
    z = Symbol('z', odd=True)
    assert refine((-1)**(x + y + z), Q.odd(x) & Q.odd(z)) == (-1)**y
    assert refine((-1)**(x + y + 1), Q.odd(x)) == (-1)**y
    assert refine((-1)**(x + y + 2), Q.odd(x)) == (-1)**(y + 1)
    x = Symbol('x')
    assert refine((-1)**(x + 3)) == (-1)**(x + 1)
    x = Symbol('x', integer=True)
    assert refine((-1)**((-1)**x/2 - S.Half), Q.integer(x)) == (-1)**x
    assert refine((-1)**((-1)**x/2 + S.Half), Q.integer(x)) == (-1)**(x + 1)
    assert refine((-1)**((-1)**x/2 + 5*S.Half), Q.integer(x)) == (-1)**(x + 1)
    assert refine((-1)**((-1)**x/2 - 7*S.Half), Q.integer(x)) == (-1)**(x + 1)
    assert refine((-1)**((-1)**x/2 - 9*S.Half), Q.integer(x)) == (-1)**x

    # powers of Abs
    x = Symbol('x', real=True)
    assert refine(Abs(x)**2, Q.real(x)) == x**2
    assert refine(Abs(x)**3, Q.real(x)) == Abs(x)**3
    x = Symbol('x')
    assert refine(Abs(x)**2) == Abs(x)**2
开发者ID:preetskhalsa97,项目名称:sympy,代码行数:53,代码来源:test_refine.py

示例6: test_odd

# 需要导入模块: from sympy import Q [as 别名]
# 或者: from sympy.Q import even [as 别名]
def test_odd():
    assert satask(Q.odd(2)) is False
    assert satask(Q.odd(3)) is True

    assert satask(Q.odd(x*y), Q.even(x) & Q.odd(y)) is False
    assert satask(Q.odd(x*y), Q.even(x) & Q.integer(y)) is False
    assert satask(Q.odd(x*y), Q.even(x) & Q.even(y)) is False
    assert satask(Q.odd(x*y), Q.odd(x) & Q.odd(y)) is True
    assert satask(Q.odd(x*y), Q.even(x)) is None
    assert satask(Q.odd(x*y), Q.odd(x) & Q.integer(y)) is None
    assert satask(Q.odd(x*y), Q.odd(x) & Q.odd(y)) is True

    assert satask(Q.odd(abs(x)), Q.even(x)) is False
    assert satask(Q.odd(abs(x)), Q.odd(x)) is True
    assert satask(Q.odd(x), Q.odd(abs(x))) is None # x could be complex
开发者ID:EuanFree,项目名称:sympy,代码行数:17,代码来源:test_satask.py


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