• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python tensor.tensor_indices函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sympy.tensor.tensor.tensor_indices函数的典型用法代码示例。如果您正苦于以下问题:Python tensor_indices函数的具体用法?Python tensor_indices怎么用?Python tensor_indices使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了tensor_indices函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_get_lines

def test_get_lines():
    i0,i1,i2,i3,i4,i5,i6,i7,i8,i9,i10,i11,i12,i13 = \
       tensor_indices('i0:14', G.LorentzIndex)
    s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15,s16 = \
       tensor_indices('s0:17', DiracSpinorIndex)
    t = G(i1,s1,-s2)*G(i2,s3,-s4)*G(i4,s2,-s6)*G(i3,s4,-s3)
    r = get_lines(t, DiracSpinorIndex)
    assert r == ([[0, 2]], [[1, 3]], [])
    t = G(i1,s1,-s2)*G(i2,s2,-s3)*G(i3,s3,-s4)*G(i4,s4,-s5)*\
        G(i5,s6,-s7)*G(i6,s7,-s8)*G(i7,s8,-s9)*G(i8,s9,-s6)
    r = get_lines(t, DiracSpinorIndex)
    assert r == ([[0, 1, 2, 3]], [[4, 5, 6, 7]], [])
    t = G(i1,s1,-s2)*G(i0,s0,-s10)*G(i2,s2,-s3)*G(i3,s3,-s4)*\
    G(i4,s4,-s5)*G(i5,s6,-s7)*G(i6,s7,-s8)*G(i7,s8,-s9)*\
    G(i8,s9,-s6)*G(i9,s10,-s0)
    r = get_lines(t, DiracSpinorIndex)
    assert r == ([[0, 2, 3, 4]], [[5, 6, 7, 8], [1, 9]], [])
    t = G(i1,s1,-s2)*G(i11,s12,-s13)*G(i0,s0,-s10)*G(i2,s2,-s3)*G(i3,s3,-s4)*\
        G(i4,s4,-s5)*G(i5,s6,-s7)*G(i10,s11,-s12)*G(i6,s7,-s8)*G(i7,s8,-s9)*\
        G(i8,s9,-s6)*G(i9,s10,-s0)
    r = get_lines(t, DiracSpinorIndex)
    assert r == ([[0, 3, 4, 5], [7, 1]], [[6, 8, 9, 10], [2, 11]], [])
    t = G(i4,s4,-s5)*G(i5,s6,-s7)*G(i10,s11,-s12)*G(i6,s7,-s8)*G(i7,s8,-s9)*\
        G(i8,s9,-s6)*G(i9,s10,-s0)*\
        G(i1,s1,-s2)*G(i11,s12,-s13)*G(i0,s0,-s10)*G(i2,s2,-s3)*G(i3,s3,-s4)
    r = get_lines(t, DiracSpinorIndex)
    assert r == ([[2, 8], [7, 10, 11, 0]], [[1, 3, 4, 5], [6, 9]], [])
    t = G(i8,s9,-s6)*G(i9,s10,-s0)*G(i4,s4,-s5)*G(i13,s14,-s15)*\
        G(i10,s11,-s12)*G(i1,s1,-s2)*G(i11,s12,-s13)*\
        G(i0,s0,-s10)*G(i6,s7,-s8)*G(i7,s8,-s9)*\
        G(i2,s2,-s3)*G(i12,s13,-s14)*G(i3,s3,-s4)*G(i5,s6,-s7)
    r = get_lines(t, DiracSpinorIndex)
    assert r == ([[4, 6, 11, 3], [5, 10, 12, 2]], [[1, 7], [0, 13, 8, 9]], [])
开发者ID:KyleWendt,项目名称:sympy,代码行数:33,代码来源:test_gamma_matrices.py


示例2: test_TensorManager

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
开发者ID:MarcdeFalco,项目名称:sympy,代码行数:35,代码来源:test_tensor.py


示例3: test_simplify_lines

def test_simplify_lines():
    i0,i1,i2,i3,i4,i5,i6,i7,i8,i9,i10,i11,i12 = tensor_indices('i0:13', G.LorentzIndex)
    s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15,s16 = \
       tensor_indices('s0:17', DiracSpinorIndex)

    g = G.LorentzIndex.metric
    Sdelta = DiracSpinorIndex.delta
    t = G(i1,s1,-s2)*G(i2,s2,-s1)*G(i3,s4,-s5)*G(i4,s5,-s6)*G(i5,s7,-s8)
    r = G.simplify_lines(t)
    assert r.equals(4*G(i5, s7, -s8)*G(i3, s4, -s0)*G(i4, s0, -s6)*g(i1, i2))

    t = G(i1,s1,-s2)*G(i2,s2,-s1)*G(i3,s4,-s5)*G(-i3,s5,-s6)*G(i5,s7,-s8)
    r = G.simplify_lines(t)
    assert r.equals(16*G(i5, s7, -s8)*Sdelta(s4, -s6)*g(i1, i2))
    t = G(i1,s1,-s2)*G(i2,s2,-s1)*G(i3,s4,-s5)*G(i4,s5,-s6)*G(i5,s7,-s8)
    r = G.simplify_lines(t)
    assert r.equals(4*G(i5, s7, -s8)*G(i3, s4, s0)*G(i4, -s0, -s6)*g(i1, i2))
    t = G(i5,s7,-s8)*G(i6,s9,-s10)*G(i1,s1,-s2)*G(i3,s4,-s5)*G(i2,s2,-s1)*G(i4,s5,-s6)*G(-i6,s10,-s9)
    r = G.simplify_lines(t)
    assert r.equals(64*G(i5, s7, -s8)*G(i3, s4, s0)*G(i4, -s0, -s6)*g(i1, i2))
    t = G(i5,s7,-s8)*G(i6,s9,-s10)*G(i1,s1,-s2)*G(i7,s12,-s11)*G(i3,s4,-s5)*\
        G(i2,s2,-s1)*G(i4,s5,-s6)*G(-i6,s10,-s9)*G(-i7,s11,-s13)
    r = G.simplify_lines(t)
    assert r.equals(256*G(i5, s7, -s8)*G(i3, s4, s0)*G(i4, -s0, -s6)*\
           g(i1, i2)*Sdelta(s12,-s13))
开发者ID:KyleWendt,项目名称:sympy,代码行数:25,代码来源:test_gamma_matrices.py


示例4: test_indices

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))
开发者ID:aterrel,项目名称:sympy,代码行数:12,代码来源:test_tensor.py


示例5: test_indices

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))
开发者ID:MarcdeFalco,项目名称:sympy,代码行数:12,代码来源:test_tensor.py


示例6: test_canonicalize2

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
开发者ID:aterrel,项目名称:sympy,代码行数:29,代码来源:test_tensor.py


示例7: test_riemann_invariants

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)"
    )
开发者ID:aterrel,项目名称:sympy,代码行数:30,代码来源:test_tensor.py


示例8: test_pprint

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)"
开发者ID:AALEKH,项目名称:sympy,代码行数:7,代码来源:test_tensor.py


示例9: test_special_eq_ne

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)
开发者ID:MarcdeFalco,项目名称:sympy,代码行数:26,代码来源:test_tensor.py


示例10: test_fun

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)
开发者ID:MarcdeFalco,项目名称:sympy,代码行数:27,代码来源:test_tensor.py


示例11: test_mul

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))
开发者ID:MarcdeFalco,项目名称:sympy,代码行数:35,代码来源:test_tensor.py


示例12: test_tensor_element

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, :]
开发者ID:asmeurer,项目名称:sympy,代码行数:25,代码来源:test_tensor_element.py


示例13: test_TensorIndexType

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)"
开发者ID:aterrel,项目名称:sympy,代码行数:17,代码来源:test_tensor.py


示例14: test_bug_correction_tensor_indices

def test_bug_correction_tensor_indices():
    # to make sure that tensor_indices does not return a list if creating
    # only one index:
    from sympy.tensor.tensor import tensor_indices, TensorIndexType, TensorIndex
    A = TensorIndexType("A")
    i = tensor_indices('i', A)
    assert not isinstance(i, (tuple, list))
    assert isinstance(i, TensorIndex)
开发者ID:MarcdeFalco,项目名称:sympy,代码行数:8,代码来源:test_tensor.py


示例15: test_TensorIndexType

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)'
开发者ID:MarcdeFalco,项目名称:sympy,代码行数:17,代码来源:test_tensor.py


示例16: test_contract_automatrix_and_data

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
开发者ID:AALEKH,项目名称:sympy,代码行数:45,代码来源:test_tensor.py


示例17: test_TensorHead

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)
开发者ID:aterrel,项目名称:sympy,代码行数:9,代码来源:test_tensor.py


示例18: test_TensorHead

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)
开发者ID:MarcdeFalco,项目名称:sympy,代码行数:9,代码来源:test_tensor.py


示例19: test_riemann_cyclic_replace

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
开发者ID:MarcdeFalco,项目名称:sympy,代码行数:9,代码来源:test_tensor.py


示例20: test_contract_metric1

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
开发者ID:MarcdeFalco,项目名称:sympy,代码行数:44,代码来源:test_tensor.py



注:本文中的sympy.tensor.tensor.tensor_indices函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python tensor.tensorhead函数代码示例发布时间:2022-05-27
下一篇:
Python dense_ndim_array.MutableDenseNDimArray类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap