Skip to content

Commit 0ca77e3

Browse files
committed
Prefer last indices
Is (B A)_{c a} a valid answer for (B)_{b c} (A)_{a b}? It isn't if "a" and "c" are indices on the same footing as "b". However, they could be pure labels which would turn the above into a commutative dot product. To avoid this, we should assume that indices go outside the bracket while labels go inside. It is therefore not enough to begin the contraction on B's last participating index. We should begin with a last index that is also participating. Sometimes this does not exist so we keep the old logic in place. Garbage in / garbage out is better than a crash. Signed-off-by: Connor Behan <[email protected]>
1 parent ea4e595 commit 0ca77e3

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

core/algorithms/combine.cc

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Algorithm::result_t combine::apply(iterator& it)
3636

3737
while(ind_dummy.begin()!=ind_dummy.end()) {
3838
bool found=false;
39-
index_map_t::iterator start=ind_dummy.begin();
39+
index_map_t::iterator start=ind_dummy.begin(), backup;
4040
while(!found && start!=ind_dummy.end()) {
4141
iterator parent=tr.parent(start->second);
4242
sibling_iterator ch=tr.begin(parent), last_part;
@@ -46,11 +46,17 @@ Algorithm::result_t combine::apply(iterator& it)
4646
++ch;
4747
}
4848
if(last_part==start->second) {
49-
// We are on a rightmost contracted index
50-
found=true;
49+
++last_part;
50+
if(last_part==tr.end(parent)) {
51+
// Dummy index with nothing to the right is preferred
52+
found=true;
53+
}
54+
else backup=start;
5155
}
52-
else ++start;
56+
if(!found) ++start;
5357
}
58+
// As a backup, we use a dummy index with only non-dummies to the right
59+
if(!found) start=backup;
5460
bool paired=true;
5561
while(paired && start!=ind_dummy.end()) {
5662
iterator parent=tr.parent(start->second);

tests/implicit.cdb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,14 @@ def test08():
9797

9898
test08()
9999

100+
def test09():
101+
__cdbkernel__=create_scope()
102+
{a,b,c}::Indices(vector);
103+
ex:=(B)_{b c} (A)_{a b};
104+
combine(_);
105+
tst:= (A B)_{a c} - @(ex);
106+
assert(tst==0)
107+
print("Test 09 passed")
108+
109+
test09()
110+

0 commit comments

Comments
 (0)