Skip to content

Commit 087a992

Browse files
authored
Merge pull request #7 from kpeeters/master
Sync with upstream
2 parents ea4e595 + 5dfdc84 commit 087a992

File tree

3 files changed

+71
-10
lines changed

3 files changed

+71
-10
lines changed

core/Props.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ namespace cadabra {
503503
if(ret1) { // property of the right type found for object 1
504504
property_map_t::const_iterator walk2=pit2.first;
505505
while(walk2!=pit2.second) {
506-
if((*walk2).second.first->match(*this, it2, ignore_parent_rel)) { // match for object 1 found
506+
if((*walk2).second.first->match(*this, it2, ignore_parent_rel)) { // match for object 2 found
507507
ret2=dynamic_cast<const T *>((*walk2).second.second);
508508
if(ret2) { // property of the right type found for object 2
509509
if(ret1==ret2 && walk1!=walk2) { // accept if properties are the same and patterns are not

core/algorithms/combine.cc

Lines changed: 42 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);
@@ -133,6 +139,38 @@ Algorithm::result_t combine::apply(iterator& it)
133139
iterator brackprod=tr.append_child(outerbrack, str_node("\\prod"));
134140
iterator parn1=tr.parent(*dums1);
135141
iterator parn2=tr.parent(*dums2);
142+
143+
// count how many sign changes stand between the two objects
144+
int sign=1;
145+
unsigned int hits=0;
146+
Ex_comparator compare(kernel.properties);
147+
sib=tr.begin(it);
148+
while(hits<2) {
149+
if(hits==1 && sib!=parn2) {
150+
// pass arguments manually as can_swap() does not check them
151+
bool isbrack=*(sib->name)=="\\indexbracket";
152+
if(isbrack && isbrack2) {
153+
auto es=compare.equal_subtree(tr.begin(parn2), tr.begin(sib));
154+
sign*=compare.can_swap(tr.begin(parn2), tr.begin(sib), es, true);
155+
}
156+
else if(isbrack && !isbrack2) {
157+
auto es=compare.equal_subtree(parn2, tr.begin(sib));
158+
sign*=compare.can_swap(parn2, tr.begin(sib), es, true);
159+
}
160+
else if(!isbrack && isbrack2) {
161+
auto es=compare.equal_subtree(tr.begin(parn2), sib);
162+
sign*=compare.can_swap(tr.begin(parn2), sib, es, true);
163+
}
164+
else {
165+
auto es=compare.equal_subtree(parn2, sib);
166+
sign*=compare.can_swap(parn2, sib, es, true);
167+
}
168+
}
169+
if(sib==parn1 || sib==parn2) ++hits;
170+
++sib;
171+
}
172+
if(sign==-1) flip_sign(brackprod->multiplier);
173+
136174
// remove the dummy index from these two objects, and move
137175
// other (dummy or not) indices to the outer indexbracket.
138176
sibling_iterator ind1=tr.begin(tr.parent(*dums1));

tests/implicit.cdb

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,18 @@ def test06():
7373
test06()
7474

7575
def test07():
76+
__cdbkernel__=create_scope()
77+
{a,b}::Indices(vector);
78+
{A,B}::AntiCommuting;
79+
ex:=(A)_{a b} (B)_{b a};
80+
combine(_)
81+
tst:= (-B A)_{b b} - @(ex);
82+
assert(tst==0)
83+
print("Test 07 passed")
84+
85+
test07()
86+
87+
def test08():
7688
__cdbkernel__=create_scope()
7789
{m,n}::Indices(vector);
7890
{a,b,c}::Indices(spinor, position=fixed);
@@ -82,18 +94,29 @@ def test07():
8294
expand(_)
8395
tst:= (\Gamma^{m})^{a}_{b} (\Gamma^{n})^{b}_{c} - @(ex);
8496
assert(tst==0)
85-
print("Test 07 passed")
97+
print("Test 08 passed")
8698

87-
test07()
99+
test08()
88100

89-
def test08():
101+
def test09():
90102
__cdbkernel__=create_scope()
91103
{a,b}::Indices(vector);
92104
ex:=(u)_{a} (M)^{a b} (v)_{b};
93105
combine(_)
94106
tst:= \indexbracket(u M v) - @(ex);
95107
assert(tst==0)
96-
print("Test 08 passed")
108+
print("Test 09 passed")
97109

98-
test08()
110+
test09()
111+
112+
def test10():
113+
__cdbkernel__=create_scope()
114+
{a,b,c}::Indices(vector);
115+
ex:=(B)_{b c} (A)_{a b};
116+
combine(_);
117+
tst:= (A B)_{a c} - @(ex);
118+
assert(tst==0)
119+
print("Test 10 passed")
120+
121+
test10()
99122

0 commit comments

Comments
 (0)