1212#include " properties/Accent.hh"
1313#include < functional>
1414
15- // #define DEBUG
15+ #define DEBUG
1616
1717using namespace cadabra ;
1818
@@ -364,18 +364,24 @@ void evaluate::merge_components(iterator it1, iterator it2)
364364 // we can be assured that the free indices match; they just may not be
365365 // in the same order).
366366
367+ #ifdef DEBUG
368+ std::cerr << " merge_components on " << Ex (it1) << " and " << Ex (it2) << std::endl;
369+ #endif
370+
367371 assert (*it1->name ==" \\ components" );
368372 assert (*it2->name ==" \\ components" );
369373 sibling_iterator sib1=tr.end (it1);
370374 --sib1;
371375 sibling_iterator sib2=tr.end (it2);
372376 --sib2;
377+ assert (*sib1->name ==" \\ comma" );
378+ assert (*sib2->name ==" \\ comma" );
373379
374- // We cannot directly compare the lhs of this equals node with the lhs
375- // of the equals node of the other components node, because the index
376- // order on the two components nodes may be different. We first
377- // have to ensure that the orders are the same (but only, of course)
378- // if we have anything to permutate in the first place.
380+ // We cannot directly compare the lhs of the equals nodes of it1
381+ // with the lhs of the equals node of it2 , because the index order
382+ // on the two components nodes may be different. We first have to
383+ // ensure that the orders are the same (but only, of course) if we
384+ // have anything to permutate in the first place.
379385
380386 if (*tr.begin (it1)->name !=" \\ comma" ) {
381387 // Look at all indices on the two components nodes. Find
@@ -384,14 +390,20 @@ void evaluate::merge_components(iterator it1, iterator it2)
384390 Perm perm;
385391 perm.find (tr.begin (it2), sib2, tr.begin (it1), sib1);
386392
387- // perm.apply(tr.begin(it2), sib2);
388- // std::cerr << "after permutation " << Ex(tr) << std::endl;
389-
393+ // For each \equals node in the it2 comma node, permute
394+ // the values so they agree with the index order on it1.
390395 cadabra::do_list (tr, sib2, [&](Ex::iterator nd) {
391- auto lhs2 = tr.begin (nd);
392- perm.apply (tr.begin (lhs2), tr.end (lhs2));
396+ // nd is an \equals node.
397+ assert (*nd->name ==" \\ equals" );
398+ auto comma = tr.begin (nd);
399+ assert (*comma->name ==" \\ comma" );
400+ perm.apply (tr.begin (comma), tr.end (comma));
393401 return true ;
394402 });
403+
404+ #ifdef DEBUG
405+ std::cerr << " permutations done" << std::endl;
406+ #endif
395407 }
396408
397409 // Now all index orders match and we can simply compare index value sets.
0 commit comments