[GiNaC-list] factorization bug

Vladimir V. Kisil V.Kisil at leeds.ac.uk
Tue Feb 1 22:52:01 CET 2022


	Hello,

	It seems that the problem is not with the factor method but with the
  parser. Take the following modification of your example:
  
#include <ginac/ginac.h>
#include <iostream>
#include <sstream>

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;
        GiNaC::ex e = reader(input);
    	
        s << factor(e);
        if (s.str().length() <= input.length())
            continue;
        std::cout << s.str() << '\n';
        return 0;
    }
}

  It behaves as your example and quickly terminates with a strange
  output. However, if the declaration "GiNaC::parser reader;" will be
  moved out of the loop then the programme will cycle forever.

  Best wishes,
  Vladimir
-- 
Vladimir V. Kisil                 http://www.maths.leeds.ac.uk/~kisilv/
  Book:      Geometry of Mobius Maps       https://doi.org/10.1142/p835
  Soft:      Geometry of cycles         http://moebinv.sourceforge.net/
  Jupyter notebooks:        https://github.com/vvkisil?tab=repositories
>>>>> On Mon, 31 Jan 2022 00:01:48 +0300, Ivan Vasilyev <grabesstimme at gmail.com> said:

    IV> Hi! I believe there's an intermittent bug in GiNaC::factor()
    IV> function.  Sometimes it leaves uncancelled terms with seemingly
    IV> random coefficients like:

    IV> 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

    IV> The minimal code to reproduce the bug in GiNaC 1.8.2 is:

    IV> #include <ginac/ginac.h> #include <iostream>

    IV> int main() { std::string
    IV> 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
    IV> (true) { std::ostringstream s; GiNaC::parser reader; s <<
    IV> factor(reader(input)); if (s.str().length() <= input.length())
    IV> continue; std::cout << s.str() << '\n'; return 0; } }

    IV> Also, this problem can be reproduced on
    IV> https://daninet.github.io/ginac-wasm/ with the same expression
    IV> being calculated several times in a row:

    IV> 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);

    IV> With best regards, Ivan.


More information about the GiNaC-list mailing list