From: Chris Dams Date: Fri, 8 Sep 2006 19:51:01 +0000 (+0000) Subject: Fixing bug with respect to canonicalizing the variance of dummy indices in X-Git-Tag: release_1-4-0~59 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=e485c265061056d29de6fb252cd82ebedd41ec41 Fixing bug with respect to canonicalizing the variance of dummy indices in the presence of a cyclic symmetry of indices. --- diff --git a/ginac/indexed.cpp b/ginac/indexed.cpp index bd41f44b..d772b3f4 100644 --- a/ginac/indexed.cpp +++ b/ginac/indexed.cpp @@ -639,6 +639,56 @@ bool reposition_dummy_indices(ex & e, exvector & variant_dummy_indices, exvector { bool something_changed = false; + // Canonicalize wrt indices that are dummies within e. I.e., their + // symbol occurs twice in an index of e. This is only done if there + // is a cyclic symmetry because in that case it may happen that after + // raising/lowering an index the indices get reshuffled by ::eval in + // such a way that the iterators no longer point to the right objects. + if (ex_to(ex_to(e).get_symmetry()).has_cyclic()) { + // Get dummy pairs of varidxes within the indexed object in e. + exvector local_var_dummies; + local_var_dummies.reserve(e.nops()/2); + for (size_t i=1; i(e.op(i))) + continue; + for (size_t j=i+1; jop(0)) { + variant_dummy_indices.erase(k); + break; + } + } + break; + } + } + } + // Try all posibilities of raising/lowering and keep the least one in + // the sense of ex_is_less. + ex optimal_e = e; + size_t numpossibs = 1 << local_var_dummies.size(); + for (size_t i=0; i(curr_idx).toggle_variance(); + m[curr_idx] = curr_toggle; + m[curr_toggle] = curr_idx; + } + try_e = e.subs(m, subs_options::no_pattern); + } + if(ex_is_less()(try_e, optimal_e)) + { optimal_e = try_e; + something_changed = true; + } + } + e = optimal_e; + } + // If a dummy index is encountered for the first time in the // product, pull it up, otherwise, pull it down exvector::const_iterator it2, it2start, it2end; diff --git a/ginac/symmetry.cpp b/ginac/symmetry.cpp index 9cee0ffb..e48e2698 100644 --- a/ginac/symmetry.cpp +++ b/ginac/symmetry.cpp @@ -266,6 +266,18 @@ void symmetry::do_print_tree(const print_tree & c, unsigned level) const // non-virtual functions in this class ////////// +bool symmetry::has_cyclic() const +{ + if (type == cyclic) + return true; + + for (exvector::const_iterator i=children.begin(); i!=children.end(); ++i) + if (ex_to(*i).has_cyclic()) + return true; + + return false; +} + symmetry &symmetry::add(const symmetry &c) { // All children must have the same number of indices diff --git a/ginac/symmetry.h b/ginac/symmetry.h index 4168013e..80a2386d 100644 --- a/ginac/symmetry.h +++ b/ginac/symmetry.h @@ -80,6 +80,8 @@ public: /** Check whether this node actually represents any kind of symmetry. */ bool has_symmetry() const {return type != none || !children.empty(); } + /** Check whether this node involves a cyclic symmetry. */ + bool has_cyclic() const; protected: void do_print(const print_context & c, unsigned level) const;