Skip to content

Commit ba747e0

Browse files
committed
Avoid infinite loop in sort_product with repeat flag.
1 parent 956dfdb commit ba747e0

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

core/algorithms/sort_product.cc

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -126,21 +126,23 @@ Algorithm::result_t sort_product::apply(iterator& st)
126126
}
127127
// We have found the element that should go at the front of the trace
128128
Ex::sibling_iterator front=one;
129-
while(tr.begin(st)!=front) {
130-
one=tr.begin(st);
131-
two=one;
132-
++two;
133-
while(two!=tr.end(st)) {
134-
compare.clear();
135-
auto es=compare.equal_subtree(one, two);
136-
int sign=compare.can_swap_components(one, two, es);
137-
if(sign==-1) flip_sign(st->multiplier);
138-
tr.swap(one);
139-
++two;
129+
if(front!=tr.begin(st)) {
130+
while(tr.begin(st)!=front) {
131+
one=tr.begin(st);
132+
two=one;
140133
++two;
134+
while(two!=tr.end(st)) {
135+
compare.clear();
136+
auto es=compare.equal_subtree(one, two);
137+
int sign=compare.can_swap_components(one, two, es);
138+
if(sign==-1) flip_sign(st->multiplier);
139+
tr.swap(one);
140+
++two;
141+
++two;
142+
}
141143
}
144+
ret=result_t::l_applied;
142145
}
143-
ret=result_t::l_applied;
144146
}
145147
}
146148

tests/implicit.cdb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,17 @@ def test15():
196196

197197
test15()
198198

199+
def test16():
200+
__cdbkernel__=create_scope()
201+
{\mu,\nu,\rho}::Indices(vector).
202+
{a^{\mu},b^{\mu},c^{\mu}}::NonCommuting.
203+
tr{#}::Trace.
204+
ex:=tr( b^{\mu} c^{\nu} a^{\rho} b^{\nu} c^{\mu} a^{\rho} );
205+
sort_product(_)
206+
rename_dummies(_)
207+
tst:= tr( a^{\mu} b^{\nu} c^{\rho} a^{\mu} b^{\rho} c^{\nu} ) - @(ex);
208+
assert(tst==0)
209+
print("Test 16 passed")
210+
211+
test16()
212+

0 commit comments

Comments
 (0)