[GiNaC-list] [[1]]!=1 ??

Sheplyakov Alexei varg at theor.jinr.ru
Sat Mar 18 10:05:31 CET 2006


Hello!

On Fri, Mar 17, 2006 at 07:52:15PM +0100, Javier Ros Ganuza wrote:
> 
> I suppose that it is a feature...

Exactly. Unit element of some algebra and number 1 are distinct objects,
so GiNaC _never_ performs implicit conversion of unit element of an
algebra to number 1 or vice a versa.

>  (matrix(3,1,lst(0,0,1)).transpose()*matrix(3,1,lst(0,0,1))).evalm()
> 
> gives a 1,1 matrix [[1]].

Yes, the product of matrices is a matrix of appropriate size.

> To convert it to a number or to a expression not containing a matrix, I
> have to take directly the 0,0 element of the matrix.
> 
> Is there a more direct method?

You could try to rewrite your expression[s] in a tensor-like form, e.g.

#include <iostream>
#include <ginac/ginac.h>
using namespace std;
using namespace GiNaC;

int main(int argc, char** argv)
{
	idx i(symbol("i"), 3);
	idx j(symbol("j"), 1);

	matrix A(1, 3);
	A = 0, 0, 1;
	ex e = indexed(A.transpose(), i, j)*indexed(A, j, i);
	cout << e << " ==> ";
	e = e.simplify_indexed();
	cout << e << endl;
}

On my system, this gives:

[[0],[0],[1]].i.j*[[0,0,1]].j.i ==> 1

> If not I'm facing errors like (in ginsh notation)
> 
> > a=[[0,0,1]]*[[0],[0],[1]];
> > a=evalm(a);
> [[1]]
> > 1+cos(a);
> add::eval(): sum of non-commutative objects has non-zero numeric term

Once again, GiNaC never performs implicit conversion of number 1 into
unit element of some algebra (in this case -- 1x1 matrices). 

Best regards,
 Alexei.

-- 
All science is either physics or stamp collecting.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.cebix.net/pipermail/ginac-list/attachments/20060318/d39631cb/attachment.pgp


More information about the GiNaC-list mailing list