If I subtract two equal matrices, I get the scalar 0. This messes up later calculations, since a scalar doesn't have op(i), transpose(), etc. If I do a+(-b) instead of a-b, I get a zero matrix as wanted. Note that the code is in Python using the swiginac bindings, which now calls evalm() automatically between operations. In [32]: m = matrix(2,2,[x,0,0,0]) In [33]: m-m Out[33]: 0 In [34]: m+(-m) Out[34]: [[0,0],[0,0]] So we have the silly relation that "a-b != a+(-b)", which can only be called a bug. -- --- Martin Sandve Alnæs PhD student, Cardiac Computations Simula Research Laboratory, Norway
Hello! On Thu, Mar 22, 2007 at 09:44:03AM +0100, Martin Sandve Alnæs wrote:
If I subtract two equal matrices, I get the scalar 0.
In GiNaC (A-A) is always transformed into 0 (number). I admit this is ugly, but fixing it would be very difficult (if possible at all).
This messes up later calculations, since a scalar doesn't have op(i),
numeric::nops() returns zero, so loops like this for (size_t i = 0; i < e.nops(); ++i) { // do something } should work fine.
transpose(), etc.
You have to explicitly check for .is_zero().
If I do a+(-b) instead of a-b, I get a zero matrix as wanted.
Interesting. I get zero (a number) in both ways: $ cat test_matr_minus.cpp #include <iostream> #include <ginac/ginac.h> using namespace std; using namespace GiNaC; int main(int argc, char** argv) { matrix a(2, 2); a = 1, 2, 3, 4; cout << "a = " << a << endl; ex test = a - a; cout << "a - a = " << test << endl; ex test2 = a + (-a); cout << "a + (-a) = " << test2 << endl; return 0; } $ g++ test_matr_minus.cpp -lginac $ ./a.out a = [[1,2],[3,4]] a - a = 0 a + (-a) = 0 Best regards, Alexei -- All science is either physics or stamp collecting.
2007/3/22, Sheplyakov Alexei <varg@theor.jinr.ru>:
Hello!
On Thu, Mar 22, 2007 at 09:44:03AM +0100, Martin Sandve Alnæs wrote:
If I subtract two equal matrices, I get the scalar 0.
In GiNaC (A-A) is always transformed into 0 (number). I admit this is ugly, but fixing it would be very difficult (if possible at all).
I see.
If I do a+(-b) instead of a-b, I get a zero matrix as wanted.
Interesting. I get zero (a number) in both ways:
Seems like the matrix with zeros only happens when using the swiginac bindings, so techniqually the bug is there. Thanks for the quick response, anyway. martin
Hi, I am a co-developer of swiginac. The bug is probably there. But, exactly as Alexei said, A-A = 0 is ugly, but, but fixing it would be very difficult (if possible at all). That's why I decided to rewrite the whole GiNaC in python directly: http://code.google.com/p/sympy/ And in SymPy, you can do: In [1]: m = Matrix(2,2,[x,0,0,0]) In [2]: m Out[2]: x 0 0 0 In [3]: m-m Out[3]: 0 0 0 0 In [4]: m+(-m) Out[4]: 0 0 0 0 Ondrej On 3/22/07, Martin Sandve Alnæs <martinal@simula.no> wrote:
2007/3/22, Sheplyakov Alexei <varg@theor.jinr.ru>:
Hello!
On Thu, Mar 22, 2007 at 09:44:03AM +0100, Martin Sandve Alnæs wrote:
If I subtract two equal matrices, I get the scalar 0.
In GiNaC (A-A) is always transformed into 0 (number). I admit this is ugly, but fixing it would be very difficult (if possible at all).
I see.
If I do a+(-b) instead of a-b, I get a zero matrix as wanted.
Interesting. I get zero (a number) in both ways:
Seems like the matrix with zeros only happens when using the swiginac bindings, so techniqually the bug is there.
Thanks for the quick response, anyway.
martin _______________________________________________ GiNaC-list mailing list GiNaC-list@ginac.de https://www.cebix.net/mailman/listinfo/ginac-list
2007/3/25, Ondrej Certik <ondrej@certik.cz>:
Hi, I am a co-developer of swiginac. The bug is probably there. But, exactly as Alexei said, A-A = 0 is ugly, but, but fixing it would be very difficult (if possible at all). That's why I decided to rewrite the whole GiNaC in python directly:
Interesting, I'll look into it later. Another alternative I considering for my application is to use swiginac for scalar expressions only, and provide matrix functionality on top in Python. -- --- Martin Sandve Alnæs PhD student, Cardiac Computations Simula Research Laboratory, Norway
participants (3)
-
Martin Sandve Alnæs
-
Ondrej Certik
-
varg@theor.jinr.ru