]> www.ginac.de Git - ginac.git/blobdiff - ginac/symmetry.cpp
Transform abs(x)^n => x^n if x is real and n is even.
[ginac.git] / ginac / symmetry.cpp
index 7d1ff9785298484b97d0fc0dacbaee9b71e8cf7d..a44cfcc5df87d0a8b02d9518d965972883c66620 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "symmetry.h"
 #include "lst.h"
+#include "add.h"
 #include "numeric.h" // for factorial()
 #include "operators.h"
 #include "archive.h"
@@ -269,6 +270,18 @@ void symmetry::do_print_tree(const print_tree & c, unsigned level) const
 // non-virtual functions in this class
 //////////
 
+bool symmetry::has_nonsymmetric() const
+{
+       if (type == antisymmetric || type == cyclic)
+               return true;
+
+       for (exvector::const_iterator i=children.begin(); i!=children.end(); ++i)
+               if (ex_to<symmetry>(*i).has_nonsymmetric())
+                       return true;
+
+       return false;
+}
+
 bool symmetry::has_cyclic() const
 {
        if (type == cyclic)
@@ -495,7 +508,8 @@ static ex symm(const ex & e, exvector::const_iterator first, exvector::const_ite
 
        // Loop over all permutations (the first permutation, which is the
        // identity, is unrolled)
-       ex sum = e;
+       exvector sum_v;
+       sum_v.push_back(e);
        while (std::next_permutation(iv, iv + num)) {
                lst new_lst;
                for (unsigned i=0; i<num; i++)
@@ -505,8 +519,9 @@ static ex symm(const ex & e, exvector::const_iterator first, exvector::const_ite
                        memcpy(iv2, iv, num * sizeof(unsigned));
                        term *= permutation_sign(iv2, iv2 + num);
                }
-               sum += term;
+               sum_v.push_back(term);
        }
+       ex sum = (new add(sum_v))->setflag(status_flags::dynallocated);
 
        delete[] iv;
        delete[] iv2;