Exemplo n.º 1
0
 def __mul__(self, *others):
     """Make a pretty multiplication.
     Parentheses are needed around +, - and neg.
     """
     args = self
     if args.binding > prettyForm.MUL: arg = stringPict(*args.parens())
     result = [args]
     for arg in others:
         result.append(xsym('*'))
         #add parentheses for weak binders
         if arg.binding > prettyForm.MUL: arg = stringPict(*arg.parens())
         result.append(arg)
     len_res = len(result)
     for i in xrange(len_res):
         if i < len_res - 1 and result[i] == '-1' and result[i + 1] == xsym(
                 '*'):
             # substitute -1 by -, like in -1*x -> -x
             result.pop(i)
             result.pop(i)
             result.insert(i, '-')
     if result[0][0] == '-':
         # if there is a - sign in front of all
         bin = prettyForm.NEG
     else:
         bin = prettyForm.MUL
     return prettyForm(binding=bin, *stringPict.next(*result))
Exemplo n.º 2
0
    def __mul__(self, *others):
        """Make a pretty multiplication.
        Parentheses are needed around +, - and neg.
        """
        if len(others) == 0:
            return self # We aren't actually multiplying... So nothing to do here.

        args = self
        if args.binding > prettyForm.MUL:
            arg = stringPict(*args.parens())
        result = [args]
        for arg in others:
            result.append(xsym('*'))
            #add parentheses for weak binders
            if arg.binding > prettyForm.MUL:
                arg = stringPict(*arg.parens())
            result.append(arg)
        len_res = len(result)
        for i in xrange(len_res):
            if i < len_res - 1 and result[i] == '-1' and result[i + 1] == xsym('*'):
                # substitute -1 by -, like in -1*x -> -x
                result.pop(i)
                result.pop(i)
                result.insert(i, '-')
        if result[0][0] == '-':
            # if there is a - sign in front of all
            # This test was failing to catch a prettyForm.__mul__(prettyForm("-1", 0, 6)) being negative
            bin = prettyForm.NEG
        else:
            bin = prettyForm.MUL
        return prettyForm(binding=bin, *stringPict.next(*result))
Exemplo n.º 3
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
Exemplo n.º 4
0
    def _print_Subs(self, e):
        pform = self._print(e.expr)
        pform = prettyForm(*pform.parens())

        h = pform.height() if pform.height() > 1 else 2
        rvert = stringPict(vobj('|', h), baseline=pform.baseline)
        pform = prettyForm(*pform.right(rvert))

        b = pform.baseline
        pform.baseline = pform.height() - 1
        pform = prettyForm(*pform.right(self._print_seq([
            self._print_seq((self._print(v[0]), xsym('=='), self._print(v[1])),
                delimiter='') for v in zip(e.variables, e.point) ])))

        pform.baseline = b
        return pform