张量#
- class sympy.tensor.tensor.TensorIndexType(name, dummy_name=None, dim=None, eps_dim=None, metric_symmetry=1, metric_name='metric', **kwargs)[源代码]#
TensorIndexType的特征是其名称和度量。
- 参数:
name :张量类型的名称
dummy_name :虚拟索引负责人的姓名
dim :维度,可以是符号或整数或
Noneeps_dim :ε张量的维数
metric_symmetry : integer that denotes metric symmetry or
Nonefor no metricmetric_name :带有度量张量名称的字符串
笔记
的可能值
metric_symmetry参数为:1:度量张量是完全对称的0度量张量不具有指数对称性-1:度量张量完全反对称None:没有度量张量(公制等于None)默认情况下,该度量被假定为对称的。也可以通过设置为自定义张量
.set_metric()方法。如果有一个指标,该指标用于提高和降低指数。
在非对称度量的情况下,将采用以下提升和降低约定:
psi(a) = g(a, b)*psi(-b); chi(-a) = chi(b)*g(-b, -a)从这些中很容易找到:
g(-a, b) = delta(-a, b)在哪里?
delta(-a, b) = delta(b, -a)是Kronecker delta(见TensorIndex指数公约)。对于反对称度量,还存在以下等式:g(a, -b) = -delta(a, -b)如果没有度量标准,则不可能提高或降低指数;例如,定义性表示的指数
SU(N)为“协变”且共轭表示为“逆变”;对于N > 2它们是线性独立的。eps_dim默认情况下等于dim,如果后者是整数;否则可以赋值(用于朴素维正则化);如果eps_dim不是整数epsilon是None.实例
>>> from sympy.tensor.tensor import TensorIndexType >>> Lorentz = TensorIndexType('Lorentz', dummy_name='L') >>> Lorentz.metric metric(Lorentz,Lorentz)
属性
metric(度量张量)
delta(
Kronecker delta)epsilon(the
Levi-Civita epsilon张量)data((已弃用)要添加的属性
ndarray值,在指定的基础上工作。)
- class sympy.tensor.tensor.TensorIndex(name, tensor_index_type, is_up=True)[源代码]#
表示张量索引
- 参数:
name :索引的名称,或
True如果你想自动分配tensor_index_type :
TensorIndexType索引的is_up :逆变索引的标志(默认情况下为“上”=真)
笔记
张量指数是用爱因斯坦求和法则收缩的。
索引可以是逆变或协变形式;在后一种情况下,它在
-索引名称。添加-对于一个协变的(is_up=False)索引使它变反。虚拟索引的名称为head由
tensor_inde_type.dummy_name带下划线和数字。类似
symbols使用tensor_indices(s, typ)在哪里s是一串名字。实例
>>> from sympy.tensor.tensor import TensorIndexType, TensorIndex, TensorHead, tensor_indices >>> Lorentz = TensorIndexType('Lorentz', dummy_name='L') >>> mu = TensorIndex('mu', Lorentz, is_up=False) >>> nu, rho = tensor_indices('nu, rho', Lorentz) >>> A = TensorHead('A', [Lorentz, Lorentz]) >>> A(mu, nu) A(-mu, nu) >>> A(-mu, -rho) A(mu, -rho) >>> A(mu, -mu) A(-L_0, L_0)
属性
nametensor_index_typeis_up
- class sympy.tensor.tensor.TensorHead(name, index_types, symmetry=None, comm=0)[源代码]#
Tensor head of the tensor.
- 参数:
name :张量的名称
index_types :TensorIndexType列表
对称性 :张量的张量对称性
comm :换向组号
笔记
类似
symbols可以使用创建多个张量头tensorhead(s, typ, sym=None, comm=0)函数,其中s是名称字符串和sym是单项张量对称性(参见tensorsymmetry)A
TensorHead属于一个交换群,由数字上的符号定义comm(见_TensorManager.set_comm)交换群中的张量具有相同的交换性质;默认情况下comm是0,交换张量组。实例
定义秩为2的完全反对称张量:
>>> from sympy.tensor.tensor import TensorIndexType, TensorHead, TensorSymmetry >>> Lorentz = TensorIndexType('Lorentz', dummy_name='L') >>> asym2 = TensorSymmetry.fully_symmetric(-2) >>> A = TensorHead('A', [Lorentz, Lorentz], asym2)
使用nArray值的示例,将组件数据分配给
TensorHead对象被假定为完全反变表示。如果需要指定表示非完全协变张量值的分量数据,请参见其他示例。>>> from sympy.tensor.tensor import tensor_indices >>> from sympy import diag >>> Lorentz = TensorIndexType('Lorentz', dummy_name='L') >>> i0, i1 = tensor_indices('i0:2', Lorentz)
指定用于在词典中保留跟踪表达式替换的张量数组。这个
TensorIndexType与用于收缩的度量相关联(完全协变形式):>>> repl = {Lorentz: diag(1, -1, -1, -1)}
让我们看一些使用电磁张量的组件的示例:
>>> from sympy import symbols >>> Ex, Ey, Ez, Bx, By, Bz = symbols('E_x E_y E_z B_x B_y B_z') >>> c = symbols('c', positive=True)
让我们来定义一下 \(F\) 反张量:
>>> F = TensorHead('F', [Lorentz, Lorentz], asym2)
让我们更新字典以包含要在替换中使用的矩阵:
>>> repl.update({F(-i0, -i1): [ ... [0, Ex/c, Ey/c, Ez/c], ... [-Ex/c, 0, -Bz, By], ... [-Ey/c, Bz, 0, -Bx], ... [-Ez/c, -By, Bx, 0]]})
现在可以检索出电磁张量的反变形式:
>>> F(i0, i1).replace_with_arrays(repl, [i0, i1]) [[0, -E_x/c, -E_y/c, -E_z/c], [E_x/c, 0, -B_z, B_y], [E_y/c, B_z, 0, -B_x], [E_z/c, -B_y, B_x, 0]]
以及混合对变协方差形式:
>>> F(i0, -i1).replace_with_arrays(repl, [i0, -i1]) [[0, E_x/c, E_y/c, E_z/c], [E_x/c, 0, B_z, -B_y], [E_y/c, -B_z, 0, B_x], [E_z/c, B_y, -B_x, 0]]
粒子的能量动量可以表示为:
>>> from sympy import symbols >>> P = TensorHead('P', [Lorentz], TensorSymmetry.no_symmetry(1)) >>> E, px, py, pz = symbols('E p_x p_y p_z', positive=True) >>> repl.update({P(i0): [E, px, py, pz]})
逆变分量和协变分量分别为:
>>> P(i0).replace_with_arrays(repl, [i0]) [E, p_x, p_y, p_z] >>> P(-i0).replace_with_arrays(repl, [-i0]) [E, -p_x, -p_y, -p_z]
单指数张量的收缩:
>>> expr = P(i0)*P(-i0) >>> expr.replace_with_arrays(repl, []) E**2 - p_x**2 - p_y**2 - p_z**2
属性
nameindex_typesrank(指数总数)
symmetrycomm(换向组)
- sympy.tensor.tensor.tensor_heads(s, index_types, symmetry=None, comm=0)[源代码]#
Returns a sequence of TensorHeads from a string \(s\)
- class sympy.tensor.tensor.TensExpr(*args)[源代码]#
张量表达式的抽象基类
笔记
张量表达式是由张量构成的表达式;目前张量的和是分布的。
A
TensExpr可以是TensAdd或ATensMul.TensMul对象由分量张量的乘积构成,并包含一个系数,这是一个辛表达式。在内部表示法中,收缩指数表示为
(ipos1, ipos2, icomp1, icomp2)在哪里icomp1是具有逆变指数的分量张量的位置,ipos1索引在分量张量中所占的槽。因此,契约指数在内部表示法中没有名字。
- replace_with_arrays(replacement_dict, indices=None)[源代码]#
用数组替换张量表达式。最终的数组将与N维数组相对应,索引按照
indices.- 参数:
replacement_dict
包含张量替换规则的字典。
indices
读取数组所依据的索引顺序。如果没有传递值,将使用原始索引顺序。
实例
>>> from sympy.tensor.tensor import TensorIndexType, tensor_indices >>> from sympy.tensor.tensor import TensorHead >>> from sympy import symbols, diag
>>> L = TensorIndexType("L") >>> i, j = tensor_indices("i j", L) >>> A = TensorHead("A", [L]) >>> A(i).replace_with_arrays({A(i): [1, 2]}, [i]) [1, 2]
由于'indexes'是可选的,如果不需要特定的索引顺序,我们也可以通过这种方式调用replace_with_arrays:
>>> A(i).replace_with_arrays({A(i): [1, 2]}) [1, 2]
>>> expr = A(i)*A(j) >>> expr.replace_with_arrays({A(i): [1, 2]}) [[1, 2], [2, 4]]
对于收缩,请指定
TensorIndexType,在本例中是L,在其协变形式中:>>> expr = A(i)*A(-i) >>> expr.replace_with_arrays({A(i): [1, 2], L: diag(1, -1)}) -3
阵列的对称化:
>>> H = TensorHead("H", [L, L]) >>> a, b, c, d = symbols("a b c d") >>> expr = H(i, j)/2 + H(j, i)/2 >>> expr.replace_with_arrays({H(i, j): [[a, b], [c, d]]}) [[a, b/2 + c/2], [b/2 + c/2, d]]
数组的反对称化:
>>> expr = H(i, j)/2 - H(j, i)/2 >>> repl = {H(i, j): [[a, b], [c, d]]} >>> expr.replace_with_arrays(repl) [[0, b/2 - c/2], [-b/2 + c/2, 0]]
同一个表达式可以通过反转来读作转置
i和j:>>> expr.replace_with_arrays(repl, [j, i]) [[0, -b/2 + c/2], [b/2 - c/2, 0]]
- class sympy.tensor.tensor.TensAdd(*args, **kw_args)[源代码]#
Sum of tensors.
- 参数:
free_args :自由索引列表
实例
>>> from sympy.tensor.tensor import TensorIndexType, tensor_heads, tensor_indices >>> Lorentz = TensorIndexType('Lorentz', dummy_name='L') >>> a, b = tensor_indices('a,b', Lorentz) >>> p, q = tensor_heads('p,q', [Lorentz]) >>> t = p(a) + q(a); t p(a) + q(a)
将分量数据添加到张量表达式中的示例:
>>> from sympy import symbols, diag >>> x, y, z, t = symbols("x y z t") >>> repl = {} >>> repl[Lorentz] = diag(1, -1, -1, -1) >>> repl[p(a)] = [1, 2, 3, 4] >>> repl[q(a)] = [x, y, z, t]
以下是:2 2 - 3 2-2个 2 - 7 2==>-58
>>> expr = p(a) + q(a) >>> expr.replace_with_arrays(repl, [a]) [x + 1, y + 2, z + 3, t + 4]
属性
args(加数元组)
rank(张量的秩)
free_args(按排序顺序列出的自由索引)
- class sympy.tensor.tensor.TensMul(*args, **kw_args)[源代码]#
Product of tensors.
- 参数:
系数 :张量的同向系数
args
笔记
args[0]名单TensorHead分量张量的。args[1]名单(ind, ipos, icomp)在哪里?ind是一个自由索引,ipos是的插槽位置ind在icomp-th分量张量。args[2]表示伪索引的元组列表。(ipos1, ipos2, icomp1, icomp2)指示逆变虚拟索引是ipos1-中的第个插槽位置icomp1-th分量张量;对应的协变指数在ipos2中的插槽位置icomp2-th分量张量。属性
components(列表
TensorHead张量分量)types(不重复列表
TensorIndexType)free(列表
(ind, ipos, icomp),见注释)dum(列表
(ipos1, ipos2, icomp1, icomp2),见注释)ext_rank(计算伪指数的张量秩)
rank(张量的秩)
coeff(张量的共系数)
free_args(按排序顺序列出的自由索引)
is_canon_bp(
True如果张量是正则形式)- canon_bp()[源代码]#
规范化使用巴特勒葡萄牙算法规范化在单项对称。
实例
>>> from sympy.tensor.tensor import TensorIndexType, tensor_indices, TensorHead, TensorSymmetry >>> Lorentz = TensorIndexType('Lorentz', dummy_name='L') >>> m0, m1, m2 = tensor_indices('m0,m1,m2', Lorentz) >>> A = TensorHead('A', [Lorentz]*2, TensorSymmetry.fully_symmetric(-2)) >>> t = A(m0,-m1)*A(m1,-m0) >>> t.canon_bp() -A(L_0, L_1)*A(-L_0, -L_1) >>> t = A(m0,-m1)*A(m1,-m2)*A(m2,-m0) >>> t.canon_bp() 0
- contract_metric(g)[源代码]#
Raise or lower indices with the metric
g.- 参数:
g :公制
笔记
See the
TensorIndexTypedocstring for the contraction conventions.实例
>>> from sympy.tensor.tensor import TensorIndexType, tensor_indices, tensor_heads >>> Lorentz = TensorIndexType('Lorentz', dummy_name='L') >>> m0, m1, m2 = tensor_indices('m0,m1,m2', Lorentz) >>> g = Lorentz.metric >>> p, q = tensor_heads('p,q', [Lorentz]) >>> t = p(m0)*q(m1)*g(-m0, -m1) >>> t.canon_bp() metric(L_0, L_1)*p(-L_0)*q(-L_1) >>> t.contract_metric(g).canon_bp() p(L_0)*q(-L_0)
- get_free_indices() list[TensorIndex][源代码]#
Returns the list of free indices of the tensor.
解释
指数是按照它们在分量张量中出现的顺序列出的。
实例
>>> from sympy.tensor.tensor import TensorIndexType, tensor_indices, tensor_heads >>> Lorentz = TensorIndexType('Lorentz', dummy_name='L') >>> m0, m1, m2 = tensor_indices('m0,m1,m2', Lorentz) >>> g = Lorentz.metric >>> p, q = tensor_heads('p,q', [Lorentz]) >>> t = p(m1)*g(m0,m2) >>> t.get_free_indices() [m1, m0, m2] >>> t2 = p(m1)*g(-m1, m2) >>> t2.get_free_indices() [m2]
- get_indices()[源代码]#
Returns the list of indices of the tensor.
解释
指数是按照它们在分量张量中出现的顺序列出的。虚拟索引的名称不会与自由索引的名称冲突。
实例
>>> from sympy.tensor.tensor import TensorIndexType, tensor_indices, tensor_heads >>> Lorentz = TensorIndexType('Lorentz', dummy_name='L') >>> m0, m1, m2 = tensor_indices('m0,m1,m2', Lorentz) >>> g = Lorentz.metric >>> p, q = tensor_heads('p,q', [Lorentz]) >>> t = p(m1)*g(m0,m2) >>> t.get_indices() [m1, m0, m2] >>> t2 = p(m1)*g(-m1, m2) >>> t2.get_indices() [L_0, -L_0, m2]
- split()[源代码]#
Returns a list of tensors, whose product is
self.解释
在不同张量分量之间收缩的伪指数成为与表示伪指数同名的自由指数。
实例
>>> from sympy.tensor.tensor import TensorIndexType, tensor_indices, tensor_heads, TensorSymmetry >>> Lorentz = TensorIndexType('Lorentz', dummy_name='L') >>> a, b, c, d = tensor_indices('a,b,c,d', Lorentz) >>> A, B = tensor_heads('A,B', [Lorentz]*2, TensorSymmetry.fully_symmetric(2)) >>> t = A(a,b)*B(-b,c) >>> t A(a, L_0)*B(-L_0, c) >>> t.split() [A(a, L_0), B(-L_0, c)]
- sympy.tensor.tensor.riemann_cyclic_replace(t_r)[源代码]#
用等价表达式代替Riemann张量
R(m,n,p,q) -> 2/3*R(m,n,p,q) - 1/3*R(m,q,n,p) + 1/3*R(m,p,n,q)
- sympy.tensor.tensor.riemann_cyclic(t2)[源代码]#
Replace each Riemann tensor with an equivalent expression satisfying the cyclic identity.
这个技巧在Cadabra参考指南中进行了讨论。
实例
>>> from sympy.tensor.tensor import TensorIndexType, tensor_indices, TensorHead, riemann_cyclic, TensorSymmetry >>> Lorentz = TensorIndexType('Lorentz', dummy_name='L') >>> i, j, k, l = tensor_indices('i,j,k,l', Lorentz) >>> R = TensorHead('R', [Lorentz]*4, TensorSymmetry.riemann()) >>> t = R(i,j,k,l)*(R(-i,-j,-k,-l) - 2*R(-i,-k,-j,-l)) >>> riemann_cyclic(t) 0
- class sympy.tensor.tensor.TensorSymmetry(*args, **kw_args)[源代码]#
张量的单项对称性(即任何对称或反对称的指数置换)。有关相关术语,请参见
tensor_can.py组合数学模块的一部分。- 参数:
bsgs :元组
(base, sgs)张量对称性的BSGS
笔记
张量可以具有由它的bsg提供的任意单项对称性。多项对称性,如Riemann张量的循环对称性(即Bianchi恒等式)不包括在内。有关如何为一般索引置换组生成bsg的信息,请参见组合学模块。简单的对称可以使用内置方法生成。
实例
定义秩为2的对称张量
>>> from sympy.tensor.tensor import TensorIndexType, TensorSymmetry, get_symmetric_group_sgs, TensorHead >>> Lorentz = TensorIndexType('Lorentz', dummy_name='L') >>> sym = TensorSymmetry(get_symmetric_group_sgs(2)) >>> T = TensorHead('T', [Lorentz]*2, sym)
注意,同样也可以使用内置的张量对称方法来实现
>>> sym2 = TensorSymmetry.fully_symmetric(2) >>> sym == sym2 True
属性
base(BSGS底座)
generators(BSG发电机)
rank(张量的秩)
- sympy.tensor.tensor.tensorsymmetry(*args)[源代码]#
返回A
TensorSymmetry对象。此方法已弃用,请使用TensorSymmetry.direct_product()或.riemann()相反。解释
我们可以用BSGS来表示张量与任何单项狭缝对称群。
args可能是BSGSargs[0]基础args[1]sgs公司张量通常是对称群的(直积)表示;
args可以是表示年轻表格形状的列表列表笔记
例如:
[[1]]矢量[[1]*n]秩的对称张量n[[n]]秩的反对称张量n[[2, 2]]黎曼张量的单项狭缝对称性[[1],[1]]矢量 vector ``[[2],[1],[1]`` (antisymmetric tensor) 矢量*矢量注意这个形状
[2, 2]我们只把黎曼张量的单项对称性联系起来;这是一种符号的滥用,因为形状[2, 2]通常对应于以单项对称性和循环对称性为特征的不可约表示。
- class sympy.tensor.tensor.TensorType(*args, **kwargs)[源代码]#
张量类型的类。已弃用,请改用tensor_heads()。
- 参数:
index_types 名单
TensorIndexType张量指数对称性 :
TensorSymmetry张量的
属性
index_typessymmetrytypes(列表
TensorIndexType不重复)
- class sympy.tensor.tensor._TensorManager[源代码]#
类来管理张量属性。
笔记
张量属于张量交换群,每个群都有一个标号
comm;有预定义的标签:0与其他张量交换的张量1张量之间的相互作用2tensors not commuting, apart with those withcomm=0可以使用定义其他组
set_comm;这些组中的张量与comm=0;默认情况下,他们不与任何其他团体通勤。- comm_symbols2i(i)[源代码]#
Get the commutation group number corresponding to
i.ican be a symbol or a number or a string.如果
i尚未定义其交换组编号已设置。
- set_comm(i, j, c)[源代码]#
Set the commutation parameter
cfor commutation groupsi, j.- 参数:
i, j :表示换向组的符号
c :组交换数
笔记
i, j可以是符号、字符串或数字,除了0, 1和2分别为交换张量、反交换张量和除交换张量外不与其他任何群交换的张量保留。对于其余的情况,使用此方法设置交换规则;默认情况下c=None.群交换数
c与组交换符号对应地分配;它可以是0通勤
1抗干扰
无无交换性质
实例
G和GH不要和自己通勤,也不要互相通勤;A是通勤。>>> from sympy.tensor.tensor import TensorIndexType, tensor_indices, TensorHead, TensorManager, TensorSymmetry >>> Lorentz = TensorIndexType('Lorentz') >>> i0,i1,i2,i3,i4 = tensor_indices('i0:5', Lorentz) >>> A = TensorHead('A', [Lorentz]) >>> G = TensorHead('G', [Lorentz], TensorSymmetry.no_symmetry(1), 'Gcomm') >>> GH = TensorHead('GH', [Lorentz], TensorSymmetry.no_symmetry(1), 'GHcomm') >>> TensorManager.set_comm('Gcomm', 'GHcomm', 0) >>> (GH(i1)*G(i0)).canon_bp() G(i0)*GH(i1) >>> (G(i1)*G(i0)).canon_bp() G(i1)*G(i0) >>> (G(i1)*A(i0)).canon_bp() A(i0)*G(i1)