for (unsigned j=0; j<rhs.nops(); j++)
v.push_back(rhs.op(j));
- // Stupid bubble sort because we only want to swap adjacent gammas
+ // Stupid recursive bubble sort because we only want to swap adjacent gammas
exvector::iterator it = v.begin(), next_to_last = v.end() - 1;
if (is_ex_of_type(it->op(0), diracgamma5))
it++;
shaker_sort(iv_lst.begin(), iv_lst.end(), ex_is_less());
lst orig_lst(iv_lst);
- // With n objects there are n! possible permutations
- int num_perms = factorial(numeric(num)).to_int();
-
// Loop over all permutations (the first permutation, which is the
// identity, is unrolled)
ex sum = e;
- int i = 1;
- do {
- next_permutation(iv_lst.begin(), iv_lst.end(), ex_is_less());
+ while (next_permutation(iv_lst.begin(), iv_lst.end(), ex_is_less())) {
ex term = e.subs(orig_lst, lst(iv_lst));
if (asymmetric) {
exlist test_lst = iv_lst;
term *= permutation_sign(test_lst.begin(), test_lst.end(), ex_is_less());
}
sum += term;
- i++;
- } while (i < num_perms);
-
- return sum / num_perms;
+ }
+ return sum / factorial(numeric(num));
}
ex symmetrize(const ex & e, exvector::const_iterator first, exvector::const_iterator last)
explicitly supplied comparison function. If the sign returned is 1 or -1,
the container is sorted after the operation. */
template <class It>
-inline int permutation_sign(It first, It last)
+int permutation_sign(It first, It last)
{
if (first == last)
return 0;
}
template <class It, class Cmp>
-inline int permutation_sign(It first, It last, Cmp comp)
+int permutation_sign(It first, It last, Cmp comp)
{
if (first == last)
return 0;
/* Implementation of shaker sort, only compares adjacent elements. */
template <class It, class Cmp>
-inline void shaker_sort(It first, It last, Cmp comp)
+void shaker_sort(It first, It last, Cmp comp)
{
if (first == last)
return;