From: Christian Bauer Date: Wed, 30 May 2001 22:38:28 +0000 (+0000) Subject: - permutation_sign() and shaker_sort() are no longer inlined X-Git-Tag: release_0-9-0~29 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=2700b3fa9c3a81236e8ceccb6aa9d5ea5848a1a0 - permutation_sign() and shaker_sort() are no longer inlined - symmetrize() no longer limited to 32-bit integers --- diff --git a/ginac/clifford.cpp b/ginac/clifford.cpp index 3af4fcae..e62def50 100644 --- a/ginac/clifford.cpp +++ b/ginac/clifford.cpp @@ -524,7 +524,7 @@ ex canonicalize_clifford(const ex & e) for (unsigned j=0; jop(0), diracgamma5)) it++; diff --git a/ginac/inifcns.cpp b/ginac/inifcns.cpp index beb51d62..03acbc7f 100644 --- a/ginac/inifcns.cpp +++ b/ginac/inifcns.cpp @@ -538,25 +538,18 @@ static ex symm(const ex & e, exvector::const_iterator first, exvector::const_ite 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) diff --git a/ginac/utils.h b/ginac/utils.h index c0bc2efe..ac7aecdf 100644 --- a/ginac/utils.h +++ b/ginac/utils.h @@ -131,7 +131,7 @@ inline unsigned golden_ratio_hash(unsigned n) explicitly supplied comparison function. If the sign returned is 1 or -1, the container is sorted after the operation. */ template -inline int permutation_sign(It first, It last) +int permutation_sign(It first, It last) { if (first == last) return 0; @@ -184,7 +184,7 @@ inline int permutation_sign(It first, It last) } template -inline int permutation_sign(It first, It last, Cmp comp) +int permutation_sign(It first, It last, Cmp comp) { if (first == last) return 0; @@ -238,7 +238,7 @@ inline int permutation_sign(It first, It last, Cmp comp) /* Implementation of shaker sort, only compares adjacent elements. */ template -inline void shaker_sort(It first, It last, Cmp comp) +void shaker_sort(It first, It last, Cmp comp) { if (first == last) return;