X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Findexed.cpp;h=4fa4256abfb286b86c95d427efa9a5c8de27c4c8;hp=f5c53a6bb956e6606b125c80a248c840840cb809;hb=fd097c33e414f72c77376ae7ad4fbd630b3ccce6;hpb=1e8bbe7edb203ebfbfb169b7d3f84354fce2a2d0 diff --git a/ginac/indexed.cpp b/ginac/indexed.cpp index f5c53a6b..4fa4256a 100644 --- a/ginac/indexed.cpp +++ b/ginac/indexed.cpp @@ -330,10 +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 (seq[0].is_zero()) + 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; @@ -347,7 +357,7 @@ ex indexed::eval(int level) const } // Let the class of the base object perform additional evaluations - return seq[0].bp->eval_indexed(*this); + return base.bp->eval_indexed(*this); } ex indexed::thisexprseq(const exvector & v) const