Esempio n. 1
0
def test_contract_automatrix_and_data():
    numpy = import_module('numpy')
    if numpy is None:
        return

    L = TensorIndexType('L')
    S = TensorIndexType('S')
    G = tensorhead('G', [L, S, S], [[1] * 3], matrix_behavior=True)

    def G_data():
        G.data = [[[1]]]
    raises(ValueError, G_data)
    L.data = [1, -1]
    raises(ValueError, G_data)
    S.data = [[1, 0], [0, 2]]
    G.data = [
        [[1, 2],
         [3, 4]],
        [[5, 6],
         [7, 8]]
    ]
    m0, m1, m2 = tensor_indices('m0:3', L)
    s0, s1, s2 = tensor_indices('s0:3', S)

    assert (G(-m0).data == numpy.array([
       [[1, 4],
        [3, 8]],
       [[-5, -12],
        [-7, -16]]
    ])).all()

    (G(m0) * G(-m0)).data
    G(m0, s0, -s1).data

    c1 = G(m0, s0, -s1)*G(-m0, s1, -s2)
    c2 = G(m0) * G(-m0)

    assert (c1.data == c2.data).all()

    del L.data
    del S.data
    del G.data
    assert L.data is None
    assert S.data is None
    assert G.data is None
Esempio n. 2
0
def test_noncommuting_components():
    numpy = import_module("numpy")
    if numpy is None:
        skip("numpy not installed.")

    euclid = TensorIndexType('Euclidean')
    euclid.data = [1, 1]
    i1, i2, i3 = tensor_indices('i1:4', euclid)

    a, b, c, d = symbols('a b c d', commutative=False)
    V1 = tensorhead('V1', [euclid] * 2, [[1]]*2)
    V1.data = [[a, b], (c, d)]
    V2 = tensorhead('V2', [euclid] * 2, [[1]]*2)
    V2.data = [[a, c], [b, d]]

    vtp = V1(i1, i2) * V2(-i2, -i1)

    assert vtp == a ** 2 + b * c + c * b + d ** 2
    assert vtp != a**2 + 2*b*c + d**2

    Vc = b * V1(i1, -i1)
    assert Vc.expand() == b * a + b * d
Esempio n. 3
0
    assert check_all(tsymmetry)


### TEST VALUED TENSORS ###

numpy = import_module('numpy')

if numpy:
    minkowski = Matrix((
        (1, 0, 0, 0),
        (0, -1, 0, 0),
        (0, 0, -1, 0),
        (0, 0, 0, -1),
    ))
    Lorentz = TensorIndexType('Lorentz', dim=4)
    Lorentz.data = minkowski

    i0, i1, i2, i3, i4 = tensor_indices('i0:5', Lorentz)

    E, px, py, pz = symbols('E px py pz')
    A = tensorhead('A', [Lorentz], [[1]])
    A.data = [E, px, py, pz]
    B = tensorhead('B', [Lorentz], [[1]], 'Gcomm')
    B.data = range(4)
    AB = tensorhead("AB", [Lorentz] * 2, [[1]]*2)
    AB.data = minkowski

    ba_matrix = Matrix((
        (1, 2, 3, 4),
        (5, 6, 7, 8),
        (9, 0, -1, -2),
Esempio n. 4
0
    ret = sympy.Matrix(ret)
    return ret


a, d, p, f, fx, fy, t, g, d2, d4 = sympy.symbols('a d p f fx fy t g d2 d4')

q = 1 - p

f = 0

d_index = TensorIndexType('d_index', dummy_fmt='L')
z_index = TensorIndexType('z_index', dummy_fmt='L')

PJ = [1, 1, 1]

d_index.data = [[PJ[0], 0, 0], [0, PJ[1], 0], [0, 0, PJ[2]]]
#d_index.data = [ [1, 0.5, 0], [0.5, 1, 0.5], [0, 0.5, 1 ] ]
print d_index.metric

P = tensorhead('P', [d_index, d_index, d_index], [[1], [1], [1]])
#R = tensorhead('R', [d_index, d_index], [[1], [1]])
R = tensorhead('R', [d_index, d_index, d_index, d_index], [[1], [1], [1], [1]])

S1 = tensorhead('S1', [d_index], [[1]])
S = tensorhead('S', [d_index, d_index], [[1], [1]])
#I = tensorhead('I', [d_index, d_index, d_index, d_index], [[1],[1],[1],[1]])

I = tensorhead(
    'I',
    [d_index, d_index, d_index, d_index, d_index, d_index, d_index, d_index],
    [[1], [1], [1], [1], [1], [1], [1], [1]])
Esempio n. 5
0
from sympy.tensor.tensor import tensor_indices, tensorhead, TensorIndexType, TensorType
import sympy

d_index = TensorIndexType('d_index', dummy_fmt='L')
#z_index = TensorIndexType('z_index', dummy_fmt='L')

P = tensorhead('P', [d_index, d_index, d_index], [[1], [1], [1]])
R = tensorhead('R', [d_index, d_index, d_index, d_index], [[1], [1], [1], [1]])
#I = tensorhead('I', [z_index, z_index, z_index, z_index], [[1]])

d_index.data = [1, 1, 1]

b0, b1, b2, b3, b4, b5 = tensor_indices('b0:6', d_index)
#	    00   01   02
#           10   11   12
#           20   21   22
P.data = [
    [
        [1.0, 0.5, 0.0],
        [0.5, .25, 0.0],  #=0
        [0.0, 0.0, 0.0]
    ],
    [
        [0.0, 0.5, 1.0],
        [0.5, 0.5, 0.5],  #=1
        [1.0, 0.5, 0.0]
    ],
    [
        [0.0, 0.0, 0.0],
        [0.0, .25, 0.5],  #=2
        [0.0, 0.5, 1.0]
Esempio n. 6
0
    assert check_all(tsymmetry)


### TEST VALUED TENSORS ###

numpy = import_module('numpy')

if numpy:
    minkowski = Matrix((
        (1, 0, 0, 0),
        (0, -1, 0, 0),
        (0, 0, -1, 0),
        (0, 0, 0, -1),
    ))
    Lorentz = TensorIndexType('Lorentz', dim=4)
    Lorentz.data = minkowski

    i0, i1, i2, i3, i4 = tensor_indices('i0:5', Lorentz)

    E, px, py, pz = symbols('E px py pz')
    A = tensorhead('A', [Lorentz], [[1]])
    A.data = [E, px, py, pz]
    B = tensorhead('B', [Lorentz], [[1]], 'Gcomm')
    B.data = range(4)
    AB = tensorhead("AB", [Lorentz] * 2, [[1]] * 2)
    AB.data = minkowski

    ba_matrix = Matrix((
        (1, 2, 3, 4),
        (5, 6, 7, 8),
        (9, 0, -1, -2),