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


Python Basic.sympify方法代码示例

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


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

示例1: __new__

# 需要导入模块: from sympy.core.basic import Basic [as 别名]
# 或者: from sympy.core.basic.Basic import sympify [as 别名]
    def __new__(cls, expr, x, xlim, direction='<', **assumptions):
        expr = Basic.sympify(expr)
        x = Basic.sympify(x)
        xlim = Basic.sympify(xlim)
        if not isinstance(x, Basic.Symbol):
            raise ValueError("Limit 2nd argument must be Symbol instance (got %s)" % (x))
        assert isinstance(x, Basic.Symbol),`x`

        if not expr.has(x):
            return expr

        if isinstance(xlim, Basic.NegativeInfinity):
            xoo = InfLimit.limit_process_symbol()
            if expr.has(xoo): 
                xoo = Basic.Symbol(x.name + '_oo',dummy=True,positive=True,unbounded=True)
            return InfLimit(expr.subs(x,-xoo), xoo)
        if isinstance(xlim, Basic.Infinity):
            return InfLimit(expr, x)
        else:
            xoo = InfLimit.limit_process_symbol()
            if expr.has(xoo): 
                xoo = Basic.Symbol(x.name + '_oo',dummy=True,positive=True,unbounded=True)
            if direction=='<':
                return InfLimit(expr.subs(x, xlim+1/xoo), xoo)
            elif direction=='>':
                return InfLimit(expr.subs(x, xlim-1/xoo), xoo)
            else:
                raise ValueError("Limit direction must be < or > (got %s)" % (direction))

        # XXX This code is currently unreachable
        obj = Basic.__new__(cls, expr, x, xlim, **assumptions)
        obj.direction = direction
        return obj
开发者ID:certik,项目名称:sympy-oldcore,代码行数:35,代码来源:limits_series.py

示例2: subs

# 需要导入模块: from sympy.core.basic import Basic [as 别名]
# 或者: from sympy.core.basic.Basic import sympify [as 别名]
 def subs(self, old, new):
     old = Basic.sympify(old)
     if old==self.func:
         arg = self[0]
         new = Basic.sympify(new)
         return new(arg.subs(old, new))
     return self
开发者ID:certik,项目名称:sympy-oldcore,代码行数:9,代码来源:exponential.py

示例3: _eval_apply

# 需要导入模块: from sympy.core.basic import Basic [as 别名]
# 或者: from sympy.core.basic.Basic import sympify [as 别名]
    def _eval_apply(cls, x, k):
        x = Basic.sympify(x)
        k = Basic.sympify(k)

        if isinstance(x, Basic.NaN):
            return S.NaN
        elif isinstance(k, Basic.Integer):
            if isinstance(k, Basic.NaN):
                return S.NaN
            elif isinstance(k, Basic.Zero):
                return S.One
            else:
                result = S.One

                if k.is_positive:
                    if isinstance(x, Basic.Infinity):
                        return S.Infinity
                    elif isinstance(x, Basic.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 isinstance(x, Basic.Infinity):
                        return S.Infinity
                    elif isinstance(x, Basic.NegativeInfinity):
                        return S.Infinity
                    else:
                        return 1/reduce(lambda r, i: r*(x+i), xrange(1, abs(int(k))+1), 1)
开发者ID:certik,项目名称:sympy-oldcore,代码行数:33,代码来源:factorials.py

示例4: __new__

# 需要导入模块: from sympy.core.basic import Basic [as 别名]
# 或者: from sympy.core.basic.Basic import sympify [as 别名]
    def __new__(cls, center, hradius, vradius, **kwargs):
        hradius = Basic.sympify(hradius)
        vradius = Basic.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:certik,项目名称:sympy-oldcore,代码行数:11,代码来源:ellipse.py

示例5: __new__

# 需要导入模块: from sympy.core.basic import Basic [as 别名]
# 或者: from sympy.core.basic.Basic import sympify [as 别名]
    def __new__(cls, *args, **kwargs):
        if isinstance(args[0], (tuple, list, set)):
            coords = tuple([Basic.sympify(x) for x in args[0]])
        else:
            coords = tuple([Basic.sympify(x) for x in args])

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

        return GeometryEntity.__new__(cls, *coords)
开发者ID:certik,项目名称:sympy-oldcore,代码行数:12,代码来源:point.py

示例6: taylor_term

# 需要导入模块: from sympy.core.basic import Basic [as 别名]
# 或者: from sympy.core.basic.Basic import sympify [as 别名]
    def taylor_term(self, n, x, *previous_terms):
        if n == 0:
            return 1 / Basic.sympify(x)
        elif n < 0 or n % 2 == 0:
            return S.Zero
        else:
            x = Basic.sympify(x)

            B = S.Bernoulli(n+1)
            F = Basic.Factorial(n+1)

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

示例7: _eval_apply

# 需要导入模块: from sympy.core.basic import Basic [as 别名]
# 或者: from sympy.core.basic.Basic import sympify [as 别名]
    def _eval_apply(self, arg, base=None, **fixme):
        if base is not None:
            base = Basic.sympify(base)

            if not isinstance(base, Basic.Exp1):
                return self(arg)/self(base)

        arg = Basic.sympify(arg)

        if isinstance(arg, Basic.Number):
            if isinstance(arg, Basic.Zero):
                return S.NegativeInfinity
            elif isinstance(arg, Basic.One):
                return S.Zero
            elif isinstance(arg, Basic.Infinity):
                return S.Infinity
            elif isinstance(arg, Basic.NegativeInfinity):
                return S.Infinity
            elif isinstance(arg, Basic.NaN):
                return S.NaN
            elif arg.is_negative:
                return S.Pi * S.ImaginaryUnit + self(-arg)
        elif isinstance(arg, Basic.Exp1):
            return S.One
        #this doesn't work due to caching: :(
        #elif isinstance(arg, exp) and arg[0].is_real:
        #using this one instead:
        elif isinstance(arg, exp):
            return arg[0]
        #this shouldn't happen automatically (see the issue 252):
        #elif isinstance(arg, Basic.Pow):
        #    if isinstance(arg.exp, Basic.Number) or \
        #       isinstance(arg.exp, Basic.NumberSymbol) or arg.exp.is_number:
        #        return arg.exp * self(arg.base)
        #elif isinstance(arg, Basic.Mul) and arg.is_real:
        #    return Basic.Add(*[self(a) for a in arg])
        elif not isinstance(arg, Basic.Add):
            coeff = arg.as_coefficient(S.ImaginaryUnit)

            if coeff is not None:
                if isinstance(coeff, Basic.Infinity):
                    return S.Infinity
                elif isinstance(coeff, Basic.NegativeInfinity):
                    return S.Infinity
                elif isinstance(coeff, Basic.Rational):
                    if coeff.is_nonnegative:
                        return S.Pi * S.ImaginaryUnit * S.Half + self(coeff)
                    else:
                        return -S.Pi * S.ImaginaryUnit * S.Half + self(-coeff)
开发者ID:certik,项目名称:sympy-oldcore,代码行数:51,代码来源:exponential.py

示例8: _eval_apply

# 需要导入模块: from sympy.core.basic import Basic [as 别名]
# 或者: from sympy.core.basic.Basic import sympify [as 别名]
    def _eval_apply(self, arg):
        arg = Basic.sympify(arg)

        if isinstance(arg, Basic.NaN):
            return S.NaN
        elif arg.is_real:
            return arg
        else:
            if not isinstance(arg, Basic.Add):
                arg = [arg]

            included, reverted, excluded = [], [], []

            for term in arg:
                coeff = term.as_coefficient(S.ImaginaryUnit)

                if coeff is not None:
                    if not coeff.is_real:
                        reverted.append(coeff)
                elif not term.has(S.ImaginaryUnit) and term.is_real:
                    excluded.append(term)
                else:
                    included.append(term)

            if len(arg[:]) != len(included):
                a, b, c = map(lambda xs: Basic.Add(*xs),
                    [included, reverted, excluded])

                return self(a) - im(b) + c
开发者ID:certik,项目名称:sympy-oldcore,代码行数:31,代码来源:complexes.py

示例9: _eval_apply

# 需要导入模块: from sympy.core.basic import Basic [as 别名]
# 或者: from sympy.core.basic.Basic import sympify [as 别名]
    def _eval_apply(self, arg):
        #XXX this doesn't work, but it should (see #390):
        #return arg**S.Half
        arg = Basic.sympify(arg)

        if isinstance(arg, Basic.Number):
            if isinstance(arg, Basic.NaN):
                return S.NaN
            if isinstance(arg, Basic.Infinity):
                return S.Infinity
            if isinstance(arg, Basic.NegativeInfinity):
                return S.ImaginaryUnit * S.Infinity
            if isinstance(arg, Basic.Rational):
                factors = arg.factors()
                sqrt_factors = {}
                eval_factors = {}
                n = Basic.Integer(1)
                for k,v in factors.items():
                    n *= Basic.Integer(k) ** (v//2)
                    if v % 2:
                        n *= Basic.Integer(k) ** S.Half
                return n
            return arg ** S.Half
        if arg.is_nonnegative:
            coeff, terms = arg.as_coeff_terms()
            if not isinstance(coeff, Basic.One):
                return self(coeff) * self(Basic.Mul(*terms))
        base, exp = arg.as_base_exp()
        if isinstance(exp, Basic.Number):
            if exp == 2:
                return Basic.abs(base)
            return base ** (exp/2)
开发者ID:certik,项目名称:sympy-oldcore,代码行数:34,代码来源:miscellaneous.py

示例10: __div__

# 需要导入模块: from sympy.core.basic import Basic [as 别名]
# 或者: from sympy.core.basic.Basic import sympify [as 别名]
 def __div__(self, divisor):
     """
     Create a new point where each coordinate in this point is
     divided by factor.
     """
     divisor = Basic.sympify(divisor)
     return Point( [x/divisor for x in self] )
开发者ID:certik,项目名称:sympy-oldcore,代码行数:9,代码来源:point.py

示例11: _eval_apply

# 需要导入模块: from sympy.core.basic import Basic [as 别名]
# 或者: from sympy.core.basic.Basic import sympify [as 别名]
    def _eval_apply(self, arg):
        arg = Basic.sympify(arg)

        if isinstance(arg, Basic.Number):
            if isinstance(arg, Basic.NaN):
                return S.NaN
            elif isinstance(arg, Basic.Infinity):
                return S.Infinity * S.ImaginaryUnit
            elif isinstance(arg, Basic.NegativeInfinity):
                return S.NegativeInfinity * S.ImaginaryUnit
            elif isinstance(arg, Basic.Zero):
                return S.Pi*S.ImaginaryUnit / 2
            elif isinstance(arg, Basic.One):
                return S.Zero
            elif isinstance(arg, Basic.NegativeOne):
                return S.Pi*S.ImaginaryUnit
            else:
                cst_table = {
                    S.Half       : S.Pi/3,
                    -S.Half      : 2*S.Pi/3,
                    S.Sqrt(2)/2  : S.Pi/4,
                    -S.Sqrt(2)/2 : 3*S.Pi/4,
                    1/S.Sqrt(2)  : S.Pi/4,
                    -1/S.Sqrt(2) : 3*S.Pi/4,
                    S.Sqrt(3)/2  : S.Pi/6,
                    -S.Sqrt(3)/2 : 5*S.Pi/6,
                }

                if arg in cst_table:
                    return cst_table[arg]*S.ImaginaryUnit
开发者ID:certik,项目名称:sympy-oldcore,代码行数:32,代码来源:hyperbolic.py

示例12: __mul__

# 需要导入模块: from sympy.core.basic import Basic [as 别名]
# 或者: from sympy.core.basic.Basic import sympify [as 别名]
 def __mul__(self, factor):
     """
     Create a new point where each coordinate in this point is
     multiplied by factor.
     """
     factor = Basic.sympify(factor)
     return Point( [x*factor for x in self] )
开发者ID:certik,项目名称:sympy-oldcore,代码行数:9,代码来源:point.py

示例13: taylor_term

# 需要导入模块: from sympy.core.basic import Basic [as 别名]
# 或者: from sympy.core.basic.Basic import sympify [as 别名]
 def taylor_term(self, n, x, *previous_terms):
     if n == 0:
         return S.Pi / 2 # FIX THIS
     elif n < 0 or n % 2 == 0:
         return S.Zero
     else:
         x = Basic.sympify(x)
         return (-1)**((n+1)//2) * x**n / n
开发者ID:certik,项目名称:sympy-oldcore,代码行数:10,代码来源:trigonometric.py

示例14: taylor_term

# 需要导入模块: from sympy.core.basic import Basic [as 别名]
# 或者: from sympy.core.basic.Basic import sympify [as 别名]
 def taylor_term(self, n, x, *previous_terms):
     if n<0: return S.Zero
     if n==0: return S.One
     x = Basic.sympify(x)
     if previous_terms:
         p = previous_terms[-1]
         if p is not None:
             return p * x / n
     return x**n/Basic.Factorial()(n)
开发者ID:certik,项目名称:sympy-oldcore,代码行数:11,代码来源:exponential.py

示例15: __new__

# 需要导入模块: from sympy.core.basic import Basic [as 别名]
# 或者: from sympy.core.basic.Basic import sympify [as 别名]
    def __new__(self, c, r, n, **kwargs):
        r = Basic.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:certik,项目名称:sympy-oldcore,代码行数:13,代码来源:polygon.py


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