• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python queries.ask函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: Add

 def Add(expr, assumptions):
     if expr.is_number:
         return AskPositiveHandler._number(expr, assumptions)
     for arg in expr.args:
         if ask(arg, Q.positive, assumptions) is not True:
             break
     else:
         # if all argument's are positive
         return True
开发者ID:KevinGoodsell,项目名称:sympy,代码行数:9,代码来源:order.py


示例17: Add

    def Add(expr, assumptions):
        """
        Even + Odd  -> Odd
        Even + Even -> Even
        Odd  + Odd  -> Even

        TODO: remove float() when issue
        http://code.google.com/p/sympy/issues/detail?id=1473
        is solved
        """
        if expr.is_number:
            return AskEvenHandler._number(expr, assumptions)
        _result = True
        for arg in expr.args:
            if ask(arg, Q.even, assumptions):
                pass
            elif ask(arg, Q.odd, assumptions):
                _result = not _result
            else: break
        else:
            return _result
开发者ID:KevinGoodsell,项目名称:sympy,代码行数:21,代码来源:ntheory.py


示例18: Add

 def Add(expr, assumptions):
     """
     Imaginary + Imaginary -> Imaginary
     Imaginary + Complex   -> ?
     Imaginary + Real      -> !Imaginary
     """
     if expr.is_number:
         return AskImaginaryHandler._number(expr, assumptions)
     reals = 0
     for arg in expr.args:
         if ask(arg, Q.imaginary, assumptions):
             pass
         elif ask(arg, Q.real, assumptions):
             reals += 1
         else:
             break
     else:
         if reals == 0:
             return True
         if reals == 1 or (len(expr.args) == reals):
             # two reals could sum 0 thus giving an imaginary
             return False
开发者ID:hazelnusse,项目名称:sympy-old,代码行数:22,代码来源:sets.py


示例19: refine_abs

def refine_abs(expr, assumptions):
    """
    Handler for the absolute value.

    Examples:

    >>> from sympy import Symbol, Assume, Q
    >>> from sympy.refine import refine_abs
    >>> x = Symbol("x")
    >>> refine_abs(abs(x), Assume(x, Q.real))
    >>> refine_abs(abs(x), Assume(x, Q.positive))
    x
    >>> refine_abs(abs(x), Assume(x, Q.negative))
    -x

    """
    arg = expr.args[0]
    if ask(arg, Q.real, assumptions) and \
            fuzzy_not(ask(arg, Q.negative, assumptions)):
        # if it's nonnegative
        return arg
    if ask(arg, Q.negative, assumptions):
        return -arg
开发者ID:KevinGoodsell,项目名称:sympy,代码行数:23,代码来源:__init__.py


示例20: test_infinitesimal

def test_infinitesimal():
    x, y = symbols('x y')
    assert ask(x, Q.infinitesimal) == None
    assert ask(x, Q.infinitesimal, Assume(x, Q.infinitesimal)) == True

    assert ask(2*x, Q.infinitesimal, Assume(x, Q.infinitesimal)) == True
    assert ask(x*y, Q.infinitesimal, Assume(x, Q.infinitesimal)) == None
    assert ask(x*y, Q.infinitesimal, Assume(x, Q.infinitesimal) & \
                     Assume(y, Q.infinitesimal)) == True
    assert ask(x*y, Q.infinitesimal, Assume(x, Q.infinitesimal) & \
                     Assume(y, Q.bounded)) == True

    assert ask(x**2, Q.infinitesimal, Assume(x, Q.infinitesimal)) == True
开发者ID:KevinGoodsell,项目名称:sympy,代码行数:13,代码来源:test_query.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python series.limit函数代码示例发布时间:2022-05-27
下一篇:
Python theanocode.theano_function函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap