本文整理汇总了Python中sympy.assumptions.Q.positive方法的典型用法代码示例。如果您正苦于以下问题:Python Q.positive方法的具体用法?Python Q.positive怎么用?Python Q.positive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.assumptions.Q
的用法示例。
在下文中一共展示了Q.positive方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_float_1
# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import positive [as 别名]
def test_float_1():
z = 1.0
assert ask(Q.commutative(z)) == True
assert ask(Q.integer(z)) == True
assert ask(Q.rational(z)) == True
assert ask(Q.real(z)) == True
assert ask(Q.complex(z)) == True
assert ask(Q.irrational(z)) == False
assert ask(Q.imaginary(z)) == False
assert ask(Q.positive(z)) == True
assert ask(Q.negative(z)) == False
assert ask(Q.even(z)) == False
assert ask(Q.odd(z)) == True
assert ask(Q.bounded(z)) == True
assert ask(Q.infinitesimal(z)) == False
assert ask(Q.prime(z)) == False
assert ask(Q.composite(z)) == True
z = 7.2123
assert ask(Q.commutative(z)) == True
assert ask(Q.integer(z)) == False
assert ask(Q.rational(z)) == True
assert ask(Q.real(z)) == True
assert ask(Q.complex(z)) == True
assert ask(Q.irrational(z)) == False
assert ask(Q.imaginary(z)) == False
assert ask(Q.positive(z)) == True
assert ask(Q.negative(z)) == False
assert ask(Q.even(z)) == False
assert ask(Q.odd(z)) == False
assert ask(Q.bounded(z)) == True
assert ask(Q.infinitesimal(z)) == False
assert ask(Q.prime(z)) == False
assert ask(Q.composite(z)) == False
示例2: test_extended_real
# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import positive [as 别名]
def test_extended_real():
x = symbols('x')
assert ask(Q.extended_real(x), Q.positive(x)) == True
assert ask(Q.extended_real(-x), Q.positive(x)) == True
assert ask(Q.extended_real(-x), Q.negative(x)) == True
assert ask(Q.extended_real(x+S.Infinity), Q.real(x)) == True
示例3: test_functions_in_assumptions
# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import positive [as 别名]
def test_functions_in_assumptions():
from sympy.logic.boolalg import Equivalent, Xor
x = symbols("x")
assert ask(x, Q.negative, Q.real(x) >> Q.positive(x)) is False
assert ask(x, Q.negative, Equivalent(Q.real(x), Q.positive(x))) is False
assert ask(x, Q.negative, Xor(Q.real(x), Q.negative(x))) is False
示例4: Pow
# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import positive [as 别名]
def Pow(expr, assumptions):
"""
Real**Integer -> Real
Positive**Real -> Real
Real**(Integer/Even) -> Real if base is nonnegative
Real**(Integer/Odd) -> Real
Real**Imaginary -> ?
Imaginary**Real -> ?
Real**Real -> ?
"""
if expr.is_number:
return AskRealHandler._number(expr, assumptions)
if ask(Q.imaginary(expr.base), assumptions):
if ask(Q.real(expr.exp), assumptions):
if ask(Q.odd(expr.exp), assumptions):
return False
elif ask(Q.even(expr.exp), assumptions):
return True
elif ask(Q.real(expr.base), assumptions):
if ask(Q.real(expr.exp), assumptions):
if expr.exp.is_Rational and \
ask(Q.even(expr.exp.q), assumptions):
return ask(Q.positive(expr.base), assumptions)
elif ask(Q.integer(expr.exp), assumptions):
return True
elif ask(Q.positive(expr.base), assumptions):
return True
elif ask(Q.negative(expr.base), assumptions):
return False
示例5: refine_atan2
# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import positive [as 别名]
def refine_atan2(expr, assumptions):
"""
Handler for the atan2 function
Examples
========
>>> from sympy import Symbol, Q, refine, atan2
>>> from sympy.assumptions.refine import refine_atan2
>>> from sympy.abc import x, y
>>> refine_atan2(atan2(y,x), Q.real(y) & Q.positive(x))
atan(y/x)
>>> refine_atan2(atan2(y,x), Q.negative(y) & Q.negative(x))
atan(y/x) - pi
>>> refine_atan2(atan2(y,x), Q.positive(y) & Q.negative(x))
atan(y/x) + pi
"""
from sympy.functions.elementary.complexes import atan
from sympy.core import S
y, x = expr.args
if ask(Q.real(y) & Q.positive(x), assumptions):
return atan(y / x)
elif ask(Q.negative(y) & Q.negative(x), assumptions):
return atan(y / x) - S.Pi
elif ask(Q.positive(y) & Q.negative(x), assumptions):
return atan(y / x) + S.Pi
else:
return expr
示例6: test_refine
# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import positive [as 别名]
def test_refine():
m0 = OperationsOnlyMatrix([[Abs(x)**2, sqrt(x**2)],
[sqrt(x**2)*Abs(y)**2, sqrt(y**2)*Abs(x)**2]])
m1 = m0.refine(Q.real(x) & Q.real(y))
assert m1 == Matrix([[x**2, Abs(x)], [y**2*Abs(x), x**2*Abs(y)]])
m1 = m0.refine(Q.positive(x) & Q.positive(y))
assert m1 == Matrix([[x**2, x], [x*y**2, x**2*y]])
m1 = m0.refine(Q.negative(x) & Q.negative(y))
assert m1 == Matrix([[x**2, -x], [-x*y**2, -x**2*y]])
示例7: Pow
# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import positive [as 别名]
def Pow(expr, assumptions):
"""
Real**Integer -> Real
Positive**Real -> Real
Real**(Integer/Even) -> Real if base is nonnegative
Real**(Integer/Odd) -> Real
Imaginary**(Integer/Even) -> Real
Imaginary**(Integer/Odd) -> not Real
Imaginary**Real -> ? since Real could be 0 (giving real) or 1 (giving imaginary)
b**Imaginary -> Real if log(b) is imaginary and b != 0 and exponent != integer multiple of I*pi/log(b)
Real**Real -> ? e.g. sqrt(-1) is imaginary and sqrt(2) is not
"""
if expr.is_number:
return AskRealHandler._number(expr, assumptions)
if expr.base.func == exp:
if ask(Q.imaginary(expr.base.args[0]), assumptions):
if ask(Q.imaginary(expr.exp), assumptions):
return True
# If the i = (exp's arg)/(I*pi) is an integer or half-integer
# multiple of I*pi then 2*i will be an integer. In addition,
# exp(i*I*pi) = (-1)**i so the overall realness of the expr
# can be determined by replacing exp(i*I*pi) with (-1)**i.
i = expr.base.args[0]/I/pi
if ask(Q.integer(2*i), assumptions):
return ask(Q.real(((-1)**i)**expr.exp), assumptions)
return
if ask(Q.imaginary(expr.base), assumptions):
if ask(Q.integer(expr.exp), assumptions):
odd = ask(Q.odd(expr.exp), assumptions)
if odd is not None:
return not odd
return
if ask(Q.imaginary(expr.exp), assumptions):
imlog = ask(Q.imaginary(log(expr.base)), assumptions)
if imlog is not None:
# I**i -> real, log(I) is imag;
# (2*I)**i -> complex, log(2*I) is not imag
return imlog
if ask(Q.real(expr.base), assumptions):
if ask(Q.real(expr.exp), assumptions):
if expr.exp.is_Rational and \
ask(Q.even(expr.exp.q), assumptions):
return ask(Q.positive(expr.base), assumptions)
elif ask(Q.integer(expr.exp), assumptions):
return True
elif ask(Q.positive(expr.base), assumptions):
return True
elif ask(Q.negative(expr.base), assumptions):
return False
示例8: test_I
# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import positive [as 别名]
def test_I():
I = S.ImaginaryUnit
z = I
assert ask(Q.commutative(z)) == True
assert ask(Q.integer(z)) == False
assert ask(Q.rational(z)) == False
assert ask(Q.real(z)) == False
assert ask(Q.complex(z)) == True
assert ask(Q.irrational(z)) == False
assert ask(Q.imaginary(z)) == True
assert ask(Q.positive(z)) == False
assert ask(Q.negative(z)) == False
assert ask(Q.even(z)) == False
assert ask(Q.odd(z)) == False
assert ask(Q.bounded(z)) == True
assert ask(Q.infinitesimal(z)) == False
assert ask(Q.prime(z)) == False
assert ask(Q.composite(z)) == False
z = 1 + I
assert ask(Q.commutative(z)) == True
assert ask(Q.integer(z)) == False
assert ask(Q.rational(z)) == False
assert ask(Q.real(z)) == False
assert ask(Q.complex(z)) == True
assert ask(Q.irrational(z)) == False
assert ask(Q.imaginary(z)) == False
assert ask(Q.positive(z)) == False
assert ask(Q.negative(z)) == False
assert ask(Q.even(z)) == False
assert ask(Q.odd(z)) == False
assert ask(Q.bounded(z)) == True
assert ask(Q.infinitesimal(z)) == False
assert ask(Q.prime(z)) == False
assert ask(Q.composite(z)) == False
z = I*(1+I)
assert ask(Q.commutative(z)) == True
assert ask(Q.integer(z)) == False
assert ask(Q.rational(z)) == False
assert ask(Q.real(z)) == False
assert ask(Q.complex(z)) == True
assert ask(Q.irrational(z)) == False
assert ask(Q.imaginary(z)) == False
assert ask(Q.positive(z)) == False
assert ask(Q.negative(z)) == False
assert ask(Q.even(z)) == False
assert ask(Q.odd(z)) == False
assert ask(Q.bounded(z)) == True
assert ask(Q.infinitesimal(z)) == False
assert ask(Q.prime(z)) == False
assert ask(Q.composite(z)) == False
示例9: test_negative
# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import positive [as 别名]
def test_negative():
x, y = symbols('x,y')
assert ask(Q.negative(x), Q.negative(x)) == True
assert ask(Q.negative(x), Q.positive(x)) == False
assert ask(Q.negative(x), ~Q.real(x)) == False
assert ask(Q.negative(x), Q.prime(x)) == False
assert ask(Q.negative(x), ~Q.prime(x)) == None
assert ask(Q.negative(-x), Q.positive(x)) == True
assert ask(Q.negative(-x), ~Q.positive(x)) == None
assert ask(Q.negative(-x), Q.negative(x)) == False
assert ask(Q.negative(-x), Q.positive(x)) == True
assert ask(Q.negative(x-1), Q.negative(x)) == True
assert ask(Q.negative(x+y)) == None
assert ask(Q.negative(x+y), Q.negative(x)) == None
assert ask(Q.negative(x+y), Q.negative(x) & Q.negative(y)) == True
assert ask(Q.negative(x**2)) == None
assert ask(Q.negative(x**2), Q.real(x)) == False
assert ask(Q.negative(x**1.4), Q.real(x)) == None
assert ask(Q.negative(x*y)) == None
assert ask(Q.negative(x*y), Q.positive(x) & Q.positive(y)) == False
assert ask(Q.negative(x*y), Q.positive(x) & Q.negative(y)) == True
assert ask(Q.negative(x*y), Q.complex(x) & Q.complex(y)) == None
assert ask(Q.negative(x**y)) == None
assert ask(Q.negative(x**y), Q.negative(x) & Q.even(y)) == False
assert ask(Q.negative(x**y), Q.negative(x) & Q.odd(y)) == True
assert ask(Q.negative(x**y), Q.positive(x) & Q.integer(y)) == False
assert ask(Q.negative(Abs(x))) == False
示例10: log
# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import positive [as 别名]
def log(expr, assumptions):
r = ask(Q.real(expr.args[0]), assumptions)
if r is not True:
return r
if ask(Q.positive(expr.args[0] - 1), assumptions):
return True
if ask(Q.negative(expr.args[0] - 1), assumptions):
return False
示例11: Add
# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import positive [as 别名]
def Add(expr, assumptions):
if expr.is_number:
return AskPositiveHandler._number(expr, assumptions)
for arg in expr.args:
if ask(Q.positive(arg), assumptions) is not True:
break
else:
# if all argument's are positive
return True
示例12: Pow
# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import positive [as 别名]
def Pow(expr, assumptions):
if expr.is_number: return expr.evalf() > 0
if ask(Q.positive(expr.base), assumptions):
return True
if ask(Q.negative(expr.base), assumptions):
if ask(Q.even(expr.exp), assumptions):
return True
if ask(Q.even(expr.exp), assumptions):
return False
示例13: test_real
# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import positive [as 别名]
def test_real():
x, y = symbols('x,y')
assert ask(Q.real(x)) == None
assert ask(Q.real(x), Q.real(x)) == True
assert ask(Q.real(x), Q.nonzero(x)) == True
assert ask(Q.real(x), Q.positive(x)) == True
assert ask(Q.real(x), Q.negative(x)) == True
assert ask(Q.real(x), Q.integer(x)) == True
assert ask(Q.real(x), Q.even(x)) == True
assert ask(Q.real(x), Q.prime(x)) == True
assert ask(Q.real(x/sqrt(2)), Q.real(x)) == True
assert ask(Q.real(x/sqrt(-2)), Q.real(x)) == False
I = S.ImaginaryUnit
assert ask(Q.real(x+1), Q.real(x)) == True
assert ask(Q.real(x+I), Q.real(x)) == False
assert ask(Q.real(x+I), Q.complex(x)) == None
assert ask(Q.real(2*x), Q.real(x)) == True
assert ask(Q.real(I*x), Q.real(x)) == False
assert ask(Q.real(I*x), Q.imaginary(x)) == True
assert ask(Q.real(I*x), Q.complex(x)) == None
assert ask(Q.real(x**2), Q.real(x)) == True
assert ask(Q.real(sqrt(x)), Q.negative(x)) == False
assert ask(Q.real(x**y), Q.real(x) & Q.integer(y)) == True
assert ask(Q.real(x**y), Q.real(x) & Q.real(y)) == None
assert ask(Q.real(x**y), Q.positive(x) & Q.real(y)) == True
# trigonometric functions
assert ask(Q.real(sin(x))) == None
assert ask(Q.real(cos(x))) == None
assert ask(Q.real(sin(x)), Q.real(x)) == True
assert ask(Q.real(cos(x)), Q.real(x)) == True
# exponential function
assert ask(Q.real(exp(x))) == None
assert ask(Q.real(exp(x)), Q.real(x)) == True
assert ask(Q.real(x + exp(x)), Q.real(x)) == True
# Q.complexes
assert ask(Q.real(re(x))) == True
assert ask(Q.real(im(x))) == True
示例14: Mul
# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import positive [as 别名]
def Mul(expr, assumptions):
if expr.is_number:
return AskPositiveHandler._number(expr, assumptions)
result = True
for arg in expr.args:
if ask(Q.positive(arg), assumptions): continue
elif ask(Q.negative(arg), assumptions):
result = result ^ True
else: return
return result
示例15: Pow
# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import positive [as 别名]
def Pow(expr, assumptions):
if expr.is_number:
return AskEvenHandler._number(expr, assumptions)
if ask(Q.integer(expr.exp), assumptions):
if ask(Q.positive(expr.exp), assumptions):
return ask(Q.even(expr.base), assumptions)
elif ask(~Q.negative(expr.exp) & Q.odd(expr.base), assumptions):
return False
elif expr.base is S.NegativeOne:
return False