<div dir="ltr">Hi! I believe there's an intermittent bug in GiNaC::factor() function. Sometimes it leaves uncancelled terms with seemingly random coefficients like:<br><br>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<br><br>The minimal code to reproduce the bug in GiNaC 1.8.2 is:<br><br>#include <ginac/ginac.h><br>#include <iostream><br><br>int main()<br>{<br>Â Â 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");<br>Â Â while (true)<br>Â Â {<br>Â Â Â Â std::ostringstream s;<br>Â Â Â Â GiNaC::parser reader;<br>Â Â Â Â s << factor(reader(input));<br>Â Â Â Â if (s.str().length() <= input.length())<br>Â Â Â Â Â Â continue;<br>Â Â Â Â std::cout << s.str() << '\n';<br>Â Â Â Â return 0;<br>Â Â }<br>}<br><br>Also, this problem can be reproduced on <a href="https://daninet.github.io/ginac-wasm/">https://daninet.github.io/ginac-wasm/</a> with the same expression being calculated several times in a row:<br><br>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);<br><br>With best regards,<br>Ivan.</div>