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


Python function._coeff_isneg函数代码示例

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


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

示例1: _find_opts

    def _find_opts(expr):

        if expr.is_Atom or expr.is_Order:
            return

        if iterable(expr):
            list(map(_find_opts, expr))
            return

        if expr in seen_subexp:
            return expr
        seen_subexp.add(expr)

        list(map(_find_opts, expr.args))

        if _coeff_isneg(expr):
            neg_expr = -expr
            if not neg_expr.is_Atom:
                opt_subs[expr] = Mul(S.NegativeOne, neg_expr, evaluate=False)
                seen_subexp.add(neg_expr)
                expr = neg_expr

        if expr.is_Mul:
            muls.add(expr)

        elif expr.is_Add:
            adds.add(expr)

        elif expr.is_Pow:
            if _coeff_isneg(expr.exp):
                opt_subs[expr] = Pow(Pow(expr.base, -expr.exp), S.NegativeOne,
                                     evaluate=False)
开发者ID:B-Rich,项目名称:sympy,代码行数:32,代码来源:cse_main.py

示例2: _find_opts

    def _find_opts(expr):

        if not isinstance(expr, Basic):
            return

        if expr.is_Atom or expr.is_Order:
            return

        if iterable(expr):
            list(map(_find_opts, expr))
            return

        if expr in seen_subexp:
            return expr
        seen_subexp.add(expr)

        list(map(_find_opts, expr.args))

        if _coeff_isneg(expr):
            neg_expr = -expr
            if not neg_expr.is_Atom:
                opt_subs[expr] = Mul(S.NegativeOne, neg_expr, evaluate=False)
                seen_subexp.add(neg_expr)
                expr = neg_expr

        if isinstance(expr, (Mul, MatMul)):
            muls.add(expr)

        elif isinstance(expr, (Add, MatAdd)):
            adds.add(expr)

        elif isinstance(expr, (Pow, MatPow)):
            if _coeff_isneg(expr.exp):
                opt_subs[expr] = Pow(Pow(expr.base, -expr.exp), S.NegativeOne,
                                     evaluate=False)
开发者ID:chaffra,项目名称:sympy,代码行数:35,代码来源:cse_main.py

示例3: as_numer_denom

 def as_numer_denom(self):
     if not self.is_commutative:
         return self, S.One
     base, exp = self.as_base_exp()
     n, d = base.as_numer_denom()
     if d is not S.One:
         if d.is_negative and n.is_negative:
             n, d = -n, -d
         if exp.is_Integer:
             if exp.is_negative:
                 n, d = d, n
                 exp = -exp
             return Pow(n, exp), Pow(d, exp)
         elif exp.is_Rational or d.is_positive:
             dneg = d.is_negative
             if dneg is not None:
                 if dneg is True:
                     n = -n
                     d = -d
                 elif dneg is False:
                     n, d = d, n
                     exp = -exp
                 if _coeff_isneg(exp):
                     n, d = d, n
                     exp = -exp
                 return Pow(n, exp), Pow(d, exp)
             # else we won't split up base but we check for neg expo below
     if _coeff_isneg(exp):
         return S.One, base**-exp
     # unprocessed float or NumberSymbol exponent
     # and Mul exp w/o negative sign
     return self, S.One
开发者ID:ENuge,项目名称:sympy,代码行数:32,代码来源:power.py

示例4: eval

    def eval(cls, arg):
        from sympy import acos
        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.Infinity
            elif arg is S.Zero:
                return S.Pi*S.ImaginaryUnit / 2
            elif arg is S.One:
                return S.Zero
            elif arg is S.NegativeOne:
                return S.Pi*S.ImaginaryUnit

        if arg.is_number:
            cst_table = {
                S.ImaginaryUnit: log(S.ImaginaryUnit*(1 + sqrt(2))),
                -S.ImaginaryUnit: log(-S.ImaginaryUnit*(1 + sqrt(2))),
                S.Half: S.Pi/3,
                -S.Half: 2*S.Pi/3,
                sqrt(2)/2: S.Pi/4,
                -sqrt(2)/2: 3*S.Pi/4,
                1/sqrt(2): S.Pi/4,
                -1/sqrt(2): 3*S.Pi/4,
                sqrt(3)/2: S.Pi/6,
                -sqrt(3)/2: 5*S.Pi/6,
                (sqrt(3) - 1)/sqrt(2**3): 5*S.Pi/12,
                -(sqrt(3) - 1)/sqrt(2**3): 7*S.Pi/12,
                sqrt(2 + sqrt(2))/2: S.Pi/8,
                -sqrt(2 + sqrt(2))/2: 7*S.Pi/8,
                sqrt(2 - sqrt(2))/2: 3*S.Pi/8,
                -sqrt(2 - sqrt(2))/2: 5*S.Pi/8,
                (1 + sqrt(3))/(2*sqrt(2)): S.Pi/12,
                -(1 + sqrt(3))/(2*sqrt(2)): 11*S.Pi/12,
                (sqrt(5) + 1)/4: S.Pi/5,
                -(sqrt(5) + 1)/4: 4*S.Pi/5
            }

            if arg in cst_table:
                if arg.is_real:
                    return cst_table[arg]*S.ImaginaryUnit
                return cst_table[arg]

        if arg is S.ComplexInfinity:
            return S.Infinity

        i_coeff = arg.as_coefficient(S.ImaginaryUnit)

        if i_coeff is not None:
            if _coeff_isneg(i_coeff):
                return S.ImaginaryUnit * acos(i_coeff)
            return S.ImaginaryUnit * acos(-i_coeff)
        else:
            if _coeff_isneg(arg):
                return -cls(-arg)
开发者ID:amitsaha,项目名称:sympy,代码行数:59,代码来源:hyperbolic.py

示例5: eval

    def eval(cls, arg):
        from sympy import cot
        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.ComplexInfinity
            elif arg.is_negative:
                return -cls(-arg)
        else:
            if arg is S.ComplexInfinity:
                return S.NaN

            i_coeff = arg.as_coefficient(S.ImaginaryUnit)

            if i_coeff is not None:
                if _coeff_isneg(i_coeff):
                    return S.ImaginaryUnit * cot(-i_coeff)
                return -S.ImaginaryUnit * cot(i_coeff)
            else:
                if _coeff_isneg(arg):
                    return -cls(-arg)

            if arg.is_Add:
                x, m = _peeloff_ipi(arg)
                if m:
                    cothm = coth(m)
                    if cothm is S.ComplexInfinity:
                        return coth(x)
                    else: # cothm == 0
                        return tanh(x)

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

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

            if arg.func == atanh:
                return 1/arg.args[0]

            if arg.func == acoth:
                return arg.args[0]
开发者ID:moorepants,项目名称:sympy,代码行数:51,代码来源:hyperbolic.py

示例6: _set_function

def _set_function(f, self):
    expr = f.expr
    if not isinstance(expr, Expr):
        return

    if len(f.variables) > 1:
        return

    n = f.variables[0]

    # f(x) + c and f(-x) + c cover the same integers
    # so choose the form that has the fewest negatives
    c = f(0)
    fx = f(n) - c
    f_x = f(-n) - c
    neg_count = lambda e: sum(_coeff_isneg(_) for _ in Add.make_args(e))
    if neg_count(f_x) < neg_count(fx):
        expr = f_x + c

    a = Wild('a', exclude=[n])
    b = Wild('b', exclude=[n])
    match = expr.match(a*n + b)
    if match and match[a]:
        # canonical shift
        expr = match[a]*n + match[b] % match[a]

    if expr != f.expr:
        return ImageSet(Lambda(n, expr), S.Integers)
开发者ID:asmeurer,项目名称:sympy,代码行数:28,代码来源:functions.py

示例7: as_numer_denom

 def as_numer_denom(self):
     if not self.is_commutative:
         return self, S.One
     base, exp = self.as_base_exp()
     n, d = base.as_numer_denom()
     # this should be the same as ExpBase.as_numer_denom wrt
     # exponent handling
     neg_exp = exp.is_negative
     if not neg_exp and not (-exp).is_negative:
         neg_exp = _coeff_isneg(exp)
     int_exp = exp.is_integer
     # the denominator cannot be separated from the numerator if
     # its sign is unknown unless the exponent is an integer, e.g.
     # sqrt(a/b) != sqrt(a)/sqrt(b) when a=1 and b=-1. But if the
     # denominator is negative the numerator and denominator can
     # be negated and the denominator (now positive) separated.
     if not (d.is_real or int_exp):
         n = base
         d = S.One
     dnonpos = d.is_nonpositive
     if dnonpos:
         n, d = -n, -d
     elif dnonpos is None and not int_exp:
         n = base
         d = S.One
     if neg_exp:
         n, d = d, n
         exp = -exp
     return self.func(n, exp), self.func(d, exp)
开发者ID:hrashk,项目名称:sympy,代码行数:29,代码来源:power.py

示例8: _print_Mul

    def _print_Mul(self, expr):

        if _coeff_isneg(expr):
            x = self.dom.createElement('apply')
            x.appendChild(self.dom.createElement('minus'))
            x.appendChild(self._print_Mul(-expr))
            return x

        from sympy.simplify import fraction
        numer, denom = fraction(expr)

        if denom is not S.One:
            x = self.dom.createElement('apply')
            x.appendChild(self.dom.createElement('divide'))
            x.appendChild(self._print(numer))
            x.appendChild(self._print(denom))
            return x

        coeff, terms = expr.as_coeff_mul()
        if coeff is S.One and len(terms) == 1:
            # XXX since the negative coefficient has been handled, I don't
            # think a coeff of 1 can remain
            return self._print(terms[0])

        if self.order != 'old':
            terms = Mul._from_args(terms).as_ordered_factors()

        x = self.dom.createElement('apply')
        x.appendChild(self.dom.createElement('times'))
        if(coeff != 1):
            x.appendChild(self._print(coeff))
        for term in terms:
            x.appendChild(self._print(term))
        return x
开发者ID:KonstantinTogoi,项目名称:sympy,代码行数:34,代码来源:mathml.py

示例9: 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:
            if arg is S.ComplexInfinity:
                return 0

            i_coeff = arg.as_coefficient(S.ImaginaryUnit)

            if i_coeff is not None:
                return -S.ImaginaryUnit * C.acot(i_coeff)
            else:
                if _coeff_isneg(arg):
                    return -cls(-arg)
开发者ID:ENuge,项目名称:sympy,代码行数:29,代码来源:hyperbolic.py

示例10: _print_Add

 def _print_Add(self, expr, order=None):
     args = self._as_ordered_terms(expr, order=order)
     lastProcessed = self._print(args[0])
     plusNodes = []
     for arg in args[1:]:
         if _coeff_isneg(arg):
             # use minus
             x = self.dom.createElement('apply')
             x.appendChild(self.dom.createElement('minus'))
             x.appendChild(lastProcessed)
             x.appendChild(self._print(-arg))
             # invert expression since this is now minused
             lastProcessed = x
             if(arg == args[-1]):
                 plusNodes.append(lastProcessed)
         else:
             plusNodes.append(lastProcessed)
             lastProcessed = self._print(arg)
             if(arg == args[-1]):
                 plusNodes.append(self._print(arg))
     if len(plusNodes) == 1:
         return lastProcessed
     x = self.dom.createElement('apply')
     x.appendChild(self.dom.createElement('plus'))
     while len(plusNodes) > 0:
         x.appendChild(plusNodes.pop(0))
     return x
开发者ID:KonstantinTogoi,项目名称:sympy,代码行数:27,代码来源:mathml.py

示例11: _print_Add

    def _print_Add(self, expr, order=None):
        if self.order == 'none':
            terms = list(expr.args)
        else:
            terms = self._as_ordered_terms(expr, order=order)
        pforms, indices = [], []

        def pretty_negative(pform, index):
            """Prepend a minus sign to a pretty form. """
            if index == 0:
                if pform.height() > 1:
                    pform_neg = '- '
                else:
                    pform_neg = '-'
            else:
                pform_neg = ' - '

            pform = stringPict.next(pform_neg, pform)
            return prettyForm(binding=prettyForm.NEG, *pform)

        for i, term in enumerate(terms):
            if term.is_Mul and _coeff_isneg(term):
                pform = self._print(-term)
                pforms.append(pretty_negative(pform, i))
            elif term.is_Rational and term.q > 1:
                pforms.append(None)
                indices.append(i)
            elif term.is_Number and term < 0:
                pform = self._print(-term)
                pforms.append(pretty_negative(pform, i))
            else:
                pforms.append(self._print(term))

        if indices:
            large = True

            for pform in pforms:
                if pform is not None and pform.height() > 1:
                    break
            else:
                large = False

            for i in indices:
                term, negative = terms[i], False

                if term < 0:
                    term, negative = -term, True

                if large:
                    pform = prettyForm(str(term.p))/prettyForm(str(term.q))
                else:
                    pform = self._print(term)

                if negative:
                    pform = pretty_negative(pform, i)

                pforms[i] = pform

        return prettyForm.__add__(*pforms)
开发者ID:Botouls,项目名称:sympy,代码行数:59,代码来源:pretty.py

示例12: eval

    def eval(cls, arg):
        from sympy import tan

        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:
            if arg is S.ComplexInfinity:
                return S.NaN

            i_coeff = arg.as_coefficient(S.ImaginaryUnit)

            if i_coeff is not None:
                if _coeff_isneg(i_coeff):
                    return -S.ImaginaryUnit * tan(-i_coeff)
                return S.ImaginaryUnit * tan(i_coeff)
            else:
                if _coeff_isneg(arg):
                    return -cls(-arg)

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

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

            if arg.func == atanh:
                return arg.args[0]

            if arg.func == acoth:
                return 1 / arg.args[0]
开发者ID:scopatz,项目名称:sympy,代码行数:43,代码来源:hyperbolic.py

示例13: _print_Add

    def _print_Add(self, expr):
        tex = str(self._print(expr.args[0]))

        for term in expr.args[1:]:
            if _coeff_isneg(term):
                tex += r" %s" % self._print(term)
            else:
                tex += r" + %s" % self._print(term)

        return tex
开发者ID:StefenYin,项目名称:sympy,代码行数:10,代码来源:latex_ex.py

示例14: _print_Add

    def _print_Add(self, expr, order=None):
        if self.order == "none":
            terms = list(expr.args)
        else:
            terms = self._as_ordered_terms(expr, order=order)
        tex = self._print(terms[0])

        for term in terms[1:]:
            if not _coeff_isneg(term):
                tex += " +"

            tex += " " + self._print(term)

        return tex
开发者ID:ENuge,项目名称:sympy,代码行数:14,代码来源:latex.py

示例15: _print_Mul

    def _print_Mul(self, expr):

        prec = precedence(expr)

        if _coeff_isneg(expr):
            expr = -expr
            sign = "-"
        else:
            sign = ""

        a = [] # items in the numerator
        b = [] # items that are in the denominator (if any)

        if self.order not in ('old', 'none'):
            args = expr.as_ordered_factors()
        else:
            # use make_args in case expr was something like -x -> x
            args = Mul.make_args(expr)

        # Gather args for numerator/denominator
        for item in args:
            if item.is_commutative and item.is_Pow and item.exp.is_Rational and item.exp.is_negative:
                if item.exp != -1:
                    b.append(Pow(item.base, -item.exp, evaluate=False))
                else:
                    b.append(Pow(item.base, -item.exp))
            elif item.is_Rational and item is not S.Infinity:
                if item.p != 1:
                    a.append(Rational(item.p))
                if item.q != 1:
                    b.append(Rational(item.q))
            else:
                a.append(item)

        a = a or [S.One]

        a_str = map(lambda x:self.parenthesize(x, prec), a)
        b_str = map(lambda x:self.parenthesize(x, prec), b)

        if len(b) == 0:
            return sign + '*'.join(a_str)
        elif len(b) == 1:
            if len(a) == 1 and not (a[0].is_Atom or a[0].is_Add):
                return sign + "%s/"%a_str[0] + '*'.join(b_str)
            else:
                return sign + '*'.join(a_str) + "/%s"%b_str[0]
        else:
            return sign + '*'.join(a_str) + "/(%s)"%'*'.join(b_str)
开发者ID:cknoll,项目名称:sympy,代码行数:48,代码来源:str.py


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