]> www.ginac.de Git - ginac.git/blobdiff - ginac/mul.cpp
fixed bug in mul::print with print_csrc
[ginac.git] / ginac / mul.cpp
index 27451f6b7e9b821c045aae29ff316ca45fc24442..efc207bb90c91d22e72a5707b499e1a8ddf2236d 100644 (file)
@@ -136,7 +136,8 @@ void mul::print(const print_context & c, unsigned level) const
 
        } else if (is_of_type(c, print_csrc)) {
 
-               c.s << "(";
+               if (precedence <= level)
+                       c.s << "(";
 
                if (!overall_coeff.is_equal(_ex1())) {
                        overall_coeff.bp->print(c, precedence);
@@ -405,7 +406,16 @@ ex mul::evalf(int level) const
 
 ex mul::simplify_ncmul(const exvector & v) const
 {
-       throw(std::logic_error("mul::simplify_ncmul() should never have been called!"));
+       if (seq.size()==0) {
+               return inherited::simplify_ncmul(v);
+       }
+
+       // Find first noncommutative element and call its simplify_ncmul()
+       for (epvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
+               if (cit->rest.return_type() == return_types::noncommutative)
+                       return cit->rest.simplify_ncmul(v);
+       }
+       return inherited::simplify_ncmul(v);
 }
 
 // protected