[GiNaC-list] symbol equality
Vladimir V. Kisil
V.Kisil at leeds.ac.uk
Thu Feb 9 09:11:59 CET 2023
Hello, Reidel,
As far as I can remember from my projects, subclassing may need
re-implementation some technical methods, e.g. compare_same_type(),
is_equal(), etc. You may also need a custom subs() for your subclass.
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
>>>>> On Thu, 9 Feb 2023 06:08:13 +0100, Marko Riedel <riedelmo at mathematik.uni-stuttgart.de> said:
MR> Greetings to all.
MR> I have been subclassing "symbol" for my project, where I need to
MR> attach an integer value to a symbol. I am not sure this is the
MR> best way to go about it but I would like to try. Everything
MR> works so far but now I have moved on to substituting variables
MR> in polynomials. Here is my sample program.
MR> #include <iostream> #include <ginac/ginac.h>
MR> #include "cindsymbol.h" #include "util.h"
MR> using namespace std; using namespace GiNaC;
MR> int main() { cindsymbol R = cindsymbol("R",0), G =
MR> cindsymbol("G",0), B = cindsymbol("B",0), X = cindsymbol("X",0);
MR> ex pl = X + pow(X, 3) + R + G + B;
MR> cout << R << G << B << " " << pl << endl; cout << pl.subs({X},
MR> {pow(X,4)}) << endl;
MR> return 0; }
MR> The output of this program is as follows (the print functions
MR> from the subclass are being invoked correctly and do not print
MR> the zero value):
MR> RGB X+R+G+B+X^3 4*X^4+X^12
MR> Obviously GiNaC thinks that R=X, B=X and G=X. How do I get this
MR> comparison to work? Do I need to override some function in my
MR> subclass? The function "cindsymbol" goes as follows (copied
MR> from the tutorial):
MR> static map<string, cindsymbol> directory;
MR> cindsymbol cindsym(const std::string & initname, unsigned cl) {
MR> std::string key = initname + "|" + std::to_string(cl);
MR> map<std::string, cindsymbol>::iterator it = directory.find(key);
MR> if (it != directory.end()) return it->second; else{
MR> std::pair<std::string, cindsymbol> ent = make_pair(key,
MR> cindsymbol(initname, cl)); return
MR> directory.insert(ent).first->second; } }
MR> Can you advise me here? Thanks!
MR> Best regards,
MR> Marko Riedel
MR> _______________________________________________ GiNaC-list
MR> mailing list GiNaC-list at ginac.de
MR> https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.ginac.de%2Fmailman%2Flistinfo%2Fginac-list&data=05%7C01%7CV.Kisil%40leeds.ac.uk%7Cf9281b2ab31d4ed0e94408db0a5ba9db%7Cbdeaeda8c81d45ce863e5232a535b7cb%7C1%7C0%7C638115161033613772%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=WPVPtJSJ3PtVNqmEf%2FYmd0vY5XkXFdBhMY79y138vYY%3D&reserved=0
More information about the GiNaC-list
mailing list