Hi! I believe there's an intermittent bug in GiNaC::factor() function. Sometimes it leaves uncancelled terms with seemingly random coefficients like: w*(w^2*(K^4*B^2+B^2-2*K^2*B^2)+196*w^2*K^4+196*w^2+C^2-196*w^2*(1+K^4-2*K^2)-392*w^2*K^2)*A The minimal code to reproduce the bug in GiNaC 1.8.2 is: #include <ginac/ginac.h> #include <iostream> int main() { std::string input("w^3*B^2*A-2*w^3*K^2*B^2*A+w*C^2*A+w^3*K^4*B^2*A"); while (true) { std::ostringstream s; GiNaC::parser reader; s << factor(reader(input)); if (s.str().length() <= input.length()) continue; std::cout << s.str() << '\n'; return 0; } } Also, this problem can be reproduced on https://daninet.github.io/ginac-wasm/ with the same expression being calculated several times in a row: factor(w^3*B^2*A-2*w^3*K^2*B^2*A+w*C^2*A+w^3*K^4*B^2*A); With best regards, Ivan.