コード例 #1
0
def test_fun():
    D = Symbol('D')
    Lorentz = TensorIndexType('Lorentz', dim=D, dummy_fmt='L')
    a, b, c, d, e = tensor_indices('a,b,c,d,e', Lorentz)
    g = Lorentz.metric

    p, q = tensorhead('p q', [Lorentz], [[1]])
    t = q(c) * p(a) * q(b) + g(a, b) * g(c, d) * q(-d)
    assert t(a, b, c) == t
    assert t - t(b, a, c) == q(c) * p(a) * q(b) - q(c) * p(b) * q(a)
    assert t(b, c, d) == q(d) * p(b) * q(c) + g(b, c) * g(d, e) * q(-e)
    t1 = t.fun_eval((a, b), (b, a))
    assert t1 == q(c) * p(b) * q(a) + g(a, b) * g(c, d) * q(-d)

    # check that g_{a b; c} = 0
    # example taken from  L. Brewin
    # "A brief introduction to Cadabra" arxiv:0903.2085
    # dg_{a b c} = \partial_{a} g_{b c} is symmetric in b, c
    dg = tensorhead('dg', [Lorentz] * 3, [[1], [1] * 2])
    # gamma^a_{b c} is the Christoffel symbol
    gamma = S.Half * g(a,
                       d) * (dg(-b, -d, -c) + dg(-c, -b, -d) - dg(-d, -b, -c))
    # t = g_{a b; c}
    t = dg(-c, -a,
           -b) - g(-a, -d) * gamma(d, -b, -c) - g(-b, -d) * gamma(d, -a, -c)
    t = t.contract_metric(g, True)
    assert t == 0
    t = q(c) * p(a) * q(b)
    assert t(b, c, d) == q(d) * p(b) * q(c)
コード例 #2
0
ファイル: test_tensor.py プロジェクト: MarcdeFalco/sympy
def test_TensorManager():
    Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
    LorentzH = TensorIndexType('LorentzH', dummy_fmt='LH')
    i, j = tensor_indices('i,j', Lorentz)
    ih, jh = tensor_indices('ih,jh', LorentzH)
    p, q = tensorhead('p q', [Lorentz], [[1]])
    ph, qh = tensorhead('ph qh', [LorentzH], [[1]])

    Gsymbol = Symbol('Gsymbol')
    GHsymbol = Symbol('GHsymbol')
    TensorManager.set_comm(Gsymbol, GHsymbol, 0)
    G = tensorhead('G', [Lorentz], [[1]], Gsymbol)
    assert TensorManager._comm_i2symbol[G.comm] == Gsymbol
    GH = tensorhead('GH', [LorentzH], [[1]], GHsymbol)
    ps = G(i)*p(-i)
    psh = GH(ih)*ph(-ih)
    t = ps + psh
    t1 = t*t
    assert t1 == ps*ps + 2*ps*psh + psh*psh
    qs = G(i)*q(-i)
    qsh = GH(ih)*qh(-ih)
    assert ps*qsh == qsh*ps
    assert ps*qs != qs*ps
    n = TensorManager.comm_symbols2i(Gsymbol)
    assert TensorManager.comm_i2symbol(n) == Gsymbol

    assert GHsymbol in TensorManager._comm_symbols2i
    raises(ValueError, lambda: TensorManager.set_comm(GHsymbol, 1, 2))
    TensorManager.set_comms((Gsymbol,GHsymbol,0),(Gsymbol,1,1))
    assert TensorManager.get_comm(n, 1) == TensorManager.get_comm(1, n) == 1
    TensorManager.clear()
    assert TensorManager.comm == [{0:0, 1:0, 2:0}, {0:0, 1:1, 2:None}, {0:0, 1:None}]
    assert GHsymbol not in TensorManager._comm_symbols2i
    nh = TensorManager.comm_symbols2i(GHsymbol)
    assert GHsymbol in TensorManager._comm_symbols2i
コード例 #3
0
ファイル: test_tensor.py プロジェクト: MarcdeFalco/sympy
def test_special_eq_ne():
    # test special equality cases:
    Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
    a,b,d0,d1,i,j,k = tensor_indices('a,b,d0,d1,i,j,k', Lorentz)
    # A, B symmetric
    A, B = tensorhead('A,B', [Lorentz]*2, [[1]*2])
    p, q, r = tensorhead('p,q,r', [Lorentz], [[1]])

    t = 0*A(a, b)
    assert t == 0
    assert t == S.Zero

    assert p(i) != A(a, b)
    assert A(a, -a) != A(a, b)
    assert 0*(A(a, b) + B(a, b)) == 0
    assert 0*(A(a, b) + B(a, b)) == S.Zero

    assert 3*(A(a, b) - A(a, b)) == S.Zero

    assert p(i) + q(i) != A(a, b)
    assert p(i) + q(i) != A(a, b) + B(a, b)

    assert p(i) - p(i) == 0
    assert p(i) - p(i) == S.Zero

    assert A(a, b) == A(b, a)
コード例 #4
0
def test_special_eq_ne():
    # test special equality cases:
    Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
    a, b, d0, d1, i, j, k = tensor_indices('a,b,d0,d1,i,j,k', Lorentz)
    # A, B symmetric
    A, B = tensorhead('A,B', [Lorentz] * 2, [[1] * 2])
    p, q, r = tensorhead('p,q,r', [Lorentz], [[1]])

    t = 0 * A(a, b)
    assert t == 0
    assert t == S.Zero

    assert p(i) != A(a, b)
    assert A(a, -a) != A(a, b)
    assert 0 * (A(a, b) + B(a, b)) == 0
    assert 0 * (A(a, b) + B(a, b)) == S.Zero

    assert 3 * (A(a, b) - A(a, b)) == S.Zero

    assert p(i) + q(i) != A(a, b)
    assert p(i) + q(i) != A(a, b) + B(a, b)

    assert p(i) - p(i) == 0
    assert p(i) - p(i) == S.Zero

    assert A(a, b) == A(b, a)
コード例 #5
0
ファイル: test_tensor.py プロジェクト: MarcdeFalco/sympy
def test_fun():
    D = Symbol('D')
    Lorentz = TensorIndexType('Lorentz', dim=D, dummy_fmt='L')
    a,b,c,d,e = tensor_indices('a,b,c,d,e', Lorentz)
    g = Lorentz.metric

    p, q = tensorhead('p q', [Lorentz], [[1]])
    t = q(c)*p(a)*q(b) + g(a,b)*g(c,d)*q(-d)
    assert t(a,b,c) == t
    assert t - t(b,a,c) == q(c)*p(a)*q(b) - q(c)*p(b)*q(a)
    assert t(b,c,d) == q(d)*p(b)*q(c) + g(b,c)*g(d,e)*q(-e)
    t1 = t.fun_eval((a,b),(b,a))
    assert t1 == q(c)*p(b)*q(a) + g(a,b)*g(c,d)*q(-d)

    # check that g_{a b; c} = 0
    # example taken from  L. Brewin
    # "A brief introduction to Cadabra" arxiv:0903.2085
    # dg_{a b c} = \partial_{a} g_{b c} is symmetric in b, c
    dg = tensorhead('dg', [Lorentz]*3, [[1], [1]*2])
    # gamma^a_{b c} is the Christoffel symbol
    gamma = S.Half*g(a,d)*(dg(-b,-d,-c) + dg(-c,-b,-d) - dg(-d,-b,-c))
    # t = g_{a b; c}
    t = dg(-c,-a,-b) - g(-a,-d)*gamma(d,-b,-c) - g(-b,-d)*gamma(d,-a,-c)
    t = t.contract_metric(g, True)
    assert t == 0
    t = q(c)*p(a)*q(b)
    assert t(b,c,d) == q(d)*p(b)*q(c)
コード例 #6
0
ファイル: test_tensor.py プロジェクト: MarcdeFalco/sympy
def test_add2():
    Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
    m, n, p, q = tensor_indices('m,n,p,q', Lorentz)
    R = tensorhead('R', [Lorentz]*4, [[2, 2]])
    A = tensorhead('A', [Lorentz]*3, [[3]])
    t1 = 2*R(m, n, p, q) - R(m, q, n, p) + R(m, p, n, q)
    t2 = t1*A(-n, -p, -q)
    assert t2 == 0
    t1 = S(2)/3*R(m,n,p,q) - S(1)/3*R(m,q,n,p) + S(1)/3*R(m,p,n,q)
    t2 = t1*A(-n, -p, -q)
    assert t2 == 0
    t = A(m, -m, n) + A(n, p, -p)
    assert t == 0
コード例 #7
0
ファイル: test_tensor.py プロジェクト: aterrel/sympy
def test_add2():
    Lorentz = TensorIndexType("Lorentz", dummy_fmt="L")
    m, n, p, q = tensor_indices("m,n,p,q", Lorentz)
    R = tensorhead("R", [Lorentz] * 4, [[2, 2]])
    A = tensorhead("A", [Lorentz] * 3, [[3]])
    t1 = 2 * R(m, n, p, q) - R(m, q, n, p) + R(m, p, n, q)
    t2 = t1 * A(-n, -p, -q)
    assert t2 == 0
    t1 = S(2) / 3 * R(m, n, p, q) - S(1) / 3 * R(m, q, n, p) + S(1) / 3 * R(m, p, n, q)
    t2 = t1 * A(-n, -p, -q)
    assert t2 == 0
    t = A(m, -m, n) + A(n, p, -p)
    assert t == 0
コード例 #8
0
def test_add2():
    Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
    m, n, p, q = tensor_indices('m,n,p,q', Lorentz)
    R = tensorhead('R', [Lorentz] * 4, [[2, 2]])
    A = tensorhead('A', [Lorentz] * 3, [[3]])
    t1 = 2 * R(m, n, p, q) - R(m, q, n, p) + R(m, p, n, q)
    t2 = t1 * A(-n, -p, -q)
    assert t2 == 0
    t1 = S(2) / 3 * R(m, n, p, q) - S(1) / 3 * R(m, q, n, p) + S(1) / 3 * R(
        m, p, n, q)
    t2 = t1 * A(-n, -p, -q)
    assert t2 == 0
    t = A(m, -m, n) + A(n, p, -p)
    assert t == 0
コード例 #9
0
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], [[1], [1]])

    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, :]
コード例 #10
0
ファイル: test_tensor.py プロジェクト: aterrel/sympy
def test_canonicalize2():
    D = Symbol("D")
    Eucl = TensorIndexType("Eucl", metric=0, dim=D, dummy_fmt="E")
    i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14 = tensor_indices("i0:15", Eucl)
    A = tensorhead("A", [Eucl] * 3, [[3]])

    # two examples from Cvitanovic, Group Theory page 59
    # of identities for antisymmetric tensors of rank 3
    # contracted according to the Kuratowski graph  eq.(6.59)
    t = A(i0, i1, i2) * A(-i1, i3, i4) * A(-i3, i7, i5) * A(-i2, -i5, i6) * A(-i4, -i6, i8)
    t1 = t.canon_bp()
    assert t1 == 0

    # eq.(6.60)
    # t = A(i0,i1,i2)*A(-i1,i3,i4)*A(-i2,i5,i6)*A(-i3,i7,i8)*A(-i6,-i7,i9)*
    #    A(-i8,i10,i13)*A(-i5,-i10,i11)*A(-i4,-i11,i12)*A(-i3,-i12,i14)
    t = (
        A(i0, i1, i2)
        * A(-i1, i3, i4)
        * A(-i2, i5, i6)
        * A(-i3, i7, i8)
        * A(-i6, -i7, i9)
        * A(-i8, i10, i13)
        * A(-i5, -i10, i11)
        * A(-i4, -i11, i12)
        * A(-i9, -i12, i14)
    )
    t1 = t.canon_bp()
    assert t1 == 0
コード例 #11
0
ファイル: test_tensor.py プロジェクト: aterrel/sympy
def test_riemann_invariants():
    Lorentz = TensorIndexType("Lorentz", dummy_fmt="L")
    d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11 = tensor_indices("d0:12", Lorentz)
    # R^{d0 d1}_{d1 d0}; ord = [d0,-d0,d1,-d1]
    # T_c = -R^{d0 d1}_{d0 d1}
    R = tensorhead("R", [Lorentz] * 4, [[2, 2]])
    t = R(d0, d1, -d1, -d0)
    tc = t.canon_bp()
    assert str(tc) == "-R(L_0, L_1, -L_0, -L_1)"

    # R_d11^d1_d0^d5 * R^{d6 d4 d0}_d5 * R_{d7 d2 d8 d9} *
    # R_{d10 d3 d6 d4} * R^{d2 d7 d11}_d1 * R^{d8 d9 d3 d10}
    # can = [0,2,4,6, 1,3,8,10, 5,7,12,14, 9,11,16,18, 13,15,20,22,
    #        17,19,21<F10,23, 24,25]
    # T_c = R^{d0 d1 d2 d3} * R_{d0 d1}^{d4 d5} * R_{d2 d3}^{d6 d7} *
    # R_{d4 d5}^{d8 d9} * R_{d6 d7}^{d10 d11} * R_{d8 d9 d10 d11}

    t = (
        R(-d11, d1, -d0, d5)
        * R(d6, d4, d0, -d5)
        * R(-d7, -d2, -d8, -d9)
        * R(-d10, -d3, -d6, -d4)
        * R(d2, d7, d11, -d1)
        * R(d8, d9, d3, d10)
    )
    tc = t.canon_bp()
    assert (
        str(tc)
        == "R(L_0, L_1, L_2, L_3)*R(-L_0, -L_1, L_4, L_5)*R(-L_2, -L_3, L_6, L_7)*R(-L_4, -L_5, L_8, L_9)*R(-L_6, -L_7, L_10, L_11)*R(-L_8, -L_9, -L_10, -L_11)"
    )
コード例 #12
0
def test_mul():
    from sympy.abc import x
    Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
    a, b, c, d = tensor_indices('a,b,c,d', Lorentz)
    sym = tensorsymmetry([1] * 2)
    t = TensMul.from_data(S.One, [], [], [])
    assert str(t) == '1'
    A, B = tensorhead('A B', [Lorentz] * 2, [[1] * 2])
    t = (1 + x) * A(a, b)
    assert str(t) == '(x + 1)*A(a, b)'
    assert t.types == [Lorentz]
    assert t.rank == 2
    assert t.dum == []
    assert t.coeff == 1 + x
    assert sorted(t.free) == [(a, 0, 0), (b, 1, 0)]
    assert t.components == [A]

    t = A(-b, a) * B(-a, c) * A(-c, d)
    t1 = tensor_mul(*t.split())
    assert t == t(-b, d)
    assert t == t1
    assert tensor_mul(*[]) == TensMul.from_data(S.One, [], [], [])

    t = TensMul.from_data(1, [], [], [])
    zsym = tensorsymmetry()
    typ = TensorType([], zsym)
    C = typ('C')
    assert str(C()) == 'C'
    assert str(t) == '1'
    assert t.split()[0] == t
    raises(ValueError, lambda: TIDS.free_dum_from_indices(a, a))
    raises(ValueError, lambda: TIDS.free_dum_from_indices(-a, -a))
    raises(ValueError, lambda: A(a, b) * A(a, c))
    t = A(a, b) * A(-a, c)
    raises(ValueError, lambda: t(a, b, c))
コード例 #13
0
ファイル: test_tensor.py プロジェクト: AALEKH/sympy
def test_pprint():
    Lorentz = TensorIndexType('Lorentz')
    i0, i1, i2, i3, i4 = tensor_indices('i0:5', Lorentz)
    A = tensorhead('A', [Lorentz], [[1]])

    assert pretty(A) == "A(Lorentz)"
    assert pretty(A(i0)) == "A(i0)"
コード例 #14
0
ファイル: test_tensor.py プロジェクト: MarcdeFalco/sympy
def test_mul():
    from sympy.abc import x
    Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
    a, b, c, d = tensor_indices('a,b,c,d', Lorentz)
    sym = tensorsymmetry([1]*2)
    t = TensMul.from_data(S.One, [], [], [])
    assert str(t) == '1'
    A, B = tensorhead('A B', [Lorentz]*2, [[1]*2])
    t = (1 + x)*A(a, b)
    assert str(t) == '(x + 1)*A(a, b)'
    assert t.types == [Lorentz]
    assert t.rank == 2
    assert t.dum == []
    assert t.coeff == 1 + x
    assert sorted(t.free) == [(a, 0, 0), (b, 1, 0)]
    assert t.components == [A]

    t = A(-b, a)*B(-a, c)*A(-c, d)
    t1 = tensor_mul(*t.split())
    assert t == t(-b, d)
    assert t == t1
    assert tensor_mul(*[]) == TensMul.from_data(S.One, [], [], [])

    t = TensMul.from_data(1, [], [], [])
    zsym = tensorsymmetry()
    typ = TensorType([], zsym)
    C = typ('C')
    assert str(C()) == 'C'
    assert str(t) == '1'
    assert t.split()[0] == t
    raises(ValueError, lambda: TIDS.free_dum_from_indices(a, a))
    raises(ValueError, lambda: TIDS.free_dum_from_indices(-a, -a))
    raises(ValueError, lambda: A(a, b)*A(a, c))
    t = A(a, b)*A(-a, c)
    raises(ValueError, lambda: t(a, b, c))
コード例 #15
0
def test_riemann_invariants():
    Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
    d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11 = \
            tensor_indices('d0:12', Lorentz)
    # R^{d0 d1}_{d1 d0}; ord = [d0,-d0,d1,-d1]
    # T_c = -R^{d0 d1}_{d0 d1}
    R = tensorhead('R', [Lorentz] * 4, [[2, 2]])
    t = R(d0, d1, -d1, -d0)
    tc = t.canon_bp()
    assert str(tc) == '-R(L_0, L_1, -L_0, -L_1)'

    # R_d11^d1_d0^d5 * R^{d6 d4 d0}_d5 * R_{d7 d2 d8 d9} *
    # R_{d10 d3 d6 d4} * R^{d2 d7 d11}_d1 * R^{d8 d9 d3 d10}
    # can = [0,2,4,6, 1,3,8,10, 5,7,12,14, 9,11,16,18, 13,15,20,22,
    #        17,19,21<F10,23, 24,25]
    # T_c = R^{d0 d1 d2 d3} * R_{d0 d1}^{d4 d5} * R_{d2 d3}^{d6 d7} *
    # R_{d4 d5}^{d8 d9} * R_{d6 d7}^{d10 d11} * R_{d8 d9 d10 d11}


    t = R(-d11,d1,-d0,d5)*R(d6,d4,d0,-d5)*R(-d7,-d2,-d8,-d9)* \
        R(-d10,-d3,-d6,-d4)*R(d2,d7,d11,-d1)*R(d8,d9,d3,d10)
    tc = t.canon_bp()
    assert str(
        tc
    ) == 'R(L_0, L_1, L_2, L_3)*R(-L_0, -L_1, L_4, L_5)*R(-L_2, -L_3, L_6, L_7)*R(-L_4, -L_5, L_8, L_9)*R(-L_6, -L_7, L_10, L_11)*R(-L_8, -L_9, -L_10, -L_11)'
コード例 #16
0
def test_TensorManager():
    Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
    LorentzH = TensorIndexType('LorentzH', dummy_fmt='LH')
    i, j = tensor_indices('i,j', Lorentz)
    ih, jh = tensor_indices('ih,jh', LorentzH)
    p, q = tensorhead('p q', [Lorentz], [[1]])
    ph, qh = tensorhead('ph qh', [LorentzH], [[1]])

    Gsymbol = Symbol('Gsymbol')
    GHsymbol = Symbol('GHsymbol')
    TensorManager.set_comm(Gsymbol, GHsymbol, 0)
    G = tensorhead('G', [Lorentz], [[1]], Gsymbol)
    assert TensorManager._comm_i2symbol[G.comm] == Gsymbol
    GH = tensorhead('GH', [LorentzH], [[1]], GHsymbol)
    ps = G(i) * p(-i)
    psh = GH(ih) * ph(-ih)
    t = ps + psh
    t1 = t * t
    assert t1 == ps * ps + 2 * ps * psh + psh * psh
    qs = G(i) * q(-i)
    qsh = GH(ih) * qh(-ih)
    assert ps * qsh == qsh * ps
    assert ps * qs != qs * ps
    n = TensorManager.comm_symbols2i(Gsymbol)
    assert TensorManager.comm_i2symbol(n) == Gsymbol

    assert GHsymbol in TensorManager._comm_symbols2i
    raises(ValueError, lambda: TensorManager.set_comm(GHsymbol, 1, 2))
    TensorManager.set_comms((Gsymbol, GHsymbol, 0), (Gsymbol, 1, 1))
    assert TensorManager.get_comm(n, 1) == TensorManager.get_comm(1, n) == 1
    TensorManager.clear()
    assert TensorManager.comm == [{
        0: 0,
        1: 0,
        2: 0
    }, {
        0: 0,
        1: 1,
        2: None
    }, {
        0: 0,
        1: None
    }]
    assert GHsymbol not in TensorManager._comm_symbols2i
    nh = TensorManager.comm_symbols2i(GHsymbol)
    assert GHsymbol in TensorManager._comm_symbols2i
コード例 #17
0
ファイル: test_tensor.py プロジェクト: MarcdeFalco/sympy
def test_riemann_cyclic_replace():
    Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
    m0, m1, m2, m3 = tensor_indices('m:4', Lorentz)
    symr = tensorsymmetry([2, 2])
    R = tensorhead('R', [Lorentz]*4, [[2, 2]])
    t = R(m0, m2, m1, m3)
    t1 = riemann_cyclic_replace(t)
    t1a = -S.One/3*R(m0, m3, m2, m1) + S.One/3*R(m0, m1, m2, m3) + Rational(2, 3)*R(m0, m2, m1, m3)
    assert t1 == t1a
コード例 #18
0
def test_TensorHead():
    assert TensAdd() == 0
    # simple example of algebraic expression
    Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
    a, b = tensor_indices('a,b', Lorentz)
    # A, B symmetric
    A = tensorhead('A', [Lorentz] * 2, [[1] * 2])
    assert A.rank == 2
    assert A.symmetry == tensorsymmetry([1] * 2)
コード例 #19
0
ファイル: test_tensor.py プロジェクト: aterrel/sympy
def test_TensorHead():
    assert TensAdd() == 0
    # simple example of algebraic expression
    Lorentz = TensorIndexType("Lorentz", dummy_fmt="L")
    a, b = tensor_indices("a,b", Lorentz)
    # A, B symmetric
    A = tensorhead("A", [Lorentz] * 2, [[1] * 2])
    assert A.rank == 2
    assert A.symmetry == tensorsymmetry([1] * 2)
コード例 #20
0
ファイル: test_tensor.py プロジェクト: MarcdeFalco/sympy
def test_TensorType():
    Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
    sym = tensorsymmetry([1]*2)
    A = tensorhead('A', [Lorentz]*2, [[1]*2])
    assert A.typ == TensorType([Lorentz]*2, sym)
    assert A.types == [Lorentz]
    typ = TensorType([Lorentz]*2, sym)
    assert str(typ) == "TensorType(['Lorentz', 'Lorentz'])"
    raises(ValueError, lambda: typ(2))
コード例 #21
0
def test_TensorType():
    Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
    sym = tensorsymmetry([1] * 2)
    A = tensorhead('A', [Lorentz] * 2, [[1] * 2])
    assert A.typ == TensorType([Lorentz] * 2, sym)
    assert A.types == [Lorentz]
    typ = TensorType([Lorentz] * 2, sym)
    assert str(typ) == "TensorType(['Lorentz', 'Lorentz'])"
    raises(ValueError, lambda: typ(2))
コード例 #22
0
ファイル: test_tensor.py プロジェクト: MarcdeFalco/sympy
def test_TensorHead():
    assert TensAdd() == 0
    # simple example of algebraic expression
    Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
    a,b = tensor_indices('a,b', Lorentz)
    # A, B symmetric
    A = tensorhead('A', [Lorentz]*2, [[1]*2])
    assert A.rank == 2
    assert A.symmetry == tensorsymmetry([1]*2)
コード例 #23
0
ファイル: test_tensor.py プロジェクト: MarcdeFalco/sympy
def test_contract_metric1():
    D = Symbol('D')
    Lorentz = TensorIndexType('Lorentz', dim=D, dummy_fmt='L')
    a, b, c, d, e = tensor_indices('a,b,c,d,e', Lorentz)
    g = Lorentz.metric
    p = tensorhead('p', [Lorentz], [[1]])
    t = g(a, b)*p(-b)
    t1 = t.contract_metric(g)
    assert t1 == p(a)
    A, B = tensorhead('A,B', [Lorentz]*2, [[1]*2])

    # case with g with all free indices
    t1 = A(a,b)*B(-b,c)*g(d, e)
    t2 = t1.contract_metric(g)
    assert t1 == t2

    # case of g(d, -d)
    t1 = A(a,b)*B(-b,c)*g(-d, d)
    t2 = t1.contract_metric(g)
    assert t2 == D*A(a, d)*B(-d, c)

    # g with one free index
    t1 = A(a,b)*B(-b,-c)*g(c, d)
    t2 = t1.contract_metric(g)
    assert t2 == A(a, c)*B(-c, d)

    # g with both indices contracted with another tensor
    t1 = A(a,b)*B(-b,-c)*g(c, -a)
    t2 = t1.contract_metric(g)
    assert t2 == A(a, b)*B(-b, -a)

    t1 = A(a,b)*B(-b,-c)*g(c, d)*g(-a, -d)
    t2 = t1.contract_metric(g)
    t2 = t2.contract_metric(g)
    assert t2 == A(a,b)*B(-b,-a)

    t1 = A(a,b)*g(-a,-b)
    t2 = t1.contract_metric(g)
    assert t2 == A(a, -a)
    assert not t2.free
    Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
    a, b = tensor_indices('a,b', Lorentz)
    g = Lorentz.metric
    raises(ValueError, lambda: g(a, -a).contract_metric(g)) # no dim
コード例 #24
0
def test_contract_metric1():
    D = Symbol('D')
    Lorentz = TensorIndexType('Lorentz', dim=D, dummy_fmt='L')
    a, b, c, d, e = tensor_indices('a,b,c,d,e', Lorentz)
    g = Lorentz.metric
    p = tensorhead('p', [Lorentz], [[1]])
    t = g(a, b) * p(-b)
    t1 = t.contract_metric(g)
    assert t1 == p(a)
    A, B = tensorhead('A,B', [Lorentz] * 2, [[1] * 2])

    # case with g with all free indices
    t1 = A(a, b) * B(-b, c) * g(d, e)
    t2 = t1.contract_metric(g)
    assert t1 == t2

    # case of g(d, -d)
    t1 = A(a, b) * B(-b, c) * g(-d, d)
    t2 = t1.contract_metric(g)
    assert t2 == D * A(a, d) * B(-d, c)

    # g with one free index
    t1 = A(a, b) * B(-b, -c) * g(c, d)
    t2 = t1.contract_metric(g)
    assert t2 == A(a, c) * B(-c, d)

    # g with both indices contracted with another tensor
    t1 = A(a, b) * B(-b, -c) * g(c, -a)
    t2 = t1.contract_metric(g)
    assert t2 == A(a, b) * B(-b, -a)

    t1 = A(a, b) * B(-b, -c) * g(c, d) * g(-a, -d)
    t2 = t1.contract_metric(g)
    t2 = t2.contract_metric(g)
    assert t2 == A(a, b) * B(-b, -a)

    t1 = A(a, b) * g(-a, -b)
    t2 = t1.contract_metric(g)
    assert t2 == A(a, -a)
    assert not t2.free
    Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
    a, b = tensor_indices('a,b', Lorentz)
    g = Lorentz.metric
    raises(ValueError, lambda: g(a, -a).contract_metric(g))  # no dim
コード例 #25
0
ファイル: test_tensor.py プロジェクト: MarcdeFalco/sympy
def test_hash():
    D = Symbol('D')
    Lorentz = TensorIndexType('Lorentz', dim=D, dummy_fmt='L')
    a,b,c,d,e = tensor_indices('a,b,c,d,e', Lorentz)
    g = Lorentz.metric

    p, q = tensorhead('p q', [Lorentz], [[1]])
    p_type = p.args[1]
    t1 = p(a)*q(b)
    t2 = p(a)*p(b)
    assert hash(t1) != hash(t2)
    t3 = p(a)*p(b) + g(a,b)
    t4 = p(a)*p(b) - g(a,b)
    assert hash(t3) != hash(t4)

    assert a.func(*a.args) == a
    assert Lorentz.func(*Lorentz.args) == Lorentz
    assert g.func(*g.args) == g
    assert p.func(*p.args) == p
    assert p_type.func(*p_type.args) == p_type
    assert p(a).func(*(p(a)).args) == p(a)
    assert t1.func(*t1.args) == t1
    assert t2.func(*t2.args) == t2
    assert t3.func(*t3.args) == t3
    assert t4.func(*t4.args) == t4

    assert hash(a.func(*a.args)) == hash(a)
    assert hash(Lorentz.func(*Lorentz.args)) == hash(Lorentz)
    assert hash(g.func(*g.args)) == hash(g)
    assert hash(p.func(*p.args)) == hash(p)
    assert hash(p_type.func(*p_type.args)) == hash(p_type)
    assert hash(p(a).func(*(p(a)).args)) == hash(p(a))
    assert hash(t1.func(*t1.args)) == hash(t1)
    assert hash(t2.func(*t2.args)) == hash(t2)
    assert hash(t3.func(*t3.args)) == hash(t3)
    assert hash(t4.func(*t4.args)) == hash(t4)

    def check_all(obj):
        return all([isinstance(_, Basic) for _ in obj.args])

    assert check_all(a)
    assert check_all(Lorentz)
    assert check_all(g)
    assert check_all(p)
    assert check_all(p_type)
    assert check_all(p(a))
    assert check_all(t1)
    assert check_all(t2)
    assert check_all(t3)
    assert check_all(t4)

    tsymmetry = tensorsymmetry([2], [1], [1, 1, 1])

    assert tsymmetry.func(*tsymmetry.args) == tsymmetry
    assert hash(tsymmetry.func(*tsymmetry.args)) == hash(tsymmetry)
    assert check_all(tsymmetry)
コード例 #26
0
def test_hash():
    D = Symbol('D')
    Lorentz = TensorIndexType('Lorentz', dim=D, dummy_fmt='L')
    a, b, c, d, e = tensor_indices('a,b,c,d,e', Lorentz)
    g = Lorentz.metric

    p, q = tensorhead('p q', [Lorentz], [[1]])
    p_type = p.args[1]
    t1 = p(a) * q(b)
    t2 = p(a) * p(b)
    assert hash(t1) != hash(t2)
    t3 = p(a) * p(b) + g(a, b)
    t4 = p(a) * p(b) - g(a, b)
    assert hash(t3) != hash(t4)

    assert a.func(*a.args) == a
    assert Lorentz.func(*Lorentz.args) == Lorentz
    assert g.func(*g.args) == g
    assert p.func(*p.args) == p
    assert p_type.func(*p_type.args) == p_type
    assert p(a).func(*(p(a)).args) == p(a)
    assert t1.func(*t1.args) == t1
    assert t2.func(*t2.args) == t2
    assert t3.func(*t3.args) == t3
    assert t4.func(*t4.args) == t4

    assert hash(a.func(*a.args)) == hash(a)
    assert hash(Lorentz.func(*Lorentz.args)) == hash(Lorentz)
    assert hash(g.func(*g.args)) == hash(g)
    assert hash(p.func(*p.args)) == hash(p)
    assert hash(p_type.func(*p_type.args)) == hash(p_type)
    assert hash(p(a).func(*(p(a)).args)) == hash(p(a))
    assert hash(t1.func(*t1.args)) == hash(t1)
    assert hash(t2.func(*t2.args)) == hash(t2)
    assert hash(t3.func(*t3.args)) == hash(t3)
    assert hash(t4.func(*t4.args)) == hash(t4)

    def check_all(obj):
        return all([isinstance(_, Basic) for _ in obj.args])

    assert check_all(a)
    assert check_all(Lorentz)
    assert check_all(g)
    assert check_all(p)
    assert check_all(p_type)
    assert check_all(p(a))
    assert check_all(t1)
    assert check_all(t2)
    assert check_all(t3)
    assert check_all(t4)

    tsymmetry = tensorsymmetry([2], [1], [1, 1, 1])

    assert tsymmetry.func(*tsymmetry.args) == tsymmetry
    assert hash(tsymmetry.func(*tsymmetry.args)) == hash(tsymmetry)
    assert check_all(tsymmetry)
コード例 #27
0
def test_riemann_cyclic_replace():
    Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
    m0, m1, m2, m3 = tensor_indices('m:4', Lorentz)
    symr = tensorsymmetry([2, 2])
    R = tensorhead('R', [Lorentz] * 4, [[2, 2]])
    t = R(m0, m2, m1, m3)
    t1 = riemann_cyclic_replace(t)
    t1a = -S.One / 3 * R(m0, m3, m2, m1) + S.One / 3 * R(
        m0, m1, m2, m3) + Rational(2, 3) * R(m0, m2, m1, m3)
    assert t1 == t1a
コード例 #28
0
def test_riemann_products():
    Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
    d0, d1, d2, d3, d4, d5, d6 = tensor_indices('d0:7', Lorentz)
    a0, a1, a2, a3, a4, a5 = tensor_indices('a0:6', Lorentz)
    a, b = tensor_indices('a,b', Lorentz)
    R = tensorhead('R', [Lorentz] * 4, [[2, 2]])
    # R^{a b d0}_d0 = 0
    t = R(a, b, d0, -d0)
    tc = t.canon_bp()
    assert tc == 0

    # R^{d0 b a}_d0
    # T_c = -R^{a d0 b}_d0
    t = R(d0, b, a, -d0)
    tc = t.canon_bp()
    assert str(tc) == '-R(a, L_0, b, -L_0)'

    # R^d1_d2^b_d0 * R^{d0 a}_d1^d2; ord=[a,b,d0,-d0,d1,-d1,d2,-d2]
    # T_c = -R^{a d0 d1 d2}* R^b_{d0 d1 d2}
    t = R(d1, -d2, b, -d0) * R(d0, a, -d1, d2)
    tc = t.canon_bp()
    assert str(tc) == '-R(a, L_0, L_1, L_2)*R(b, -L_0, -L_1, -L_2)'

    # A symmetric commuting
    # R^{d6 d5}_d2^d1 * R^{d4 d0 d2 d3} * A_{d6 d0} A_{d3 d1} * A_{d4 d5}
    # g = [12,10,5,2, 8,0,4,6, 13,1, 7,3, 9,11,14,15]
    # T_c = -R^{d0 d1 d2 d3} * R_d0^{d4 d5 d6} * A_{d1 d4}*A_{d2 d5}*A_{d3 d6}
    V = tensorhead('V', [Lorentz] * 2, [[1] * 2])
    t = R(d6, d5, -d2, d1) * R(d4, d0, d2, d3) * V(-d6, -d0) * V(-d3, -d1) * V(
        -d4, -d5)
    tc = t.canon_bp()
    assert str(
        tc
    ) == '-R(L_0, L_1, L_2, L_3)*R(-L_0, L_4, L_5, L_6)*V(-L_1, -L_4)*V(-L_2, -L_5)*V(-L_3, -L_6)'

    # R^{d2 a0 a2 d0} * R^d1_d2^{a1 a3} * R^{a4 a5}_{d0 d1}
    # T_c = R^{a0 d0 a2 d1}*R^{a1 a3}_d0^d2*R^{a4 a5}_{d1 d2}
    t = R(d2, a0, a2, d0) * R(d1, -d2, a1, a3) * R(a4, a5, -d0, -d1)
    tc = t.canon_bp()
    assert str(
        tc) == 'R(a0, L_0, a2, L_1)*R(a1, a3, -L_0, L_2)*R(a4, a5, -L_1, -L_2)'
コード例 #29
0
ファイル: test_tensor.py プロジェクト: MarcdeFalco/sympy
def test_indices():
    Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
    a, b, c, d = tensor_indices('a,b,c,d', Lorentz)
    assert a.tensortype == Lorentz
    assert a != -a
    A, B = tensorhead('A B', [Lorentz]*2, [[1]*2])
    t = A(a,b)*B(-b,c)
    indices = t.get_indices()
    L_0 = TensorIndex('L_0', Lorentz)
    assert indices == [a, L_0, -L_0, c]
    raises(ValueError, lambda: tensor_indices(3, Lorentz))
    raises(ValueError, lambda: A(a,b,c))
コード例 #30
0
def test_substitute_indices():
    Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
    i, j, k, l, m, n, p, q = tensor_indices('i,j,k,l,m,n,p,q', Lorentz)
    A, B = tensorhead('A,B', [Lorentz] * 2, [[1] * 2])
    t = A(i, k) * B(-k, -j)
    t1 = t.substitute_indices((i, j), (j, k))
    t1a = A(j, l) * B(-l, -k)
    assert t1 == t1a

    p = tensorhead('p', [Lorentz], [[1]])
    t = p(i)
    t1 = t.substitute_indices((j, k))
    assert t1 == t
    t1 = t.substitute_indices((i, j))
    assert t1 == p(j)
    t1 = t.substitute_indices((i, -j))
    assert t1 == p(-j)
    t1 = t.substitute_indices((-i, j))
    assert t1 == p(-j)
    t1 = t.substitute_indices((-i, -j))
    assert t1 == p(j)
コード例 #31
0
ファイル: test_tensor.py プロジェクト: aterrel/sympy
def test_indices():
    Lorentz = TensorIndexType("Lorentz", dummy_fmt="L")
    a, b, c, d = tensor_indices("a,b,c,d", Lorentz)
    assert a.tensortype == Lorentz
    assert a != -a
    A, B = tensorhead("A B", [Lorentz] * 2, [[1] * 2])
    t = A(a, b) * B(-b, c)
    indices = t.get_indices()
    L_0 = TensorIndex("L_0", Lorentz)
    assert indices == [a, L_0, -L_0, c]
    raises(ValueError, lambda: tensor_indices(3, Lorentz))
    raises(ValueError, lambda: A(a, b, c))
コード例 #32
0
ファイル: test_tensor.py プロジェクト: MarcdeFalco/sympy
def test_substitute_indices():
    Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
    i, j, k, l, m, n, p, q = tensor_indices('i,j,k,l,m,n,p,q', Lorentz)
    A, B = tensorhead('A,B', [Lorentz]*2, [[1]*2])
    t = A(i, k)*B(-k, -j)
    t1 = t.substitute_indices((i, j), (j, k))
    t1a = A(j, l)*B(-l, -k)
    assert t1 == t1a

    p = tensorhead('p', [Lorentz], [[1]])
    t = p(i)
    t1 = t.substitute_indices((j, k))
    assert t1 == t
    t1 = t.substitute_indices((i, j))
    assert t1 == p(j)
    t1 = t.substitute_indices((i, -j))
    assert t1 == p(-j)
    t1 = t.substitute_indices((-i, j))
    assert t1 == p(-j)
    t1 = t.substitute_indices((-i, -j))
    assert t1 == p(j)
コード例 #33
0
ファイル: test_tensor.py プロジェクト: aterrel/sympy
def test_substitute_indices():
    Lorentz = TensorIndexType("Lorentz", dummy_fmt="L")
    i, j, k, l, m, n, p, q = tensor_indices("i,j,k,l,m,n,p,q", Lorentz)
    A, B = tensorhead("A,B", [Lorentz] * 2, [[1] * 2])
    t = A(i, k) * B(-k, -j)
    t1 = t.substitute_indices((i, j), (j, k))
    t1a = A(j, l) * B(-l, -k)
    assert t1 == t1a

    p = tensorhead("p", [Lorentz], [[1]])
    t = p(i)
    t1 = t.substitute_indices((j, k))
    assert t1 == t
    t1 = t.substitute_indices((i, j))
    assert t1 == p(j)
    t1 = t.substitute_indices((i, -j))
    assert t1 == p(-j)
    t1 = t.substitute_indices((-i, j))
    assert t1 == p(-j)
    t1 = t.substitute_indices((-i, -j))
    assert t1 == p(j)
コード例 #34
0
def test_indices():
    Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
    a, b, c, d = tensor_indices('a,b,c,d', Lorentz)
    assert a.tensortype == Lorentz
    assert a != -a
    A, B = tensorhead('A B', [Lorentz] * 2, [[1] * 2])
    t = A(a, b) * B(-b, c)
    indices = t.get_indices()
    L_0 = TensorIndex('L_0', Lorentz)
    assert indices == [a, L_0, -L_0, c]
    raises(ValueError, lambda: tensor_indices(3, Lorentz))
    raises(ValueError, lambda: A(a, b, c))
コード例 #35
0
def test_div():
    Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
    m0, m1, m2, m3 = tensor_indices('m0:4', Lorentz)
    R = tensorhead('R', [Lorentz] * 4, [[2, 2]])
    t = R(m0, m1, -m1, m3)
    t1 = t / S(4)
    assert str(t1) == '1/4*R(m0, L_0, -L_0, m3)'
    t = t.canon_bp()
    assert not t1._is_canon_bp
    t1 = t * 4
    assert t1._is_canon_bp
    t1 = t1 / 4
    assert t1._is_canon_bp
コード例 #36
0
ファイル: test_tensor.py プロジェクト: Acebulf/sympy
def test_hash():
    D = Symbol('D')
    Lorentz = TensorIndexType('Lorentz', dim=D, dummy_fmt='L')
    a,b,c,d,e = tensor_indices('a,b,c,d,e', Lorentz)
    g = Lorentz.metric

    p, q = tensorhead('p q', [Lorentz], [[1]])
    t1 = p(a)*q(b)
    t2 = p(a)*p(b)
    assert hash(t1) != hash(t2)
    t3 = p(a)*p(b) + g(a,b)
    t4 = p(a)*p(b) - g(a,b)
    assert hash(t3) != hash(t4)
コード例 #37
0
ファイル: test_tensor.py プロジェクト: vchekan/sympy
def test_hash():
    D = Symbol('D')
    Lorentz = TensorIndexType('Lorentz', dim=D, dummy_fmt='L')
    a, b, c, d, e = tensor_indices('a,b,c,d,e', Lorentz)
    g = Lorentz.metric

    p, q = tensorhead('p q', [Lorentz], [[1]])
    t1 = p(a) * q(b)
    t2 = p(a) * p(b)
    assert hash(t1) != hash(t2)
    t3 = p(a) * p(b) + g(a, b)
    t4 = p(a) * p(b) - g(a, b)
    assert hash(t3) != hash(t4)
コード例 #38
0
ファイル: test_tensor.py プロジェクト: aterrel/sympy
def test_div():
    Lorentz = TensorIndexType("Lorentz", dummy_fmt="L")
    m0, m1, m2, m3 = tensor_indices("m0:4", Lorentz)
    R = tensorhead("R", [Lorentz] * 4, [[2, 2]])
    t = R(m0, m1, -m1, m3)
    t1 = t / S(4)
    assert str(t1) == "1/4*R(m0, L_0, -L_0, m3)"
    t = t.canon_bp()
    assert not t1._is_canon_bp
    t1 = t * 4
    assert t1._is_canon_bp
    t1 = t1 / 4
    assert t1._is_canon_bp
コード例 #39
0
ファイル: test_tensor.py プロジェクト: shashankn91/sympy
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
コード例 #40
0
ファイル: test_tensor.py プロジェクト: MarcdeFalco/sympy
def test_div():
    Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
    m0,m1,m2,m3 = tensor_indices('m0:4', Lorentz)
    R = tensorhead('R', [Lorentz]*4, [[2, 2]])
    t = R(m0,m1,-m1,m3)
    t1 = t/S(4)
    assert str(t1) == '1/4*R(m0, L_0, -L_0, m3)'
    t = t.canon_bp()
    assert not t1._is_canon_bp
    t1 = t*4
    assert t1._is_canon_bp
    t1 = t1/4
    assert t1._is_canon_bp
コード例 #41
0
ファイル: test_tensor.py プロジェクト: MarcdeFalco/sympy
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
コード例 #42
0
ファイル: test_tensor.py プロジェクト: aterrel/sympy
def test_canonicalize3():
    D = Symbol("D")
    Spinor = TensorIndexType("Spinor", dim=D, metric=True, dummy_fmt="S")
    a0, a1, a2, a3, a4 = tensor_indices("a0:5", Spinor)
    C = Spinor.metric
    chi, psi = tensorhead("chi,psi", [Spinor], [[1]], 1)

    t = chi(a1) * psi(a0)
    t1 = t.canon_bp()
    assert t1 == t

    t = psi(a1) * chi(a0)
    t1 = t.canon_bp()
    assert t1 == -chi(a0) * psi(a1)
コード例 #43
0
ファイル: test_tensor.py プロジェクト: MarcdeFalco/sympy
def test_canonicalize3():
    D = Symbol('D')
    Spinor = TensorIndexType('Spinor', dim=D, metric=True, dummy_fmt='S')
    a0,a1,a2,a3,a4 = tensor_indices('a0:5', Spinor)
    C = Spinor.metric
    chi, psi = tensorhead('chi,psi', [Spinor], [[1]], 1)

    t = chi(a1)*psi(a0)
    t1 = t.canon_bp()
    assert t1 == t

    t = psi(a1)*chi(a0)
    t1 = t.canon_bp()
    assert t1 == -chi(a0)*psi(a1)
コード例 #44
0
def test_canonicalize3():
    D = Symbol('D')
    Spinor = TensorIndexType('Spinor', dim=D, metric=True, dummy_fmt='S')
    a0, a1, a2, a3, a4 = tensor_indices('a0:5', Spinor)
    C = Spinor.metric
    chi, psi = tensorhead('chi,psi', [Spinor], [[1]], 1)

    t = chi(a1) * psi(a0)
    t1 = t.canon_bp()
    assert t1 == t

    t = psi(a1) * chi(a0)
    t1 = t.canon_bp()
    assert t1 == -chi(a0) * psi(a1)
コード例 #45
0
ファイル: test_tensor.py プロジェクト: MarcdeFalco/sympy
def test_riemann_products():
    Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
    d0, d1, d2, d3, d4, d5, d6 = tensor_indices('d0:7', Lorentz)
    a0, a1, a2, a3, a4, a5 = tensor_indices('a0:6', Lorentz)
    a, b = tensor_indices('a,b', Lorentz)
    R = tensorhead('R', [Lorentz]*4, [[2, 2]])
    # R^{a b d0}_d0 = 0
    t = R(a, b, d0, -d0)
    tc = t.canon_bp()
    assert tc == 0

    # R^{d0 b a}_d0
    # T_c = -R^{a d0 b}_d0
    t = R(d0, b, a, -d0)
    tc = t.canon_bp()
    assert str(tc) == '-R(a, L_0, b, -L_0)'

    # R^d1_d2^b_d0 * R^{d0 a}_d1^d2; ord=[a,b,d0,-d0,d1,-d1,d2,-d2]
    # T_c = -R^{a d0 d1 d2}* R^b_{d0 d1 d2}
    t = R(d1, -d2, b, -d0)*R(d0, a, -d1, d2)
    tc = t.canon_bp()
    assert str(tc) == '-R(a, L_0, L_1, L_2)*R(b, -L_0, -L_1, -L_2)'

    # A symmetric commuting
    # R^{d6 d5}_d2^d1 * R^{d4 d0 d2 d3} * A_{d6 d0} A_{d3 d1} * A_{d4 d5}
    # g = [12,10,5,2, 8,0,4,6, 13,1, 7,3, 9,11,14,15]
    # T_c = -R^{d0 d1 d2 d3} * R_d0^{d4 d5 d6} * A_{d1 d4}*A_{d2 d5}*A_{d3 d6}
    V = tensorhead('V', [Lorentz]*2, [[1]*2])
    t = R(d6, d5, -d2, d1)*R(d4, d0, d2, d3)*V(-d6, -d0)*V(-d3, -d1)*V(-d4, -d5)
    tc = t.canon_bp()
    assert str(tc) == '-R(L_0, L_1, L_2, L_3)*R(-L_0, L_4, L_5, L_6)*V(-L_1, -L_4)*V(-L_2, -L_5)*V(-L_3, -L_6)'

    # R^{d2 a0 a2 d0} * R^d1_d2^{a1 a3} * R^{a4 a5}_{d0 d1}
    # T_c = R^{a0 d0 a2 d1}*R^{a1 a3}_d0^d2*R^{a4 a5}_{d1 d2}
    t = R(d2, a0, a2, d0)*R(d1, -d2, a1, a3)*R(a4, a5, -d0, -d1)
    tc = t.canon_bp()
    assert str(tc) == 'R(a0, L_0, a2, L_1)*R(a1, a3, -L_0, L_2)*R(a4, a5, -L_1, -L_2)'
コード例 #46
0
def test_gamma_matrix_class():
    i, j, k = tensor_indices('i,j,k', G.LorentzIndex)

    # define another type of TensorHead to see if exprs are correctly handled:
    A = tensorhead('A', [G.LorentzIndex], [[1]])

    t = A(k)*G(i)*G(-i)
    ts = simplify(t)
    assert _is_tensor_eq(ts, 4*A(k)*DiracSpinorIndex.delta(DiracSpinorIndex.auto_left, -DiracSpinorIndex.auto_right))

    t = G(i)*A(k)*G(j)
    ts = simplify(t)
    assert _is_tensor_eq(ts, A(k)*G(i)*G(j))

    execute_gamma_simplify_tests_for_function(simplify, D=4)
コード例 #47
0
def test_gamma_matrix_class():
    i, j, k = tensor_indices('i,j,k', G.Lorentz)

    # define another type of TensorHead to see if exprs are correctly handled:
    A = tensorhead('A', [G.Lorentz], [[1]])

    t = A(k) * G(i) * G(-i)
    ts = simplify(t)
    assert ts == 4 * A(k)

    t = G(i) * A(k) * G(j)
    ts = simplify(t)
    assert ts == A(k) * G(i) * G(j)

    execute_gamma_simplify_tests_for_function(simplify, D=4)
コード例 #48
0
def test_gamma_matrix_class():
    i, j, k = tensor_indices('i,j,k', G.Lorentz)

    # define another type of TensorHead to see if exprs are correctly handled:
    A = tensorhead('A', [G.Lorentz], [[1]])

    t = A(k)*G(i)*G(-i)
    ts = simplify(t)
    assert ts == 4*A(k)

    t = G(i)*A(k)*G(j)
    ts = simplify(t)
    assert ts == A(k)*G(i)*G(j)

    execute_gamma_simplify_tests_for_function(simplify, D=4)
コード例 #49
0
def test_gamma_matrix_class():
    i, j, k = tensor_indices('i,j,k', G.LorentzIndex)

    # define another type of TensorHead to see if exprs are correctly handled:
    A = tensorhead('A', [G.LorentzIndex], [[1]])

    t = A(k) * G(i) * G(-i)
    ts = simplify(t)
    assert _is_tensor_eq(
        ts, 4 * A(k) * DiracSpinorIndex.delta(DiracSpinorIndex.auto_left,
                                              -DiracSpinorIndex.auto_right))

    t = G(i) * A(k) * G(j)
    ts = simplify(t)
    assert _is_tensor_eq(ts, A(k) * G(i) * G(j))

    execute_gamma_simplify_tests_for_function(simplify, D=4)
コード例 #50
0
ファイル: test_tensor.py プロジェクト: MarcdeFalco/sympy
def test_TensorIndexType():
    D = Symbol('D')
    G = Metric('g', False)
    Lorentz = TensorIndexType('Lorentz', metric=G, dim=D, dummy_fmt='L')
    m0, m1, m2, m3, m4 = tensor_indices('m0:5', Lorentz)
    sym2 = tensorsymmetry([1]*2)
    sym2n = tensorsymmetry(*get_symmetric_group_sgs(2))
    assert sym2 == sym2n
    g = Lorentz.metric
    assert str(g) == 'g(Lorentz,Lorentz)'
    assert Lorentz.eps_dim == Lorentz.dim

    TSpace = TensorIndexType('TSpace')
    i0, i1 = tensor_indices('i0 i1', TSpace)
    g = TSpace.metric
    A = tensorhead('A', [TSpace]*2, [[1]*2])
    assert  str(A(i0,-i0).canon_bp()) == 'A(TSpace_0, -TSpace_0)'
コード例 #51
0
def test_TensorIndexType():
    D = Symbol('D')
    G = Metric('g', False)
    Lorentz = TensorIndexType('Lorentz', metric=G, dim=D, dummy_fmt='L')
    m0, m1, m2, m3, m4 = tensor_indices('m0:5', Lorentz)
    sym2 = tensorsymmetry([1] * 2)
    sym2n = tensorsymmetry(*get_symmetric_group_sgs(2))
    assert sym2 == sym2n
    g = Lorentz.metric
    assert str(g) == 'g(Lorentz,Lorentz)'
    assert Lorentz.eps_dim == Lorentz.dim

    TSpace = TensorIndexType('TSpace')
    i0, i1 = tensor_indices('i0 i1', TSpace)
    g = TSpace.metric
    A = tensorhead('A', [TSpace] * 2, [[1] * 2])
    assert str(A(i0, -i0).canon_bp()) == 'A(TSpace_0, -TSpace_0)'
コード例 #52
0
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], [[1]])

    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)
コード例 #53
0
def test_riemann_cyclic():
    Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
    i, j, k, l, m, n, p, q = tensor_indices('i,j,k,l,m,n,p,q', Lorentz)
    R = tensorhead('R', [Lorentz] * 4, [[2, 2]])
    t = R(i,j,k,l) + R(i,l,j,k) + R(i,k,l,j) - \
        R(i,j,l,k) - R(i,l,k,j) - R(i,k,j,l)
    t2 = t * R(-i, -j, -k, -l)
    t3 = riemann_cyclic(t2)
    assert t3 == 0
    t = R(i, j, k, l) * (R(-i, -j, -k, -l) - 2 * R(-i, -k, -j, -l))
    t1 = riemann_cyclic(t)
    assert t1 == 0
    t = R(i, j, k, l)
    t1 = riemann_cyclic(t)
    assert t1 == -S(1) / 3 * R(i, l, j, k) + S(1) / 3 * R(
        i, k, j, l) + S(2) / 3 * R(i, j, k, l)

    t = R(i, j, k, l) * R(-k, -l, m,
                          n) * (R(-m, -n, -i, -j) + 2 * R(-m, -j, -n, -i))
    t1 = riemann_cyclic(t)
    assert t1 == 0
コード例 #54
0
def test_TensExpr():
    Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
    a, b, c, d = tensor_indices('a,b,c,d', Lorentz)
    g = Lorentz.metric
    A, B = tensorhead('A B', [Lorentz] * 2, [[1] * 2])
    raises(ValueError, lambda: g(c, d) / g(a, b))
    raises(ValueError, lambda: S.One / g(a, b))
    raises(ValueError, lambda: (A(c, d) + g(c, d)) / g(a, b))
    raises(ValueError, lambda: S.One / (A(c, d) + g(c, d)))
    raises(ValueError, lambda: A(a, b) + A(a, c))
    t = A(a, b) + B(a, b)
    raises(NotImplementedError, lambda: TensExpr.__mul__(t, 'a'))
    raises(NotImplementedError, lambda: TensExpr.__add__(t, 'a'))
    raises(NotImplementedError, lambda: TensExpr.__radd__(t, 'a'))
    raises(NotImplementedError, lambda: TensExpr.__sub__(t, 'a'))
    raises(NotImplementedError, lambda: TensExpr.__rsub__(t, 'a'))
    raises(NotImplementedError, lambda: TensExpr.__div__(t, 'a'))
    raises(NotImplementedError, lambda: TensExpr.__rdiv__(t, 'a'))
    raises(NotImplementedError, lambda: A(a, b)**2)
    raises(NotImplementedError, lambda: 2**A(a, b))
    raises(NotImplementedError, lambda: abs(A(a, b)))
コード例 #55
0
def test_canonicalize2():
    D = Symbol('D')
    Eucl = TensorIndexType('Eucl', metric=0, dim=D, dummy_fmt='E')
    i0,i1,i2,i3,i4,i5,i6,i7,i8,i9,i10,i11,i12,i13,i14 = \
            tensor_indices('i0:15', Eucl)
    A = tensorhead('A', [Eucl] * 3, [[3]])

    # two examples from Cvitanovic, Group Theory page 59
    # of identities for antisymmetric tensors of rank 3
    # contracted according to the Kuratowski graph  eq.(6.59)
    t = A(i0, i1, i2) * A(-i1, i3, i4) * A(-i3, i7, i5) * A(-i2, -i5, i6) * A(
        -i4, -i6, i8)
    t1 = t.canon_bp()
    assert t1 == 0

    # eq.(6.60)
    #t = A(i0,i1,i2)*A(-i1,i3,i4)*A(-i2,i5,i6)*A(-i3,i7,i8)*A(-i6,-i7,i9)*
    #    A(-i8,i10,i13)*A(-i5,-i10,i11)*A(-i4,-i11,i12)*A(-i3,-i12,i14)
    t = A(i0,i1,i2)*A(-i1,i3,i4)*A(-i2,i5,i6)*A(-i3,i7,i8)*A(-i6,-i7,i9)*\
        A(-i8,i10,i13)*A(-i5,-i10,i11)*A(-i4,-i11,i12)*A(-i9,-i12,i14)
    t1 = t.canon_bp()
    assert t1 == 0
コード例 #56
0
def test_epsilon():
    Lorentz = TensorIndexType('Lorentz', dim=4, dummy_fmt='L')
    a, b, c, d, e = tensor_indices('a,b,c,d,e', Lorentz)
    g = Lorentz.metric
    epsilon = Lorentz.epsilon
    p, q, r, s = tensorhead('p,q,r,s', [Lorentz], [[1]])

    t = epsilon(b, a, c, d)
    t1 = t.canon_bp()
    assert t1 == -epsilon(a, b, c, d)

    t = epsilon(c, b, d, a)
    t1 = t.canon_bp()
    assert t1 == epsilon(a, b, c, d)

    t = epsilon(c, a, d, b)
    t1 = t.canon_bp()
    assert t1 == -epsilon(a, b, c, d)

    t = epsilon(a, b, c, d) * p(-a) * q(-b)
    t1 = t.canon_bp()
    assert t1 == epsilon(c, d, a, b) * p(-a) * q(-b)

    t = epsilon(c, b, d, a) * p(-a) * q(-b)
    t1 = t.canon_bp()
    assert t1 == epsilon(c, d, a, b) * p(-a) * q(-b)

    t = epsilon(c, a, d, b) * p(-a) * q(-b)
    t1 = t.canon_bp()
    assert t1 == -epsilon(c, d, a, b) * p(-a) * q(-b)

    t = epsilon(c, a, d, b) * p(-a) * p(-b)
    t1 = t.canon_bp()
    assert t1 == 0

    t = epsilon(c, a, d, b) * p(-a) * q(-b) + epsilon(a, b, c,
                                                      d) * p(-b) * q(-a)
    t1 = t.canon_bp()
    assert t1 == -2 * epsilon(c, d, a, b) * p(-a) * q(-b)
コード例 #57
0
def test_no_metric_symmetry():
    # no metric symmetry; A no symmetry
    # A^d1_d0 * A^d0_d1
    # T_c = A^d0_d1 * A^d1_d0
    Lorentz = TensorIndexType('Lorentz', metric=None, dummy_fmt='L')
    d0, d1, d2, d3 = tensor_indices('d:4', Lorentz)
    A = tensorhead('A', [Lorentz] * 2, [[1], [1]])
    t = A(d1, -d0) * A(d0, -d1)
    tc = t.canon_bp()
    assert str(tc) == 'A(L_0, -L_1)*A(L_1, -L_0)'

    # A^d1_d2 * A^d0_d3 * A^d2_d1 * A^d3_d0
    # T_c = A^d0_d1 * A^d1_d0 * A^d2_d3 * A^d3_d2
    t = A(d1, -d2) * A(d0, -d3) * A(d2, -d1) * A(d3, -d0)
    tc = t.canon_bp()
    assert str(tc) == 'A(L_0, -L_1)*A(L_1, -L_0)*A(L_2, -L_3)*A(L_3, -L_2)'

    # A^d0_d2 * A^d1_d3 * A^d3_d0 * A^d2_d1
    # T_c = A^d0_d1 * A^d1_d2 * A^d2_d3 * A^d3_d0
    t = A(d0, -d1) * A(d1, -d2) * A(d2, -d3) * A(d3, -d0)
    tc = t.canon_bp()
    assert str(tc) == 'A(L_0, -L_1)*A(L_1, -L_2)*A(L_2, -L_3)*A(L_3, -L_0)'
コード例 #58
0
    def __new__(cls, label: str, indices: str, symmetry=None, comm=0, **kwargs):
        if isinstance(indices, str):
            indices = indices.split()

        # classify index types and indices by name
        # e.g. 'i0' -> isospin, 'c0' -> colour, etc.
        tensor_indices = [Index(i) for i in indices]
        index_types = [i.tensor_index_type for i in tensor_indices]

        if symmetry is None:
            n_gauge_indices = (
                len(indices) if GENERATION not in index_types else len(indices) - 1
            )
            symmetry = [[1] * n_gauge_indices] if indices else []

        if isinstance(label, tensor.TensorHead):
            tensor_head = label
            label = str(label.args[0])
        else:
            sym = symmetry + ([[1]] if GENERATION in index_types else [])
            tensor_head = tensor.tensorhead(label, index_types, sym=sym, comm=comm)

        return super(IndexedField, cls).__new__(cls, tensor_head, tensor_indices)
コード例 #59
0
def test_gamma_matrix_trace():
    gamma_trace = G.gamma_trace
    g = G.LorentzIndex.metric

    m0, m1, m2, m3, m4, m5, m6 = tensor_indices('m0:7', G.LorentzIndex)
    n0, n1, n2, n3, n4, n5 = tensor_indices('n0:6', G.LorentzIndex)

    # working in D=4 dimensions
    D = 4

    # traces of odd number of gamma matrices are zero:
    t = G(m0)
    t1 = gamma_trace(t)
    assert t1.equals(0)

    t = G(m0) * G(m1) * G(m2)
    t1 = gamma_trace(t)
    assert t1.equals(0)

    t = G(m0) * G(m1) * G(-m0)
    t1 = gamma_trace(t)
    assert t1.equals(0)

    t = G(m0) * G(m1) * G(m2) * G(m3) * G(m4)
    t1 = gamma_trace(t)
    assert t1.equals(0)

    # traces without internal contractions:
    t = G(m0) * G(m1)
    t1 = gamma_trace(t)
    assert _is_tensor_eq(t1, 4 * g(m0, m1))

    t = G(m0) * G(m1) * G(m2) * G(m3)
    t1 = gamma_trace(t)
    t2 = -4 * g(m0, m2) * g(m1, m3) + 4 * g(m0, m1) * g(m2, m3) + 4 * g(
        m0, m3) * g(m1, m2)
    st2 = str(t2)
    assert _is_tensor_eq(t1, t2)

    t = G(m0) * G(m1) * G(m2) * G(m3) * G(m4) * G(m5)
    t1 = gamma_trace(t)
    t2 = t1 * g(-m0, -m5)
    t2 = t2.contract_metric(g)
    assert _is_tensor_eq(t2, D * gamma_trace(G(m1) * G(m2) * G(m3) * G(m4)))

    # traces of expressions with internal contractions:
    t = G(m0) * G(-m0)
    t1 = gamma_trace(t)
    assert t1.equals(4 * D)

    t = G(m0) * G(m1) * G(-m0) * G(-m1)
    t1 = gamma_trace(t)
    assert t1.equals(8 * D - 4 * D**2)

    t = G(m0) * G(m1) * G(m2) * G(m3) * G(m4) * G(-m0)
    t1 = gamma_trace(t)
    t2 = (-4*D)*g(m1, m3)*g(m2, m4) + (4*D)*g(m1, m2)*g(m3, m4) + \
                 (4*D)*g(m1, m4)*g(m2, m3)
    assert t1.equals(t2)

    t = G(-m5) * G(m0) * G(m1) * G(m2) * G(m3) * G(m4) * G(-m0) * G(m5)
    t1 = gamma_trace(t)
    t2 = (32*D + 4*(-D + 4)**2 - 64)*(g(m1, m2)*g(m3, m4) - \
            g(m1, m3)*g(m2, m4) + g(m1, m4)*g(m2, m3))
    assert t1.equals(t2)

    t = G(m0) * G(m1) * G(-m0) * G(m3)
    t1 = gamma_trace(t)
    assert t1.equals((-4 * D + 8) * g(m1, m3))

    #    p, q = S1('p,q')
    #    ps = p(m0)*G(-m0)
    #    qs = q(m0)*G(-m0)
    #    t = ps*qs*ps*qs
    #    t1 = gamma_trace(t)
    #    assert t1 == 8*p(m0)*q(-m0)*p(m1)*q(-m1) - 4*p(m0)*p(-m0)*q(m1)*q(-m1)

    t = G(m0) * G(m1) * G(m2) * G(m3) * G(m4) * G(m5) * G(-m0) * G(-m1) * G(
        -m2) * G(-m3) * G(-m4) * G(-m5)
    t1 = gamma_trace(t)
    assert t1.equals(-4 * D**6 + 120 * D**5 - 1040 * D**4 + 3360 * D**3 -
                     4480 * D**2 + 2048 * D)

    t = G(m0) * G(m1) * G(n1) * G(m2) * G(n2) * G(m3) * G(m4) * G(-n2) * G(
        -n1) * G(-m0) * G(-m1) * G(-m2) * G(-m3) * G(-m4)
    t1 = gamma_trace(t)
    tresu = -7168 * D + 16768 * D**2 - 14400 * D**3 + 5920 * D**4 - 1232 * D**5 + 120 * D**6 - 4 * D**7
    assert t1.equals(tresu)

    # checked with Mathematica
    # In[1]:= <<Tracer.m
    # In[2]:= Spur[l];
    # In[3]:= GammaTrace[l, {m0},{m1},{n1},{m2},{n2},{m3},{m4},{n3},{n4},{m0},{m1},{m2},{m3},{m4}]
    t = G(m0) * G(m1) * G(n1) * G(m2) * G(n2) * G(m3) * G(m4) * G(n3) * G(
        n4) * G(-m0) * G(-m1) * G(-m2) * G(-m3) * G(-m4)
    t1 = gamma_trace(t)
    #    t1 = t1.expand_coeff()
    c1 = -4 * D**5 + 120 * D**4 - 1200 * D**3 + 5280 * D**2 - 10560 * D + 7808
    c2 = -4 * D**5 + 88 * D**4 - 560 * D**3 + 1440 * D**2 - 1600 * D + 640
    assert _is_tensor_eq(t1, c1*g(n1, n4)*g(n2, n3) + c2*g(n1, n2)*g(n3, n4) + \
            (-c1)*g(n1, n3)*g(n2, n4))

    p, q = tensorhead('p,q', [G.LorentzIndex], [[1]])
    ps = p(m0) * G(-m0)
    qs = q(m0) * G(-m0)
    p2 = p(m0) * p(-m0)
    q2 = q(m0) * q(-m0)
    pq = p(m0) * q(-m0)
    t = ps * qs * ps * qs
    r = gamma_trace(t)
    assert _is_tensor_eq(r, 8 * pq * pq - 4 * p2 * q2)
    t = ps * qs * ps * qs * ps * qs
    r = gamma_trace(t)
    assert r.equals(-12 * p2 * pq * q2 + 16 * pq * pq * pq)
    t = ps * qs * ps * qs * ps * qs * ps * qs
    r = gamma_trace(t)
    assert r.equals(-32 * pq * pq * p2 * q2 + 32 * pq * pq * pq * pq +
                    4 * p2 * p2 * q2 * q2)

    t = 4 * p(m1) * p(m0) * p(-m0) * q(-m1) * q(m2) * q(-m2)
    assert _is_tensor_eq(gamma_trace(t), t)
    t = ps * ps * ps * ps * ps * ps * ps * ps
    r = gamma_trace(t)
    assert r.equals(4 * p2 * p2 * p2 * p2)