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


Python queries.ask函数代码示例

本文整理汇总了Python中sympy.queries.ask函数的典型用法代码示例。如果您正苦于以下问题:Python ask函数的具体用法?Python ask怎么用?Python ask使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: 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(arg, Q.integer, assumptions):
             if arg.is_Rational:
                 if arg.q == 2:
                     return ask(2 * expr, Q.even, assumptions)
                 if ~(arg.q & 1):
                     return None
             elif ask(arg, Q.irrational, assumptions):
                 if _output:
                     _output = False
                 else:
                     return
             else:
                 return
     else:
         return _output
开发者ID:hazelnusse,项目名称:sympy-old,代码行数:26,代码来源:sets.py

示例2: test_extended_real

def test_extended_real():
    x = symbols('x')
    assert ask(x, Q.extended_real, Assume(x, Q.positive)) == True
    assert ask(-x, Q.extended_real, Assume(x, Q.positive)) == True
    assert ask(-x, Q.extended_real, Assume(x, Q.negative)) == True

    assert ask(x+S.Infinity, Q.extended_real, Assume(x, Q.real)) == True
开发者ID:KevinGoodsell,项目名称:sympy,代码行数:7,代码来源:test_query.py

示例3: Basic

 def Basic(expr, assumptions):
     _integer = ask(expr, Q.integer, assumptions)
     if _integer:
         _even = ask(expr, Q.even, assumptions)
         if _even is None: return None
         return not _even
     return _integer
开发者ID:KevinGoodsell,项目名称:sympy,代码行数:7,代码来源:ntheory.py

示例4: refine_Pow

def refine_Pow(expr, assumptions):
    """
    Handler for instances of Pow.

    >>> from sympy import Symbol, Assume, Q
    >>> from sympy.refine import refine_Pow
    >>> x = Symbol("x")
    >>> refine_Pow((-1)**x, Assume(x, Q.real))
    >>> refine_Pow((-1)**x, Assume(x, Q.even))
    1
    >>> refine_Pow((-1)**x, Assume(x, Q.odd))
    -1

    """
    from sympy.core import Pow, Rational
    from sympy.functions import sign
    if ask(expr.base, Q.real, assumptions):
        if expr.base.is_number:
            if ask(expr.exp, Q.even, assumptions):
                return abs(expr.base) ** expr.exp
            if ask(expr.exp, Q.odd, assumptions):
                return sign(expr.base) * abs(expr.base) ** expr.exp
        if isinstance(expr.exp, Rational):
            if type(expr.base) is Pow:
                return abs(expr.base.base) ** (expr.base.exp * expr.exp)
开发者ID:KevinGoodsell,项目名称:sympy,代码行数:25,代码来源:__init__.py

示例5: refine_exp

def refine_exp(expr, assumptions):
    """
    Handler for exponential function.

    >>> from sympy import Symbol, Assume, Q, exp, I, pi
    >>> from sympy.refine import refine_exp
    >>> x = Symbol("x")
    >>> refine_exp(exp(pi*I*2*x), Assume(x, Q.real))
    >>> refine_exp(exp(pi*I*2*x), Assume(x, Q.integer))
    1

    """
    arg = expr.args[0]
    if arg.is_Mul:
        coeff = arg.as_coefficient(S.Pi*S.ImaginaryUnit)
        if coeff:
            if ask(2*coeff, Q.integer, assumptions):
                if ask(coeff, Q.even, assumptions):
                    return S.One
                elif ask(coeff, Q.odd, assumptions):
                    return S.NegativeOne
                elif ask(coeff + S.Half, Q.even, assumptions):
                    return -S.ImaginaryUnit
                elif ask(coeff + S.Half, Q.odd, assumptions):
                    return S.ImaginaryUnit
开发者ID:KevinGoodsell,项目名称:sympy,代码行数:25,代码来源:__init__.py

示例6: 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(arg, Q.integer, assumptions):
             if ask(arg, Q.even, assumptions):
                 even = True
             elif ask(arg, Q.odd, assumptions):
                 odd += 1
         elif ask(arg, Q.irrational, 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:KevinGoodsell,项目名称:sympy,代码行数:28,代码来源:ntheory.py

示例7: test_global

def test_global():
    """Test ask with global assumptions"""
    x = symbols('x')
    assert ask(x, Q.integer) == None
    global_assumptions.add(Assume(x, Q.integer))
    assert ask(x, Q.integer) == True
    global_assumptions.clear()
    assert ask(x, Q.integer) == None
开发者ID:KevinGoodsell,项目名称:sympy,代码行数:8,代码来源:test_query.py

示例8: Pow

 def Pow(expr, assumptions):
     if expr.is_number: return expr.evalf() > 0
     if ask(expr.base, Q.positive, assumptions):
         return True
     if ask(expr.base, Q.negative, assumptions):
         if ask(expr.exp, Q.even, assumptions):
             return True
         if ask(expr.exp, Q.even, assumptions):
             return False
开发者ID:KevinGoodsell,项目名称:sympy,代码行数:9,代码来源:order.py

示例9: Pow

 def Pow(expr, assumptions):
     """
     Integer**Integer     -> !Prime
     """
     if expr.is_number:
         return AskPrimeHandler._number(expr, assumptions)
     if ask(expr.exp, Q.integer, assumptions) and \
             ask(expr.base, Q.integer, assumptions):
         return False
开发者ID:KevinGoodsell,项目名称:sympy,代码行数:9,代码来源:ntheory.py

示例10: Basic

 def Basic(expr, assumptions):
     _real = ask(expr, Q.real, assumptions)
     if _real:
         _rational = ask(expr, Q.rational, assumptions)
         if _rational is None:
             return None
         return not _rational
     else:
         return _real
开发者ID:hazelnusse,项目名称:sympy-old,代码行数:9,代码来源:sets.py

示例11: Mul

 def Mul(expr, assumptions):
     if expr.is_number:
         return AskPositiveHandler._number(expr, assumptions)
     result = True
     for arg in expr.args:
         if ask(arg, Q.positive, assumptions): continue
         elif ask(arg, Q.negative, assumptions):
             result = result ^ True
         else: return
     return result
开发者ID:KevinGoodsell,项目名称:sympy,代码行数:10,代码来源:order.py

示例12: Pow

 def Pow(expr, assumptions):
     """
     Rational ** Integer      -> Rational
     Irrational ** Rational   -> Irrational
     Rational ** Irrational   -> ?
     """
     if ask(expr.exp, Q.integer, assumptions):
         return ask(expr.base, Q.rational, assumptions)
     elif ask(expr.exp, Q.rational, assumptions):
         if ask(expr.base, Q.prime, assumptions):
             return False
开发者ID:hazelnusse,项目名称:sympy-old,代码行数:11,代码来源:sets.py

示例13: test_key_extensibility

def test_key_extensibility():
    """test that you can add keys to the ask system at runtime"""
    x = Symbol('x')
    # make sure thie key is not defined
    raises(KeyError, "ask(x, 'my_key')")
    class MyAskHandler(AskHandler):
        @staticmethod
        def Symbol(expr, assumptions):
            return True
    register_handler('my_key', MyAskHandler)
    assert ask(x, 'my_key') == True
    assert ask(x+1, 'my_key') == None
    remove_handler('my_key', MyAskHandler)
开发者ID:KevinGoodsell,项目名称:sympy,代码行数:13,代码来源:test_query.py

示例14: Pow

 def Pow(expr, assumptions):
     """
     Unbounded ** Whatever -> Unbounded
     Bounded ** Unbounded -> Unbounded if base > 1
     Bounded ** Unbounded -> Unbounded if base < 1
     """
     base_bounded = ask(expr.base, Q.bounded, assumptions)
     if not base_bounded: return base_bounded
     if ask(expr.exp, Q.bounded, assumptions) \
         and base_bounded: return True
     if base_bounded and expr.base.is_number:
         # We need to implement relations for this
         if abs(expr.base) > 1:
             return False
         return True
开发者ID:KevinGoodsell,项目名称:sympy,代码行数:15,代码来源:calculus.py

示例15: Mul

 def Mul(expr, assumptions):
     """
     Infinitesimal*Bounded -> Infinitesimal
     """
     if expr.is_number:
         return AskInfinitesimalHandler._number(expr, assumptions)
     result = False
     for arg in expr.args:
         if ask(arg, Q.infinitesimal, assumptions):
             result = True
         elif ask(arg, Q.bounded, assumptions):
             continue
         else: break
     else:
         return result
开发者ID:KevinGoodsell,项目名称:sympy,代码行数:15,代码来源:calculus.py


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