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

Python assumptions.ask函数代码示例

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

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



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

示例1: refine_Pow

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

    >>> from sympy import Symbol, Assume, Q
    >>> from sympy.assumptions.refine import refine_Pow
    >>> from sympy.abc import 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:smichr,项目名称:sympy-live,代码行数:26,代码来源:refine.py


示例2: refine_atan2

def refine_atan2(expr, assumptions):
    """
    Handler for the atan2 function

    Examples
    ========

    >>> from sympy import Symbol, Q, refine, atan2
    >>> from sympy.assumptions.refine import refine_atan2
    >>> from sympy.abc import x, y
    >>> refine_atan2(atan2(y,x), Q.real(y) & Q.positive(x))
    atan(y/x)
    >>> refine_atan2(atan2(y,x), Q.negative(y) & Q.negative(x))
    atan(y/x) - pi
    >>> refine_atan2(atan2(y,x), Q.positive(y) & Q.negative(x))
    atan(y/x) + pi
    """
    from sympy.functions.elementary.complexes import atan
    from sympy.core import S
    y, x = expr.args
    if ask(Q.real(y) & Q.positive(x), assumptions):
        return atan(y / x)
    elif ask(Q.negative(y) & Q.negative(x), assumptions):
        return atan(y / x) - S.Pi
    elif ask(Q.positive(y) & Q.negative(x), assumptions):
        return atan(y / x) + S.Pi
    else:
        return expr
开发者ID:AdrianPotter,项目名称:sympy,代码行数:28,代码来源:refine.py


示例3: MatPow

 def MatPow(expr, assumptions):
     # only for integer powers
     base, exp = expr.args
     int_exp = ask(Q.integer(exp), assumptions)
     if int_exp:
         return ask(Q.unitary(base), assumptions)
     return None
开发者ID:Lenqth,项目名称:sympy,代码行数:7,代码来源:matrices.py


示例4: 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


示例5: test_extended_real

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

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


示例6: 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


示例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: 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


示例9: 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:Aang,项目名称:sympy,代码行数:7,代码来源:test_query.py


示例10: test_functions_in_assumptions

def test_functions_in_assumptions():
    from sympy.logic.boolalg import Equivalent, Xor

    x = symbols("x")
    assert ask(x, Q.negative, Q.real(x) >> Q.positive(x)) is False
    assert ask(x, Q.negative, Equivalent(Q.real(x), Q.positive(x))) is False
    assert ask(x, Q.negative, Xor(Q.real(x), Q.negative(x))) is False
开发者ID:sympy,项目名称:sympy,代码行数:7,代码来源:test_query.py


示例11: 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


示例12: 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:Sumith1896,项目名称:sympy-polys,代码行数:7,代码来源:sets.py


示例13: 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


示例14: 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


示例15: 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


示例16: 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


示例17: 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


示例18: 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:Aang,项目名称:sympy,代码行数:8,代码来源:test_query.py


示例19: test_custom_context

def test_custom_context():
    """Test ask with custom assumptions context"""
    x = symbols('x')
    assert ask(x, Q.integer) == None
    local_context = AssumptionsContext()
    local_context.add(Assume(x, Q.integer))
    assert ask(x, Q.integer, context = local_context) == True
    assert ask(x, Q.integer) == None
开发者ID:Aang,项目名称:sympy,代码行数:8,代码来源:test_query.py


示例20: 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



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python assumptions.Q类代码示例发布时间:2022-05-27
下一篇:
Python x.subs函数代码示例发布时间: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