Hello, On Wed, Sep 16, 2009 at 10:46:34AM -0400, jros wrote:
We now that for matrix class objects A, GiNaC simplifies
matrix A; cout << A-A << endl;
give 0
The same way that
symbol a cout << a-a << endl;
gives 0
But I think that for coherence
matrix A; cout << A*pow(A,-1) << endl;
should give 1,
First of all, GiNaC does not evaluate matrix products and powers automatically, one should call evalm() for that (this is documented in the manual, see http://www.ginac.de/tutorial/Matrices.html#Matrices). Secondly, the expression is ill defined because A is zero (on the other hand, A - A is OK).
(I mean reduced to numeric(1) regardless the particular form of A,
The expression above is a matrix. Why should we replace it with a number?
the same way as
symbol a cout << a*pow(a,-1) << endl;
is 1
By the way it would be wonderful if A-A give matrix-es instead of numeric-s, although I think you've already had long discussions about that.
I agree, it's nice, but also it's very difficult to implement in any *useful* way.
PD: I wouldn't mind to derive a class from matrix to change this behavior the easy way, but I don't know if this can be done this way.
The expr - expr => 0 transformations are done by the `add' class, and the expr/expr => 1 transformation is done by the `mul' class, respectively. Therefore subclassing matrix won't help. Best regards, Alexei