Greetings to all. I am at this time considering to use GiNaC for some computations from group theory. I am not a C++ programmer. I would like to ask for assistance with the following task. I have a polynomial in several variables like a[1], a[2], a[5] etc. I understand I can initialize these by creating a symbol object with the variable name. The problem is, I need an easy and conformal means of accessing the integer in the variable name. This could be done by matching the name to a regular expression and extracting the value but I imagine there must be a 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. Furthermore, another question, does the C++ standard library have a means of memoizing functions? Thank you for your assistance. Marko Riedel
Post Scriptum. I managed to get the subscripts by subclassing the symbol class to attach an integer to it. Still I wonder if that is the best way to go about it. Am 05.02.23 um 23:07 schrieb Marko Riedel:
Greetings to all.
I am at this time considering to use GiNaC for some computations from group theory. I am not a C++ programmer. I would like to ask for assistance with the following task. I have a polynomial in several variables like a[1], a[2], a[5] etc. I understand I can initialize these by creating a symbol object with the variable name. The problem is, I need an easy and conformal means of accessing the integer in the variable name. This could be done by matching the name to a regular expression and extracting the value but I imagine there must be a 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. Furthermore, another question, does the C++ standard library have a means of memoizing functions?
Thank you for your assistance.
Marko Riedel
_______________________________________________ GiNaC-list mailing list GiNaC-list@ginac.de https://www.ginac.de/mailman/listinfo/ginac-list
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
participants (2)
-
Marko Riedel
-
Vladimir V. Kisil