X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Findexed.cpp;h=86fe6115d9b8863819c44e3a393d9c99cd0b01d4;hp=e23709d5f506647280eca2f54fb528f807a5dc8f;hb=08d556dc3ac3fbf2b0ad3acd37016a1f925d7c02;hpb=40f36ba910959d73cf9b24fcf01f6ded35c4d873 diff --git a/ginac/indexed.cpp b/ginac/indexed.cpp index e23709d5..86fe6115 100644 --- a/ginac/indexed.cpp +++ b/ginac/indexed.cpp @@ -679,13 +679,21 @@ try_again: } find_free_and_dummy(un.begin(), un.end(), free_indices, dummy_indices); + ex r; if (something_changed) { if (non_commutative) - return ncmul(v); + r = ncmul(v); else - return mul(v); + r = mul(v); } else - return e; + r = e; + + // Product of indexed object with a scalar? + if (is_ex_exactly_of_type(r, mul) && r.nops() == 2 + && is_ex_exactly_of_type(r.op(1), numeric) && is_ex_of_type(r.op(0), indexed)) + return r.op(0).op(0).bp->scalar_mul_indexed(r.op(0), ex_to_numeric(r.op(1))); + else + return r; } /** Simplify indexed expression, return list of free indices. */