本文整理汇总了Python中sympy.assumptions.Q类的典型用法代码示例。如果您正苦于以下问题:Python Q类的具体用法?Python Q怎么用?Python Q使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Q类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: refine_abs
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
开发者ID:scopatz,项目名称:sympy,代码行数:25,代码来源:refine.py
示例2: test_finally
def test_finally():
try:
with assuming(Q.integer(x)):
1/0
except ZeroDivisionError:
pass
assert not ask(Q.integer(x))
开发者ID:Abhityagi16,项目名称:sympy,代码行数:7,代码来源:test_context.py
示例3: Mul
def Mul(expr, assumptions):
"""
Even * Integer -> Even
Even * Odd -> Even
Integer * Odd -> ?
Odd * Odd -> Odd
"""
if expr.is_number:
return AskEvenHandler._number(expr, assumptions)
even, odd, irrational = False, 0, False
for arg in expr.args:
# check for all integers and at least one even
if ask(Q.integer(arg), assumptions):
if ask(Q.even(arg), assumptions):
even = True
elif ask(Q.odd(arg), assumptions):
odd += 1
elif ask(Q.irrational(arg), assumptions):
# one irrational makes the result False
# two makes it undefined
if irrational:
break
irrational = True
else:
break
else:
if irrational:
return False
if even:
return True
if odd == len(expr.args):
return False
开发者ID:Abhityagi16,项目名称:sympy,代码行数:32,代码来源:ntheory.py
示例4: Basic
def Basic(expr, assumptions):
_integer = ask(Q.integer(expr), assumptions)
if _integer:
_even = ask(Q.even(expr), assumptions)
if _even is None: return None
return not _even
return _integer
开发者ID:BDGLunde,项目名称:sympy,代码行数:7,代码来源:ntheory.py
示例5: MatPow
def MatPow(expr, assumptions):
# only for integer powers
base, exp = expr.args
int_exp = ask(Q.integer(exp), assumptions)
if int_exp and ask(~Q.negative(exp), assumptions):
return ask(Q.fullrank(base), assumptions)
return None
开发者ID:Lenqth,项目名称:sympy,代码行数:7,代码来源:matrices.py
示例6: refine_exp
def refine_exp(expr, assumptions):
"""
Handler for exponential function.
>>> from sympy import Symbol, Q, exp, I, pi
>>> from sympy.assumptions.refine import refine_exp
>>> from sympy.abc import x
>>> refine_exp(exp(pi*I*2*x), Q.real(x))
>>> refine_exp(exp(pi*I*2*x), Q.integer(x))
1
"""
arg = expr.args[0]
if arg.is_Mul:
coeff = arg.as_coefficient(S.Pi*S.ImaginaryUnit)
if coeff:
if ask(Q.integer(2*coeff), assumptions):
if ask(Q.even(coeff), assumptions):
return S.One
elif ask(Q.odd(coeff), assumptions):
return S.NegativeOne
elif ask(Q.even(coeff + S.Half), assumptions):
return -S.ImaginaryUnit
elif ask(Q.odd(coeff + S.Half), assumptions):
return S.ImaginaryUnit
开发者ID:kumarkrishna,项目名称:sympy,代码行数:25,代码来源:refine.py
示例7: Mul
def Mul(expr, assumptions):
"""
Return True if expr is bounded, False if not and None if unknown.
TRUTH TABLE
B U ?
s /s
+---+---+---+---+
B | B | U | ? | legend:
+---+---+---+---+ B = Bounded
U | U | U | ? | U = Unbounded
+---+---+---+ ? = unknown boundedness
? | ? | s = signed (hence nonzero)
+---+---+ /s = not signed
"""
result = True
for arg in expr.args:
_bounded = ask(Q.bounded(arg), assumptions)
if _bounded:
continue
elif _bounded is None:
if result is None:
return None
if ask(Q.nonzero(arg), assumptions) is None:
return None
if result is not False:
result = None
else:
result = False
return result
开发者ID:101man,项目名称:sympy,代码行数:32,代码来源:calculus.py
示例8: MatMul
def MatMul(expr, assumptions):
factor, mmul = expr.as_coeff_mmul()
if all(ask(Q.invertible(arg), assumptions) for arg in mmul.args):
return True
if any(ask(Q.invertible(arg), assumptions) is False
for arg in mmul.args):
return False
开发者ID:Maihj,项目名称:sympy,代码行数:7,代码来源:matrices.py
示例9: Mul
def Mul(expr, assumptions):
"""
Integer*Integer -> Integer
Integer*Irrational -> !Integer
Odd/Even -> !Integer
Integer*Rational -> ?
"""
if expr.is_number:
return AskIntegerHandler._number(expr, assumptions)
_output = True
for arg in expr.args:
if not ask(Q.integer(arg), assumptions):
if arg.is_Rational:
if arg.q == 2:
return ask(Q.even(2*expr), assumptions)
if ~(arg.q & 1):
return None
elif ask(Q.irrational(arg), assumptions):
if _output:
_output = False
else:
return
else:
return
else:
return _output
开发者ID:Tarang1993,项目名称:sympy,代码行数:26,代码来源:sets.py
示例10: Basic
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
开发者ID:101man,项目名称:sympy,代码行数:7,代码来源:sets.py
示例11: test_remove_safe
def test_remove_safe():
global_assumptions.add(Q.integer(x))
with assuming():
assert ask(Q.integer(x))
global_assumptions.remove(Q.integer(x))
assert not ask(Q.integer(x))
assert ask(Q.integer(x))
global_assumptions.clear() # for the benefit of other tests
开发者ID:Abhityagi16,项目名称:sympy,代码行数:8,代码来源:test_context.py
示例12: MatMul
def MatMul(expr, assumptions):
factor, mmul = expr.as_coeff_mmul()
if (all(ask(Q.orthogonal(arg), assumptions) for arg in mmul.args) and
factor == 1):
return True
if any(ask(Q.invertible(arg), assumptions) == False
for arg in mmul.args):
return False
开发者ID:xoedusk,项目名称:sympy,代码行数:8,代码来源:matrices.py
示例13: Pow
def Pow(expr, assumptions):
"""
Integer**Integer -> !Prime
"""
if expr.is_number:
return AskPrimeHandler._number(expr, assumptions)
if ask(Q.integer(expr.exp), assumptions) and ask(Q.integer(expr.base), assumptions):
return False
开发者ID:JoenyBui,项目名称:sympy,代码行数:8,代码来源:ntheory.py
示例14: test_custom_context
def test_custom_context():
"""Test ask with custom assumptions context"""
x = symbols('x')
assert ask(Q.integer(x)) == None
local_context = AssumptionsContext()
local_context.add(Q.integer(x))
assert ask(Q.integer(x), context = local_context) == True
assert ask(Q.integer(x)) == None
开发者ID:lazovich,项目名称:sympy,代码行数:8,代码来源:test_query.py
示例15: test_global
def test_global():
"""Test ask with global assumptions"""
x = symbols('x')
assert ask(Q.integer(x)) == None
global_assumptions.add(Q.integer(x))
assert ask(Q.integer(x)) == True
global_assumptions.clear()
assert ask(Q.integer(x)) == None
开发者ID:lazovich,项目名称:sympy,代码行数:8,代码来源:test_query.py
示例16: MatMul
def MatMul(expr, assumptions):
factor, mmul = expr.as_coeff_mmul()
if (all(ask(Q.positive_definite(arg), assumptions)
for arg in mmul.args) and factor > 0):
return True
if len(mmul.args) >= 2 and mmul.args[0] == mmul.args[-1].T:
return ask(Q.positive_definite(
MatMul(*mmul.args[1:-1])), assumptions)
开发者ID:abhik137,项目名称:sympy,代码行数:8,代码来源:matrices.py
示例17: MatMul
def MatMul(expr, assumptions):
factor, mmul = expr.as_coeff_mmul()
if all(ask(Q.symmetric(arg), assumptions) for arg in mmul.args):
return True
if len(mmul.args) >= 2 and mmul.args[0] == mmul.args[-1].T:
if len(mmul.args) == 2:
return True
return ask(Q.symmetric(MatMul(*mmul.args[1:-1])), assumptions)
开发者ID:A-turing-machine,项目名称:sympy,代码行数:8,代码来源:matrices.py
示例18: Symbol
def Symbol(expr, assumptions):
"""Objects are expected to be commutative unless otherwise stated"""
assumps = conjuncts(assumptions)
if Q.commutative(expr) in assumps:
return True
elif ~Q.commutative(expr) in assumps:
return False
return True
开发者ID:Abhityagi16,项目名称:sympy,代码行数:8,代码来源:__init__.py
示例19: log
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
开发者ID:A-turing-machine,项目名称:sympy,代码行数:8,代码来源:order.py
示例20: Pow
def Pow(expr, assumptions):
"""
Hermitian**Integer -> Hermitian
"""
if expr.is_number:
return AskRealHandler._number(expr, assumptions)
if ask(Q.hermitian(expr.base), assumptions):
if ask(Q.integer(expr.exp), assumptions):
return True
开发者ID:Tarang1993,项目名称:sympy,代码行数:9,代码来源:sets.py
注:本文中的sympy.assumptions.Q类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论