本文整理汇总了Python中sympy.assumptions.Q.real方法的典型用法代码示例。如果您正苦于以下问题:Python Q.real方法的具体用法?Python Q.real怎么用?Python Q.real使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.assumptions.Q
的用法示例。
在下文中一共展示了Q.real方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_positive
# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import real [as 别名]
def test_positive():
x, y, z, w = symbols('x,y,z,w')
assert ask(Q.positive(x), Q.positive(x)) == True
assert ask(Q.positive(x), Q.negative(x)) == False
assert ask(Q.positive(x), Q.nonzero(x)) == None
assert ask(Q.positive(-x), Q.positive(x)) == False
assert ask(Q.positive(-x), Q.negative(x)) == True
assert ask(Q.positive(x+y), Q.positive(x) & Q.positive(y)) == True
assert ask(Q.positive(x+y), Q.positive(x) & Q.negative(y)) == None
assert ask(Q.positive(2*x), Q.positive(x)) == True
assumptions = Q.positive(x) & Q.negative(y) & Q.negative(z) & Q.positive(w)
assert ask(Q.positive(x*y*z)) == None
assert ask(Q.positive(x*y*z), assumptions) == True
assert ask(Q.positive(-x*y*z), assumptions) == False
assert ask(Q.positive(x**2), Q.positive(x)) == True
assert ask(Q.positive(x**2), Q.negative(x)) == True
#exponential
assert ask(Q.positive(exp(x)), Q.real(x)) == True
assert ask(Q.positive(x + exp(x)), Q.real(x)) == None
#absolute value
assert ask(Q.positive(Abs(x))) == None # Abs(0) = 0
assert ask(Q.positive(Abs(x)), Q.positive(x)) == True
示例2: test_functions_in_assumptions
# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import real [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
示例3: Pow
# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import real [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
示例4: test_float_1
# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import real [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
示例5: test_negative
# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import real [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
示例6: test_refine
# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import real [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 real [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 real [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_extended_real
# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import real [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
示例10: Basic
# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import real [as 别名]
def Basic(expr, assumptions):
_real = ask(Q.real(expr), assumptions)
if _real:
_rational = ask(Q.rational(expr), assumptions)
if _rational is None: return None
return not _rational
else: return _real
示例11: refine_abs
# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import real [as 别名]
def refine_abs(expr, assumptions):
"""
Handler for the absolute value.
Examples
========
>>> from sympy import Symbol, Q, refine, Abs
>>> from sympy.assumptions.refine import refine_abs
>>> from sympy.abc import x
>>> refine_abs(Abs(x), Q.real(x))
>>> refine_abs(Abs(x), Q.positive(x))
x
>>> refine_abs(Abs(x), Q.negative(x))
-x
"""
from sympy.core.logic import fuzzy_not
arg = expr.args[0]
if ask(Q.real(arg), assumptions) and fuzzy_not(ask(Q.negative(arg), assumptions)):
# if it's nonnegative
return arg
if ask(Q.negative(arg), assumptions):
return -arg
示例12: Pow
# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import real [as 别名]
def Pow(expr, assumptions):
"""
Real ** Even -> NonNegative
Real ** Odd -> same_as_base
NonNegative ** Positive -> NonNegative
"""
if expr.is_number:
return AskNegativeHandler._number(expr, assumptions)
if ask(Q.real(expr.base), assumptions):
if ask(Q.positive(expr.base), assumptions):
if ask(Q.real(expr.exp), assumptions):
return False
if ask(Q.even(expr.exp), assumptions):
return False
if ask(Q.odd(expr.exp), assumptions):
return ask(Q.negative(expr.base), assumptions)
示例13: Basic
# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import real [as 别名]
def Basic(expr, assumptions):
if expr.is_number:
notpositive = fuzzy_not(AskPositiveHandler._number(expr, assumptions))
if notpositive:
return ask(Q.real(expr), assumptions)
else:
return notpositive
示例14: refine_atan2
# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import real [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
示例15: reduce_abs_inequality
# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import real [as 别名]
def reduce_abs_inequality(expr, rel, gen, assume=True):
"""Reduce an inequality with nested absolute values. """
if not ask(Q.real(gen), assumptions=assume):
raise NotImplementedError("can't solve inequalities with absolute values of a complex variable")
def bottom_up_scan(expr):
exprs = []
if expr.is_Add or expr.is_Mul:
op = expr.__class__
for arg in expr.args:
_exprs = bottom_up_scan(arg)
if not exprs:
exprs = _exprs
else:
args = []
for expr, conds in exprs:
for _expr, _conds in _exprs:
args.append((op(expr, _expr), conds + _conds))
exprs = args
elif expr.is_Pow:
n = expr.exp
if not n.is_Integer or n < 0:
raise ValueError("only non-negative integer powers are allowed")
_exprs = bottom_up_scan(expr.base)
for expr, conds in _exprs:
exprs.append((expr ** n, conds))
elif isinstance(expr, Abs):
_exprs = bottom_up_scan(expr.args[0])
for expr, conds in _exprs:
exprs.append((expr, conds + [Ge(expr, 0)]))
exprs.append((-expr, conds + [Lt(expr, 0)]))
else:
exprs = [(expr, [])]
return exprs
exprs = bottom_up_scan(expr)
mapping = {"<": ">", "<=": ">="}
inequalities = []
for expr, conds in exprs:
if rel not in mapping.keys():
expr = Relational(expr, 0, rel)
else:
expr = Relational(-expr, 0, mapping[rel])
inequalities.append([expr] + conds)
return reduce_poly_inequalities(inequalities, gen, assume)