当前位置: 首页>>代码示例>>Python>>正文


Python Q.even方法代码示例

本文整理汇总了Python中sympy.assumptions.Q.even方法的典型用法代码示例。如果您正苦于以下问题:Python Q.even方法的具体用法?Python Q.even怎么用?Python Q.even使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sympy.assumptions.Q的用法示例。


在下文中一共展示了Q.even方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Pow

# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import even [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
开发者ID:Tarang1993,项目名称:sympy,代码行数:31,代码来源:sets.py

示例2: refine_exp

# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import even [as 别名]
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,代码行数:27,代码来源:refine.py

示例3: test_float_1

# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import even [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
开发者ID:lazovich,项目名称:sympy,代码行数:36,代码来源:test_query.py

示例4: Pow

# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import even [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
开发者ID:101man,项目名称:sympy,代码行数:11,代码来源:order.py

示例5: test_I

# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import even [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
开发者ID:lazovich,项目名称:sympy,代码行数:54,代码来源:test_query.py

示例6: Mul

# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import even [as 别名]
 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,代码行数:28,代码来源:sets.py

示例7: Mul

# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import even [as 别名]
 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,代码行数:34,代码来源:ntheory.py

示例8: test_composite_proposition

# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import even [as 别名]
def test_composite_proposition():
    from sympy.logic.boolalg import Equivalent, Implies
    x = symbols('x')
    assert ask(True) is True
    assert ask(~Q.negative(x), Q.positive(x)) is True
    assert ask(~Q.real(x), Q.commutative(x)) is None
    assert ask(Q.negative(x) & Q.integer(x), Q.positive(x)) is False
    assert ask(Q.negative(x) & Q.integer(x)) is None
    assert ask(Q.real(x) | Q.integer(x), Q.positive(x)) is True
    assert ask(Q.real(x) | Q.integer(x)) is None
    assert ask(Q.real(x) >> Q.positive(x), Q.negative(x)) is False
    assert ask(Implies(Q.real(x), Q.positive(x), evaluate=False), Q.negative(x)) is False
    assert ask(Implies(Q.real(x), Q.positive(x), evaluate=False)) is None
    assert ask(Equivalent(Q.integer(x), Q.even(x)), Q.even(x)) is True
    assert ask(Equivalent(Q.integer(x), Q.even(x))) is None
    assert ask(Equivalent(Q.positive(x), Q.integer(x)), Q.integer(x)) is None
开发者ID:lazovich,项目名称:sympy,代码行数:18,代码来源:test_query.py

示例9: test_negative

# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import even [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
开发者ID:lazovich,项目名称:sympy,代码行数:35,代码来源:test_query.py

示例10: Basic

# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import even [as 别名]
 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,代码行数:9,代码来源:ntheory.py

示例11: _eval_refine

# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import even [as 别名]
    def _eval_refine(self, assumptions):
        from sympy.assumptions import ask, Q
        arg = self.args[0]
        if arg.is_Mul:
            Ioo = S.ImaginaryUnit*S.Infinity
            if arg in [Ioo, -Ioo]:
                return S.NaN

            coeff = arg.as_coefficient(S.Pi*S.ImaginaryUnit)
            if coeff:
                if ask(Q.integer(2*coeff)):
                    if ask(Q.even(coeff)):
                        return S.One
                    elif ask(Q.odd(coeff)):
                        return S.NegativeOne
                    elif ask(Q.even(coeff + S.Half)):
                        return -S.ImaginaryUnit
                    elif ask(Q.odd(coeff + S.Half)):
                        return S.ImaginaryUnit
开发者ID:baoqchau,项目名称:sympy,代码行数:21,代码来源:exponential.py

示例12: Pow

# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import even [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
开发者ID:EuanFree,项目名称:sympy,代码行数:12,代码来源:ntheory.py

示例13: test_integer

# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import even [as 别名]
def test_integer():
    x = symbols('x')
    assert ask(Q.integer(x)) == None
    assert ask(Q.integer(x), Q.integer(x)) == True
    assert ask(Q.integer(x), ~Q.integer(x)) == False
    assert ask(Q.integer(x), ~Q.real(x)) == False
    assert ask(Q.integer(x), ~Q.positive(x)) == None
    assert ask(Q.integer(x), Q.even(x) | Q.odd(x)) == True

    assert ask(Q.integer(2*x), Q.integer(x)) == True
    assert ask(Q.integer(2*x), Q.even(x)) == True
    assert ask(Q.integer(2*x), Q.prime(x)) == True
    assert ask(Q.integer(2*x), Q.rational(x)) == None
    assert ask(Q.integer(2*x), Q.real(x)) == None
    assert ask(Q.integer(sqrt(2)*x), Q.integer(x)) == False

    assert ask(Q.integer(x/2), Q.odd(x)) == False
    assert ask(Q.integer(x/2), Q.even(x)) == True
    assert ask(Q.integer(x/3), Q.odd(x)) == None
    assert ask(Q.integer(x/3), Q.even(x)) == None
开发者ID:lazovich,项目名称:sympy,代码行数:22,代码来源:test_query.py

示例14: Pow

# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import even [as 别名]
 def Pow(expr, assumptions):
     if expr.is_number:
         return AskPositiveHandler._number(expr, assumptions)
     if ask(Q.positive(expr.base), assumptions):
         if ask(Q.real(expr.exp), assumptions):
             return True
     if ask(Q.negative(expr.base), assumptions):
         if ask(Q.even(expr.exp), assumptions):
             return True
         if ask(Q.odd(expr.exp), assumptions):
             return False
开发者ID:A-turing-machine,项目名称:sympy,代码行数:13,代码来源:order.py

示例15: Pow

# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import even [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
开发者ID:Davidjohnwilson,项目名称:sympy,代码行数:55,代码来源:sets.py


注:本文中的sympy.assumptions.Q.even方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。