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


Python stringpict.prettyForm函数代码示例

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


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

示例1: _print_Add

 def _print_Add(self, sum):
     args = list(sum.args)
     args.sort(Basic._compare_pretty)
     pforms = []
     for x in args:
         # Check for negative "things" so that this information can be enforce upon
         # the pretty form so that it can be made of use (such as in a sum).
         if x.is_Mul and x.as_coeff_terms()[0] < 0:
             pform1 = self._print(-x)
             if len(pforms) == 0:
                 if pform1.height() > 1:
                     pform2 = '- '
                 else:
                     pform2 = '-'
             else:
                 pform2 = ' - '
             pform = stringPict.next(pform2, pform1)
             pforms.append(prettyForm(binding=prettyForm.NEG, *pform))
         elif x.is_Number and x < 0:
             pform1 = self._print(-x)
             if len(pforms) == 0:
                 if pform1.height() > 1:
                     pform2 = '- '
                 else:
                     pform2 = '-'
                 pform = stringPict.next(pform2, pform1)
             else:
                 pform = stringPict.next(' - ', pform1)
             pforms.append(prettyForm(binding=prettyForm.NEG, *pform))
         else:
             pforms.append(self._print(x))
     return prettyForm.__add__(*pforms)
开发者ID:jcockayne,项目名称:sympy-rkern,代码行数:32,代码来源:pretty.py

示例2: _print_catalan

 def _print_catalan(self, e):
     pform = prettyForm("C")
     arg = self._print(e.args[0])
     pform_arg = prettyForm(" "*arg.width())
     pform_arg = prettyForm(*pform_arg.below(arg))
     pform = prettyForm(*pform.right(pform_arg))
     return pform
开发者ID:meo-meo,项目名称:sympy,代码行数:7,代码来源:pretty.py

示例3: _print_Relational

    def _print_Relational(self, e):
        op = prettyForm(' ' + xsym(e.rel_op) + ' ')

        l = self._print(e.lhs)
        r = self._print(e.rhs)
        pform = prettyForm(*stringPict.next(l, op, r))
        return pform
开发者ID:TeddyBoomer,项目名称:wxgeometrie,代码行数:7,代码来源:pretty.py

示例4: _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 term.as_coeff_mul()[0] < 0:
                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:meo-meo,项目名称:sympy,代码行数:59,代码来源:pretty.py

示例5: adjust

 def adjust(p1, p2):
     diff = p1.width() - p2.width()
     if diff == 0:
         return p1, p2
     elif diff > 0:
         return p1, prettyForm(*p2.left(' '*diff))
     else:
         return prettyForm(*p1.left(' '*-diff)), p2
开发者ID:meo-meo,项目名称:sympy,代码行数:8,代码来源:pretty.py

示例6: _print_factorial

 def _print_factorial(self, e):
     x = e.args[0]
     pform = self._print(x)
     # Add parentheses if needed
     if not ((x.is_Integer and x.is_nonnegative) or x.is_Symbol):
         pform = prettyForm(*pform.parens())
     pform = prettyForm(*pform.right('!'))
     return pform
开发者ID:TeddyBoomer,项目名称:wxgeometrie,代码行数:8,代码来源:pretty.py

示例7: _print_gamma

 def _print_gamma(self, e):
     if self._use_unicode:
         pform = self._print(e.args[0])
         pform = prettyForm(*pform.parens())
         pform = prettyForm(*pform.left(greek['gamma'][1]))
         return pform
     else:
         return self._print_Function(e)
开发者ID:TeddyBoomer,项目名称:wxgeometrie,代码行数:8,代码来源:pretty.py

示例8: _print_lowergamma

 def _print_lowergamma(self, e):
     if self._use_unicode:
         pform = self._print(e.args[0])
         pform = prettyForm(*pform.right(", ", self._print(e.args[1])))
         pform = prettyForm(*pform.parens())
         pform = prettyForm(*pform.left(greek["gamma"][0]))
         return pform
     else:
         return self._print_Function(e)
开发者ID:rhythm-gupta,项目名称:sympy,代码行数:9,代码来源:pretty.py

示例9: _print_RootSum

    def _print_RootSum(self, expr):
        args = [self._print_Add(expr.expr, order='lex')]

        if expr.fun is not S.IdentityFunction:
            args.append(self._print(expr.fun))

        pform = prettyForm(*self._print_seq(args).parens())
        pform = prettyForm(*pform.left('RootSum'))

        return pform
开发者ID:TeddyBoomer,项目名称:wxgeometrie,代码行数:10,代码来源:pretty.py

示例10: _print_Derivative

    def _print_Derivative(self, deriv):
        # XXX use U('PARTIAL DIFFERENTIAL') here ?
        syms = list(reversed(deriv.variables))
        x = None

        for sym, num in group(syms, multiple=False):
            s = self._print(sym)
            ds = prettyForm(*s.left('d'))

            if num > 1:
                ds = ds**prettyForm(str(num))

            if x is None:
                x = ds
            else:
                x = prettyForm(*x.right(' '))
                x = prettyForm(*x.right(ds))

        f = prettyForm(binding=prettyForm.FUNC, *self._print(deriv.expr).parens())

        pform = prettyForm('d')

        if len(syms) > 1:
            pform = pform**prettyForm(str(len(syms)))

        pform = prettyForm(*pform.below(stringPict.LINE, x))
        pform.baseline = pform.baseline + 1
        pform = prettyForm(*stringPict.next(pform, f))

        return pform
开发者ID:TeddyBoomer,项目名称:wxgeometrie,代码行数:30,代码来源:pretty.py

示例11: _print_Not

    def _print_Not(self, e):
        if self._use_unicode:
            arg = e.args[0]
            pform = self._print(arg)

            if arg.is_Boolean and not arg.is_Not:
                pform = prettyForm(*pform.parens())

            return prettyForm(*pform.left(u"\u00ac "))
        else:
            return self._print_Function(e)
开发者ID:TeddyBoomer,项目名称:wxgeometrie,代码行数:11,代码来源:pretty.py

示例12: _print_KroneckerDelta

 def _print_KroneckerDelta(self, e):
     pform = self._print(e.args[0])
     pform = prettyForm(*pform.right((prettyForm(','))))
     pform = prettyForm(*pform.right((self._print(e.args[1]))))
     if self._use_unicode:
         a = stringPict(pretty_symbol('delta'))
     else:
         a = stringPict('d')
     b = pform
     top = stringPict(*b.left(' '*a.width()))
     bot = stringPict(*a.right(' '*b.width()))
     return prettyForm(binding=prettyForm.POW, *bot.below(top))
开发者ID:Botouls,项目名称:sympy,代码行数:12,代码来源:pretty.py

示例13: _print_Piecewise

    def _print_Piecewise(self, pexpr):

        P = {}
        for n, ec in enumerate(pexpr.args):
            P[n,0] = self._print(ec.expr)
            if ec.cond == True:
                P[n,1] = prettyForm('otherwise')
            else:
                P[n,1] = prettyForm(*prettyForm('for ').right(self._print(ec.cond)))
        hsep = 2
        vsep = 1
        len_args = len(pexpr.args)

        # max widths
        maxw = [max([P[i,j].width() for i in xrange(len_args)]) \
                    for j in xrange(2)]

        # FIXME: Refactor this code and matrix into some tabular environment.
        # drawing result
        D = None

        for i in xrange(len_args):
            D_row = None
            for j in xrange(2):
                p = P[i,j]
                assert p.width() <= maxw[j]

                wdelta = maxw[j] - p.width()
                wleft  = wdelta // 2
                wright = wdelta - wleft

                p = prettyForm(*p.right(' '*wright))
                p = prettyForm(*p.left (' '*wleft))

                if D_row is None:
                    D_row = p
                    continue

                D_row = prettyForm(*D_row.right(' '*hsep))  # h-spacer
                D_row = prettyForm(*D_row.right(p))
            if D is None:
                D = D_row       # first row in a picture
                continue

            # v-spacer
            for _ in range(vsep):
                D = prettyForm(*D.below(' '))

            D = prettyForm(*D.below(D_row))

        D = prettyForm(*D.parens('{',''))
        return D
开发者ID:TeddyBoomer,项目名称:wxgeometrie,代码行数:52,代码来源:pretty.py

示例14: _print_Chi

    def _print_Chi(self, e):
        # This needs a special case since otherwise it comes out as greek
        # letter chi...
        prettyFunc = prettyForm("Chi")
        prettyArgs = prettyForm(*self._print_seq(e.args).parens())

        pform = prettyForm(binding=prettyForm.FUNC, *stringPict.next(prettyFunc, prettyArgs))

        # store pform parts so it can be reassembled e.g. when powered
        pform.prettyFunc = prettyFunc
        pform.prettyArgs = prettyArgs

        return pform
开发者ID:Botouls,项目名称:sympy,代码行数:13,代码来源:pretty.py

示例15: _print_Derivative

    def _print_Derivative(self, deriv):
        # XXX use U('PARTIAL DIFFERENTIAL') here ?
        syms = list(deriv.symbols)
        syms.reverse()
        x = None
        for sym in syms:
            s = self._print(sym)
            ds = prettyForm(*s.left('d'))

            if x is None:
                x = ds
            else:
                x = prettyForm(*x.right(' '))
                x = prettyForm(*x.right(ds))

        f = prettyForm(binding=prettyForm.FUNC, *self._print(deriv.expr).parens())

        pform = prettyForm('d')
        if len(syms) > 1:
            pform = pform ** prettyForm(str(len(deriv.symbols)))

        pform = prettyForm(*pform.below(stringPict.LINE, x))
        pform.baseline = pform.baseline + 1
        pform = prettyForm(*stringPict.next(pform, f))
        return pform
开发者ID:Sumith1896,项目名称:sympy-polys,代码行数:25,代码来源:pretty.py


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