Example #1
0
 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)
Example #2
0
    def _print_seq(self,
                   seq,
                   left=None,
                   right=None,
                   delimiter=', ',
                   parenthesize=lambda x: False):
        s = None

        for item in seq:
            pform = self._print(item)

            if parenthesize(item):
                pform = prettyForm(*pform.parens())
            if s is None:
                # first element
                s = pform
            else:
                s = prettyForm(*stringPict.next(s, delimiter))
                s = prettyForm(*stringPict.next(s, pform))

        if s is None:
            s = stringPict('')

        s = prettyForm(*s.parens(left, right, ifascii_nougly=True))
        return s
Example #3
0
 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)
Example #4
0
    def __print_set(self, set_):
        items = list(set_)
        items.sort(Basic.compare_pretty)

        s = self._print_seq(items, "(", ")")
        s = prettyForm(*stringPict.next(type(set_).__name__, s))
        return s
Example #5
0
    def __print_set(self, s):
        items = list(s)
        items.sort( Basic.compare_pretty )

        S = self._print_seq(items, '(', ')')
        S = prettyForm(*stringPict.next(type(s).__name__, S))
        return S
Example #6
0
    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
Example #7
0
    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
Example #8
0
    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
Example #9
0
    def __print_set(self, set_):
        items = list(set_)
        items.sort(Basic.compare_pretty)

        s = self._print_seq(items, '(', ')')
        s = prettyForm(*stringPict.next(type(set_).__name__, s))
        return s
Example #10
0
    def __print_set(self, set_):
        items = list(set_)
        items.sort( key=cmp_to_key(Basic.compare_pretty) )

        s = self._print_seq(items, '(', ')')
        s = prettyForm(*stringPict.next(type(set_).__name__, s))
        return s
Example #11
0
    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
Example #12
0
    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
Example #13
0
    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
Example #14
0
    def _print_seq(self, seq, left=None, right=None):
        S = None

        for item in seq:
            pform = self._print(item)

            if S is None:
                # first element
                S = pform
            else:
                S = prettyForm(*stringPict.next(S, ', '))
                S = prettyForm(*stringPict.next(S, pform))

        if S is None:
            S = stringPict('')

        S = prettyForm(*S.parens(left, right, ifascii_nougly=True))
        return S
Example #15
0
    def _print_seq(self, seq, left=None, right=None, delimiter=', '):
        s = None

        for item in seq:
            pform = self._print(item)

            if s is None:
                # first element
                s = pform
            else:
                s = prettyForm(*stringPict.next(s, delimiter))
                s = prettyForm(*stringPict.next(s, pform))

        if s is None:
            s = stringPict('')

        s = prettyForm(*s.parens(left, right, ifascii_nougly=True))
        return s
Example #16
0
    def _print_seq(self, seq, left=None, right=None):
        S = None

        for item in seq:
            pform = self._print(item)

            if S is None:
                # first element
                S = pform
            else:
                S = prettyForm(*stringPict.next(S, ', '))
                S = prettyForm(*stringPict.next(S, pform))

        if S is None:
            S = stringPict('')

        S = prettyForm(*S.parens(left, right, ifascii_nougly=True))
        return S
Example #17
0
    def _print_seq(self, seq, left=None, right=None, delimiter=", ", parenthesize=lambda x: False):
        s = None

        for item in seq:
            pform = self._print(item)

            if parenthesize(item):
                pform = prettyForm(*pform.parens())
            if s is None:
                # first element
                s = pform
            else:
                s = prettyForm(*stringPict.next(s, delimiter))
                s = prettyForm(*stringPict.next(s, pform))

        if s is None:
            s = stringPict("")

        s = prettyForm(*s.parens(left, right, ifascii_nougly=True))
        return s
Example #18
0
    def _print_dict(self, d):
        keys = sorted(d.keys(), key=default_sort_key)
        items = []

        for k in keys:
            K = self._print(k)
            V = self._print(d[k])
            s = prettyForm(*stringPict.next(K, ': ', V))

            items.append(s)

        return self._print_seq(items, '{', '}')
Example #19
0
    def _print_Union(self, u):
        other_sets, singletons = [], []
        for set in u.args:
            if isinstance(set, Interval) and set.measure == 0:
                singletons.append(set.start)
            else:
                other_sets.append(set)

        union_delimiter = ' %s ' % pretty_atom('Union')

        s2 = self._print_seq(other_sets, None, None, union_delimiter)

        if len(singletons) > 0:
            s1 = self._print_seq(singletons, '{', '}')

            s = prettyForm(*stringPict.next(s1, union_delimiter))
            s = prettyForm(*stringPict.next(s, s2))
        else:
            s = s2

        return s
Example #20
0
    def _print_dict(self, d):
        items = []

        keys = sorted(d.keys(), key=cmp_to_key(Basic.compare_pretty) )
        for k in keys:
            K = self._print(k)
            V = self._print(d[k])
            s = prettyForm(*stringPict.next(K, ': ', V))

            items.append(s)

        return self._print_seq(items, '{', '}')
Example #21
0
        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)
Example #22
0
    def _print_dict(self, d):
        keys = sorted(d.keys(), key=default_sort_key)
        items = []

        for k in keys:
            K = self._print(k)
            V = self._print(d[k])
            s = prettyForm(*stringPict.next(K, ': ', V))

            items.append(s)

        return self._print_seq(items, '{', '}')
Example #23
0
        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)
Example #24
0
    def _print_Union(self, u):
        other_sets, singletons = [], []
        for set in u.args:
            if isinstance(set, Interval) and set.measure == 0:
                singletons.append(set.start)
            else:
                other_sets.append(set)

        union_delimiter = ' %s ' % pretty_atom('Union')

        s2 = self._print_seq(other_sets, None, None, union_delimiter)

        if len(singletons) > 0:
            s1 = self._print_seq(singletons, '{', '}')

            s = prettyForm(*stringPict.next(s1, union_delimiter))
            s = prettyForm(*stringPict.next(s, s2))
        else:
            s = s2

        return s
Example #25
0
    def _print_Add(self, expr):
        if self.order is None:
            terms = sorted(expr.args, Basic._compare_pretty)
        else:
            terms = [ elt[-1] for elt in self.analyze(expr) ]

        pforms = []

        for term in terms:
            if term.is_Mul and term.as_coeff_terms()[0] < 0:
                pform1 = self._print(-term)

                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 term.is_Number and term < 0:
                pform1 = self._print(-term)

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

        return prettyForm.__add__(*pforms)
Example #26
0
    def _print_Add(self, expr):
        if self.order is None:
            terms = sorted(expr.args, Basic._compare_pretty)
        else:
            terms = [ elt[-1] for elt in self.analyze(expr) ]

        pforms = []

        for term in terms:
            if term.is_Mul and term.args[0] < 0:
                pform1 = self._print(-term)

                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 term.is_Number and term < 0:
                pform1 = self._print(-term)

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

        return prettyForm.__add__(*pforms)
Example #27
0
    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
Example #28
0
    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
Example #29
0
    def _print_dict(self, d):
        items = []

        keys = d.keys()
        keys.sort(Basic.compare_pretty)

        for k in keys:
            K = self._print(k)
            V = self._print(d[k])
            s = prettyForm(*stringPict.next(K, ': ', V))

            items.append(s)

        return self._print_seq(items, '{', '}')
Example #30
0
    def _print_dict(self, d):
        items = []

        keys = d.keys()
        keys.sort( Basic.compare_pretty )

        for k in keys:
            K = self._print(k)
            V = self._print(d[k])
            S = prettyForm(*stringPict.next(K, ': ', V))

            items.append(S)

        return self._print_seq(items, '{', '}')
Example #31
0
    def _print_dict(self, d):
        items = []

        keys = d.keys()
        keys.sort(Basic.compare_pretty)

        for k in keys:
            K = self._print(k)
            V = self._print(d[k])
            s = prettyForm(*stringPict.next(K, ": ", V))

            items.append(s)

        return self._print_seq(items, "{", "}")
Example #32
0
    def _print_Function(self, e):
        # 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())

        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
Example #33
0
    def _print_Function(self, e):
        # XXX works only for applied functions
        func = e.func
        args = e.args
        n = len(args)

        func_name = func.__name__

        prettyFunc = self._print(C.Symbol(func_name));
        prettyArgs = prettyForm(*self._print_seq(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
Example #34
0
    def _print_Lambda(self, e):
        symbols, expr = e.args

        if len(symbols) == 1:
            symbols = self._print(symbols[0])
        else:
            symbols = self._print(tuple(symbols))

        args = (symbols, self._print(expr))

        prettyFunc = self._print(C.Symbol("Lambda"))
        prettyArgs = prettyForm(*self._print_seq(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
Example #35
0
    def _print_Lambda(self, e):
        symbols, expr = e.args

        if len(symbols) == 1:
            symbols = self._print(symbols[0])
        else:
            symbols = self._print(tuple(symbols))

        args = (symbols, self._print(expr))

        prettyFunc = self._print(C.Symbol("Lambda"))
        prettyArgs = prettyForm(*self._print_seq(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
Example #36
0
 def _print_tuple(self, t):
     if len(t) == 1:
         ptuple = prettyForm(*stringPict.next(self._print(t[0]), ','))
         return prettyForm(*ptuple.parens('(', ')', ifascii_nougly=True))
     else:
         return self._print_seq(t, '(', ')')
Example #37
0
 def _print_set(self, s):
     items = sorted(s, key=default_sort_key)
     pretty = self._print_seq(items, '(', ')')
     pretty = prettyForm(*stringPict.next(type(s).__name__, pretty))
     return pretty
Example #38
0
 def _print_tuple(self, t):
     if len(t) == 1:
         ptuple = prettyForm(*stringPict.next(self._print(t[0]), ','))
         return prettyForm(*ptuple.parens('(', ')', ifascii_nougly=True))
     else:
         return self._print_seq(t, '(', ')')
Example #39
0
 def _print_set(self, s):
     items = sorted(s, key=default_sort_key)
     pretty = self._print_seq(items, '[', ']')
     pretty = prettyForm(*pretty.parens('(', ')', ifascii_nougly=True))
     pretty = prettyForm(*stringPict.next(type(s).__name__, pretty))
     return pretty
Example #40
0
 def _print_set(self, s):
     items = sorted(s, key=default_sort_key)
     pretty = self._print_seq(items, '[', ']')
     pretty = prettyForm(*pretty.parens('(', ')', ifascii_nougly=True))
     pretty = prettyForm(*stringPict.next(type(s).__name__, pretty))
     return pretty
Example #41
0
 def _print_set(self, s):
     items = sorted(s, key=default_sort_key)
     pretty = self._print_seq(items, '(', ')')
     pretty = prettyForm(*stringPict.next(type(s).__name__, pretty))
     return pretty