Esempio n. 1
0
 def _pretty(self, printer):
     ret = []
     for i, v in enumerate(self.args):
         if i != 0:
             ret.append(self._op_pretty)
         ret.append(printer._print(v))
     return prettyForm(*stringPict.next(*ret))
Esempio n. 2
0
    def _print_Sequence(self, seq):
        from sympy.printing.pretty.stringpict import prettyForm, stringPict

        pforms = []
        if seq.start_trunc:
            pforms.append('...')

        for item, n1 in zip(seq.vals, seq.n):
            if pforms:
                pforms.append(', ')
            if n1 == 0:
                pforms.append('_')
            pform = self._print(item)
            pforms.append(pform)

        if seq.end_trunc:
            if pforms:
                pforms.append(', ')
            pforms.append('...')

        if not pforms:
            s = stringPict('')
        else:
            s = prettyForm(*stringPict.next(*pforms))

        s = prettyForm(*s.parens('{', '}', ifascii_nougly=True))
        return s
Esempio n. 3
0
 def _pretty(self, printer):
     a, b = self.args
     pform = prettyForm(*stringPict.next(
         printer._print(a),
         printer._print(U('DOT OPERATOR')),
         printer._print(b),
     ))
     return prettyForm(*pform.parens())
Esempio n. 4
0
 def _print_Function(self, e):
     from sympy.physics.vector.functions import dynamicsymbols
     t = dynamicsymbols._t
     # XXX works only for applied functions
     func = e.func
     args = e.args
     func_name = func.__name__
     prettyFunc = self._print(C.Symbol(func_name))
     prettyArgs = prettyForm(*self._print_seq(args).parens())
     # If this function is an Undefined function of t, it is probably a
     # dynamic symbol, so we'll skip the (t). The rest of the code is
     # identical to the normal PrettyPrinter code
     if isinstance(func, UndefinedFunction) and (args == (t,)):
         pform = prettyForm(binding=prettyForm.FUNC,
                    *stringPict.next(prettyFunc))
     else:
         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
Esempio n. 5
0
    def _pretty(self, p, func):
        from sympy.printing.pretty.stringpict import prettyForm, stringPict                    
        prettyFunc = p._print("%s[%s]" % (func,
                                          ','.join([limit._format_ineq(p) for limit in self.limits])))
        prettyArgs = prettyForm(*p._print_seq([self.function], delimiter=', ').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                
Esempio n. 6
0
 def _print_Function(self, e):
     from sympy.physics.vector.functions import dynamicsymbols
     t = dynamicsymbols._t
     # XXX works only for applied functions
     func = e.func
     args = e.args
     func_name = func.__name__
     prettyFunc = self._print(C.Symbol(func_name))
     prettyArgs = prettyForm(*self._print_seq(args).parens())
     # If this function is an Undefined function of t, it is probably a
     # dynamic symbol, so we'll skip the (t). The rest of the code is
     # identical to the normal PrettyPrinter code
     if isinstance(func, UndefinedFunction) and (args == (t, )):
         pform = prettyForm(binding=prettyForm.FUNC,
                            *stringPict.next(prettyFunc))
     else:
         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
Esempio n. 7
0
    def _print_Derivative(self, deriv):
        from sympy.physics.vector.functions import dynamicsymbols
        # XXX use U('PARTIAL DIFFERENTIAL') here ?
        t = dynamicsymbols._t
        dots = 0
        can_break = True
        syms = list(reversed(deriv.variables))
        x = None

        while len(syms) > 0:
            if syms[-1] == t:
                syms.pop()
                dots += 1
            else:
                break

        f = prettyForm(binding=prettyForm.FUNC, *self._print(deriv.expr))
        if not (isinstance(type(deriv.expr), UndefinedFunction)
                and (deriv.expr.args == (t,))):
            dots = 0
            can_break = False
            f = prettyForm(binding=prettyForm.FUNC,
                    *self._print(deriv.expr).parens())

        if dots == 0:
            dots = u("")
        elif dots == 1:
            dots = u("\u0307")
        elif dots == 2:
            dots = u("\u0308")
        elif dots == 3:
            dots = u("\u20db")
        elif dots == 4:
            dots = u("\u20dc")

        uni_subs = [u("\u2080"), u("\u2081"), u("\u2082"), u("\u2083"), u("\u2084"),
                    u("\u2085"), u("\u2086"), u("\u2087"), u("\u2088"), u("\u2089"),
                    u("\u208a"), u("\u208b"), u("\u208c"), u("\u208d"), u("\u208e"),
                    u("\u208f"), u("\u2090"), u("\u2091"), u("\u2092"), u("\u2093"),
                    u("\u2094"), u("\u2095"), u("\u2096"), u("\u2097"), u("\u2098"),
                    u("\u2099"), u("\u209a"), u("\u209b"), u("\u209c"), u("\u209d"),
                    u("\u209e"), u("\u209f")]

        fpic = f.__dict__['picture']
        funi = f.__dict__['unicode']
        ind = len(funi)
        val = ""

        for i in uni_subs:
            cur_ind = funi.find(i)
            if (cur_ind != -1) and (cur_ind < ind):
                ind = cur_ind
                val = i
        if ind == len(funi):
            funi += dots
        else:
            funi = funi.replace(val, dots + val)

        if f.__dict__['picture'] == [f.__dict__['unicode']]:
            fpic = [funi]
        f.__dict__['picture'] = fpic
        f.__dict__['unicode'] = funi

        if (len(syms)) == 0 and can_break:
            return f

        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))
        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
Esempio n. 8
0
    def _print_Derivative(self, deriv):
        from sympy.physics.vector.functions import dynamicsymbols
        # XXX use U('PARTIAL DIFFERENTIAL') here ?
        t = dynamicsymbols._t
        dots = 0
        can_break = True
        syms = list(reversed(deriv.variables))
        x = None

        while len(syms) > 0:
            if syms[-1] == t:
                syms.pop()
                dots += 1
            else:
                break

        f = prettyForm(binding=prettyForm.FUNC, *self._print(deriv.expr))
        if not (isinstance(type(deriv.expr), UndefinedFunction) and
                (deriv.expr.args == (t, ))):
            dots = 0
            can_break = False
            f = prettyForm(binding=prettyForm.FUNC,
                           *self._print(deriv.expr).parens())

        if dots == 0:
            dots = u("")
        elif dots == 1:
            dots = u("\u0307")
        elif dots == 2:
            dots = u("\u0308")
        elif dots == 3:
            dots = u("\u20db")
        elif dots == 4:
            dots = u("\u20dc")

        uni_subs = [
            u("\u2080"),
            u("\u2081"),
            u("\u2082"),
            u("\u2083"),
            u("\u2084"),
            u("\u2085"),
            u("\u2086"),
            u("\u2087"),
            u("\u2088"),
            u("\u2089"),
            u("\u208a"),
            u("\u208b"),
            u("\u208c"),
            u("\u208d"),
            u("\u208e"),
            u("\u208f"),
            u("\u2090"),
            u("\u2091"),
            u("\u2092"),
            u("\u2093"),
            u("\u2094"),
            u("\u2095"),
            u("\u2096"),
            u("\u2097"),
            u("\u2098"),
            u("\u2099"),
            u("\u209a"),
            u("\u209b"),
            u("\u209c"),
            u("\u209d"),
            u("\u209e"),
            u("\u209f")
        ]

        fpic = f.__dict__['picture']
        funi = f.__dict__['unicode']
        ind = len(funi)
        val = ""

        for i in uni_subs:
            cur_ind = funi.find(i)
            if (cur_ind != -1) and (cur_ind < ind):
                ind = cur_ind
                val = i
        if ind == len(funi):
            funi += dots
        else:
            funi = funi.replace(val, dots + val)

        if f.__dict__['picture'] == [f.__dict__['unicode']]:
            fpic = [funi]
        f.__dict__['picture'] = fpic
        f.__dict__['unicode'] = funi

        if (len(syms)) == 0 and can_break:
            return f

        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))
        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