Skip to content

Commit 83f9e3f

Browse files
committed
Finding bug in map_sympy with tensor prefactors
1 parent a302eb5 commit 83f9e3f

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

core/SympyCdb.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
using namespace cadabra;
1313

14-
//#define DEBUG
14+
#define DEBUG
1515

1616
Ex::iterator sympy::apply(const Kernel& kernel, Ex& ex, Ex::iterator& it, const std::vector<std::string>& wrap, const std::string& args,
1717
const std::string& method)

core/algorithms/evaluate.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ Ex::iterator evaluate::handle_sum(iterator it)
159159
auto sib2=sib1;
160160
++sib2;
161161
while(sib2!=tr.end(it)) {
162-
std::cerr << "merging components " << Ex(sib1) << " and " << Ex(sib2) << std::endl;
162+
// std::cerr << "merging components " << Ex(sib1) << " and " << Ex(sib2) << std::endl;
163163
merge_components(sib1, sib2);
164164
sib2=tr.erase(sib2);
165165
}

core/algorithms/map_sympy.cc

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)