Hi again, I've got an application I'm working on which needs the ability to handle STL maps and sets containing symbols. In order to be able to use these classes, I have to define an ordering (a less-than operator) for symbols. At the moment I use the 'get_name' method and then compare symbol names as strings, but this isn't really ideal, since it takes a a lot of processing, plus GiNaC is quite happy to tolerate more than one symbol with the same name, so my map/set should be as well. I notice that GiNaC's symbol class has a 'serial number' as one of its properties. Is there any way I can access that value via a public method? Or is there another method suggested for creating sets and maps of symbols? //// Ordering for symbols based on name (there should be a better way)/ *class* symbol_lt{ *public*: bool *operator*()(const GiNaC::symbol &a, const GiNaC::symbol &b) const; }; Cheers JP
On Thu, Sep 15, 2005 at 12:12:41AM +1000, John Pye wrote:
I've got an application I'm working on which needs the ability to handle STL maps and sets containing symbols.
Use std::map<ex, foo, ex_is_less>, see http://www.ginac.de/FAQ.html#stlcontainers If you _really_ want to use std::map<symbol, foo, ...> struct symbol_is_less { inline const bool operator()(const symbol& a, const symbol& b) { return ex_is_less()(a, b); } }; Best regards, Alexei -- All science is either physics or stamp collecting.
Hi Alexei, I _really_ wanted to use std::map<symbol, symbol> What's a better idea then? I'm using it to keep track of variables which I've eliminated from a system of nonlinear equations... Cheers JP Sheplyakov Alexei wrote:
On Thu, Sep 15, 2005 at 12:12:41AM +1000, John Pye wrote:
I've got an application I'm working on which needs the ability to handle STL maps and sets containing symbols.
Use std::map<ex, foo, ex_is_less>, see http://www.ginac.de/FAQ.html#stlcontainers
If you _really_ want to use std::map<symbol, foo, ...>
struct symbol_is_less { inline const bool operator()(const symbol& a, const symbol& b) { return ex_is_less()(a, b); } };
Best regards, Alexei
------------------------------------------------------------------------
_______________________________________________ GiNaC-list mailing list GiNaC-list@ginac.de http://thep.physik.uni-mainz.de/mailman/listinfo/ginac-list
On Thu, Sep 15, 2005 at 01:08:45AM +1000, John Pye wrote:
I _really_ wanted to use
std::map<symbol, symbol>
What's a better idea then?
You can define ordering as struct symbol_is_less { inline const bool operator()(const symbol& a, const symbol& b) { return ex_is_less()(a, b); } }; and use std::map<symbol, symbol, symbol_is_less> Here is a simple example: #include <iostream> #include <iterator> #include <map> #include <ginac/ginac.h> using namespace std; using namespace GiNaC; struct symbol_is_less { inline const bool operator()(const symbol& x, const symbol& y) { return ex_is_less()(x, y); } }; typedef map<symbol, symbol, symbol_is_less> ssmap; int main(int argc, char** argv) { symbol x("x"); symbol y("y"); symbol z("z"); symbol t("t"); ssmap foo; foo[x] = z; foo[y] = t; for (ssmap::const_iterator i=foo.begin(); i!=foo.end(); ++i) cout << i->first << " ==> " << i->second << endl; return 0; } Is this good enough for your purpose? Best regards, Alexei -- All science is either physics or stamp collecting.
participants (2)
-
John Pye
-
varg@theor.jinr.ru