Exemplo n.º 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)
Exemplo n.º 2
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)
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
    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)
Exemplo n.º 5
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)
Exemplo n.º 6
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)