@@ -42,6 +42,7 @@ Algorithm::result_t combine::apply(iterator& it)
4242
4343 bool isbrack1=false , isbrack2=false ;
4444 bool ismatorvec1=false , ismatorvec2=false ;
45+ bool diffparents=tr.parent (dums1->second )!=tr.parent (dums2->second );
4546 const Matrix *mat1=kernel.properties .get <Matrix>(tr.parent (dums1->second ));
4647 if (mat1)
4748 ismatorvec1=true ;
@@ -61,22 +62,24 @@ Algorithm::result_t combine::apply(iterator& it)
6162 else if (tr.number_of_children (tr.parent (dums2->second ))==1 )
6263 ismatorvec2=true ;
6364
64- if (ismatorvec1 && ismatorvec2) {
65+ if (ismatorvec1 && ismatorvec2 && diffparents ) {
6566 // txtout << "gluing " << *(dums2->second->name) << std::endl;
6667 // create new indexbracket with product node
6768 iterator outerbrack=tr.insert (tr.parent (dums1->second ), str_node (" \\ indexbracket" ));
6869 iterator brackprod=tr.append_child (outerbrack, str_node (" \\ prod" ));
6970 iterator parn1=tr.parent (dums1->second );
7071 iterator parn2=tr.parent (dums2->second );
7172 // remove the dummy index from these two objects, and move
72- // the non- dummy indices to the outer indexbracket.
73+ // other ( dummy or not) indices to the outer indexbracket.
7374 sibling_iterator ind1=tr.begin (tr.parent (dums1->second ));
7475 sibling_iterator stop1=tr.end (tr.parent (dums1->second ));
7576 if (isbrack1)
7677 ++ind1;
7778 while (ind1!=stop1) {
7879 if (ind1!=dums1->second ) {
79- tr.append_child (outerbrack, iterator (ind1));
80+ sibling_iterator nxt=ind1;
81+ ++nxt;
82+ tr.reparent (outerbrack, ind1, nxt);
8083 }
8184 ++ind1;
8285 // ind1=tr.erase(ind1);
@@ -88,7 +91,9 @@ Algorithm::result_t combine::apply(iterator& it)
8891 ++ind2;
8992 while (ind2!=stop2) {
9093 if (ind2!=dums2->second ) {
91- tr.append_child (outerbrack, iterator (ind2));
94+ sibling_iterator nxt=ind2;
95+ ++nxt;
96+ tr.reparent (outerbrack, ind2, nxt);
9297 }
9398 ++ind2;
9499 // ind2=tr.erase(ind2);
@@ -129,7 +134,7 @@ Algorithm::result_t combine::apply(iterator& it)
129134 ++dums1;
130135 }
131136
132- std::cerr << it << std::endl;
137+ // std::cerr << it << std::endl;
133138
134139 // prodflatten pf(tr, tr.end());
135140 // pf.apply_recursive(it, false);
0 commit comments