[GiNaC-list] to_polynomial function does not return a polynomial

Feng Feng f.feng at outlook.com
Tue Dec 28 09:41:24 CET 2021


Dear all,


I am using the function to_polynomial to produce a polynomial from a expression,
it seems that to_polynomial does not return a polynomial in some cases, 
as illustrated in the following example, note that it works well on expression e2,
while it does nothing on e3 (e3=e2^2), and does not return a polynomial.




#include "ginac/GiNaC.h"
using namespace GiNaC;
using namespace std;
int main() {
    symbol x("x"), y("y");
    auto e1 = x+y;
    auto e2 = e1+1/e1+pow(e1,4);
    auto e3 = pow(e2, 2);
    exmap mp2;
    ex p2 = e2.to_polynomial(mp2);
    cout << " = " << p2 << "\n   with " << mp2 << endl; 
    //= y+symbol4+x+(y+x)^4
    //   with {symbol4==(y+x)^(-1)}
    exmap mp3;
    ex p3 = e3.to_polynomial(mp3);
    cout << " = " << p3 << "\n   with " << mp3 << endl;
    //= (y+(y+x)^(-1)+x+(y+x)^4)^2
    //with {}
    return 0;
}


Best regards!
Feng
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.ginac.de/pipermail/ginac-list/attachments/20211228/617c1df4/attachment.htm>


More information about the GiNaC-list mailing list