本文整理汇总了Python中sympy.Q.real方法的典型用法代码示例。如果您正苦于以下问题:Python Q.real方法的具体用法?Python Q.real怎么用?Python Q.real使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.Q
的用法示例。
在下文中一共展示了Q.real方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_reduce_rational_inequalities_real_relational
# 需要导入模块: from sympy import Q [as 别名]
# 或者: from sympy.Q import real [as 别名]
def test_reduce_rational_inequalities_real_relational():
def OpenInterval(a, b):
return Interval(a, b, True, True)
def LeftOpenInterval(a, b):
return Interval(a, b, True, False)
def RightOpenInterval(a, b):
return Interval(a, b, False, True)
with assuming(Q.real(x)):
assert reduce_rational_inequalities([[(x**2 + 3*x + 2)/(x**2 - 16) >= 0]], x, relational=False) == \
Union(OpenInterval(-oo, -4), Interval(-2, -1), OpenInterval(4, oo))
assert reduce_rational_inequalities([[((-2*x - 10)*(3 - x))/((x**2 + 5)*(x - 2)**2) < 0]], x, relational=False) == \
Union(OpenInterval(-5, 2), OpenInterval(2, 3))
assert reduce_rational_inequalities([[(x + 1)/(x - 5) <= 0]], x, assume=Q.real(x), relational=False) == \
RightOpenInterval(-1, 5)
assert reduce_rational_inequalities([[(x**2 + 4*x + 3)/(x - 1) > 0]], x, assume=Q.real(x), relational=False) == \
Union(OpenInterval(-3, -1), OpenInterval(1, oo))
assert reduce_rational_inequalities([[(x**2 - 16)/(x - 1)**2 < 0]], x, assume=Q.real(x), relational=False) == \
Union(OpenInterval(-4, 1), OpenInterval(1, 4))
assert reduce_rational_inequalities([[(3*x + 1)/(x + 4) >= 1]], x, assume=Q.real(x), relational=False) == \
Union(OpenInterval(-oo, -4), RightOpenInterval(S(3)/2, oo))
assert reduce_rational_inequalities([[(x - 8)/x <= 3 - x]], x, assume=Q.real(x), relational=False) == \
Union(LeftOpenInterval(-oo, -2), LeftOpenInterval(0, 4))
示例2: test_pow
# 需要导入模块: from sympy import Q [as 别名]
# 或者: from sympy.Q import real [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
示例3: test_reduce_poly_inequalities_real_relational
# 需要导入模块: from sympy import Q [as 别名]
# 或者: from sympy.Q import real [as 别名]
def test_reduce_poly_inequalities_real_relational():
global_assumptions.add(Q.real(x))
global_assumptions.add(Q.real(y))
assert reduce_poly_inequalities([[Eq(x ** 2, 0)]], x, relational=True) == Eq(x, 0)
assert reduce_poly_inequalities([[Le(x ** 2, 0)]], x, relational=True) == Eq(x, 0)
assert reduce_poly_inequalities([[Lt(x ** 2, 0)]], x, relational=True) == False
assert reduce_poly_inequalities([[Ge(x ** 2, 0)]], x, relational=True) == True
assert reduce_poly_inequalities([[Gt(x ** 2, 0)]], x, relational=True) == Or(Lt(x, 0), Lt(0, x))
assert reduce_poly_inequalities([[Ne(x ** 2, 0)]], x, relational=True) == Or(Lt(x, 0), Lt(0, x))
assert reduce_poly_inequalities([[Eq(x ** 2, 1)]], x, relational=True) == Or(Eq(x, -1), Eq(x, 1))
assert reduce_poly_inequalities([[Le(x ** 2, 1)]], x, relational=True) == And(Le(-1, x), Le(x, 1))
assert reduce_poly_inequalities([[Lt(x ** 2, 1)]], x, relational=True) == And(Lt(-1, x), Lt(x, 1))
assert reduce_poly_inequalities([[Ge(x ** 2, 1)]], x, relational=True) == Or(Le(x, -1), Le(1, x))
assert reduce_poly_inequalities([[Gt(x ** 2, 1)]], x, relational=True) == Or(Lt(x, -1), Lt(1, x))
assert reduce_poly_inequalities([[Ne(x ** 2, 1)]], x, relational=True) == Or(
Lt(x, -1), And(Lt(-1, x), Lt(x, 1)), Lt(1, x)
)
assert (
reduce_poly_inequalities([[Eq(x ** 2, 1.0)]], x, relational=True).evalf() == Or(Eq(x, -1.0), Eq(x, 1.0)).evalf()
)
assert reduce_poly_inequalities([[Le(x ** 2, 1.0)]], x, relational=True) == And(Le(-1.0, x), Le(x, 1.0))
assert reduce_poly_inequalities([[Lt(x ** 2, 1.0)]], x, relational=True) == And(Lt(-1.0, x), Lt(x, 1.0))
assert reduce_poly_inequalities([[Ge(x ** 2, 1.0)]], x, relational=True) == Or(Le(x, -1.0), Le(1.0, x))
assert reduce_poly_inequalities([[Gt(x ** 2, 1.0)]], x, relational=True) == Or(Lt(x, -1.0), Lt(1.0, x))
assert reduce_poly_inequalities([[Ne(x ** 2, 1.0)]], x, relational=True) == Or(
Lt(x, -1.0), And(Lt(-1.0, x), Lt(x, 1.0)), Lt(1.0, x)
)
global_assumptions.remove(Q.real(x))
global_assumptions.remove(Q.real(y))
示例4: test_pow
# 需要导入模块: from sympy import Q [as 别名]
# 或者: from sympy.Q import real [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)
示例5: test_pow4
# 需要导入模块: from sympy import Q [as 别名]
# 或者: from sympy.Q import real [as 别名]
def test_pow4():
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
示例6: test_reduce_poly_inequalities_real_interval
# 需要导入模块: from sympy import Q [as 别名]
# 或者: from sympy.Q import real [as 别名]
def test_reduce_poly_inequalities_real_interval():
global_assumptions.add(Q.real(x))
global_assumptions.add(Q.real(y))
assert reduce_poly_inequalities(
[[Eq(x**2, 0)]], x, relational=False) == FiniteSet(0)
assert reduce_poly_inequalities(
[[Le(x**2, 0)]], x, relational=False) == FiniteSet(0)
assert reduce_poly_inequalities(
[[Lt(x**2, 0)]], x, relational=False) == S.EmptySet
assert reduce_poly_inequalities(
[[Ge(x**2, 0)]], x, relational=False) == Interval(-oo, oo)
assert reduce_poly_inequalities(
[[Gt(x**2, 0)]], x, relational=False) == FiniteSet(0).complement
assert reduce_poly_inequalities(
[[Ne(x**2, 0)]], x, relational=False) == FiniteSet(0).complement
assert reduce_poly_inequalities(
[[Eq(x**2, 1)]], x, relational=False) == FiniteSet(-1, 1)
assert reduce_poly_inequalities(
[[Le(x**2, 1)]], x, relational=False) == Interval(-1, 1)
assert reduce_poly_inequalities(
[[Lt(x**2, 1)]], x, relational=False) == Interval(-1, 1, True, True)
assert reduce_poly_inequalities([[Ge(x**2, 1)]], x, relational=False) == Union(Interval(-oo, -1), Interval(1, oo))
assert reduce_poly_inequalities(
[[Gt(x**2, 1)]], x, relational=False) == Interval(-1, 1).complement
assert reduce_poly_inequalities(
[[Ne(x**2, 1)]], x, relational=False) == FiniteSet(-1, 1).complement
assert reduce_poly_inequalities([[Eq(
x**2, 1.0)]], x, relational=False) == FiniteSet(-1.0, 1.0).evalf()
assert reduce_poly_inequalities(
[[Le(x**2, 1.0)]], x, relational=False) == Interval(-1.0, 1.0)
assert reduce_poly_inequalities([[Lt(
x**2, 1.0)]], x, relational=False) == Interval(-1.0, 1.0, True, True)
assert reduce_poly_inequalities([[Ge(x**2, 1.0)]], x, relational=False) == Union(Interval(-inf, -1.0), Interval(1.0, inf))
assert reduce_poly_inequalities([[Gt(x**2, 1.0)]], x, relational=False) == Union(Interval(-inf, -1.0, right_open=True), Interval(1.0, inf, left_open=True))
assert reduce_poly_inequalities([[Ne(
x**2, 1.0)]], x, relational=False) == FiniteSet(-1.0, 1.0).complement
s = sqrt(2)
assert reduce_poly_inequalities([[Lt(
x**2 - 1, 0), Gt(x**2 - 1, 0)]], x, relational=False) == S.EmptySet
assert reduce_poly_inequalities([[Le(x**2 - 1, 0), Ge(
x**2 - 1, 0)]], x, relational=False) == FiniteSet(-1, 1)
assert reduce_poly_inequalities([[Le(x**2 - 2, 0), Ge(x**2 - 1, 0)]], x, relational=False) == Union(Interval(-s, -1, False, False), Interval(1, s, False, False))
assert reduce_poly_inequalities([[Le(x**2 - 2, 0), Gt(x**2 - 1, 0)]], x, relational=False) == Union(Interval(-s, -1, False, True), Interval(1, s, True, False))
assert reduce_poly_inequalities([[Lt(x**2 - 2, 0), Ge(x**2 - 1, 0)]], x, relational=False) == Union(Interval(-s, -1, True, False), Interval(1, s, False, True))
assert reduce_poly_inequalities([[Lt(x**2 - 2, 0), Gt(x**2 - 1, 0)]], x, relational=False) == Union(Interval(-s, -1, True, True), Interval(1, s, True, True))
assert reduce_poly_inequalities([[Lt(x**2 - 2, 0), Ne(x**2 - 1, 0)]], x, relational=False) == Union(Interval(-s, -1, True, True), Interval(-1, 1, True, True), Interval(1, s, True, True))
global_assumptions.remove(Q.real(x))
global_assumptions.remove(Q.real(y))
示例7: test_solve_inequalities
# 需要导入模块: from sympy import Q [as 别名]
# 或者: from sympy.Q import real [as 别名]
def test_solve_inequalities():
system = [Lt(x**2 - 2, 0), Gt(x**2 - 1, 0)]
assert solve(system) == \
And(Or(And(Lt(-sqrt(2), re(x)), Lt(re(x), -1)),
And(Lt(1, re(x)), Lt(re(x), sqrt(2)))), Eq(im(x), 0))
assert solve(system, assume=Q.real(x)) == \
Or(And(Lt(-sqrt(2), x), Lt(x, -1)), And(Lt(1, x), Lt(x, sqrt(2))))
# issue 3528, 3448
assert solve((x - 3)/(x - 2) < 0, x, assume=Q.real(x)) == And(Lt(2, x), Lt(x, 3))
assert solve(x/(x + 1) > 1, x, assume=Q.real(x)) == Lt(x, -1)
示例8: test_pow
# 需要导入模块: from sympy import Q [as 别名]
# 或者: from sympy.Q import real [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
示例9: test_pow_pos_neg
# 需要导入模块: from sympy import Q [as 别名]
# 或者: from sympy.Q import real [as 别名]
def test_pow_pos_neg():
assert satask(Q.nonnegative(x**2), Q.positive(x)) is True
assert satask(Q.nonpositive(x**2), Q.positive(x)) is False
assert satask(Q.positive(x**2), Q.positive(x)) is True
assert satask(Q.negative(x**2), Q.positive(x)) is False
assert satask(Q.real(x**2), Q.positive(x)) is True
assert satask(Q.nonnegative(x**2), Q.negative(x)) is True
assert satask(Q.nonpositive(x**2), Q.negative(x)) is False
assert satask(Q.positive(x**2), Q.negative(x)) is True
assert satask(Q.negative(x**2), Q.negative(x)) is False
assert satask(Q.real(x**2), Q.negative(x)) is True
assert satask(Q.nonnegative(x**2), Q.nonnegative(x)) is True
assert satask(Q.nonpositive(x**2), Q.nonnegative(x)) is None
assert satask(Q.positive(x**2), Q.nonnegative(x)) is None
assert satask(Q.negative(x**2), Q.nonnegative(x)) is False
assert satask(Q.real(x**2), Q.nonnegative(x)) is True
assert satask(Q.nonnegative(x**2), Q.nonpositive(x)) is True
assert satask(Q.nonpositive(x**2), Q.nonpositive(x)) is None
assert satask(Q.positive(x**2), Q.nonpositive(x)) is None
assert satask(Q.negative(x**2), Q.nonpositive(x)) is False
assert satask(Q.real(x**2), Q.nonpositive(x)) is True
assert satask(Q.nonnegative(x**3), Q.positive(x)) is True
assert satask(Q.nonpositive(x**3), Q.positive(x)) is False
assert satask(Q.positive(x**3), Q.positive(x)) is True
assert satask(Q.negative(x**3), Q.positive(x)) is False
assert satask(Q.real(x**3), Q.positive(x)) is True
assert satask(Q.nonnegative(x**3), Q.negative(x)) is False
assert satask(Q.nonpositive(x**3), Q.negative(x)) is True
assert satask(Q.positive(x**3), Q.negative(x)) is False
assert satask(Q.negative(x**3), Q.negative(x)) is True
assert satask(Q.real(x**3), Q.negative(x)) is True
assert satask(Q.nonnegative(x**3), Q.nonnegative(x)) is True
assert satask(Q.nonpositive(x**3), Q.nonnegative(x)) is None
assert satask(Q.positive(x**3), Q.nonnegative(x)) is None
assert satask(Q.negative(x**3), Q.nonnegative(x)) is False
assert satask(Q.real(x**3), Q.nonnegative(x)) is True
assert satask(Q.nonnegative(x**3), Q.nonpositive(x)) is None
assert satask(Q.nonpositive(x**3), Q.nonpositive(x)) is True
assert satask(Q.positive(x**3), Q.nonpositive(x)) is False
assert satask(Q.negative(x**3), Q.nonpositive(x)) is None
assert satask(Q.real(x**3), Q.nonpositive(x)) is True
# If x is zero, x**negative is not real.
assert satask(Q.nonnegative(x**-2), Q.nonpositive(x)) is None
assert satask(Q.nonpositive(x**-2), Q.nonpositive(x)) is None
assert satask(Q.positive(x**-2), Q.nonpositive(x)) is None
assert satask(Q.negative(x**-2), Q.nonpositive(x)) is None
assert satask(Q.real(x**-2), Q.nonpositive(x)) is None
示例10: isolate
# 需要导入模块: from sympy import Q [as 别名]
# 或者: from sympy.Q import real [as 别名]
def isolate(alg, eps=None, fast=False):
"""Give a rational isolating interval for an algebraic number. """
alg = sympify(alg)
if alg.is_Rational:
return (alg, alg)
elif not ask(Q.real(alg)):
raise NotImplementedError(
"complex algebraic numbers are not supported")
func = lambdify((), alg, modules="mpmath", printer=IntervalPrinter())
poly = minpoly(alg, polys=True)
intervals = poly.intervals(sqf=True)
dps, done = mp.dps, False
try:
while not done:
alg = func()
for a, b in intervals:
if a <= alg.a and alg.b <= b:
done = True
break
else:
mp.dps *= 2
finally:
mp.dps = dps
if eps is not None:
a, b = poly.refine_root(a, b, eps=eps, fast=fast)
return (a, b)
示例11: test_solve_inequalities
# 需要导入模块: from sympy import Q [as 别名]
# 或者: from sympy.Q import real [as 别名]
def test_solve_inequalities():
system = [Lt(x ** 2 - 2, 0), Gt(x ** 2 - 1, 0)]
assert solve(system) == And(
Or(And(Lt(-sqrt(2), re(x)), Lt(re(x), -1)), And(Lt(1, re(x)), Lt(re(x), sqrt(2)))), Eq(im(x), 0)
)
assert solve(system, assume=Q.real(x)) == Or(And(Lt(-sqrt(2), x), Lt(x, -1)), And(Lt(1, x), Lt(x, sqrt(2))))
示例12: test_field_assumptions
# 需要导入模块: from sympy import Q [as 别名]
# 或者: from sympy.Q import real [as 别名]
def test_field_assumptions():
X = MatrixSymbol('X', 4, 4)
Y = MatrixSymbol('Y', 4, 4)
assert ask(Q.real_elements(X), Q.real_elements(X))
assert not ask(Q.integer_elements(X), Q.real_elements(X))
assert ask(Q.complex_elements(X), Q.real_elements(X))
assert ask(Q.complex_elements(X**2), Q.real_elements(X))
assert ask(Q.real_elements(X**2), Q.integer_elements(X))
assert ask(Q.real_elements(X+Y), Q.real_elements(X)) is None
assert ask(Q.real_elements(X+Y), Q.real_elements(X) & Q.real_elements(Y))
from sympy.matrices.expressions.hadamard import HadamardProduct
assert ask(Q.real_elements(HadamardProduct(X, Y)),
Q.real_elements(X) & Q.real_elements(Y))
assert ask(Q.complex_elements(X+Y), Q.real_elements(X) & Q.complex_elements(Y))
assert ask(Q.real_elements(X.T), Q.real_elements(X))
assert ask(Q.real_elements(X.I), Q.real_elements(X) & Q.invertible(X))
assert ask(Q.real_elements(Trace(X)), Q.real_elements(X))
assert ask(Q.integer_elements(Determinant(X)), Q.integer_elements(X))
assert not ask(Q.integer_elements(X.I), Q.integer_elements(X))
alpha = Symbol('alpha')
assert ask(Q.real_elements(alpha*X), Q.real_elements(X) & Q.real(alpha))
assert ask(Q.real_elements(LofLU(X)), Q.real_elements(X))
e = Symbol('e', integer=True, negative=True)
assert ask(Q.real_elements(X**e), Q.real_elements(X) & Q.invertible(X))
assert ask(Q.real_elements(X**e), Q.real_elements(X)) is None
示例13: test_Abs
# 需要导入模块: from sympy import Q [as 别名]
# 或者: from sympy.Q import real [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
示例14: test_pow1
# 需要导入模块: from sympy import Q [as 别名]
# 或者: from sympy.Q import real [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)
示例15: test_reduce_abs_inequalities
# 需要导入模块: from sympy import Q [as 别名]
# 或者: from sympy.Q import real [as 别名]
def test_reduce_abs_inequalities():
real = Q.real(x)
assert reduce_inequalities(abs(x - 5) < 3, assume=real) == And(Gt(x, 2), Lt(x, 8))
assert reduce_inequalities(abs(2*x + 3) >= 8, assume=real) == Or(Le(x, -S(11)/2), Ge(x, S(5)/2))
assert reduce_inequalities(abs(x - 4) + abs(3*x - 5) < 7, assume=real) == And(Gt(x, S(1)/2), Lt(x, 4))
assert reduce_inequalities(abs(x - 4) + abs(3*abs(x) - 5) < 7, assume=real) == Or(And(-2 < x, x < -1), And(S(1)/2 < x, x < 4))
raises(NotImplementedError, "reduce_inequalities(abs(x - 5) < 3)")