<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Thank you, Vladimir. It was a great suggestion. Your comments reflect the statement in section 4.5 of the tutorial.</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
"GiNaC will assign the symbol an internal, unique name of the form <code>symbolNNN</code>. This won’t affect the usability of the symbol but the output of your calculations will become more readable if you give your symbols sensible names....."</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
My context was a bit different. I was trying to use the Lagrange interpolation theorem generically. I created three methods for basis, interpolation, and utility.</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
It was my ignorance to assume symbols are more like literals. </div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
After your guidance, I passed the symbol from one function to another so that it could be used.</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Beauty, now I do not have to add/subtract the coefficient of equal degree terms for which I was planning to write a method.</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Thanks again. BTW, I am reading your paper "CLASSICAL/QUANTUM=COMMUTATIVE/NONCOMMUTATIVE?"</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Regards,</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Santos</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Vladimir V. Kisil <V.Kisil@leeds.ac.uk><br>
<b>Sent:</b> Wednesday, July 3, 2024 4:38 AM<br>
<b>To:</b> GiNaC discussion list <ginac-list@ginac.de>; Santos Jha <sjha2@gmu.edu><br>
<b>Cc:</b> Vladimir V. Kisil <V.Kisil@leeds.ac.uk><br>
<b>Subject:</b> Re: [GiNaC-list] degree function</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText"> Hello,<br>
<br>
I think the problem is with your declaration of symb in<br>
subExpres.degree(symb). Did you get it from a string "x" through a<br>
parser? In this case it may be different from x in the poly. Then,<br>
it is absent from a monomial and its degree is indeed zero.<br>
Here is an output from a complete example code (see below):<br>
<br>
----------------------------------------<br>
Polynomial is x^2, it is a sum of monomials: false<br>
x is polynomial=true and degree=1<br>
2 is polynomial=true and degree=0<br>
<br>
----------------------------------------<br>
Polynomial is 1+3*x^2+2*x, it is a sum of monomials: true<br>
3*x^2 is polynomial=true and degree=2<br>
2*x is polynomial=true and degree=1<br>
1 is polynomial=true and degree=0<br>
<br>
Note that your polynomial is actually a monomial (but not a sum of<br>
monomials) and this situation needs to be treated differently.<br>
The complete code is:<br>
<br>
#include <iostream><br>
#include <ginac/ginac.h><br>
using namespace std;<br>
using namespace GiNaC;<br>
<br>
int main() {<br>
<br>
realsymbol x("x");<br>
lst expressions = lst{-4*(-3+x)*(-1+x)+numeric(9,2)*(-2+x)*(-1+x)+numeric(1,2)*(-2+x)*(-3+x),<br>
3*pow(x,2)+2*x+1};<br>
<br>
for ( auto poly : expressions) {<br>
cout << endl << "----------------------------------------" << endl;<br>
<br>
poly = poly.expand();<br>
cout << "Polynomial is " << poly<br>
<< ", it is a sum of monomials: " << boolalpha << is_a<add>(poly) <<endl;<br>
<br>
for (size_t i = 0; i != poly.nops(); ++i) { // Here poly is polynomial as above<br>
<br>
ex subExpres=poly.op(i); // I get individual terms<br>
cout << subExpres<< " is polynomial="<< is_polynomial(subExpres,x) ;<br>
// GiNaC::ex pow2=pow(symb,2);<br>
cout << " and degree=" << subExpres.degree(x) << endl; <br>
}<br>
}<br>
<br>
return 0;<br>
}<br>
<br>
Best wishes,<br>
Vladimir<br>
-- <br>
Vladimir V. Kisil <a href="http://secure-web.cisco.com/1uavsA2G3CFg_3gcda5sStFEOvAflaJ2bvsS5fAGJLsvRhxmygxZpeJRcqg2QK_FVg34KGTN8REdXOdOooOeM8sgTWpZ3F67a-r3dX77zlhoiVmjogKWey3de4bHkriJs6vltoSgdKxnmVPR0q_Ciy5Yc8s7eUDeqz5rV8zpLyqHw7C6CzET3jV09f7-CfKMdNBBV1wIYsGFJcq3snZEYyonaLjZBVETNlCBifvTpvYyzGF5VGVLnOjgUg43ePKrNwYRJzHDL2LqYi2vnCvReRQ2yYcisllgfB6p2XaVaOApxnalBcI9HNzPeGWC5VyoF6psC0QWNquyN2LPh9zmQfht9vrx39ZgGFY0q9eBsWafhZyA7GjcOB4RciK_NThkyKIrQqs2y0tMsCz0f4uROcsslpK23m905FNZWgls-Zxyj3wn33HBUahBunSwQPFPw/http%3A%2F%2Fv-v-kisil.scienceontheweb.net">
http://secure-web.cisco.com/1uavsA2G3CFg_3gcda5sStFEOvAflaJ2bvsS5fAGJLsvRhxmygxZpeJRcqg2QK_FVg34KGTN8REdXOdOooOeM8sgTWpZ3F67a-r3dX77zlhoiVmjogKWey3de4bHkriJs6vltoSgdKxnmVPR0q_Ciy5Yc8s7eUDeqz5rV8zpLyqHw7C6CzET3jV09f7-CfKMdNBBV1wIYsGFJcq3snZEYyonaLjZBVETNlCBifvTpvYyzGF5VGVLnOjgUg43ePKrNwYRJzHDL2LqYi2vnCvReRQ2yYcisllgfB6p2XaVaOApxnalBcI9HNzPeGWC5VyoF6psC0QWNquyN2LPh9zmQfht9vrx39ZgGFY0q9eBsWafhZyA7GjcOB4RciK_NThkyKIrQqs2y0tMsCz0f4uROcsslpK23m905FNZWgls-Zxyj3wn33HBUahBunSwQPFPw/http%3A%2F%2Fv-v-kisil.scienceontheweb.net</a><br>
Book: Geometry of Mobius Maps <a href="https://doi.org/10.1142/p835">
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdoi.org%2F10.1142%2Fp835&data=05%7C02%7Csjha2%40gmu.edu%7Cab75458dc71e4de789db08dc9b3b92f9%7C9e857255df574c47a0c00546460380cb%7C0%7C0%7C638555927388803258%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=OY%2FslNRAJWreEeqwmKmcccmjoZKJoA%2FpqrqTdFEwvq0%3D&reserved=0</a><br>
Soft: Geometry of cycles <a href="http://moebinv.sourceforge.net/">
https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmoebinv.sourceforge.net%2F&data=05%7C02%7Csjha2%40gmu.edu%7Cab75458dc71e4de789db08dc9b3b92f9%7C9e857255df574c47a0c00546460380cb%7C0%7C0%7C638555927388811673%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=JRxAoUu7GIaMuB8QzE6%2BKzj2Ou72VMoV3TjAaifZWXk%3D&reserved=0</a><br>
Jupyter notebooks: <a href="https://github.com/vvkisil?tab=repositories">
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fvvkisil%3Ftab%3Drepositories&data=05%7C02%7Csjha2%40gmu.edu%7Cab75458dc71e4de789db08dc9b3b92f9%7C9e857255df574c47a0c00546460380cb%7C0%7C0%7C638555927388816616%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=LGDJLxcJXIotHH%2FwrMMwQ37lWlA2EQcg1gvn3w0pfGk%3D&reserved=0</a><br>
>>>>> On Wed, 3 Jul 2024 03:19:30 +0000, Santos Jha <sjha2@gmu.edu> said:<br>
<br>
SI> Greetings,<br>
<br>
SI> I am new to GiNac. I was trying to use the degree function, but<br>
SI> I got a weird result.<br>
<br>
SI> My initial expression is<br>
<br>
SI> -4*(-3+x)*(-1+x)+9/2*(-2+x)*(-1+x)+1/2*(-2+x)*(-3+x)<br>
<br>
SI> After the "expand" function call, it returns<br>
<br>
SI> 9/2*x^2-5/2*x-4*x^2+16*x-27/2*x+1/2*x^2<br>
<br>
SI> My goal is to add/subtract the coefficient of equal degree<br>
SI> terms. I could not find any function for that. ( if it is<br>
SI> already there, please point me) I wanted to write a function to<br>
SI> achieve it. To do so. I am taking each term and try to see if<br>
<br>
SI> for (size_t i = 0; i != poly.nops(); ++i) { // Here poly is<br>
SI> polynomial as above<br>
<br>
SI> ex subExpres=poly.op(i); // I get individual terms<br>
SI> cout << "is polynomial="<< is_polynomial(subExpres,symb) <<endl;<br>
SI> // GiNaC::ex pow2=pow(symb,2); cout << subExpres<< " degree=" <<<br>
SI> subExpres.degree(symb) << endl;<br>
<br>
SI> }<br>
<br>
SI> It determines the subexpression as a polynomial but can not<br>
SI> determine the degree. E.g<br>
<br>
SI> is polynomial=1 9/2*x^2 degree=0 // Here degree returned is<br>
SI> wrong.<br>
<br>
SI> Your thoughts will be appreciated. Regards, Santos<br>
<br>
<br>
<br>
SI> ----------------------------------------------------<br>
SI> Alternatives:<br>
<br>
SI> ----------------------------------------------------<br>
SI> _______________________________________________ GiNaC-list<br>
SI> mailing list GiNaC-list@ginac.de<br>
SI> <a href="https://secure-web.cisco.com/1W7ynipL-PtPXpNNCM8HaXVaflBXe5T6IsuNZG01-EjQ46nlW1KQgYXiDlPCSJ_dtrpcpYE-G1-aWiPc-PXi_V6ItAhj4t0vXSxiACgIo1xSacx78zQipu7HCrP0wbGGjFvCOCJvrxT-lnRljTV3oMQ8MLid7ALAUOSVtG38772FPluPMoU_LIA1rHb_CIPB8Mb5YKtEMincICyQoiBMs7UzsQsxSav45O1WlSdBCnz-6CYTOcQpRmMJkbngZpblNk4gOMZKi2RfVJ1k1vDYoPytTWhd9QIEshR2J45HiC5wfA-9GaJz8NxSS2cmE_ReERWgeUgyZrRXw0J1HaFppXQt9CqUmu_cdMPePOxT7wH1jxek0cP_1mfY-woY9T69Fg6OWFRP99PGliTHz0tPEuTiOP67hwV9TWy_b5Ir3i7OyE0bNLGlIDFRDis_D6ezY/https%3A%2F%2Fwww.ginac.de%2Fmailman%2Flistinfo%2Fginac-list">
https://secure-web.cisco.com/1W7ynipL-PtPXpNNCM8HaXVaflBXe5T6IsuNZG01-EjQ46nlW1KQgYXiDlPCSJ_dtrpcpYE-G1-aWiPc-PXi_V6ItAhj4t0vXSxiACgIo1xSacx78zQipu7HCrP0wbGGjFvCOCJvrxT-lnRljTV3oMQ8MLid7ALAUOSVtG38772FPluPMoU_LIA1rHb_CIPB8Mb5YKtEMincICyQoiBMs7UzsQsxSav45O1WlSdBCnz-6CYTOcQpRmMJkbngZpblNk4gOMZKi2RfVJ1k1vDYoPytTWhd9QIEshR2J45HiC5wfA-9GaJz8NxSS2cmE_ReERWgeUgyZrRXw0J1HaFppXQt9CqUmu_cdMPePOxT7wH1jxek0cP_1mfY-woY9T69Fg6OWFRP99PGliTHz0tPEuTiOP67hwV9TWy_b5Ir3i7OyE0bNLGlIDFRDis_D6ezY/https%3A%2F%2Fwww.ginac.de%2Fmailman%2Flistinfo%2Fginac-list</a><br>
</div>
</span></font></div>
</body>
</html>