]> www.ginac.de Git - ginac.git/blobdiff - ginac/mul.cpp
- added symmetrize() and antisymmetrize() functions
[ginac.git] / ginac / mul.cpp
index 82b721e323b9341afe336955a7ddab739c295c36..8e641caf2ddec551ccfd6f86308649b5690b9d06 100644 (file)
@@ -136,11 +136,11 @@ void mul::print(const print_context & c, unsigned level) const
 
        } else if (is_of_type(c, print_csrc)) {
 
-               if (precedence <= level)
+               if (precedence() <= level)
                        c.s << "(";
 
                if (!overall_coeff.is_equal(_ex1())) {
-                       overall_coeff.bp->print(c, precedence);
+                       overall_coeff.bp->print(c, precedence());
                        c.s << "*";
                }
        
@@ -158,7 +158,7 @@ void mul::print(const print_context & c, unsigned level) const
 
                        // If the exponent is 1 or -1, it is left out
                        if (it->coeff.compare(_ex1()) == 0 || it->coeff.compare(_num_1()) == 0)
-                               it->rest.print(c, precedence);
+                               it->rest.print(c, precedence());
                        else {
                                // Outer parens around ex needed for broken gcc-2.95 parser:
                                (ex(power(it->rest, abs(ex_to_numeric(it->coeff))))).print(c, level);
@@ -174,13 +174,17 @@ void mul::print(const print_context & c, unsigned level) const
                        }
                }
 
-               if (precedence <= level)
+               if (precedence() <= level)
                        c.s << ")";
 
        } 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,32 +196,42 @@ 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);
+                                       (-coeff).print(c, precedence());
                                else
-                                       coeff.print(c, precedence);
+                                       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;
                        }
-                       recombine_pair_to_ex(*it).print(c, precedence);
+                       recombine_pair_to_ex(*it).print(c, precedence());
                        it++;
                }
 
-               if (precedence <= level)
-                       c.s << ")";
+               if (precedence() <= level) {
+                       if (is_of_type(c, print_latex))
+                               c.s << ")}";
+                       else
+                               c.s << ")";
+               }
        }
 }
 
@@ -392,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
@@ -694,12 +717,4 @@ epvector * mul::expandchildren(unsigned options) const
        return 0; // nothing has changed
 }
 
-//////////
-// static member variables
-//////////
-
-// protected
-
-unsigned mul::precedence = 50;
-
 } // namespace GiNaC