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


Python basic.sympify函数代码示例

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


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


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