[GiNaC-list] symbol equality
Marko Riedel
riedelmo at mathematik.uni-stuttgart.de
Thu Feb 9 06:08:13 CET 2023
Greetings to all.
I have been subclassing "symbol" for my project, where I need to attach
an integer value to a symbol. I am not sure this is the best way to go
about it but I would like to try. Everything works so far but now I have
moved on to substituting variables in polynomials. Here is my sample
program.
#include <iostream>
#include <ginac/ginac.h>
#include "cindsymbol.h"
#include "util.h"
using namespace std;
using namespace GiNaC;
int main()
{
cindsymbol R = cindsymbol("R",0), G = cindsymbol("G",0),
B = cindsymbol("B",0), X = cindsymbol("X",0);
ex pl = X + pow(X, 3) + R + G + B;
cout << R << G << B << " " << pl << endl;
cout << pl.subs({X}, {pow(X,4)}) << endl;
return 0;
}
The output of this program is as follows (the print functions from the
subclass are being invoked correctly and do not print the zero value):
RGB X+R+G+B+X^3
4*X^4+X^12
Obviously GiNaC thinks that R=X, B=X and G=X. How do I get this
comparison to work? Do I need to override some function in my subclass?
The function "cindsymbol" goes as follows (copied from the tutorial):
static map<string, cindsymbol> directory;
cindsymbol cindsym(const std::string & initname,
unsigned cl)
{
std::string key = initname + "|" + std::to_string(cl);
map<std::string, cindsymbol>::iterator it = directory.find(key);
if (it != directory.end())
return it->second;
else{
std::pair<std::string, cindsymbol> ent =
make_pair(key, cindsymbol(initname, cl));
return directory.insert(ent).first->second;
}
}
Can you advise me here? Thanks!
Best regards,
Marko Riedel
More information about the GiNaC-list
mailing list