On Friday, October 31, 2014 8:16:35 PM UTC+1, Jamie Titus wrote:
>
> I think the most instructive thing that I found confusing is was my
> attempt to symmetrize a tensor. This minimal snippet, taken almost entirely
> from the examples in documentation, should demonstrate my point.
> from sympy import *
> from sympy.tensor.tensor import TensorIndexType, tensorsymmetry,
> TensorType
>
> Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
> sym2 = tensorsymmetry([1]*2)
> S2 = TensorType([Lorentz]*2, sym2)
> A = S2('A')
> from sympy.tensor.tensor import tensor_indices, tensorhead
> Lorentz.data = [1, -1, -1, -1]
> i0, i1 = tensor_indices('i0:2', Lorentz)
> A.data = [[j+2*i for j in range(2)] for i in range(2)]
> A.data
> A_symm = A(i0, i1) + A(i1, i0)
> A_symm.data
>
> A.data is [[0, 1], [2, 3]], One would want A_symm.data to be [[0, 3],[3,
> 6]], a symmetric tensor. However, Sympy is computing it as 2*A. Indeed,
> that is exactly how sympy represents A_symm.
>
>
You declare *A *to be symmetric, but you add non-symmetric data to it. The
code should raise an error on the assignment, I am aware of this problem,
the solution of which requires the canonicalizer to support repeated
indices.
If you call *tensorsymmetry([1]*2)* which is equivalent to
*tensorsymmetry([1,1])*, you declare the indices to be symmetric, so A(i0,
i1) = A(i1, i0). Use *tensorsymmetry([1], [1])* if you don't want that.
In [28]: tensorsymmetry([1,1]).generators
Out[28]: (Permutation(3)(0, 1),)
In [29]: tensorsymmetry([1],[1]).generators
Out[29]: (Permutation(3),)
You see, in Out[28] there is a permutation (0, 1), meaning that the first
and second indices can be permuted. In Out[29] there is no permutation,
meaning that A(i0, i1) would be unequal to A(i1, i0).
I start off with this example because I am genuinely not sure if this is
> the intended behaviour, since it is unclear to me whether or not the Tensor
> module is supposed to support typical Einstein notation. If this is a
> "bug," then there are many things which must be tested and fixed. If this
> is a "feature," then I probably need to look for a different module to do
> GR with.
>
>
The approach to the tensor module is very ambitious, support both symbolic
tensor expressions and component data, be coordinate-independent yet allow
to operate on coordinate bases. A more challenging point would be to add
support to covariant and partial derivatives. Unfortunately this requires a
lot of time. The algorithm to handle the symbolic index structure is quite
complicated.
In *sympy.diffgeom* you simply work on the components of a tensor using the
*TensorProduct* object. You don't have a compact expression as A(i0, i1),
but you can do partial, covariant and Lie derivatives, which are currently
unsupported in *sympy.tensor.tensor*.
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/b1b7eb06-13ad-4789-a721-11ec17abd0b2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.