]> www.ginac.de Git - ginac.git/blobdiff - ginac/mul.cpp
- symbols can have a LaTeX name, e.g. symbol s("s", "\\sigma");
[ginac.git] / ginac / mul.cpp
index 82b721e323b9341afe336955a7ddab739c295c36..75f74b4ba2cb7d06fc1ce969f4072ba7e4494618 100644 (file)
@@ -136,8 +136,7 @@ void mul::print(const print_context & c, unsigned level) const
 
        } else if (is_of_type(c, print_csrc)) {
 
-               if (precedence <= level)
-                       c.s << "(";
+               c.s << "(";
 
                if (!overall_coeff.is_equal(_ex1())) {
                        overall_coeff.bp->print(c, precedence);
@@ -179,8 +178,12 @@ void mul::print(const print_context & c, unsigned level) const
 
        } else {
 
-               if (precedence <= level)
-                       c.s << "(";
+               if (precedence <= level) {
+                       if (is_of_type(c, print_latex))
+                               c.s << "{(";
+                       else
+                               c.s << "(";
+               }
 
                bool first = true;
 
@@ -192,23 +195,29 @@ void mul::print(const print_context & c, unsigned level) const
                        !coeff.is_equal(_num_1())) {
                        if (coeff.is_rational()) {
                                if (coeff.is_negative())
-                                       (-coeff).print(c, precedence);
+                                       (-coeff).print(c);
                                else
-                                       coeff.print(c, precedence);
+                                       coeff.print(c);
                        } else {
                                if (coeff.csgn() == -1)
                                        (-coeff).print(c, precedence);
                                else
                                        coeff.print(c, precedence);
                        }
-                       c.s << '*';
+                       if (is_of_type(c, print_latex))
+                               c.s << ' ';
+                       else
+                               c.s << '*';
                }
 
                // Then proceed with the remaining factors
                epvector::const_iterator it = seq.begin(), itend = seq.end();
                while (it != itend) {
                        if (!first) {
-                               c.s << '*';
+                               if (is_of_type(c, print_latex))
+                                       c.s << ' ';
+                               else
+                                       c.s << '*';
                        } else {
                                first = false;
                        }
@@ -216,8 +225,12 @@ void mul::print(const print_context & c, unsigned level) const
                        it++;
                }
 
-               if (precedence <= level)
-                       c.s << ")";
+               if (precedence <= level) {
+                       if (is_of_type(c, print_latex))
+                               c.s << ")}";
+                       else
+                               c.s << ")";
+               }
        }
 }
 
@@ -392,7 +405,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