From: Christian Bauer Date: Mon, 2 Aug 2004 21:40:25 +0000 (+0000) Subject: (p.i*p.i).get_free_indices() returned (.i) instead of () X-Git-Tag: release_1-3-0~42 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=58f0cc954e01d67cbb42a55e2fc37dcea0757294;ds=inline (p.i*p.i).get_free_indices() returned (.i) instead of () --- diff --git a/ginac/indexed.cpp b/ginac/indexed.cpp index d1d5f728..ad17a497 100644 --- a/ginac/indexed.cpp +++ b/ginac/indexed.cpp @@ -499,10 +499,27 @@ exvector ncmul::get_free_indices() const return free_indices; } +struct is_summation_idx : public std::unary_function { + bool operator()(const ex & e) + { + return is_dummy_pair(e, e); + } +}; + exvector power::get_free_indices() const { - // Return free indices of basis - return basis.get_free_indices(); + // Get free indices of basis + exvector basis_indices = basis.get_free_indices(); + + if (exponent.info(info_flags::even)) { + // If the exponent is an even number, then any "free" index that + // forms a dummy pair with itself is actually a summation index + exvector really_free; + std::remove_copy_if(basis_indices.begin(), basis_indices.end(), + std::back_inserter(really_free), is_summation_idx()); + return really_free; + } else + return basis_indices; } /** Rename dummy indices in an expression.