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

Python stringpict.prettyForm函数代码示例

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

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



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


示例16: join

    def join(self, delimiter, args):
        pform = None

        for arg in args:
            if pform is None:
                pform = arg
            else:
                pform = prettyForm(*pform.right(delimiter))
                pform = prettyForm(*pform.right(arg))

        if pform is None:
            return prettyForm("")
        else:
            return pform
开发者ID:meo-meo,项目名称:sympy,代码行数:14,代码来源:pretty.py


示例17: _print_Pow

    def _print_Pow(self, power):
        from sympy import fraction
        b, e = power.as_base_exp()
        if power.is_commutative:
            if e is S.NegativeOne:
                return prettyForm("1")/self._print(b)
            n, d = fraction(e)
            if n is S.One and d.is_Atom and not e.is_Integer:
                return self._print_nth_root(b, e)
            if e.is_Rational and e < 0:
                return prettyForm("1")/self._print(b)**self._print(-e)

        # None of the above special forms, do a standard power
        return self._print(b)**self._print(e)
开发者ID:gsagrawal,项目名称:sympy,代码行数:14,代码来源:pretty.py


示例18: _hprint_vec

    def _hprint_vec(self, v):
        D = None

        for a in v:
            p = a
            if D is None:
                D = p
            else:
                D = prettyForm(*D.right(', '))
                D = prettyForm(*D.right(p))
        if D is None:
            D = stringPict(' ')

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


示例19: _print_Pow

    def _print_Pow(self, power):
        # square roots, other roots or n-th roots
        # test for fraction 1/n or power x**-1
        if power.is_commutative:
            if (isinstance(power.exp, C.Rational) and power.exp.p == 1 and power.exp.q != 1) or (
                isinstance(power.exp, C.Pow)
                and isinstance(power.exp.args[0], C.Symbol)
                and power.exp.args[1] == S.NegativeOne
            ):
                bpretty = self._print(power.base)

                # construct root sign, start with the \/ shape
                _zZ = xobj("/", 1)
                rootsign = xobj("\\", 1) + _zZ
                # make exponent number to put above it
                if isinstance(power.exp, C.Rational):
                    exp = str(power.exp.q)
                    if exp == "2":
                        exp = ""
                else:
                    exp = str(power.exp.args[0])
                exp = exp.ljust(2)
                if len(exp) > 2:
                    rootsign = " " * (len(exp) - 2) + rootsign
                # stack the exponent
                rootsign = stringPict(exp + "\n" + rootsign)
                rootsign.baseline = 0
                # diagonal: length is one less than height of base
                linelength = bpretty.height() - 1
                diagonal = stringPict("\n".join(" " * (linelength - i - 1) + _zZ + " " * i for i in range(linelength)))
                # put baseline just below lowest line: next to exp
                diagonal.baseline = linelength - 1
                # make the root symbol
                rootsign = prettyForm(*rootsign.right(diagonal))
                # set the baseline to match contents to fix the height
                # but if the height of bpretty is one, the rootsign must be one higher
                rootsign.baseline = max(1, bpretty.baseline)
                # build result
                s = prettyForm(hobj("_", 2 + bpretty.width()))
                s = prettyForm(*bpretty.above(s))
                s = prettyForm(*s.left(rootsign))
                return s
            elif power.exp.is_Rational and power.exp.is_negative:
                # Things like 1/x
                return prettyForm("1") / self._print(C.Pow(power.base, -power.exp))

        # None of the above special forms, do a standard power
        b, e = power.as_base_exp()
        return self._print(b) ** self._print(e)
开发者ID:rhythm-gupta,项目名称:sympy,代码行数:49,代码来源:pretty.py


示例20: _print_binomial

    def _print_binomial(self, e):
        n, k = e.args

        n_pform = self._print(n)
        k_pform = self._print(k)

        bar = ' '*max(n_pform.width(), k_pform.width())

        pform = prettyForm(*k_pform.above(bar))
        pform = prettyForm(*pform.above(n_pform))
        pform = prettyForm(*pform.parens('(', ')'))

        pform.baseline = (pform.baseline + 1)//2

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



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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