]> www.ginac.de Git - ginac.git/blobdiff - ginac/indexed.cpp
- added numer_denom() to get numerator and denominator in one pass
[ginac.git] / ginac / indexed.cpp
index acbf7d489967445a4d1e2d52f79cf5d91f06d850..a2eda2c482b1621e7a94798a5db3ebece9ffbff4 100644 (file)
@@ -30,6 +30,7 @@
 #include "ncmul.h"
 #include "power.h"
 #include "lst.h"
+#include "inifcns.h" // for symmetrize()
 #include "print.h"
 #include "archive.h"
 #include "utils.h"
@@ -307,15 +308,15 @@ ex indexed::eval(int level) const
 
        // If the base object is a product, pull out the numeric factor
        if (is_ex_exactly_of_type(base, mul) && is_ex_exactly_of_type(base.op(base.nops() - 1), numeric)) {
-               exvector v = seq;
+               exvector v(seq);
                ex f = ex_to_numeric(base.op(base.nops() - 1));
                v[0] = seq[0] / f;
                return f * thisexprseq(v);
        }
 
        // Canonicalize indices according to the symmetry properties
-       if (seq.size() > 2 && (symmetry != unknown && symmetry != mixed)) {
-               exvector v = seq;
+       if (seq.size() > 2 && (symmetry == symmetric || symmetry == antisymmetric)) {
+               exvector v(seq);
                int sig = canonicalize_indices(v.begin() + 1, v.end(), symmetry == antisymmetric);
                if (sig != INT_MAX) {
                        // Something has changed while sorting indices, more evaluations later
@@ -710,7 +711,7 @@ contraction_done:
                                        // Non-commutative products are always re-expanded to give
                                        // simplify_ncmul() the chance to re-order and canonicalize
                                        // the product
-                                       ex r = (non_commutative ? ex(ncmul(v)) : ex(mul(v)));
+                                       ex r = (non_commutative ? ex(ncmul(v, true)) : ex(mul(v)));
                                        return simplify_indexed(r, free_indices, dummy_indices, sp);
                                }
 
@@ -744,7 +745,7 @@ contraction_done:
 
        ex r;
        if (something_changed)
-               r = non_commutative ? ex(ncmul(v)) : ex(mul(v));
+               r = non_commutative ? ex(ncmul(v, true)) : ex(mul(v));
        else
                r = e;
 
@@ -814,17 +815,41 @@ ex simplify_indexed(const ex & e, exvector & free_indices, exvector & dummy_indi
        return e_expanded;
 }
 
-ex simplify_indexed(const ex & e)
+/** Simplify/canonicalize expression containing indexed objects. This
+ *  performs contraction of dummy indices where possible and checks whether
+ *  the free indices in sums are consistent.
+ *
+ *  @return simplified expression */
+ex ex::simplify_indexed(void) const
 {
        exvector free_indices, dummy_indices;
        scalar_products sp;
-       return simplify_indexed(e, free_indices, dummy_indices, sp);
+       return GiNaC::simplify_indexed(*this, free_indices, dummy_indices, sp);
 }
 
-ex simplify_indexed(const ex & e, const scalar_products & sp)
+/** Simplify/canonicalize expression containing indexed objects. This
+ *  performs contraction of dummy indices where possible, checks whether
+ *  the free indices in sums are consistent, and automatically replaces
+ *  scalar products by known values if desired.
+ *
+ *  @param sp Scalar products to be replaced automatically
+ *  @return simplified expression */
+ex ex::simplify_indexed(const scalar_products & sp) const
 {
        exvector free_indices, dummy_indices;
-       return simplify_indexed(e, free_indices, dummy_indices, sp);
+       return GiNaC::simplify_indexed(*this, free_indices, dummy_indices, sp);
+}
+
+/** Symmetrize expression over its free indices. */
+ex ex::symmetrize(void) const
+{
+       return GiNaC::symmetrize(*this, get_free_indices());
+}
+
+/** Antisymmetrize expression over its free indices. */
+ex ex::antisymmetrize(void) const
+{
+       return GiNaC::antisymmetrize(*this, get_free_indices());
 }
 
 //////////