本文整理汇总了Python中sympy.assumptions.ask.Q类的典型用法代码示例。如果您正苦于以下问题:Python Q类的具体用法?Python Q怎么用?Python Q使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Q类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: refine_MatMul
def refine_MatMul(expr, assumptions):
"""
>>> from sympy import MatrixSymbol, Q, assuming, refine
>>> X = MatrixSymbol('X', 2, 2)
>>> expr = X * X.T
>>> print(expr)
X*X.T
>>> with assuming(Q.orthogonal(X)):
... print(refine(expr))
I
"""
newargs = []
exprargs = []
for args in expr.args:
if args.is_Matrix:
exprargs.append(args)
else:
newargs.append(args)
last = exprargs[0]
for arg in exprargs[1:]:
if arg == last.T and ask(Q.orthogonal(arg), assumptions):
last = Identity(arg.shape[0])
elif arg == last.conjugate() and ask(Q.unitary(arg), assumptions):
last = Identity(arg.shape[0])
else:
newargs.append(last)
last = arg
newargs.append(last)
return MatMul(*newargs)
开发者ID:sympy,项目名称:sympy,代码行数:32,代码来源:matmul.py
示例2: test_is_literal
def test_is_literal():
assert is_literal(True) is True
assert is_literal(False) is True
assert is_literal(A) is True
assert is_literal(~A) is True
assert is_literal(Or(A, B)) is False
assert is_literal(Q.zero(A)) is True
assert is_literal(Not(Q.zero(A))) is True
assert is_literal(Or(A, B)) is False
assert is_literal(And(Q.zero(A), Q.zero(B))) is False
开发者ID:Lenqth,项目名称:sympy,代码行数:10,代码来源:test_boolalg.py
示例3: test_global
def test_global():
"""Test for global assumptions"""
global_assumptions.add(Q.is_true(x > 0))
assert Q.is_true(x > 0) in global_assumptions
global_assumptions.remove(Q.is_true(x > 0))
assert not Q.is_true(x > 0) in global_assumptions
# same with multiple of assumptions
global_assumptions.add(Q.is_true(x > 0), Q.is_true(y > 0))
assert Q.is_true(x > 0) in global_assumptions
assert Q.is_true(y > 0) in global_assumptions
global_assumptions.clear()
assert not Q.is_true(x > 0) in global_assumptions
assert not Q.is_true(y > 0) in global_assumptions
开发者ID:StefenYin,项目名称:sympy,代码行数:13,代码来源:test_assumptions_2.py
示例4: test_binary_symbols
def test_binary_symbols():
assert ITE(x < 1, y, z).binary_symbols == set((y, z))
for f in (Eq, Ne):
assert f(x, 1).binary_symbols == set()
assert f(x, True).binary_symbols == set([x])
assert f(x, False).binary_symbols == set([x])
assert S.true.binary_symbols == set()
assert S.false.binary_symbols == set()
assert x.binary_symbols == set([x])
assert And(x, Eq(y, False), Eq(z, 1)).binary_symbols == set([x, y])
assert Q.prime(x).binary_symbols == set()
assert Q.is_true(x < 1).binary_symbols == set()
assert Q.is_true(x).binary_symbols == set([x])
assert Q.is_true(Eq(x, True)).binary_symbols == set([x])
assert Q.prime(x).binary_symbols == set()
开发者ID:Lenqth,项目名称:sympy,代码行数:15,代码来源:test_boolalg.py
示例5: refine_Inverse
def refine_Inverse(expr, assumptions):
"""
>>> from sympy import MatrixSymbol, Q, assuming, refine
>>> X = MatrixSymbol('X', 2, 2)
>>> X.I
X**(-1)
>>> with assuming(Q.orthogonal(X)):
... print(refine(X.I))
X.T
"""
if ask(Q.orthogonal(expr), assumptions):
return expr.arg.T
elif ask(Q.unitary(expr), assumptions):
return expr.arg.conjugate()
elif ask(Q.singular(expr), assumptions):
raise ValueError("Inverse of singular matrix %s" % expr.arg)
return expr
开发者ID:asmeurer,项目名称:sympy,代码行数:18,代码来源:inverse.py
示例6: refine_Determinant
def refine_Determinant(expr, assumptions):
"""
>>> from sympy import MatrixSymbol, Q, assuming, refine, det
>>> X = MatrixSymbol('X', 2, 2)
>>> det(X)
Determinant(X)
>>> with assuming(Q.orthogonal(X)):
... print(refine(det(X)))
1
"""
if ask(Q.orthogonal(expr.arg), assumptions):
return S.One
elif ask(Q.singular(expr.arg), assumptions):
return S.Zero
elif ask(Q.unit_triangular(expr.arg), assumptions):
return S.One
return expr
开发者ID:Carreau,项目名称:sympy,代码行数:18,代码来源:determinant.py
示例7: refine_Transpose
def refine_Transpose(expr, assumptions):
"""
>>> from sympy import MatrixSymbol, Q, assuming, refine
>>> X = MatrixSymbol('X', 2, 2)
>>> X.T
X.T
>>> with assuming(Q.symmetric(X)):
... print(refine(X.T))
X
"""
if ask(Q.symmetric(expr), assumptions):
return expr.arg
return expr
开发者ID:cklb,项目名称:sympy,代码行数:14,代码来源:transpose.py
示例8: _contains
def _contains(self, other):
from sympy.assumptions.ask import ask, Q
if ask(Q.real(other)) is False:
return False
if self.left_open:
expr = other > self.start
else:
expr = other >= self.start
if self.right_open:
expr = And(expr, other < self.end)
else:
expr = And(expr, other <= self.end)
return expr
开发者ID:codebog,项目名称:sympy,代码行数:16,代码来源:sets.py
示例9: _contains
def _contains(self, other):
from sympy.assumptions.ask import ask, Q
return (other >= self.inf and other <= self.sup and
ask(Q.integer((self.start - other)/self.step)))
开发者ID:Jeyatharsini,项目名称:sympy,代码行数:4,代码来源:fancysets.py
示例10: register_fact
def register_fact(klass, fact, registry=fact_registry):
registry[klass] |= set([fact])
for klass, fact in [
(Mul, Equivalent(Q.zero, AnyArgs(Q.zero))),
(MatMul, Implies(AllArgs(Q.square), Equivalent(Q.invertible, AllArgs(Q.invertible)))),
(Add, Implies(AllArgs(Q.positive), Q.positive)),
(Add, Implies(AllArgs(Q.negative), Q.negative)),
(Mul, Implies(AllArgs(Q.positive), Q.positive)),
(Mul, Implies(AllArgs(Q.commutative), Q.commutative)),
(Mul, Implies(AllArgs(Q.real), Q.commutative)),
# This one can still be made easier to read. I think we need basic pattern
# matching, so that we can just write Equivalent(Q.zero(x**y), Q.zero(x) & Q.positive(y))
(Pow, CustomLambda(lambda power: Equivalent(Q.zero(power), Q.zero(power.base) & Q.positive(power.exp)))),
(Integer, CheckIsPrime(Q.prime)),
# Implicitly assumes Mul has more than one arg
# Would be AllArgs(Q.prime | Q.composite) except 1 is composite
(Mul, Implies(AllArgs(Q.prime), ~Q.prime)),
# More advanced prime assumptions will require inequalities, as 1 provides
# a corner case.
(Mul, Implies(AllArgs(Q.imaginary | Q.real), Implies(ExactlyOneArg(Q.imaginary), Q.imaginary))),
(Mul, Implies(AllArgs(Q.real), Q.real)),
(Add, Implies(AllArgs(Q.real), Q.real)),
#General Case: Odd number of imaginary args implies mul is imaginary(To be implemented)
(Mul, Implies(AllArgs(Q.real), Implies(ExactlyOneArg(Q.irrational),
Q.irrational))),
(Add, Implies(AllArgs(Q.real), Implies(ExactlyOneArg(Q.irrational),
Q.irrational))),
(Mul, Implies(AllArgs(Q.rational), Q.rational)),
开发者ID:Davidjohnwilson,项目名称:sympy,代码行数:30,代码来源:sathandlers.py
示例11: test_equal
def test_equal():
"""Test for equality"""
assert Q.positive(x) == Q.positive(x)
assert Q.positive(x) != ~Q.positive(x)
assert ~Q.positive(x) == ~Q.positive(x)
开发者ID:StefenYin,项目名称:sympy,代码行数:5,代码来源:test_assumptions_2.py
示例12: test_composite_predicates
def test_composite_predicates():
pred = Q.integer | ~Q.positive
assert type(pred(x)) is Or
assert pred(x) == Q.integer(x) | ~Q.positive(x)
开发者ID:StefenYin,项目名称:sympy,代码行数:4,代码来源:test_assumptions_2.py
示例13: test_equal
def test_equal():
"""Test for equality"""
x = symbols('x')
assert Q.positive(x) == Q.positive(x)
assert Q.positive(x) != ~Q.positive(x)
assert ~Q.positive(x) == ~Q.positive(x)
开发者ID:AlexandruFlorescu,项目名称:sympy,代码行数:6,代码来源:test_assumptions_2.py
示例14: test_pretty
def test_pretty():
x = symbols('x')
assert pretty(Q.positive(x)) == "Q.positive(x)"
开发者ID:AlexandruFlorescu,项目名称:sympy,代码行数:3,代码来源:test_assumptions_2.py
示例15: test_pretty
def test_pretty():
assert pretty(Q.positive(x)) == "Q.positive(x)"
开发者ID:ALGHeArT,项目名称:sympy,代码行数:2,代码来源:test_assumptions_2.py
示例16: _contains
def _contains(self, other):
if ask(Q.positive(other)) and ask(Q.integer(other)):
return True
return False
开发者ID:AALEKH,项目名称:sympy,代码行数:4,代码来源:fancysets.py
示例17: register_fact
def register_fact(klass, fact, registry=fact_registry):
registry[klass] |= {fact}
for klass, fact in [
(Mul, Equivalent(Q.zero, AnyArgs(Q.zero))),
(MatMul, Implies(AllArgs(Q.square), Equivalent(Q.invertible, AllArgs(Q.invertible)))),
(Add, Implies(AllArgs(Q.positive), Q.positive)),
(Add, Implies(AllArgs(Q.negative), Q.negative)),
(Mul, Implies(AllArgs(Q.positive), Q.positive)),
(Mul, Implies(AllArgs(Q.commutative), Q.commutative)),
(Mul, Implies(AllArgs(Q.real), Q.commutative)),
(Pow, CustomLambda(lambda power: Implies(Q.real(power.base) &
Q.even(power.exp) & Q.nonnegative(power.exp), Q.nonnegative(power)))),
(Pow, CustomLambda(lambda power: Implies(Q.nonnegative(power.base) & Q.odd(power.exp) & Q.nonnegative(power.exp), Q.nonnegative(power)))),
(Pow, CustomLambda(lambda power: Implies(Q.nonpositive(power.base) & Q.odd(power.exp) & Q.nonnegative(power.exp), Q.nonpositive(power)))),
# This one can still be made easier to read. I think we need basic pattern
# matching, so that we can just write Equivalent(Q.zero(x**y), Q.zero(x) & Q.positive(y))
(Pow, CustomLambda(lambda power: Equivalent(Q.zero(power), Q.zero(power.base) & Q.positive(power.exp)))),
(Integer, CheckIsPrime(Q.prime)),
# Implicitly assumes Mul has more than one arg
# Would be AllArgs(Q.prime | Q.composite) except 1 is composite
(Mul, Implies(AllArgs(Q.prime), ~Q.prime)),
# More advanced prime assumptions will require inequalities, as 1 provides
# a corner case.
(Mul, Implies(AllArgs(Q.imaginary | Q.real), Implies(ExactlyOneArg(Q.imaginary), Q.imaginary))),
(Mul, Implies(AllArgs(Q.real), Q.real)),
开发者ID:asmeurer,项目名称:sympy,代码行数:29,代码来源:sathandlers.py
示例18: test_pretty
def test_pretty():
assert pretty(Q.positive(x)) == "Q.positive(x)"
assert pretty(set([Q.positive, Q.integer])) == "set([Q.integer, Q.positive])"
开发者ID:StefenYin,项目名称:sympy,代码行数:3,代码来源:test_assumptions_2.py
注:本文中的sympy.assumptions.ask.Q类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论