def test_tensor_element(): L = TensorIndexType("L") i, j, k, l, m, n = tensor_indices("i j k l m n", L) A = TensorHead("A", [L, L], TensorSymmetry.no_symmetry(2)) a = A(i, j) assert isinstance(TensorElement(a, {}), Tensor) assert isinstance(TensorElement(a, {k: 1}), Tensor) te1 = TensorElement(a, {Symbol("i"): 1}) assert te1.free == [(j, 0)] assert te1.get_free_indices() == [j] assert te1.dum == [] te2 = TensorElement(a, {i: 1}) assert te2.free == [(j, 0)] assert te2.get_free_indices() == [j] assert te2.dum == [] assert te1 == te2 array = Array([[1, 2], [3, 4]]) assert te1.replace_with_arrays({A(i, j): array}, [j]) == array[1, :]
def test_gamma_matrix_class(): i, j, k = tensor_indices("i,j,k", LorentzIndex) # define another type of TensorHead to see if exprs are correctly handled: A = TensorHead("A", [LorentzIndex]) t = A(k) * G(i) * G(-i) ts = simplify_gamma_expression(t) assert _is_tensor_eq( ts, Matrix([[4, 0, 0, 0], [0, 4, 0, 0], [0, 0, 4, 0], [0, 0, 0, 4]]) * A(k) ) t = G(i) * A(k) * G(j) ts = simplify_gamma_expression(t) assert _is_tensor_eq(ts, A(k) * G(i) * G(j)) execute_gamma_simplify_tests_for_function(simplify_gamma_expression, D=4)
from sympy.tensor.toperators import PartialDerivative from sympy.tensor.tensor import (TensorIndexType, tensor_indices, TensorHead, tensor_heads) from sympy import symbols, diag from sympy import Array, Rational from random import randint L = TensorIndexType("L") i, j, k, m, m1, m2, m3, m4 = tensor_indices("i j k m m1 m2 m3 m4", L) i0 = tensor_indices("i0", L) L_0, L_1 = tensor_indices("L_0 L_1", L) A, B, C, D = tensor_heads("A B C D", [L]) H = TensorHead("H", [L, L]) def test_invalid_partial_derivative_valence(): raises(ValueError, lambda: PartialDerivative(C(j), D(-j))) raises(ValueError, lambda: PartialDerivative(C(-j), D(j))) def test_tensor_partial_deriv(): # Test flatten: expr = PartialDerivative(PartialDerivative(A(i), A(j)), A(i)) assert expr.expr == A(L_0) assert expr.variables == (A(j), A(L_0)) expr1 = PartialDerivative(A(i), A(j)) assert expr1.expr == A(i)
metric(LorentzIndex,LorentzIndex) """ from sympy.core.mul import Mul from sympy.core.singleton import S from sympy.matrices.dense import eye from sympy.matrices.expressions.trace import trace from sympy.tensor.tensor import TensorIndexType, TensorIndex,\ TensMul, TensAdd, tensor_mul, Tensor, TensorHead, TensorSymmetry # DiracSpinorIndex = TensorIndexType('DiracSpinorIndex', dim=4, dummy_name="S") LorentzIndex = TensorIndexType('LorentzIndex', dim=4, dummy_name="L") GammaMatrix = TensorHead("GammaMatrix", [LorentzIndex], TensorSymmetry.no_symmetry(1), comm=None) def extract_type_tens(expression, component): """ Extract from a ``TensExpr`` all tensors with `component`. Returns two tensor expressions: * the first contains all ``Tensor`` of having `component`. * the second contains all remaining. """ if isinstance(expression, Tensor):