Well, I did some more digging. The parser itself is fine. What matters is the hashing order of the symbols. There's one particular sequence that drives the factorization routine off the rails.
#include <ginac/ginac.h>
#include <iostream>
#include <algorithm>
int main()
{
GiNaC::symbol ar[5];
std::sort(std::begin(ar), std::end(ar), [](const auto &a, const auto &b)
{ return a.gethash() < b.gethash(); });
GiNaC::symbol &A = ar[4], &w = ar[0], &K = ar[1], &C = ar[2], &B = ar[3];
A.set_name("A");
B.set_name("B");
C.set_name("C");
K.set_name("K");
w.set_name("w");
std::cout << factor(w*w*w*B*B*A-2*w*w*w*K*K*B*B*A+w*C*C*A+w*w*w*K*K*K*K*B*B*A) << '\n';
}
Interestingly, for the library version before 1.8.0, there were four more permutations that produced weird output:
// GiNaC::symbol &A = ar[0], &w = ar[1], &K = ar[2], &C = ar[3], &B = ar[4];
// GiNaC::symbol &A = ar[1], &w = ar[0], &K = ar[2], &C = ar[3], &B = ar[4];
// GiNaC::symbol &A = ar[2], &w = ar[0], &K = ar[1], &C = ar[3], &B = ar[4];
// GiNaC::symbol &A = ar[3], &w = ar[0], &K = ar[1], &C = ar[2], &B = ar[4];
As Richard B. Kreckel <kreckel at
in.terlu.de> wrote, this is not a bug. So, I apologize for misreporting.
But still, the result of factorization looks somewhat counterintuitive.
With best regards,
Ivan