* Implementation of GiNaC's indexed expressions. */
/*
- * GiNaC Copyright (C) 1999-2011 Johannes Gutenberg University Mainz, Germany
+ * GiNaC Copyright (C) 1999-2015 Johannes Gutenberg University Mainz, Germany
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
// Perform contractions
bool something_changed = false;
+ bool has_nonsymmetric = false;
GINAC_ASSERT(v.size() > 1);
exvector::iterator it1, itend = v.end(), next_to_last = itend - 1;
for (it1 = v.begin(); it1 != next_to_last; it1++) {
continue;
bool first_noncommutative = (it1->return_type() != return_types::commutative);
+ bool first_nonsymmetric = ex_to<symmetry>(ex_to<indexed>(*it1).get_symmetry()).has_nonsymmetric();
// Indexed factor found, get free indices and look for contraction
// candidates
// Non-commutative products are always re-expanded to give
// eval_ncmul() the chance to re-order and canonicalize
// the product
+ bool is_a_product = (is_exactly_a<mul>(*it1) || is_exactly_a<ncmul>(*it1)) &&
+ (is_exactly_a<mul>(*it2) || is_exactly_a<ncmul>(*it2));
ex r = (non_commutative ? ex(ncmul(v, true)) : ex(mul(v)));
- return simplify_indexed(r, free_indices, dummy_indices, sp);
+
+ // If new expression is a product we can call this function again,
+ // otherwise we need to pass argument to simplify_indexed() to be expanded
+ if (is_a_product)
+ return simplify_indexed_product(r, free_indices, dummy_indices, sp);
+ else
+ return simplify_indexed(r, free_indices, dummy_indices, sp);
}
// Both objects may have new indices now or they might
something_changed = true;
goto try_again;
}
+ else if (!has_nonsymmetric &&
+ (first_nonsymmetric ||
+ ex_to<symmetry>(ex_to<indexed>(*it2).get_symmetry()).has_nonsymmetric())) {
+ has_nonsymmetric = true;
+ }
}
}
// The result should be symmetric with respect to exchange of dummy
// indices, so if the symmetrization vanishes, the whole expression is
// zero. This detects things like eps.i.j.k * p.j * p.k = 0.
- ex q = idx_symmetrization<idx>(r, local_dummy_indices);
- if (q.is_zero()) {
- free_indices.clear();
- return _ex0;
- }
- q = idx_symmetrization<varidx>(q, local_dummy_indices);
- if (q.is_zero()) {
- free_indices.clear();
- return _ex0;
- }
- q = idx_symmetrization<spinidx>(q, local_dummy_indices);
- if (q.is_zero()) {
- free_indices.clear();
- return _ex0;
+ if (has_nonsymmetric) {
+ ex q = idx_symmetrization<idx>(r, local_dummy_indices);
+ if (q.is_zero()) {
+ free_indices.clear();
+ return _ex0;
+ }
+ q = idx_symmetrization<varidx>(q, local_dummy_indices);
+ if (q.is_zero()) {
+ free_indices.clear();
+ return _ex0;
+ }
+ q = idx_symmetrization<spinidx>(q, local_dummy_indices);
+ if (q.is_zero()) {
+ free_indices.clear();
+ return _ex0;
+ }
}
// Dummy index renaming