[GiNaC-list] factorization bug

Richard B. Kreckel kreckel at in.terlu.de
Wed Feb 2 11:15:55 CET 2022


Hi,

On 30.01.22 22:01, Ivan Vasilyev wrote:
> 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;
>     }
> }

As far as I can see, all the results are correct and the three factors
are always found.

What happens is that, for now, GiNaC deliberately refrains from
expanding the factors. As a result, it produces (non-monomial) factors
in unforeseeable ways.

   -richy.


More information about the GiNaC-list mailing list