def test_index_contraction2(): _type = (2, 1) basis = [t, x, y, z] dim = len(basis) c_indices = gr.get_all_multiindices(2, 4) ct_indices = gr.get_all_multiindices(1, 4) dict_of_values = {(a, b): 2**a[0] * 3**a[1] * 5**b[0] for a in c_indices for b in ct_indices} tensor = gr.Tensor(basis, _type, dict_of_values) contracted_tensor_1 = gr.contract_indices(tensor, 1, 0) dict_of_values2 = {((a, ), ()): sum([2**a * 3**r * 5**r for r in range(dim)]) for a in range(dim)} contracted_tensor_2 = gr.Tensor(basis, (1, 0), dict_of_values2) assert contracted_tensor_1 == contracted_tensor_2
def test_index_contraction1(): _type = (2, 2) indices = gr.get_all_multiindices(2, 4) dict_of_values = {(a, b): sum(a) / (sum(b) + 1) for a in indices for b in indices} basis = [t, x, y, z] tensor = gr.Tensor(basis, _type, dict_of_values) new_tensor = gr.contract_indices(tensor, 1, 0) other_indices = gr.get_all_multiindices(1, 4) other_dict_of_values = {(a, b): sum([(sum(a) + r) / (sum(b) + r + 1) for r in range(4)]) for a in other_indices for b in other_indices} other_tensor = gr.Tensor(basis, (1, 1), other_dict_of_values) assert other_tensor == new_tensor
def test_lower_index1(): _type = (2, 1) basis = [t, x, y, z] dim = len(basis) c_indices = gr.get_all_multiindices(2, 4) ct_indices = gr.get_all_multiindices(1, 4) dict_of_values = {(a, b): 2**a[0] * 3**a[1] * 5**b[0] for a in c_indices for b in ct_indices} tensor = gr.Tensor(basis, _type, dict_of_values) metric = gr.get_tensor_from_matrix(sympy.diag(-1, 1, 1, 1), basis) lowered_tensor_1 = gr.lower_index(tensor, metric, 1) _type2 = (1, 2) ct_indices_2 = gr.get_all_multiindices(1, 4) c_indices_2 = gr.get_all_multiindices(2, 4) dict_of_values_2 = {(a, b): sum( [metric[(), (r, b[0])] * tensor[(a[0], r), b[1]] for r in range(dim)]) for a in ct_indices_2 for b in c_indices_2} lowered_tensor_2 = gr.Tensor(basis, _type2, dict_of_values_2) assert lowered_tensor_1 == lowered_tensor_2
def test_raise_index1(): _type = (2, 1) basis = [t, x, y, z] dim = len(basis) c_indices = gr.get_all_multiindices(2, 4) ct_indices = gr.get_all_multiindices(1, 4) dict_of_values = {(a, b): 2**a[0] * 3**a[1] * 5**b[0] for a in c_indices for b in ct_indices} tensor = gr.Tensor(basis, _type, dict_of_values) metric = gr.get_tensor_from_matrix(sympy.diag(-1, 1, 1, 1), basis) raised_tensor_1 = gr.raise_index(tensor, metric, 0) inv_metric = gr.get_matrix_from_tensor(metric).inv() _type2 = (3, 0) c_indices_2 = gr.get_all_multiindices(3, 4) ct_indices_2 = gr.get_all_multiindices(0, 4) dict_of_values_2 = {(a, b): sum( [inv_metric[r, a[2]] * tensor[(a[0], a[1]), r] for r in range(dim)]) for a in c_indices_2 for b in ct_indices_2} raised_tensor_2 = gr.Tensor(basis, _type2, dict_of_values_2) assert raised_tensor_1 == raised_tensor_2