@@ -35,6 +35,9 @@ bool map_sympy::can_apply(iterator st)
3535 // In a product, it is still possible that there is a sub-product which
3636 // contains no indices.
3737 if (*st->name ==" \\ prod" ) {
38+ // Find the factors in the product which have a proper index on them. Do this by
39+ // starting at the index, and if it is not coordinate or symbol, then go up until we
40+ // reach the first child level of the product.
3841 for (auto & ind: ind_free) {
3942 const Coordinate *cdn=kernel.properties .get_composite <Coordinate>(ind.second , true );
4043 const Symbol *smb=kernel.properties .get_composite <Symbol>(ind.second , true );
@@ -73,13 +76,20 @@ Algorithm::result_t map_sympy::apply(iterator& it)
7376 wrap.push_back (head_);
7477
7578 if (left.size ()>0 ) {
76- std::cerr << " Sub-product with " << left.size () << " non-index carrying factors" << std::endl;
7779 Ex prod (" \\ prod" );
7880 for (auto & fac: left)
79- prod.append_child (fac);
81+ prod.append_child (prod. begin (), fac);
8082 auto top=prod.begin ();
8183 sympy::apply (kernel, prod, top, wrap, " " , " " );
82- for (auto & kl: index_factors)
84+ // Now remove the non-index carrying factors and replace with
85+ // the factors of 'prod' just simplified.
86+ sibling_iterator ps=prod.begin (top);
87+ while (ps!=prod.end (top)) {
88+ tr.insert_subtree (*left.begin (), ps);
89+ ++ps;
90+ }
91+ std::cerr << " Before erasing " << Ex (it) << std::endl;
92+ for (auto & kl: left)
8393 tr.erase (kl);
8494
8595 return result_t ::l_no_action;
0 commit comments