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


Python Q.positive方法代码示例

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


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

示例1: test_CheckOldAssump

# 需要导入模块: from sympy import Q [as 别名]
# 或者: from sympy.Q import positive [as 别名]
def test_CheckOldAssump():
    # TODO: Make these tests more complete

    class Test1(Expr):
        def _eval_is_positive(self):
            return True
        def _eval_is_negative(self):
            return False

    class Test2(Expr):
        def _eval_is_finite(self):
            return True
        def _eval_is_positive(self):
            return True
        def _eval_is_negative(self):
            return False

    t1 = Test1()
    t2 = Test2()

    # We can't say if it's positive or negative in the old assumptions without
    # bounded. Remember, True means "no new knowledge", and
    # Q.positive(t2) means "t2 is positive."
    assert CheckOldAssump(Q.positive(t1)) == True
    assert CheckOldAssump(Q.negative(t1)) == ~Q.negative(t1)

    assert CheckOldAssump(Q.positive(t2)) == Q.positive(t2)
    assert CheckOldAssump(Q.negative(t2)) == ~Q.negative(t2)
开发者ID:A-turing-machine,项目名称:sympy,代码行数:30,代码来源:test_sathandlers.py

示例2: test_pow

# 需要导入模块: from sympy import Q [as 别名]
# 或者: from sympy.Q import positive [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

示例3: test_pow

# 需要导入模块: from sympy import Q [as 别名]
# 或者: from sympy.Q import positive [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

示例4: test_Abs

# 需要导入模块: from sympy import Q [as 别名]
# 或者: from sympy.Q import positive [as 别名]
def test_Abs():
    assert refine(Abs(x), Q.positive(x)) == x
    assert refine(1 + Abs(x), Q.positive(x)) == 1 + x
    assert refine(Abs(x), Q.negative(x)) == -x
    assert refine(1 + Abs(x), Q.negative(x)) == 1 - x

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

示例5: test_refine_issue_12724

# 需要导入模块: from sympy import Q [as 别名]
# 或者: from sympy.Q import positive [as 别名]
def test_refine_issue_12724():
    expr1 = refine(Abs(x * y), Q.positive(x))
    expr2 = refine(Abs(x * y * z), Q.positive(x))
    assert expr1 == x * Abs(y)
    assert expr2 == x * Abs(y * z)
    y1 = Symbol('y1', real = True)
    expr3 = refine(Abs(x * y1**2 * z), Q.positive(x))
    assert expr3 == x * y1**2 * Abs(z)
开发者ID:KonstantinTogoi,项目名称:sympy,代码行数:10,代码来源:test_refine.py

示例6: test_ExactlyOneArg

# 需要导入模块: from sympy import Q [as 别名]
# 或者: from sympy.Q import positive [as 别名]
def test_ExactlyOneArg():
    a = ExactlyOneArg(Q.zero)
    b = ExactlyOneArg(Q.positive | Q.negative)
    assert a.rcall(x*y) == Or(Q.zero(x) & ~Q.zero(y), Q.zero(y) & ~Q.zero(x))
    assert a.rcall(x*y*z) == Or(Q.zero(x) & ~Q.zero(y) & ~Q.zero(z), Q.zero(y)
        & ~Q.zero(x) & ~Q.zero(z), Q.zero(z) & ~Q.zero(x) & ~Q.zero(y))
    assert b.rcall(x*y) == Or((Q.positive(x) | Q.negative(x)) &
        ~(Q.positive(y) | Q.negative(y)), (Q.positive(y) | Q.negative(y)) &
        ~(Q.positive(x) | Q.negative(x)))
开发者ID:A-turing-machine,项目名称:sympy,代码行数:11,代码来源:test_sathandlers.py

示例7: test_atan2

# 需要导入模块: from sympy import Q [as 别名]
# 或者: from sympy.Q import positive [as 别名]
def test_atan2():
    assert refine(atan2(y, x), Q.real(y) & Q.positive(x)) == atan(y/x)
    assert refine(atan2(y, x), Q.negative(y) & Q.positive(x)) == atan(y/x)
    assert refine(atan2(y, x), Q.negative(y) & Q.negative(x)) == atan(y/x) - pi
    assert refine(atan2(y, x), Q.positive(y) & Q.negative(x)) == atan(y/x) + pi
    assert refine(atan2(y, x), Q.zero(y) & Q.negative(x)) == pi
    assert refine(atan2(y, x), Q.positive(y) & Q.zero(x)) == pi/2
    assert refine(atan2(y, x), Q.negative(y) & Q.zero(x)) == -pi/2
    assert refine(atan2(y, x), Q.zero(y) & Q.zero(x)) == nan
开发者ID:preetskhalsa97,项目名称:sympy,代码行数:11,代码来源:test_refine.py

示例8: test_pos_neg

# 需要导入模块: from sympy import Q [as 别名]
# 或者: from sympy.Q import positive [as 别名]
def test_pos_neg():
    assert satask(~Q.positive(x), Q.negative(x)) is True
    assert satask(~Q.negative(x), Q.positive(x)) is True
    assert satask(Q.positive(x + y), Q.positive(x) & Q.positive(y)) is True
    assert satask(Q.negative(x + y), Q.negative(x) & Q.negative(y)) is True
    assert satask(Q.positive(x + y), Q.negative(x) & Q.negative(y)) is False
    assert satask(Q.negative(x + y), Q.positive(x) & Q.positive(y)) is False
开发者ID:asmeurer,项目名称:sympy,代码行数:9,代码来源:test_satask.py

示例9: test_zero_pow

# 需要导入模块: from sympy import Q [as 别名]
# 或者: from sympy.Q import positive [as 别名]
def test_zero_pow():
    assert satask(Q.zero(x**y), Q.zero(x) & Q.positive(y)) is True
    assert satask(Q.zero(x**y), Q.nonzero(x) & Q.zero(y)) is False

    assert satask(Q.zero(x), Q.zero(x**y)) is True

    assert satask(Q.zero(x**y), Q.zero(x)) is None
开发者ID:EuanFree,项目名称:sympy,代码行数:9,代码来源:test_satask.py

示例10: test_abs

# 需要导入模块: from sympy import Q [as 别名]
# 或者: from sympy.Q import positive [as 别名]
def test_abs():
    assert satask(Q.nonnegative(abs(x))) is True
    assert satask(Q.positive(abs(x)), ~Q.zero(x)) is True
    assert satask(Q.zero(x), ~Q.zero(abs(x))) is False
    assert satask(Q.zero(x), Q.zero(abs(x))) is True
    assert satask(Q.nonzero(x), ~Q.zero(abs(x))) is None # x could be complex
    assert satask(Q.zero(abs(x)), Q.zero(x)) is True
开发者ID:EuanFree,项目名称:sympy,代码行数:9,代码来源:test_satask.py

示例11: test_pow1

# 需要导入模块: from sympy import Q [as 别名]
# 或者: from sympy.Q import positive [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

示例12: test_old_assump

# 需要导入模块: from sympy import Q [as 别名]
# 或者: from sympy.Q import positive [as 别名]
def test_old_assump():
    assert satask(Q.positive(1)) is True
    assert satask(Q.positive(-1)) is False
    assert satask(Q.positive(0)) is False
    assert satask(Q.positive(I)) is False
    assert satask(Q.positive(pi)) is True

    assert satask(Q.negative(1)) is False
    assert satask(Q.negative(-1)) is True
    assert satask(Q.negative(0)) is False
    assert satask(Q.negative(I)) is False
    assert satask(Q.negative(pi)) is False

    assert satask(Q.zero(1)) is False
    assert satask(Q.zero(-1)) is False
    assert satask(Q.zero(0)) is True
    assert satask(Q.zero(I)) is False
    assert satask(Q.zero(pi)) is False

    assert satask(Q.nonzero(1)) is True
    assert satask(Q.nonzero(-1)) is True
    assert satask(Q.nonzero(0)) is False
    assert satask(Q.nonzero(I)) is False
    assert satask(Q.nonzero(pi)) is True

    assert satask(Q.nonpositive(1)) is False
    assert satask(Q.nonpositive(-1)) is True
    assert satask(Q.nonpositive(0)) is True
    assert satask(Q.nonpositive(I)) is False
    assert satask(Q.nonpositive(pi)) is False

    assert satask(Q.nonnegative(1)) is True
    assert satask(Q.nonnegative(-1)) is False
    assert satask(Q.nonnegative(0)) is True
    assert satask(Q.nonnegative(I)) is False
    assert satask(Q.nonnegative(pi)) is True
开发者ID:EuanFree,项目名称:sympy,代码行数:38,代码来源:test_satask.py

示例13: test_positive_definite

# 需要导入模块: from sympy import Q [as 别名]
# 或者: from sympy.Q import positive [as 别名]
def test_positive_definite():
    assert ask(Q.positive_definite(X), Q.positive_definite(X))
    assert ask(Q.positive_definite(X.T), Q.positive_definite(X)) is True
    assert ask(Q.positive_definite(X.I), Q.positive_definite(X)) is True
    assert ask(Q.positive_definite(Y)) is False
    assert ask(Q.positive_definite(X)) is None
    assert ask(Q.positive_definite(X*Z*X),
            Q.positive_definite(X) & Q.positive_definite(Z)) is True
    assert ask(Q.positive_definite(X), Q.orthogonal(X))
    assert ask(Q.positive_definite(Y.T*X*Y),
            Q.positive_definite(X) & Q.fullrank(Y)) is True
    assert not ask(Q.positive_definite(Y.T*X*Y), Q.positive_definite(X))
    assert ask(Q.positive_definite(Identity(3))) is True
    assert ask(Q.positive_definite(ZeroMatrix(3, 3))) is False
    assert ask(Q.positive_definite(X + Z), Q.positive_definite(X) &
            Q.positive_definite(Z)) is True
    assert not ask(Q.positive_definite(-X), Q.positive_definite(X))
    assert ask(Q.positive(X[1, 1]), Q.positive_definite(X))
开发者ID:KonstantinTogoi,项目名称:sympy,代码行数:20,代码来源:test_matrices.py

示例14: test_call

# 需要导入模块: from sympy import Q [as 别名]
# 或者: from sympy.Q import positive [as 别名]
def test_call():
    x, y = symbols('x y')
    # See the long history of this in issues 5026 and 5105.

    raises(TypeError, lambda: sin(x)({ x : 1, sin(x) : 2}))
    raises(TypeError, lambda: sin(x)(1))

    # No effect as there are no callables
    assert sin(x).rcall(1) == sin(x)
    assert (1 + sin(x)).rcall(1) == 1 + sin(x)

    # Effect in the pressence of callables
    l = Lambda(x, 2*x)
    assert (l + x).rcall(y) == 2*y + x
    assert (x**l).rcall(2) == x**4
    # TODO UndefinedFunction does not subclass Expr
    #f = Function('f')
    #assert (2*f)(x) == 2*f(x)

    assert (Q.real & Q.positive).rcall(x) == Q.real(x) & Q.positive(x)
开发者ID:A-turing-machine,项目名称:sympy,代码行数:22,代码来源:test_basic.py

示例15: test_satask

# 需要导入模块: from sympy import Q [as 别名]
# 或者: from sympy.Q import positive [as 别名]
def test_satask():
    # No relevant facts
    assert satask(Q.real(x), Q.real(x)) is True
    assert satask(Q.real(x), ~Q.real(x)) is False
    assert satask(Q.real(x)) is None

    assert satask(Q.real(x), Q.positive(x)) is True
    assert satask(Q.positive(x), Q.real(x)) is None
    assert satask(Q.real(x), ~Q.positive(x)) is None
    assert satask(Q.positive(x), ~Q.real(x)) is False

    raises(ValueError, lambda: satask(Q.real(x), Q.real(x) & ~Q.real(x)))

    with assuming(Q.positive(x)):
        assert satask(Q.real(x)) is True
        assert satask(~Q.positive(x)) is False
        raises(ValueError, lambda: satask(Q.real(x), ~Q.positive(x)))

    assert satask(Q.zero(x), Q.nonzero(x)) is False
    assert satask(Q.positive(x), Q.zero(x)) is False
    assert satask(Q.real(x), Q.zero(x)) is True
    assert satask(Q.zero(x), Q.zero(x*y)) is None
    assert satask(Q.zero(x*y), Q.zero(x))
开发者ID:EuanFree,项目名称:sympy,代码行数:25,代码来源:test_satask.py


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