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


Python Q.integer方法代码示例

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


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

示例1: test_float_1

# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import integer [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

示例2: test_finally

# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import integer [as 别名]
def test_finally():
    try:
        with assuming(Q.integer(x)):
            1/0
    except ZeroDivisionError:
        pass
    assert not ask(Q.integer(x))
开发者ID:Abhityagi16,项目名称:sympy,代码行数:9,代码来源:test_context.py

示例3: Pow

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

示例4: test_custom_context

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

示例5: test_global

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

示例6: test_remove_safe

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

示例7: Pow

# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import integer [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

示例8: test_I

# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import integer [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

示例9: MatPow

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

示例10: test_negative

# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import integer [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

示例11: Pow

# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import integer [as 别名]
 def Pow(expr, assumptions):
     """
     Imaginary**integer -> Imaginary if integer % 2 == 1
     Imaginary**integer -> real if integer % 2 == 0
     Imaginary**Imaginary    -> ?
     Imaginary**Real         -> ?
     """
     if expr.is_number:
         return AskImaginaryHandler._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 True
             elif ask(Q.even(expr.exp), assumptions):
                 return False
     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.negative(expr.base),assumptions)
             elif ask(Q.integer(expr.exp), assumptions):
                 return False
             elif ask(Q.positive(expr.base), assumptions):
                 return False
             elif ask(Q.negative(expr.base), assumptions):
                 return True
开发者ID:Tarang1993,项目名称:sympy,代码行数:28,代码来源:sets.py

示例12: refine_exp

# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import integer [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

示例13: Mul

# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import integer [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

示例14: Mul

# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import integer [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

示例15: Basic

# 需要导入模块: from sympy.assumptions import Q [as 别名]
# 或者: from sympy.assumptions.Q import integer [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


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