Good day, Marko,
On Mon, 6 Feb 2023 06:18:11 +0100, Marko Riedel <riedelmo@mathematik.uni-stuttgart.de> said:
MR> Post Scriptum. I managed to get the subscripts by subclassing MR> the symbol class to attach an integer to it. Still I wonder if MR> that is the best way to go about it. It depends on your purpose, why do you need integer associated to symbols? An alternative solution to keep a C++ std::map<GiNaC::ex, int> which will be a dictionary converting symbols to respective indices. Or consider a usage of GiNaC::indexed ex a=symbol("a"), i=symbol("i"); ex ai=indexed(a, idx(i,4)); ex a1=ai.subs(i==1); ex a2=ai.subs(i==2); ex a3=ai.subs(i==3); ex e = 2*pow(a1, 2) + 3*a1*a2 + 4*pow(a2, 3); cout << e << endl; // -> 4*(a.2)^3+3*a.1*a.2+2*(a.1)^2 cout << a2.op(1).op(0) << endl; // -> 2 for (int j=1; j < 4; ++j) cout << "Variable with index " << j << " has degree " << e.degree(ai.subs(i == j)) << endl; /* -> Variable with index 1 has degree 2 -> Variable with index 2 has degree 3 -> Variable with index 3 has degree 0 */ The example also suggests a solution to your other question: MR> Am 05.02.23 um 23:07 schrieb Marko Riedel: >> better way. I am also looking for a means of extracting a set of >> variables that are present in a polynomial, or the degree these >> variables have. Best wishes, Vladimir -- Vladimir V. Kisil http://www1.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