def _print_MatMul(self, expr): a = list(expr.args) for i in xrange(0, len(a)): if a[i].is_Add and len(a) > 1: a[i] = prettyForm(*self._print(a[i]).parens()) else: a[i] = self._print(a[i]) return prettyForm.__mul__(*a)
def _print_Mul(self, product): a = [] # items in the numerator b = [] # items that are in the denominator (if any) if self.order != 'old': args = product.as_ordered_factors() else: args = product.args # Gather terms for numerator/denominator for item in args: if item.is_Pow and item.exp.is_Rational and item.exp.is_negative: b.append(C.Pow(item.base, -item.exp)) elif item.is_Rational and item is not S.Infinity: if item.p != 1: a.append( C.Rational(item.p) ) if item.q != 1: b.append( C.Rational(item.q) ) else: a.append(item) # Convert to pretty forms. Add parens to Add instances if there # is more than one term in the numer/denom for i in xrange(0, len(a)): if a[i].is_Add and len(a) > 1: a[i] = prettyForm(*self._print(a[i]).parens()) else: a[i] = self._print(a[i]) for i in xrange(0, len(b)): if b[i].is_Add and len(b) > 1: b[i] = prettyForm(*self._print(b[i]).parens()) else: b[i] = self._print(b[i]) # Construct a pretty form if len(b) == 0: return prettyForm.__mul__(*a) else: if len(a) == 0: a.append( self._print(S.One) ) return prettyForm.__mul__(*a) / prettyForm.__mul__(*b)
def _print_Mul(self, product): a = [] # items in the numerator b = [] # items that are in the denominator (if any) if self.order not in ('old', 'none'): args = product.as_ordered_factors() else: args = product.args # Gather terms for numerator/denominator for item in args: if item.is_commutative and item.is_Pow and item.exp.is_Rational and item.exp.is_negative: b.append(C.Pow(item.base, -item.exp)) elif item.is_Rational and item is not S.Infinity: if item.p != 1: a.append(C.Rational(item.p)) if item.q != 1: b.append(C.Rational(item.q)) else: a.append(item) # Convert to pretty forms. Add parens to Add instances if there # is more than one term in the numer/denom for i in xrange(0, len(a)): if a[i].is_Add and len(a) > 1: a[i] = prettyForm(*self._print(a[i]).parens()) else: a[i] = self._print(a[i]) for i in xrange(0, len(b)): if b[i].is_Add and len(b) > 1: b[i] = prettyForm(*self._print(b[i]).parens()) else: b[i] = self._print(b[i]) # Construct a pretty form if len(b) == 0: return prettyForm.__mul__(*a) else: if len(a) == 0: a.append(self._print(S.One)) return prettyForm.__mul__(*a) / prettyForm.__mul__(*b)