X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Findexed.cpp;h=3240c8dd7fe86293918c0aabf807cecd91e101b8;hp=3c7005e2a2d4b462defcd31bfe471f2dae95fe1e;hb=6c9a7dfd6b92368b21a2fe5aaf3638bc849099ba;hpb=ae41c1e2347d2308a1019746b8d7e3feed02e9e6 diff --git a/ginac/indexed.cpp b/ginac/indexed.cpp index 3c7005e2..3240c8dd 100644 --- a/ginac/indexed.cpp +++ b/ginac/indexed.cpp @@ -666,12 +666,16 @@ try_again: } if (contracted) { contraction_done: - if (is_ex_exactly_of_type(*it1, add) || is_ex_exactly_of_type(*it2, add) + if (non_commutative + || is_ex_exactly_of_type(*it1, add) || is_ex_exactly_of_type(*it2, add) || is_ex_exactly_of_type(*it1, mul) || is_ex_exactly_of_type(*it2, mul) || is_ex_exactly_of_type(*it1, ncmul) || is_ex_exactly_of_type(*it2, ncmul)) { // One of the factors became a sum or product: // re-expand expression and run again + // 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))); return simplify_indexed(r, free_indices, sp); } @@ -785,6 +789,19 @@ void scalar_products::add(const ex & v1, const ex & v2, const ex & sp) spm[make_key(v1, v2)] = sp; } +void scalar_products::add_vectors(const lst & l) +{ + // Add all possible pairs of products + unsigned num = l.nops(); + for (unsigned i=0; i