]> www.ginac.de Git - ginac.git/commitdiff
synced to HEAD (power::get_free_indices()) [Alexei Sheplyakov]
authorChristian Bauer <Christian.Bauer@uni-mainz.de>
Mon, 2 Aug 2004 21:44:44 +0000 (21:44 +0000)
committerChristian Bauer <Christian.Bauer@uni-mainz.de>
Mon, 2 Aug 2004 21:44:44 +0000 (21:44 +0000)
check/exam_indexed.cpp
ginac/indexed.cpp

index 3d9b307db4f26fdcc33f8a6d245bb97fa41a973c..e20b56433b00ab8d7957f343ffaaa6f8a75733c9 100644 (file)
@@ -375,6 +375,15 @@ static unsigned dummy_check()
        e = indexed(p, mu.toggle_variance(), mu) - indexed(p, nu, nu.toggle_variance());
        result += check_equal_simplify(e, 0);
 
+       // GiNaC 1.2.1 had a bug here because p.i*p.i -> (p.i)^2
+       e = indexed(p, i) * indexed(p, i) * indexed(p, j) + indexed(p, j);
+       ex fi = exprseq(e.get_free_indices());
+       if (!fi.is_equal(exprseq(j))) {
+               clog << "get_free_indices(" << e << ") erroneously returned "
+                    << fi << " instead of (.j)" << endl;
+               ++result;
+       }
+
        return result;
 }
 
index d1d5f7287b07d01a723f22adf0e21c37ffdcb15d..ad17a497a9dc703e52cd435d6901312071beab42 100644 (file)
@@ -499,10 +499,27 @@ exvector ncmul::get_free_indices() const
        return free_indices;
 }
 
+struct is_summation_idx : public std::unary_function<ex, bool> {
+       bool operator()(const ex & e)
+       {
+               return is_dummy_pair(e, e);
+       }
+};
+
 exvector power::get_free_indices() const
 {
-       // Return free indices of basis
-       return basis.get_free_indices();
+       // Get free indices of basis
+       exvector basis_indices = basis.get_free_indices();
+
+       if (exponent.info(info_flags::even)) {
+               // If the exponent is an even number, then any "free" index that
+               // forms a dummy pair with itself is actually a summation index
+               exvector really_free;
+               std::remove_copy_if(basis_indices.begin(), basis_indices.end(),
+                                   std::back_inserter(really_free), is_summation_idx());
+               return really_free;
+       } else
+               return basis_indices;
 }
 
 /** Rename dummy indices in an expression.