Changing symbol string names on-the-fly
Christian.Bauer at Uni-Mainz.DE
Wed Jul 9 19:40:34 CEST 2003
On Wed, Jul 09, 2003 at 11:02:07AM +0100, Dr. Vassilis S. Vassiliadis wrote:
> Is it possible to change on-the-fly the string names used in a symbol?
There is a symbol::set_name(), but it only works for symbols that are not
already part of an expression.
> The names used internally utilize the object-partitioning
> of my code e.g. :
> symbol x("system.composition.x")
> The output in raw C++ form is desired to be a simple counting
> scheme e.g. for the above symbol:
> will be substituted.
Maybe we should add a "csrc" name for symbols in the same manner as there
is a TeX name. But this seems like overkill...
> I have tried to use an auxiliary vector list with new symbols and
> then substitute the new symbols for the old, using .subs().
subs() would be the recommended solution to your problem.
> However, when the number of substitutions is beyond say a couple of
> hundred even a 2.5 GHz machine cannot run the problem efficiently.
Specifying subs_options::subs_no_pattern might speed it up. If it's still
too slow, find out why and send us a patch. :-)
Maybe subs() should use maps instead of lists?
> Without resorting to brute force outputing and replacing of strings,
> I wonder if there is an elegant and economical way to do the above in GiNaC.
There is another way that is undocumented but gets the job done: symbols
can be assigned expressions, including other symbols:
symbol a("a"), b("b");
ex e = a + 2*b;
cout << e << endl;
// prints "2*b+a"
cout << e.eval() << endl;
// prints "2*bar+foo", the eval() is necessary
/ Physics is an algorithm
More information about the GiNaC-list