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

Python basic.sympify函数代码示例

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

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



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

示例1: _eval_subs

 def _eval_subs(self, old, new):
     old = sympify(old)
     if old==self.func:
         arg = self.args[0]
         new = sympify(new)
         return new(arg._eval_subs(old, new))
     return self
开发者ID:jcockayne,项目名称:sympy-rkern,代码行数:7,代码来源:exponential.py


示例2: _eval_expand_log

 def _eval_expand_log(self, deep=True, **hints):
     if deep:
         arg = self.args[0].expand(deep=deep, **hints)
     else:
         arg = self.args[0]
     if arg.is_Mul:
         expr = sympify(0)
         nonpos = sympify(1)
         for x in arg.args:
             if deep:
                 x = x.expand(deep=deep, **hints)
             if x.is_positive:
                 expr += self.func(x)._eval_expand_log(deep=deep, **hints)
             else:
                 nonpos *= x
         return expr + log(nonpos)
     elif arg.is_Pow:
         if arg.exp.is_real:# and arg.base.is_positive:
             # This should only run when base.is_positive, but it breaks
             # nseries, so it will have to wait for the new assumptions system.
             # See the variable obj2 in log._eval_nseries.
             if deep:
                 b = arg.base.expand(deep=deep, **hints)
                 e = arg.exp.expand(deep=deep, **hints)
             else:
                 b = arg.base
                 e = arg.exp
             return e * self.func(b)._eval_expand_log(deep=deep,\
             **hints)
     return self.func(arg)
开发者ID:Praveen-Ramanujam,项目名称:MobRAVE,代码行数:30,代码来源:exponential.py


示例3: __new__

    def __new__(cls, center=None, hradius=None, vradius=None, eccentricity=None,
                **kwargs):
        hradius = sympify(hradius)
        vradius = sympify(vradius)
        eccentricity = sympify(eccentricity)

        if len(filter(None, (hradius, vradius, eccentricity))) != 2:
            raise ValueError, 'Exactly two arguments between "hradius", '\
                '"vradius", and "eccentricity" must be not None."'

        if eccentricity is not None:
            if hradius is None:
                hradius = vradius / sqrt(1 - eccentricity**2)
            elif vradius is None:
                vradius = hradius * sqrt(1 - eccentricity**2)
        else:
            if hradius is None and vradius is None:
                raise ValueError("At least two arguments between hradius, "
                    "vradius and eccentricity must not be none.")

        if center is None:
            center = Point(0, 0)

        if not isinstance(center, Point):
            raise TypeError("center must be a Point")

        if hradius == vradius:
            return Circle(center, hradius, **kwargs)
        return GeometryEntity.__new__(cls, center, hradius, vradius, **kwargs)
开发者ID:bibile,项目名称:sympy,代码行数:29,代码来源:ellipse.py


示例4: eval

    def eval(cls, x, k):
        x = sympify(x)
        k = sympify(k)

        if x is S.NaN:
            return S.NaN
        elif k.is_Integer:
            if k is S.NaN:
                return S.NaN
            elif k is S.Zero:
                return S.One
            else:
                result = S.One

                if k.is_positive:
                    if x is S.Infinity:
                        return S.Infinity
                    elif x is S.NegativeInfinity:
                        if k.is_odd:
                            return S.NegativeInfinity
                        else:
                            return S.Infinity
                    else:
                        return reduce(lambda r, i: r*(x-i), xrange(0, int(k)), 1)
                else:
                    if x is S.Infinity:
                        return S.Infinity
                    elif x is S.NegativeInfinity:
                        return S.Infinity
                    else:
                        return 1/reduce(lambda r, i: r*(x+i), xrange(1, abs(int(k))+1), 1)
开发者ID:bibile,项目名称:sympy,代码行数:31,代码来源:factorials.py


示例5: __new__

    def __new__(cls, center, hradius, vradius, **kwargs):
        hradius = sympify(hradius)
        vradius = sympify(vradius)
        if not isinstance(center, Point):
            raise TypeError("center must be be a Point")

        if hradius == vradius:
            return Circle(center, hradius, **kwargs)
        return GeometryEntity.__new__(cls, center, hradius, vradius, **kwargs)
开发者ID:jcockayne,项目名称:sympy-rkern,代码行数:9,代码来源:ellipse.py


示例6: eval

    def eval(cls, arg, base=None):
        if base is not None:
            base = sympify(base)

            if arg.is_positive and arg.is_Integer and \
               base.is_positive and base.is_Integer:
                base = int(base)
                arg = int(arg)
                n = multiplicity(base, arg)
                return S(n) + log(arg // base ** n) / log(base)
            if base is not S.Exp1:
                return cls(arg)/cls(base)
            else:
                return cls(arg)

        arg = sympify(arg)

        if arg.is_Number:
            if arg is S.Zero:
                return S.NegativeInfinity
            elif arg is S.One:
                return S.Zero
            elif arg is S.Infinity:
                return S.Infinity
            elif arg is S.NegativeInfinity:
                return S.Infinity
            elif arg is S.NaN:
                return S.NaN
            elif arg.is_negative:
                return S.Pi * S.ImaginaryUnit + cls(-arg)
        elif arg is S.Exp1:
            return S.One
        #this doesn't work due to caching: :(
        #elif arg.func is exp and arg.args[0].is_real:
        #using this one instead:
        elif arg.func is exp:
            return arg.args[0]
        #this shouldn't happen automatically (see the issue 252):
        #elif arg.is_Pow:
        #    if arg.exp.is_Number or arg.exp.is_NumberSymbol or \
        #        arg.exp.is_number:
        #        return arg.exp * self(arg.base)
        #elif arg.is_Mul and arg.is_real:
        #    return C.Add(*[self(a) for a in arg])
        elif not arg.is_Add:
            coeff = arg.as_coefficient(S.ImaginaryUnit)

            if coeff is not None:
                if coeff is S.Infinity:
                    return S.Infinity
                elif coeff is S.NegativeInfinity:
                    return S.Infinity
                elif coeff.is_Rational:
                    if coeff.is_nonnegative:
                        return S.Pi * S.ImaginaryUnit * S.Half + cls(coeff)
                    else:
                        return -S.Pi * S.ImaginaryUnit * S.Half + cls(-coeff)
开发者ID:Praveen-Ramanujam,项目名称:MobRAVE,代码行数:57,代码来源:exponential.py


示例7: __new__

    def __new__(cls, *args, **kwargs):
        if isinstance(args[0], (tuple, list, set)):
            coords = tuple([sympify(x) for x in args[0]])
        else:
            coords = tuple([sympify(x) for x in args])

        if len(coords) != 2:
            raise NotImplementedError("Only two dimensional points currently supported")

        return GeometryEntity.__new__(cls, *coords)
开发者ID:Praveen-Ramanujam,项目名称:MobRAVE,代码行数:10,代码来源:point.py


示例8: canonize

 def canonize(cls, arg, k = 0):
     k = sympify(k)
     if not k.is_Integer or k.is_negative:
         raise ValueError("Error: the second argument of DiracDelta must be \
         a non-negative integer, %s given instead." %(k,))
     arg = sympify(arg)
     if arg is S.NaN:
         return S.NaN
     if arg.is_positive or arg.is_negative:
         return S.Zero
     elif arg.is_zero:
         return S.Infinity
开发者ID:jcockayne,项目名称:sympy-rkern,代码行数:12,代码来源:delta_functions.py


示例9: taylor_term

    def taylor_term(n, x, *previous_terms):
        if n == 0:
            return 1 / sympify(x)
        elif n < 0 or n % 2 == 0:
            return S.Zero
        else:
            x = sympify(x)

            B = C.bernoulli(n+1)
            F = C.factorial(n+1)

            return (-1)**((n+1)//2) * 2**(n+1) * B/F * x**n
开发者ID:jcreus,项目名称:sympy,代码行数:12,代码来源:trigonometric.py


示例10: eval

    def eval(cls, arg):
        arg = sympify(arg)

        if arg.is_Number:
            if arg is S.NaN:
                return S.NaN
            elif arg is S.Infinity:
                return S.One
            elif arg is S.NegativeInfinity:
                return S.NegativeOne
            elif arg is S.Zero:
                return S.Zero
            elif arg.is_negative:
                return -cls(-arg)
        else:
            i_coeff = arg.as_coefficient(S.ImaginaryUnit)

            if i_coeff is not None:
                return S.ImaginaryUnit * C.tan(i_coeff)
            else:
                coeff, terms = arg.as_coeff_terms()

                if coeff.is_negative:
                    return -cls(-arg)

            if isinstance(arg, asinh):
                x = arg.args[0]
                return x/sqrt(1+x**2)

            if isinstance(arg, acosh):
                x = arg.args[0]
                return sqrt(x-1) * sqrt(x+1) / x

            if isinstance(arg, atanh):
                return arg.args[0]
开发者ID:ryanGT,项目名称:sympy,代码行数:35,代码来源:hyperbolic.py


示例11: __div__

 def __div__(self, divisor):
     """
     Create a new point where each coordinate in this point is
     divided by factor.
     """
     divisor = sympify(divisor)
     return Point( [x/divisor for x in self] )
开发者ID:Praveen-Ramanujam,项目名称:MobRAVE,代码行数:7,代码来源:point.py


示例12: __mul__

 def __mul__(self, factor):
     """
     Create a new point where each coordinate in this point is
     multiplied by factor.
     """
     factor = sympify(factor)
     return Point( [x*factor for x in self] )
开发者ID:Praveen-Ramanujam,项目名称:MobRAVE,代码行数:7,代码来源:point.py


示例13: eval

    def eval(cls, arg):
        arg = sympify(arg)

        if arg.is_Number:
            if arg is S.NaN:
                return S.NaN
            elif arg is S.Infinity:
                return S.Zero
            elif arg is S.NegativeInfinity:
                return S.Zero
            elif arg is S.Zero:
                return S.Pi * S.ImaginaryUnit / 2
            elif arg is S.One:
                return S.Infinity
            elif arg is S.NegativeOne:
                return S.NegativeInfinity
            elif arg.is_negative:
                return -cls(-arg)
        else:
            i_coeff = arg.as_coefficient(S.ImaginaryUnit)

            if i_coeff is not None:
                return -S.ImaginaryUnit * C.acot(i_coeff)
            else:
                coeff, terms = arg.as_coeff_terms()

                if coeff.is_negative:
                    return -cls(-arg)
开发者ID:nkinar,项目名称:sympy,代码行数:28,代码来源:hyperbolic.py


示例14: canonize

    def canonize(cls, arg):
        arg = sympify(arg)

        if arg.is_Number:
            if arg is S.NaN:
                return S.NaN
            elif arg is S.Infinity:
                return S.Infinity
            elif arg is S.NegativeInfinity:
                return S.NegativeInfinity
            elif arg is S.Zero:
                return S.Zero
            elif arg is S.One:
                return C.log(2**S.Half + 1)
            elif arg is S.NegativeOne:
                return C.log(2**S.Half - 1)
            elif arg.is_negative:
                return -cls(-arg)
        else:
            i_coeff = arg.as_coefficient(S.ImaginaryUnit)

            if i_coeff is not None:
                return S.ImaginaryUnit * C.asin(i_coeff)
            else:
                coeff, terms = arg.as_coeff_terms()

                if coeff.is_negative:
                    return -cls(-arg)
开发者ID:jcockayne,项目名称:sympy-rkern,代码行数:28,代码来源:hyperbolic.py


示例15: taylor_term

 def taylor_term(n, x, *previous_terms):
     if n == 0:
         return S.Pi * S.ImaginaryUnit / 2
     elif n < 0 or n % 2 == 0:
         return S.Zero
     else:
         x = sympify(x)
         return x ** n / n
开发者ID:nkinar,项目名称:sympy,代码行数:8,代码来源:hyperbolic.py


示例16: _pi_coeff

def _pi_coeff(arg, cycles=1):
    """
    When arg is a Number times pi (e.g. 3*pi/2) then return the Number
    normalized to be in the range [0, 2], else None.

    When an even multiple of pi is encountered, if it is multiplying
    something with known parity then the multiple is returned as 0 otherwise
    as 2.

    Examples:
    >>> from sympy.functions.elementary.trigonometric import _pi_coeff as coeff
    >>> from sympy import pi
    >>> from sympy.abc import x, y
    >>> coeff(3*x*pi)
    3*x
    >>> coeff(11*pi/7)
    11/7
    >>> coeff(-11*pi/7)
    3/7
    >>> coeff(4*pi)
    0
    >>> coeff(5*pi)
    1
    >>> coeff(5.0*pi)
    1
    >>> coeff(5.5*pi)
    3/2
    >>> coeff(2 + pi)

    """
    arg = sympify(arg)
    if arg is S.Pi:
        return S.One
    elif not arg:
        return S.Zero
    elif arg.is_Mul:
        cx = arg.coeff(S.Pi)
        if cx:
            c, x = cx.as_coeff_Mul() # pi is not included as coeff
            if c.is_Float:
                # recast exact binary fractions to Rationals
                m = int(c*2)
                if Float(float(m)/2) == c:
                    c = Rational(m, 2)
            if x is not S.One or not (c.is_Rational and c.q != 1):
                if x.is_integer:
                    c2 = c % 2
                    if c2 == 1:
                        return x
                    elif not c2:
                        if x.is_even is not None: # known parity
                            return S.Zero
                        return 2*x
                    else:
                        return c2*x
                return cx
            else:
                return Rational(c.p % (2*c.q), c.q)
开发者ID:jcreus,项目名称:sympy,代码行数:58,代码来源:trigonometric.py


示例17: taylor_term

 def taylor_term(n, x, *previous_terms):
     if n<0: return S.Zero
     if n==0: return S.One
     x = sympify(x)
     if previous_terms:
         p = previous_terms[-1]
         if p is not None:
             return p * x / n
     return x**n/C.Factorial()(n)
开发者ID:jcockayne,项目名称:sympy-rkern,代码行数:9,代码来源:exponential.py


示例18: taylor_term

 def taylor_term(n, x, *previous_terms): # of log(1+x)
     from sympy import powsimp
     if n<0: return S.Zero
     x = sympify(x)
     if n==0: return x
     if previous_terms:
         p = previous_terms[-1]
         if p is not None:
             return powsimp((-n) * p * x / (n+1), deep=True, combine='exp')
     return (1-2*(n%2)) * x**(n+1)/(n+1)
开发者ID:Praveen-Ramanujam,项目名称:MobRAVE,代码行数:10,代码来源:exponential.py


示例19: __new__

    def __new__(self, c, r, n, **kwargs):
        r = sympify(r)
        if not isinstance(c, Point):
            raise GeometryError("RegularPolygon.__new__ requires c to be a Point instance")
        if not isinstance(r, Basic):
            raise GeometryError("RegularPolygon.__new__ requires r to be a number or Basic instance")
        if n < 3:
            raise GeometryError("RegularPolygon.__new__ requires n >= 3")

        obj = GeometryEntity.__new__(self, c, r, n, **kwargs)
        return obj
开发者ID:Praveen-Ramanujam,项目名称:MobRAVE,代码行数:11,代码来源:polygon.py


示例20: taylor_term

    def taylor_term(n, x, *previous_terms):
        if n < 0 or n % 2 == 0:
            return S.Zero
        else:
            x = sympify(x)

            k = (n - 1)//2

            if len(previous_terms) > 2:
                return -previous_terms[-2] * x**2 * (n-2)/(n*k)
            else:
                return 2*(-1)**k * x**n/(n*C.Factorial(k)*sqrt(S.Pi))
开发者ID:tovrstra,项目名称:sympy,代码行数:12,代码来源:error_functions.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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