Hi all, I have a set of custom objects that is declared like this: struct cindsym_is_less { bool operator() (const cindsymbol &lh, const cindsymbol &rh) const { return lh.compare(rh) < 0; } }; typedef std::set<cindsymbol, cindsym_is_less> cindsymset; Now I want to collect all custom objects that appear in an expression tree into this kind of set. I tried this: void indets_recurse(ex src, cindsymset & coll) { if(is_a<add>(src) || is_a<mul>(src) || is_a<power>(src)){ for(size_t idx = 0; idx < src.nops(); idx++) indets_recurse(src.op(idx), coll); return; } if(is_a<cindsymbol>(src)){ coll.insert(src); } } However this will produce the error "no matching function call" because src is an expression and not a cindsymbol. I know that I have my kind of symbol because is_a<cindsymbol> returned true. How can I get at the symbol wrapped in the expression? Best regards, Marko
Never mind, I am still learning. I found the ex_to converter and now everything is working. Marko Am 10.02.23 um 00:34 schrieb Marko Riedel:
Hi all,
I have a set of custom objects that is declared like this:
struct cindsym_is_less { bool operator() (const cindsymbol &lh, const cindsymbol &rh) const { return lh.compare(rh) < 0; } };
typedef std::set<cindsymbol, cindsym_is_less> cindsymset;
Now I want to collect all custom objects that appear in an expression tree into this kind of set. I tried this:
void indets_recurse(ex src, cindsymset & coll) { if(is_a<add>(src) || is_a<mul>(src) || is_a<power>(src)){ for(size_t idx = 0; idx < src.nops(); idx++) indets_recurse(src.op(idx), coll); return; }
if(is_a<cindsymbol>(src)){ coll.insert(src); } }
However this will produce the error "no matching function call" because src is an expression and not a cindsymbol. I know that I have my kind of symbol because is_a<cindsymbol> returned true. How can I get at the symbol wrapped in the expression?
Best regards,
Marko _______________________________________________ GiNaC-list mailing list GiNaC-list@ginac.de https://www.ginac.de/mailman/listinfo/ginac-list
Also, I found that exset is sufficient for my purposes, so that is one fewer type to implement. Am 10.02.23 um 01:37 schrieb Marko Riedel:
Never mind, I am still learning. I found the ex_to converter and now everything is working.
Marko
Am 10.02.23 um 00:34 schrieb Marko Riedel:
Hi all,
I have a set of custom objects that is declared like this:
struct cindsym_is_less { bool operator() (const cindsymbol &lh, const cindsymbol &rh) const { return lh.compare(rh) < 0; } };
typedef std::set<cindsymbol, cindsym_is_less> cindsymset;
Now I want to collect all custom objects that appear in an expression tree into this kind of set. I tried this:
void indets_recurse(ex src, cindsymset & coll) { if(is_a<add>(src) || is_a<mul>(src) || is_a<power>(src)){ for(size_t idx = 0; idx < src.nops(); idx++) indets_recurse(src.op(idx), coll); return; }
if(is_a<cindsymbol>(src)){ coll.insert(src); } }
However this will produce the error "no matching function call" because src is an expression and not a cindsymbol. I know that I have my kind of symbol because is_a<cindsymbol> returned true. How can I get at the symbol wrapped in the expression?
Best regards,
Marko _______________________________________________ GiNaC-list mailing list GiNaC-list@ginac.de https://www.ginac.de/mailman/listinfo/ginac-list
GiNaC-list mailing list GiNaC-list@ginac.de https://www.ginac.de/mailman/listinfo/ginac-list
On 2/10/23 01:39, Marko Riedel wrote:
Also, I found that exset is sufficient for my purposes, so that is one fewer type to implement.
I suggest having a look at find_symbols_map in factor.cpp and how's it used there. (Maybe GiNaC should expose something like this if it's useful?) -richy.
Greetings to all. I would like to briefly correct some code I posted to this list where I used "idx" as the name of an iterator. I had not realized that this was one of the built-in classes, which could cause confusion. I will be alert to this in the future. I was able to resolve all my other problems and I now have a working program, part of a series I plan to write. I must say I am very favourably impressed with the speed of my program, it is easily as fast as Maple if not better. I am new to C++ but I have some experience with Objective C which helps with the general design paradigms. Best regards, Marko
participants (2)
-
Marko Riedel
-
Richard B. Kreckel