Hi, I am wondering how to convince GiNaC that the following to expressions are equal: [[-1,0],[0,1]~mu~mu * a~mu [[-1,0],[0,1].nu~mu * a~nu Thanks for an advice, Vladimir -- Vladimir V. Kisil email: kisilv@maths.leeds.ac.uk -- www: http://maths.leeds.ac.uk/~kisilv/
Hello, On Mon, Apr 25, 2005 at 03:06:56PM +0100, Vladimir Kisil wrote:
I am wondering how to convince GiNaC that the following to expressions are equal:
[[-1,0],[0,1]~mu~mu * a~mu [[-1,0],[0,1].nu~mu * a~nu
First of all, I'm wondering how to convince _me_ that those expressions are equal: the second expression is a vector, and the first one looks like diagonal elements of a tensor of the 3'rd rank. Second. Probably, you expected that [[-1,0],[0,1]~mu~mu * a~mu is [-a~0, a~1]. [[-1, 0], [0, 1]].nu~mu * a~nu is [ -a~0, a~1] too. But that is NOT the case with GiNaC. In general: expression a.i a~i has very little to do with a_0 a_0 - a_1 a_1 - ... - a_N a_N for a good reason (GiNaC is (was?) a library for calculation of Feynman integrals, so dimension of indices are NOT required to be positive integers). N.B.: The `matrix' class CAN be used with indices to do some simple linear algebra (probably, just to add more confusion). But this code #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; return 0; } gives [[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 (once again: first expression is a tensor 3'rd rank, while second expression is a vector) So, (unless I'm missing something fundamental) you are out of luck... -- ROOT: an octopus made by nailing extra legs onto a cat.
Dear Alexei, Thanks for the explanations. 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? I would prefer if not all objects with indexes in GiNaC will be necessarily a tensors. 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. Thanks, Vladimir -- Vladimir V. Kisil email: kisilv@maths.leeds.ac.uk -- www: http://maths.leeds.ac.uk/~kisilv/
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.
participants (2)
-
varg@theor.jinr.ru
-
Vladimir Kisil