From ee1af48a44dbe1e3b743c3683cd3601deb7ce0ed Mon Sep 17 00:00:00 2001 From: Christian Bauer Date: Sat, 25 May 2002 18:39:43 +0000 Subject: [PATCH] added an additional dummy index symmetrization run over sums in simplify_indexed(), to find possible cancellations --- check/exam_indexed.cpp | 5 ++++- ginac/indexed.cpp | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/check/exam_indexed.cpp b/check/exam_indexed.cpp index a8c7cbd6..4d09bdff 100644 --- a/check/exam_indexed.cpp +++ b/check/exam_indexed.cpp @@ -155,7 +155,7 @@ static unsigned symmetry_check(void) unsigned result = 0; idx i(symbol("i"), 3), j(symbol("j"), 3), k(symbol("k"), 3), l(symbol("l"), 3); - symbol A("A"), B("B"); + symbol A("A"), B("B"), C("C"); ex e; result += check_equal(indexed(A, sy_symm(), i, j), indexed(A, sy_symm(), j, i)); @@ -187,6 +187,9 @@ static unsigned symmetry_check(void) result += check_equal(symmetrize(e), 0); result += check_equal(antisymmetrize(e), e); + e = (indexed(A, sy_anti(), i, j, k, l) * (indexed(B, j) * indexed(C, k) + indexed(B, k) * indexed(C, j)) + indexed(B, i, l)).expand(); + result += check_equal_simplify(e, indexed(B, i, l)); + return result; } diff --git a/ginac/indexed.cpp b/ginac/indexed.cpp index dcd6d951..dca12fd8 100644 --- a/ginac/indexed.cpp +++ b/ginac/indexed.cpp @@ -870,6 +870,27 @@ ex simplify_indexed(const ex & e, exvector & free_indices, exvector & dummy_indi } } + if (sum.is_zero()) { + free_indices.clear(); + return sum; + } + + // Symmetrizing over the dummy indices may cancel terms + int num_terms_orig = (is_a(sum) ? sum.nops() : 1); + if (num_terms_orig > 1 && dummy_indices.size() >= 2) { + lst dummy_syms; + for (int i=0; i(sum_symm) ? sum_symm.nops() : 1); + if (num_terms < num_terms_orig) + return sum_symm; + } + return sum; } -- 2.31.1