[GiNaC-list] degree function

Santos Jha sjha2 at gmu.edu
Wed Jul 3 05:19:30 CEST 2024


Greetings,

I am new to GiNac. I was trying to use the degree function, but I got a weird result.

My initial expression is

-4*(-3+x)*(-1+x)+9/2*(-2+x)*(-1+x)+1/2*(-2+x)*(-3+x)

After the "expand"  function call, it returns

9/2*x^2-5/2*x-4*x^2+16*x-27/2*x+1/2*x^2

My goal is to add/subtract the coefficient of equal degree terms. I could not find any function for that. ( if it is already there, please point me)
I wanted to write a function to achieve it. To do so. I am taking each term and try to see if

for (size_t i = 0; i != poly.nops(); ++i)   {  // Here poly is polynomial as above

            ex subExpres=poly.op(i); // I get individual terms
            cout << "is polynomial="<< is_polynomial(subExpres,symb) <<endl;
           // GiNaC::ex pow2=pow(symb,2);
            cout << subExpres<< " degree=" << subExpres.degree(symb) << endl;

}

It determines the subexpression as a polynomial but can not determine the degree. E.g

is polynomial=1
9/2*x^2 degree=0  // Here degree returned is wrong.

Your thoughts will be appreciated.
Regards,
Santos


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.ginac.de/pipermail/ginac-list/attachments/20240703/61ab4c65/attachment.htm>


More information about the GiNaC-list mailing list