[GiNaC-list] Equal indexed expressions

Sheplyakov Alexei varg at theor.jinr.ru
Tue Apr 26 09:02:34 CEST 2005


On Mon, Apr 25, 2005 at 07:04:29PM +0100, Vladimir Kisil wrote:

> 	I added to your code just two lines  at the end:
> 
> #include <iostream>
> #include <ginac/ginac.h>
> using namespace std;
> using namespace GiNaC;
> 
> int main(int argc, char** argv)
> {
> 	varidx i(symbol("i"), 2);
> 	varidx j(symbol("j"), 2);
> 
> 	matrix mink2_matr(2, 2, lst(-1, 0, 0, 1));
> 	matrix a(1, 2, lst(symbol("a0"), symbol("a1")));
> 
> 	ex test1 = indexed(mink2_matr, i, i)*indexed(a, i);
> 	ex test2 = indexed(mink2_matr, j.toggle_variance(), i)*indexed(a, j);
> 
> 	cout << test1 << " = " << test1.simplify_indexed() << endl;
> 	cout << test2 << " = " << test2.simplify_indexed() << endl;
> 	cout << "test1 substituted = " << test1.simplify_indexed().subs(i == varidx(0, 2)) << endl;
> 	cout << "test2 substituted = " << test2.simplify_indexed().subs(i == varidx(0, 2)) << endl;
> 	return 0;
> }
> 
>   and the output now becomes:
> 
> [[a0,a1]]~i*[[-1,0],[0,1]]~i~i = [[a0,a1]]~i*[[-1,0],[0,1]]~i~i
> [[a0,a1]]~j*[[-1,0],[0,1]].j~i = [[-a0,a1]]~i
> test1 substituted = -a0
> test2 substituted = -a0
> 
>   i.e., the initial difference between objects disappeared after the
>   substitution was made. Should it be classified as a bug?

After substitution expression is not an indexed object any more,
you get just particular element of a matrix (see ginac/matrix.cpp::eval_indexed)

I think this is intended (but rather confusing) behaviour. Most 
indexed objects in GiNaC are tensors,  while some are arrays
(like indexed matrices). Expression

indexed(m, i, j)

means _different_ things for tensors and arrays. Unfortunately, 
mixing tensors and arrays (like some_matrix~i*some_vector.i) does NOT
raise an exception (or compile-time error), thus, it is possible
to write a lot of meaningless expressions :(

> I would prefer if not all objects with indexes in GiNaC will 
> be necessarily a tensors. 

I would prefer if tensors and arrays would be completely different
(have different types), so both tensor and array expressions are 
possible [and type-safe], but meaningless mixtures of both are not.

> I had already a code which expand dummy-index summations in order
> to see "equality" (in non-tensor sense) similar to above, but I wish
> to check, that this cannot be already done by some standard tools.

You could use indexed matrices or write your own tensor (like tensdelta,
tensepsilon and friends, see ginac/tensor.{cpp,h}).

-- 
ROOT: an octopus made by nailing extra legs onto a cat.





More information about the GiNaC-list mailing list