Changing symbol string names on-the-fly

Christian Bauer Christian.Bauer at Uni-Mainz.DE
Thu Jul 10 17:36:11 CEST 2003


On Thu, Jul 10, 2003 at 10:05:46AM +0100, Dr. Vassilis S. Vassiliadis wrote:
> thanks for the tips.  I shall try your suggestions today.

Addendum: You can actually use symbol::set_name(), but then you have to
know exactly what your objects are.

For example, the naive approach doesn't work:

    symbol a("a"), b("b");
    ex e = a + 2*b;
    a.set_name("foo"); b.set_name("bar");
    cout << e << endl;
     // prints "2*b+a"

because the symbol objects in the expression are heap-allocated copies
of "a" and "b", but this works:

    symbol &a_sym = *new symbol("a"); a_sym.setflag(status_flags::dynallocated);
    symbol &b_sym = *new symbol("b"); b_sym.setflag(status_flags::dynallocated);
    ex a = a_sym, b = b_sym;
    ex e = a + 2*b;
    a_sym.set_name("foo"); b_sym.set_name("bar");
    cout << e << endl;
     // prints "2*bar+foo"

> One issue: I think yes, the .subs() method should use maps or some hash
> structure to speed things up.

I'll have a look at it.


  / Physics is an algorithm

More information about the GiNaC-list mailing list