]> www.ginac.de Git - ginac.git/blobdiff - ginac/indexed.cpp
- the tensor returned by metric_tensor() is symmetric
[ginac.git] / ginac / indexed.cpp
index fb34df9502a861c35f32cd739f01c4410e605ed6..4fa4256abfb286b86c95d427efa9a5c8de27c4c8 100644 (file)
@@ -330,6 +330,20 @@ ex indexed::eval(int level) const
        if (level > 1)
                return indexed(symmetry, evalchildren(level));
 
+       const ex &base = seq[0];
+
+       // If the base object is 0, the whole object is 0
+       if (base.is_zero())
+               return _ex0();
+
+       // 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;
+               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;
@@ -343,7 +357,7 @@ ex indexed::eval(int level) const
        }
 
        // Let the class of the base object perform additional evaluations
-       return op(0).bp->eval_indexed(*this);
+       return base.bp->eval_indexed(*this);
 }
 
 ex indexed::thisexprseq(const exvector & v) const