[GiNaC-list] setting and getting numeric values from indexed expressions

Chris Dams Chris.Dams at mi.infn.it
Fri Jul 28 07:30:38 CEST 2006

Dear Alejandro,

On Thu, 27 Jul 2006, Alejandro Limache wrote:

>           // -> [[-13,-6],[1,2]].i.j
> Is there a way to get the numeric values of each of the components of e?
> I would like to be able to do something like
>          double d;
>          d = e(0,0);
> to get:
>          d=-13


You should only do that if you are certain that the relevant matrix entry
is numeric or all hell will break loose. Safer is to first do a test:
if (is_a<numeric>(....))
> 2) Can something similar be done for indexed expression not defined as 
> matrices?
> For example given something like
>          symbol  A("A")....
>          idx i(.., 3), j(.., 3), k(..,10);
>          ex e = indexed(A,i,j,k)
> could I set for example: i=2, j=0, k=4 and set A(2,0,4)=3.5 ?
> could I then somehow get the value "3.5" back?

Not directly. The closest that you can get to that is keeping an exmap m
and say m[A(2,0,4)] = 3.5 and then do .subs(m) in an expression where you
have unrolled the dummy indices. With the dimensions you give above this
could get a costly though. If you don't have any patterns in the exmap you
could use the option subs_options::no_pattern to speed it up a quite bit.
Best wishes,

More information about the GiNaC-list mailing list