张量

class sympy.tensor.tensor.TensorIndexType(
name,
dummy_name=None,
dim=None,
eps_dim=None,
metric_symmetry=1,
metric_name='metric',
**kwargs,
)[源代码][源代码]

TensorIndexType 的特点是其名称和度量。

参数:
名称张量类型名称
dummy_name虚拟指标的头部名称
dim : 维度,它可以是一个符号、一个整数或 None维度,它可以是一个符号、一个整数或
eps_dimepsilon 张量的维度
metric_symmetry : 表示度量对称性的整数,或者 None 表示无度量表示度量对称性的整数或
metric_name带有度量张量名称的字符串
属性:
``metric``度量张量
``delta``Kronecker delta
``epsilon`` : Levi-Civita epsilon 张量
``data`` : (已弃用) 一个用于添加 ndarray 值的属性,以便在指定的基下工作。(已弃用)一个添加属性

方法

as_content_primitive([radical, clear])

一个存根,允许在计算表达式的内容和基本组件时跳过基本参数(如元组)。

as_dummy()

返回表达式,其中任何具有结构绑定符号的对象都被替换为在其出现的对象中唯一的规范符号,并且仅对交换性具有默认假设为True。

atoms(*types)

返回构成当前对象的原子。

class_key()

类的好顺序。

compare(other)

如果对象在规范意义上小于、等于或大于其他对象,则返回 -1、0、1。

count(query)

计算匹配的子表达式的数量。

count_ops([visual])

用于返回操作计数的 count_ops 的包装器。

doit(**hints)

评估默认情况下不评估的对象,如极限、积分、求和和乘积。

dummy_eq(other[, symbol])

比较两个表达式并处理哑符号。

find(query[, group])

查找所有匹配查询的子表达式。

fromiter(args, **assumptions)

从可迭代对象创建一个新对象。

has(*patterns)

测试是否有任何子表达式匹配任何模式。

has_free(*patterns)

如果 self 包含对象 x 作为自由表达式,则返回 True,否则返回 False。

has_xfree(s)

如果 self 有 s 中的任何一个模式作为自由参数,则返回 True,否则返回 False。

is_same(b[, approx])

如果 a 和 b 结构相同则返回 True,否则返回 False。

match(pattern[, old])

模式匹配。

matches(expr[, repl_dict, old])

用于 match() 的辅助方法,用于在 self 中的通配符符号与 expr 中的表达式之间寻找匹配。

rcall(*args)

通过表达式树递归应用于参数。

refine([assumption])

请参阅 sympy.assumptions 中的 refine 函数。

replace(query, value[, map, simultaneous, exact])

self 中匹配的子表达式替换为 value

rewrite(*args[, deep])

使用定义的规则重写 self

simplify(**kwargs)

请参阅 sympy.simplify 中的 simplify 函数。

sort_key([order])

返回一个排序键。

subs(*args, **kwargs)

在简化参数后,在表达式中用新内容替换旧内容。

xreplace(rule)

替换表达式中对象的出现。

复制

could_extract_minus_sign

get_epsilon

get_kronecker_delta

is_hypergeometric

set_metric

注释

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)
class sympy.tensor.tensor.TensorIndex(name, tensor_index_type, is_up=True)[源代码][源代码]

表示一个张量索引

参数:
名称 : 索引的名称,或者如果希望自动分配则为 True索引的名称,或
tensor_index_type : TensorIndexType 的索引索引的TensorIndexType
is_up逆变指标的标志(默认 is_up=True)
属性:
``name``
``tensor_index_type``
``is_up``

方法

as_content_primitive([radical, clear])

一个存根,允许在计算表达式的内容和基本组件时跳过基本参数(如元组)。

as_dummy()

返回表达式,其中任何具有结构绑定符号的对象都被替换为在其出现的对象中唯一的规范符号,并且仅对交换性具有默认假设为True。

atoms(*types)

返回构成当前对象的原子。

class_key()

类的好顺序。

compare(other)

如果对象在规范意义上小于、等于或大于其他对象,则返回 -1、0、1。

count(query)

计算匹配的子表达式的数量。

count_ops([visual])

用于返回操作计数的 count_ops 的包装器。

doit(**hints)

评估默认情况下不评估的对象,如极限、积分、求和和乘积。

dummy_eq(other[, symbol])

比较两个表达式并处理哑符号。

find(query[, group])

查找所有匹配查询的子表达式。

fromiter(args, **assumptions)

从可迭代对象创建一个新对象。

has(*patterns)

测试是否有任何子表达式匹配任何模式。

has_free(*patterns)

如果 self 包含对象 x 作为自由表达式,则返回 True,否则返回 False。

has_xfree(s)

如果 self 有 s 中的任何一个模式作为自由参数,则返回 True,否则返回 False。

is_same(b[, approx])

如果 a 和 b 结构相同则返回 True,否则返回 False。

match(pattern[, old])

模式匹配。

matches(expr[, repl_dict, old])

用于 match() 的辅助方法,用于在 self 中的通配符符号与 expr 中的表达式之间寻找匹配。

rcall(*args)

通过表达式树递归应用于参数。

refine([assumption])

请参阅 sympy.assumptions 中的 refine 函数。

replace(query, value[, map, simultaneous, exact])

self 中匹配的子表达式替换为 value

rewrite(*args[, deep])

使用定义的规则重写 self

simplify(**kwargs)

请参阅 sympy.simplify 中的 simplify 函数。

sort_key([order])

返回一个排序键。

subs(*args, **kwargs)

在简化参数后,在表达式中用新内容替换旧内容。

xreplace(rule)

替换表达式中对象的出现。

复制

could_extract_minus_sign

is_hypergeometric

注释

张量指标通过爱因斯坦求和约定进行缩并。

索引可以是逆变形式或协变形式;在后一种情况下,它通过在索引名称前加上 - 来表示。将 - 添加到协变(is_up=False)索引使其变为逆变。

虚拟指标的名称由 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)
class sympy.tensor.tensor.TensorHead(
name,
index_types,
symmetry=None,
comm=0,
)[源代码][源代码]

张量的张量头。

参数:
名称张量的名称
索引类型TensorIndexType 列表
对称性张量的张量对称性
comm换向组编号
属性:
``name``
``index_types``
``rank``索引总数
``symmetry``
``comm``commutation group

方法

__call__(*indices, **kw_args)

返回一个带有索引的张量。

as_content_primitive([radical, clear])

一个存根,允许在计算表达式的内容和基本组件时跳过基本参数(如元组)。

as_dummy()

返回表达式,其中任何具有结构绑定符号的对象都被替换为在其出现的对象中唯一的规范符号,并且仅对交换性具有默认假设为True。

atoms(*types)

返回构成当前对象的原子。

class_key()

类的好顺序。

commutes_with(other)

如果 selfother 对易,则返回 0 ;如果它们反对易,则返回 1

compare(other)

如果对象在规范意义上小于、等于或大于其他对象,则返回 -1、0、1。

count(query)

计算匹配的子表达式的数量。

count_ops([visual])

用于返回操作计数的 count_ops 的包装器。

doit(**hints)

评估默认情况下不评估的对象,如极限、积分、求和和乘积。

dummy_eq(other[, symbol])

比较两个表达式并处理哑符号。

find(query[, group])

查找所有匹配查询的子表达式。

fromiter(args, **assumptions)

从可迭代对象创建一个新对象。

has(*patterns)

测试是否有任何子表达式匹配任何模式。

has_free(*patterns)

如果 self 包含对象 x 作为自由表达式,则返回 True,否则返回 False。

has_xfree(s)

如果 self 有 s 中的任何一个模式作为自由参数,则返回 True,否则返回 False。

is_same(b[, approx])

如果 a 和 b 结构相同则返回 True,否则返回 False。

match(pattern[, old])

模式匹配。

matches(expr[, repl_dict, old])

用于 match() 的辅助方法,用于在 self 中的通配符符号与 expr 中的表达式之间寻找匹配。

rcall(*args)

通过表达式树递归应用于参数。

refine([assumption])

请参阅 sympy.assumptions 中的 refine 函数。

replace(query, value[, map, simultaneous, exact])

self 中匹配的子表达式替换为 value

rewrite(*args[, deep])

使用定义的规则重写 self

simplify(**kwargs)

请参阅 sympy.simplify 中的 simplify 函数。

sort_key([order])

返回一个排序键。

subs(*args, **kwargs)

在简化参数后,在表达式中用新内容替换旧内容。

xreplace(rule)

替换表达式中对象的出现。

复制

could_extract_minus_sign

is_hypergeometric

注释

类似于 symbols ,可以使用 tensorhead(s, typ, sym=None, comm=0) 函数创建多个 TensorHeads,其中 s 是名称字符串,sym 是单项张量的对称性(参见 tensorsymmetry)。

一个 TensorHead 属于一个交换组,由数字 comm 上的符号定义(参见 _TensorManager.set_comm);交换组中的张量具有相同的交换性质;默认情况下,comm0,即交换张量的组。

示例

定义一个完全反对称的二阶张量:

>>> 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)

带有 ndarray 值的示例,分配给 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]

一个1-指标张量与其自身的收缩:

>>> expr = P(i0)*P(-i0)
>>> expr.replace_with_arrays(repl, [])
E**2 - p_x**2 - p_y**2 - p_z**2
commutes_with(other)[源代码][源代码]

如果 selfother 对易,则返回 0 ;如果它们反对易,则返回 1

如果 selfother 既不交换也不反交换,则返回 None

sympy.tensor.tensor.tensor_heads(
s,
index_types,
symmetry=None,
comm=0,
)[源代码][源代码]

从字符串 \(s\) 返回一个 TensorHeads 序列

class sympy.tensor.tensor.TensExpr(*args)[源代码][源代码]

张量表达式的抽象基类

属性:
args

返回 ‘self’ 的参数元组。

assumptions0

返回对象 \(type\) 假设。

canonical_variables

返回一个字典,将 self.bound_symbols 中定义的任何变量映射到与表达式中任何自由符号不冲突的符号。

coeff

返回包含 x**n 的项中的系数。

expr_free_symbols

类似于 free_symbols,但仅在自由符号包含在表达式节点中时返回它们。

free_symbols

从自身的原子中返回那些自由符号。

func

表达式中的顶级函数。

is_antihermitian
is_comparable

如果 self 可以计算为一个具有精度的实数(或已经是一个实数),则返回 True,否则返回 False。

is_finite
is_hermitian
is_infinite
is_number

如果 self 没有自由符号且没有未定义的函数(确切地说,是 AppliedUndef),则返回 True。

is_polar
nocoeff

方法

apart([x])

请参阅 sympy.polys 中的 apart 函数。

args_cnc([cset, warn, split_1])

返回 [交换因子, 非交换因子] 的自身。

as_coeff_Add([rational])

高效地提取求和的系数。

as_coeff_Mul([rational])

高效地提取乘积的系数。

as_coeff_add(*deps)

返回元组 (c, args),其中 self 被写成一个 Add,a

as_coeff_exponent(x)

c*x**e -> c,e 其中 x 可以是任何符号表达式。

as_coeff_mul(*deps, **kwargs)

返回元组 (c, args),其中 self 被写成一个 Mul,m

as_coefficient(expr)

提取给定表达式中的符号系数。

as_coefficients_dict(*syms)

返回一个字典,将术语映射到它们的 Rational 系数。

as_content_primitive([radical, clear])

此方法应递归地从所有参数中移除一个 Rational,并返回该内容和新的 self(原始类型)。

as_dummy()

返回表达式,其中任何具有结构绑定符号的对象都被替换为在其出现的对象中唯一的规范符号,并且仅对交换性具有默认假设为True。

as_expr(*gens)

将多项式转换为 SymPy 表达式。

as_independent(*deps, **hint)

将 Mul 或 Add 的大部分天真分离为不依赖于 deps 的参数。

as_leading_term(*symbols[, logx, cdir])

返回自身级数展开的主导(非零)项。

as_numer_denom()

返回一个表达式的分子和分母。

as_ordered_factors([order])

返回有序因子列表(如果是 Mul),否则返回 [self]。

as_ordered_terms([order, data])

将表达式转换为有序的项列表。

as_poly(*gens, **args)

self 转换为多项式,或返回 None

as_powers_dict()

将自身作为一个因子的字典返回,每个因子都被视为一个幂。

as_real_imag([deep])

对 'self' 执行复杂的扩展,并返回一个包含收集到的实部和虚部的元组。

as_terms()

将一个表达式转换为项的列表。

aseries([x, n, bound, hir])

自变量的渐近级数展开

atoms(*types)

返回构成当前对象的原子。

cancel(*gens, **args)

参见 sympy.polys 中的取消函数

class_key()

类的好顺序。

collect(syms[, func, evaluate, exact, ...])

请参阅 sympy.simplify 中的 collect 函数。

combsimp()

请参阅 sympy.simplify 中的 combsimp 函数。

compare(other)

如果对象在规范意义上小于、等于或大于其他对象,则返回 -1、0、1。

compute_leading_term(x[, logx])

已弃用的函数,用于计算级数的首项。

conjugate()

返回 'self' 的复数共轭。

could_extract_minus_sign()

如果 self 以 -1 作为前导因子,或在求和中有比正号更多的负号,则返回 True,否则返回 False。

count(query)

计算匹配的子表达式的数量。

count_ops([visual])

doit(**hints)

评估默认情况下不评估的对象,如极限、积分、求和和乘积。

dummy_eq(other[, symbol])

比较两个表达式并处理哑符号。

equals(other[, failing_expression])

如果 self == other 则返回 True,如果不相等则返回 False,或者返回 None。

evalf([n, subs, maxn, chop, strict, quad, ...])

将给定的公式计算到 n 位精度。

expand(**hints)

extract_additively(c)

如果可以从自身减去 c 并且使所有匹配的系数趋向于零,则返回 self - c,否则返回 None。

extract_branch_factor([allow_half])

尝试以 exp_polar(2*pi*I*n)*z 的方式优雅地表达自身。

extract_multiplicatively(c)

如果无法以一种良好的方式将 self 表示为 c * something,即保留 self 参数的属性,则返回 None。

factor(*gens, **args)

参见 sympy.polys.polytools 中的 factor() 函数

find(query[, group])

查找所有匹配查询的子表达式。

fourier_series([limits])

计算自身的傅里叶正弦/余弦级数。

fps([x, x0, dir, hyper, order, rational, full])

计算自身的形式幂级数。

fromiter(args, **assumptions)

从可迭代对象创建一个新对象。

gammasimp()

参见 sympy.simplify 中的 gammasimp 函数

getO()

如果有加法 O(..) 符号,则返回该符号,否则返回 None。

get_matrix()

已弃用:请勿使用。

getn()

返回表达式的顺序。

has(*patterns)

测试是否有任何子表达式匹配任何模式。

has_free(*patterns)

如果 self 包含对象 x 作为自由表达式,则返回 True,否则返回 False。

has_xfree(s)

如果 self 有 s 中的任何一个模式作为自由参数,则返回 True,否则返回 False。

integrate(*args, **kwargs)

请参阅 sympy.integrals 中的 integrate 函数。

invert(g, *gens, **args)

返回 selfg 的乘法逆元,其中 self``(和 ``g)可以是符号表达式。

is_algebraic_expr(*syms)

此测试给定的表达式是否在给定的符号 syms 中是代数的。

is_constant(*wrt, **flags)

如果 self 是常量则返回 True,如果不是则返回 False,如果无法明确确定常量性则返回 None。

is_meromorphic(x, a)

此测试表达式是否作为给定符号 x 的函数在点 a 处是亚纯的。

is_polynomial(*syms)

如果 self 是 syms 中的多项式,则返回 True,否则返回 False。

is_rational_function(*syms)

测试函数是否是给定符号 syms 中的两个多项式的比率。

is_same(b[, approx])

如果 a 和 b 结构相同则返回 True,否则返回 False。

leadterm(x[, logx, cdir])

返回前导项 a*x**b 作为元组 (a, b)。

limit(x, xlim[, dir])

计算极限 x->xlim。

lseries([x, x0, dir, logx, cdir])

用于生成序列项的迭代器的包装器。

match(pattern[, old])

模式匹配。

matches(expr[, repl_dict, old])

用于 match() 的辅助方法,用于在 self 中的通配符符号与 expr 中的表达式之间寻找匹配。

n([n, subs, maxn, chop, strict, quad, verbose])

将给定的公式计算到 n 位精度。

normal()

返回表达式为分数形式。

nseries([x, x0, n, dir, logx, cdir])

如果假设允许,则包装到 _eval_nseries,否则包装到 series。

nsimplify([constants, tolerance, full])

参见 sympy.simplify 中的 nsimplify 函数

powsimp(*args, **kwargs)

请参阅 sympy.simplify 中的 powsimp 函数

primitive()

返回可以从自身每个项中非递归提取的正有理数(即,将自身视为一个加法)。

radsimp(**kwargs)

参见 sympy.simplify 中的 radsimp 函数

ratsimp()

参见 sympy.simplify 中的 ratsimp 函数。

rcall(*args)

通过表达式树递归应用于参数。

refine([assumption])

请参阅 sympy.assumptions 中的 refine 函数。

removeO()

如果存在,移除加性的 O(..) 符号

replace(query, value[, map, simultaneous, exact])

self 中匹配的子表达式替换为 value

replace_with_arrays(replacement_dict[, indices])

将张量表达式替换为数组。

rewrite(*args[, deep])

使用定义的规则重写 self

round([n])

返回 x 四舍五入到给定的十进制位数。

separate([deep, force])

参见 sympy.simplify 中的单独函数

series([x, x0, n, dir, logx, cdir])

x = x0 附近对 "self" 进行级数展开,当 n=None 时逐项给出级数项(即惰性级数),否则当 n != None 时一次性给出所有项。

simplify(**kwargs)

请参阅 sympy.simplify 中的 simplify 函数。

sort_key([order])

subs(*args, **kwargs)

在简化参数后,在表达式中用新内容替换旧内容。

taylor_term(n, x, *previous_terms)

泰勒项的一般方法。

together(*args, **kwargs)

请参阅 sympy.polys 中的 together 函数。

trigsimp(**args)

参见 sympy.simplify 中的 trigsimp 函数

xreplace(rule)

替换表达式中对象的出现。

伴随

as_base_exp

复制

差异

目录

fun_eval

get_free_indices

get_indices

is_hypergeometric

转置

注释

张量表达式是由张量构成的表达式;目前张量的和是分布式的。

一个 TensExpr 可以是 TensAddTensMul

TensMul 对象由分量张量的乘积形成,并包含一个系数,该系数是一个 SymPy 表达式。

在内部表示中,缩并的指标由 (ipos1, ipos2, icomp1, icomp2) 表示,其中 icomp1 是具有逆变指标的分量张量的位置,ipos1 是该指标在该分量张量中占据的槽位。

因此,在内部表示中,缩并的指标是无名的。

get_matrix()[源代码][源代码]

已弃用:请勿使用。

如果组件数据可用且 ndarray 维度不超过 2,则将 ndarray 组件数据作为矩阵返回。

replace_with_arrays(
replacement_dict,
indices=None,
)[源代码][源代码]

将张量表达式替换为数组。最终的数组将对应于按 indices 排列索引的 N 维数组。

参数:
replacement_dict

包含张量替换规则的字典。

索引

数组读取的索引顺序。如果没有传递值,将使用原始索引顺序。

示例

>>> 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]

由于’indices’是可选的,如果我们不需要特定的索引顺序,也可以通过这种方式调用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]]

同样的表达式可以通过交换 ij 来理解为转置:

>>> 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)[源代码][源代码]

张量之和。

参数:
自由参数自由指标列表
属性:
``args``加数的元组
``rank``张量的秩
``free_args``按排序顺序列出自由指标

方法

__call__(*indices)

apart([x])

请参阅 sympy.polys 中的 apart 函数。

args_cnc([cset, warn, split_1])

返回 [交换因子, 非交换因子] 的自身。

as_coeff_Add([rational])

高效地提取求和的系数。

as_coeff_Mul([rational])

高效地提取乘积的系数。

as_coeff_add(*deps)

返回元组 (c, args),其中 self 被写成一个 Add,a

as_coeff_exponent(x)

c*x**e -> c,e 其中 x 可以是任何符号表达式。

as_coeff_mul(*deps, **kwargs)

返回元组 (c, args),其中 self 被写成一个 Mul,m

as_coefficient(expr)

提取给定表达式中的符号系数。

as_coefficients_dict(*syms)

返回一个字典,将术语映射到它们的 Rational 系数。

as_content_primitive([radical, clear])

此方法应递归地从所有参数中移除一个 Rational,并返回该内容和新的 self(原始类型)。

as_dummy()

返回表达式,其中任何具有结构绑定符号的对象都被替换为在其出现的对象中唯一的规范符号,并且仅对交换性具有默认假设为True。

as_expr(*gens)

将多项式转换为 SymPy 表达式。

as_independent(*deps, **hint)

将 Mul 或 Add 的大部分天真分离为不依赖于 deps 的参数。

as_leading_term(*symbols[, logx, cdir])

返回自身级数展开的主导(非零)项。

as_numer_denom()

返回一个表达式的分子和分母。

as_ordered_factors([order])

返回有序因子列表(如果是 Mul),否则返回 [self]。

as_ordered_terms([order, data])

将表达式转换为有序的项列表。

as_poly(*gens, **args)

self 转换为多项式,或返回 None

as_powers_dict()

将自身作为一个因子的字典返回,每个因子都被视为一个幂。

as_real_imag([deep])

对 'self' 执行复杂的扩展,并返回一个包含收集到的实部和虚部的元组。

as_terms()

将一个表达式转换为项的列表。

aseries([x, n, bound, hir])

自变量的渐近级数展开

atoms(*types)

返回构成当前对象的原子。

cancel(*gens, **args)

参见 sympy.polys 中的取消函数

canon_bp()

使用Butler-Portugal算法在单项式对称性下进行规范化。

class_key()

类的好顺序。

collect(syms[, func, evaluate, exact, ...])

请参阅 sympy.simplify 中的 collect 函数。

combsimp()

请参阅 sympy.simplify 中的 combsimp 函数。

compare(other)

如果对象在规范意义上小于、等于或大于其他对象,则返回 -1、0、1。

compute_leading_term(x[, logx])

已弃用的函数,用于计算级数的首项。

conjugate()

返回 'self' 的复数共轭。

contract_metric(g)

使用度量 g 提升或降低指标。

could_extract_minus_sign()

如果 self 以 -1 作为前导因子,或在求和中有比正号更多的负号,则返回 True,否则返回 False。

count(query)

计算匹配的子表达式的数量。

count_ops([visual])

doit(**hints)

dummy_eq(other[, symbol])

比较两个表达式并处理哑符号。

equals(other)

evalf([n, subs, maxn, chop, strict, quad, ...])

将给定的公式计算到 n 位精度。

expand(**hints)

extract_additively(c)

如果可以从自身减去 c 并且使所有匹配的系数趋向于零,则返回 self - c,否则返回 None。

extract_branch_factor([allow_half])

尝试以 exp_polar(2*pi*I*n)*z 的方式优雅地表达自身。

extract_multiplicatively(c)

如果无法以一种良好的方式将 self 表示为 c * something,即保留 self 参数的属性,则返回 None。

factor(*gens, **args)

参见 sympy.polys.polytools 中的 factor() 函数

find(query[, group])

查找所有匹配查询的子表达式。

flatten(seq)

返回序列,使得序列中没有任何元素的类型为 \(cls\)

fourier_series([limits])

计算自身的傅里叶正弦/余弦级数。

fps([x, x0, dir, hyper, order, rational, full])

计算自身的形式幂级数。

fromiter(args, **assumptions)

从可迭代对象创建一个新对象。

gammasimp()

参见 sympy.simplify 中的 gammasimp 函数

getO()

如果有加法 O(..) 符号,则返回该符号,否则返回 None。

get_matrix()

已弃用:请勿使用。

getn()

返回表达式的顺序。

has(*patterns)

测试是否有任何子表达式匹配任何模式。

has_free(*patterns)

如果 self 包含对象 x 作为自由表达式,则返回 True,否则返回 False。

has_xfree(s)

如果 self 有 s 中的任何一个模式作为自由参数,则返回 True,否则返回 False。

integrate(*args, **kwargs)

请参阅 sympy.integrals 中的 integrate 函数。

invert(g, *gens, **args)

返回 selfg 的乘法逆元,其中 self``(和 ``g)可以是符号表达式。

is_algebraic_expr(*syms)

此测试给定的表达式是否在给定的符号 syms 中是代数的。

is_constant(*wrt, **flags)

如果 self 是常量则返回 True,如果不是则返回 False,如果无法明确确定常量性则返回 None。

is_meromorphic(x, a)

此测试表达式是否作为给定符号 x 的函数在点 a 处是亚纯的。

is_polynomial(*syms)

如果 self 是 syms 中的多项式,则返回 True,否则返回 False。

is_rational_function(*syms)

测试函数是否是给定符号 syms 中的两个多项式的比率。

is_same(b[, approx])

如果 a 和 b 结构相同则返回 True,否则返回 False。

leadterm(x[, logx, cdir])

返回前导项 a*x**b 作为元组 (a, b)。

limit(x, xlim[, dir])

计算极限 x->xlim。

lseries([x, x0, dir, logx, cdir])

用于生成序列项的迭代器的包装器。

make_args(expr)

返回一个元素序列 \(args\) 使得 cls(*args) == expr

match(pattern[, old])

模式匹配。

matches(expr[, repl_dict, old])

n([n, subs, maxn, chop, strict, quad, verbose])

将给定的公式计算到 n 位精度。

normal()

返回表达式为分数形式。

nseries([x, x0, n, dir, logx, cdir])

如果假设允许,则包装到 _eval_nseries,否则包装到 series。

nsimplify([constants, tolerance, full])

参见 sympy.simplify 中的 nsimplify 函数

powsimp(*args, **kwargs)

请参阅 sympy.simplify 中的 powsimp 函数

primitive()

返回可以从自身每个项中非递归提取的正有理数(即,将自身视为一个加法)。

radsimp(**kwargs)

参见 sympy.simplify 中的 radsimp 函数

ratsimp()

参见 sympy.simplify 中的 ratsimp 函数。

rcall(*args)

通过表达式树递归应用于参数。

refine([assumption])

请参阅 sympy.assumptions 中的 refine 函数。

removeO()

如果存在,移除加性的 O(..) 符号

replace(query, value[, map, simultaneous, exact])

self 中匹配的子表达式替换为 value

replace_with_arrays(replacement_dict[, indices])

将张量表达式替换为数组。

rewrite(*args[, deep])

使用定义的规则重写 self

round([n])

返回 x 四舍五入到给定的十进制位数。

separate([deep, force])

参见 sympy.simplify 中的单独函数

series([x, x0, n, dir, logx, cdir])

x = x0 附近对 "self" 进行级数展开,当 n=None 时逐项给出级数项(即惰性级数),否则当 n != None 时一次性给出所有项。

simplify(**kwargs)

请参阅 sympy.simplify 中的 simplify 函数。

sort_key([order])

subs(*args, **kwargs)

在简化参数后,在表达式中用新内容替换旧内容。

taylor_term(n, x, *previous_terms)

泰勒项的一般方法。

together(*args, **kwargs)

请参阅 sympy.polys 中的 together 函数。

trigsimp(**args)

参见 sympy.simplify 中的 trigsimp 函数

xreplace(rule)

替换表达式中对象的出现。

伴随

as_base_exp

contract_delta

复制

差异

目录

fun_eval

get_free_indices

get_indices

is_hypergeometric

substitute_indices

转置

示例

>>> 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]
canon_bp()[源代码][源代码]

使用Butler-Portugal算法在单项式对称性下进行规范化。

contract_metric(g)[源代码][源代码]

使用度量 g 提升或降低指标。

参数:
g指标
contract_all : 如果为 True,消除所有被收缩的 g如果为真,消除所有

注释

请参阅 TensorIndexType 的文档字符串以了解收缩约定

class sympy.tensor.tensor.TensMul(*args, **kw_args)[源代码][源代码]

张量的乘积。

参数:
coeffSymPy 张量的系数
参数
属性:
``components`` : TensorHead 的列表,表示分量张量列表
``types`` : 非重复 TensorIndexType 的列表非重复列表
``free`` : (ind, ipos, icomp) 的列表,参见注释列表
``dum`` : (ipos1, ipos2, icomp1, icomp2) 的列表, 见注释列表
``ext_rank``张量的秩,计算虚拟指标
``rank``张量的秩
``coeff``SymPy 张量的系数
``free_args``按排序顺序列出自由指标
``is_canon_bp`` : 如果张量是标准形式,则为 True如果张量处于规范形式,则为真

方法

__call__(*indices)

apart([x])

请参阅 sympy.polys 中的 apart 函数。

args_cnc([cset, warn, split_1])

返回 [交换因子, 非交换因子] 的自身。

as_coeff_Add([rational])

高效地提取求和的系数。

as_coeff_Mul([rational])

高效地提取乘积的系数。

as_coeff_add(*deps)

返回元组 (c, args),其中 self 被写成一个 Add,a

as_coeff_exponent(x)

c*x**e -> c,e 其中 x 可以是任何符号表达式。

as_coeff_mul(*deps, **kwargs)

返回元组 (c, args),其中 self 被写成一个 Mul,m

as_coefficient(expr)

提取给定表达式中的符号系数。

as_coefficients_dict(*syms)

返回一个字典,将术语映射到它们的 Rational 系数。

as_content_primitive([radical, clear])

此方法应递归地从所有参数中移除一个 Rational,并返回该内容和新的 self(原始类型)。

as_dummy()

返回表达式,其中任何具有结构绑定符号的对象都被替换为在其出现的对象中唯一的规范符号,并且仅对交换性具有默认假设为True。

as_expr(*gens)

将多项式转换为 SymPy 表达式。

as_independent(*deps, **hint)

将 Mul 或 Add 的大部分天真分离为不依赖于 deps 的参数。

as_leading_term(*symbols[, logx, cdir])

返回自身级数展开的主导(非零)项。

as_numer_denom()

返回一个表达式的分子和分母。

as_ordered_factors([order])

返回有序因子列表(如果是 Mul),否则返回 [self]。

as_ordered_terms([order, data])

将表达式转换为有序的项列表。

as_poly(*gens, **args)

self 转换为多项式,或返回 None

as_powers_dict()

将自身作为一个因子的字典返回,每个因子都被视为一个幂。

as_real_imag([deep])

对 'self' 执行复杂的扩展,并返回一个包含收集到的实部和虚部的元组。

as_terms()

将一个表达式转换为项的列表。

aseries([x, n, bound, hir])

自变量的渐近级数展开

atoms(*types)

返回构成当前对象的原子。

cancel(*gens, **args)

参见 sympy.polys 中的取消函数

canon_bp()

使用Butler-Portugal算法在单项式对称性下进行规范化。

class_key()

类的好顺序。

collect(syms[, func, evaluate, exact, ...])

请参阅 sympy.simplify 中的 collect 函数。

combsimp()

请参阅 sympy.simplify 中的 combsimp 函数。

compare(other)

如果对象在规范意义上小于、等于或大于其他对象,则返回 -1、0、1。

compute_leading_term(x[, logx])

已弃用的函数,用于计算级数的首项。

conjugate()

返回 'self' 的复数共轭。

contract_metric(g)

使用度量 g 提升或降低指标。

could_extract_minus_sign()

如果 self 以 -1 作为前导因子,或在求和中有比正号更多的负号,则返回 True,否则返回 False。

count(query)

计算匹配的子表达式的数量。

count_ops([visual])

doit(**hints)

dummy_eq(other[, symbol])

比较两个表达式并处理哑符号。

equals(other)

evalf([n, subs, maxn, chop, strict, quad, ...])

将给定的公式计算到 n 位精度。

expand(**hints)

extract_additively(c)

如果可以从自身减去 c 并且使所有匹配的系数趋向于零,则返回 self - c,否则返回 None。

extract_branch_factor([allow_half])

尝试以 exp_polar(2*pi*I*n)*z 的方式优雅地表达自身。

extract_multiplicatively(c)

如果无法以一种良好的方式将 self 表示为 c * something,即保留 self 参数的属性,则返回 None。

factor(*gens, **args)

参见 sympy.polys.polytools 中的 factor() 函数

find(query[, group])

查找所有匹配查询的子表达式。

flatten(seq)

返回序列,使得序列中没有任何元素的类型为 \(cls\)

fourier_series([limits])

计算自身的傅里叶正弦/余弦级数。

fps([x, x0, dir, hyper, order, rational, full])

计算自身的形式幂级数。

from_data(coeff, components, free, dum, ...)

fromiter(args, **assumptions)

从可迭代对象创建一个新对象。

gammasimp()

参见 sympy.simplify 中的 gammasimp 函数

getO()

如果有加法 O(..) 符号,则返回该符号,否则返回 None。

get_free_indices()

返回张量的自由指标列表。

get_indices()

返回张量的索引列表。

get_matrix()

已弃用:请勿使用。

getn()

返回表达式的顺序。

has(*patterns)

测试是否有任何子表达式匹配任何模式。

has_free(*patterns)

如果 self 包含对象 x 作为自由表达式,则返回 True,否则返回 False。

has_xfree(s)

如果 self 有 s 中的任何一个模式作为自由参数,则返回 True,否则返回 False。

integrate(*args, **kwargs)

请参阅 sympy.integrals 中的 integrate 函数。

invert(g, *gens, **args)

返回 selfg 的乘法逆元,其中 self``(和 ``g)可以是符号表达式。

is_algebraic_expr(*syms)

此测试给定的表达式是否在给定的符号 syms 中是代数的。

is_constant(*wrt, **flags)

如果 self 是常量则返回 True,如果不是则返回 False,如果无法明确确定常量性则返回 None。

is_meromorphic(x, a)

此测试表达式是否作为给定符号 x 的函数在点 a 处是亚纯的。

is_polynomial(*syms)

如果 self 是 syms 中的多项式,则返回 True,否则返回 False。

is_rational_function(*syms)

测试函数是否是给定符号 syms 中的两个多项式的比率。

is_same(b[, approx])

如果 a 和 b 结构相同则返回 True,否则返回 False。

leadterm(x[, logx, cdir])

返回前导项 a*x**b 作为元组 (a, b)。

limit(x, xlim[, dir])

计算极限 x->xlim。

lseries([x, x0, dir, logx, cdir])

用于生成序列项的迭代器的包装器。

make_args(expr)

返回一个元素序列 \(args\) 使得 cls(*args) == expr

match(pattern[, old])

模式匹配。

matches(expr[, repl_dict, old])

n([n, subs, maxn, chop, strict, quad, verbose])

将给定的公式计算到 n 位精度。

normal()

返回表达式为分数形式。

nseries([x, x0, n, dir, logx, cdir])

如果假设允许,则包装到 _eval_nseries,否则包装到 series。

nsimplify([constants, tolerance, full])

参见 sympy.simplify 中的 nsimplify 函数

perm2tensor(g[, is_canon_bp])

返回对应于排列 g 的张量

powsimp(*args, **kwargs)

请参阅 sympy.simplify 中的 powsimp 函数

primitive()

返回可以从自身每个项中非递归提取的正有理数(即,将自身视为一个加法)。

radsimp(**kwargs)

参见 sympy.simplify 中的 radsimp 函数

ratsimp()

参见 sympy.simplify 中的 ratsimp 函数。

rcall(*args)

通过表达式树递归应用于参数。

refine([assumption])

请参阅 sympy.assumptions 中的 refine 函数。

removeO()

如果存在,移除加性的 O(..) 符号

replace(query, value[, map, simultaneous, exact])

self 中匹配的子表达式替换为 value

replace_with_arrays(replacement_dict[, indices])

将张量表达式替换为数组。

rewrite(*args[, deep])

使用定义的规则重写 self

round([n])

返回 x 四舍五入到给定的十进制位数。

separate([deep, force])

参见 sympy.simplify 中的单独函数

series([x, x0, n, dir, logx, cdir])

x = x0 附近对 "self" 进行级数展开,当 n=None 时逐项给出级数项(即惰性级数),否则当 n != None 时一次性给出所有项。

simplify(**kwargs)

请参阅 sympy.simplify 中的 simplify 函数。

sort_key([order])

sorted_components()

返回一个组件已排序的张量积。

split()

返回一个张量列表,其乘积为 self

subs(*args, **kwargs)

在简化参数后,在表达式中用新内容替换旧内容。

taylor_term(n, x, *previous_terms)

泰勒项的一般方法。

together(*args, **kwargs)

请参阅 sympy.polys 中的 together 函数。

trigsimp(**args)

参见 sympy.simplify 中的 trigsimp 函数

xreplace(rule)

替换表达式中对象的出现。

伴随

as_base_exp

contract_delta

复制

差异

目录

fun_eval

is_hypergeometric

substitute_indices

转置

注释

args[0] 组件张量的 TensorHead 列表。

args[1] 是一个 (ind, ipos, icomp) 的列表,其中 ind 是一个自由指标,iposind 在第 icomp 个分量张量中的槽位位置。

args[2] 表示哑指标的元组列表。(ipos1, ipos2, icomp1, icomp2) 表示逆变哑指标位于第 icomp1 个分量张量的第 ipos1 个槽位;相应的协变指标位于第 icomp2 个分量张量的第 ipos2 个槽位。

canon_bp()[源代码][源代码]

使用Butler-Portugal算法在单项式对称性下进行规范化。

示例

>>> 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)[源代码][源代码]

使用度量 g 提升或降低指标。

参数:
g指标

注释

请参阅 TensorIndexType 的文档字符串以了解收缩约定。

示例

>>> 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][源代码][源代码]

返回张量的自由指标列表。

示例

>>> 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()[源代码][源代码]

返回张量的索引列表。

示例

>>> 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]
perm2tensor(g, is_canon_bp=False)[源代码][源代码]

返回对应于排列 g 的张量

更多详情,请参见 TIDS 中同名的方法。

sorted_components()[源代码][源代码]

返回一个组件已排序的张量积。

split()[源代码][源代码]

返回一个张量列表,其乘积为 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.canon_bp(p)[源代码][源代码]

Butler-Portugal 规范化。详情请参见组合学模块中的 tensor_can.py

sympy.tensor.tensor.riemann_cyclic_replace(t_r)[源代码][源代码]

将黎曼张量替换为等价表达式

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)[源代码][源代码]

将每个黎曼张量替换为满足循环恒等式的等价表达式。

这个技巧在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元组
属性:
``base``BSGS 的基础
``generators``BSGS 的生成器
``rank``张量的秩

方法

as_content_primitive([radical, clear])

一个存根,允许在计算表达式的内容和基本组件时跳过基本参数(如元组)。

as_dummy()

返回表达式,其中任何具有结构绑定符号的对象都被替换为在其出现的对象中唯一的规范符号,并且仅对交换性具有默认假设为True。

atoms(*types)

返回构成当前对象的原子。

class_key()

类的好顺序。

compare(other)

如果对象在规范意义上小于、等于或大于其他对象,则返回 -1、0、1。

count(query)

计算匹配的子表达式的数量。

count_ops([visual])

用于返回操作计数的 count_ops 的包装器。

direct_product(*args)

返回一个 TensorSymmetry 对象,该对象是全(反)对称指标置换群的直接乘积。

doit(**hints)

评估默认情况下不评估的对象,如极限、积分、求和和乘积。

dummy_eq(other[, symbol])

比较两个表达式并处理哑符号。

find(query[, group])

查找所有匹配查询的子表达式。

fromiter(args, **assumptions)

从可迭代对象创建一个新对象。

fully_symmetric(rank)

返回一个完全对称(如果 rank``<0 则为反对称)的 TensorSymmetry 对象,适用于 ``abs(rank) 个指标。

has(*patterns)

测试是否有任何子表达式匹配任何模式。

has_free(*patterns)

如果 self 包含对象 x 作为自由表达式,则返回 True,否则返回 False。

has_xfree(s)

如果 self 有 s 中的任何一个模式作为自由参数,则返回 True,否则返回 False。

is_same(b[, approx])

如果 a 和 b 结构相同则返回 True,否则返回 False。

match(pattern[, old])

模式匹配。

matches(expr[, repl_dict, old])

用于 match() 的辅助方法,用于在 self 中的通配符符号与 expr 中的表达式之间寻找匹配。

no_symmetry(rank)

TensorSymmetry 对象,适用于没有对称性的 rank 指标

rcall(*args)

通过表达式树递归应用于参数。

refine([assumption])

请参阅 sympy.assumptions 中的 refine 函数。

replace(query, value[, map, simultaneous, exact])

self 中匹配的子表达式替换为 value

rewrite(*args[, deep])

使用定义的规则重写 self

riemann()

返回黎曼张量的单色对称性

simplify(**kwargs)

请参阅 sympy.simplify 中的 simplify 函数。

sort_key([order])

返回一个排序键。

subs(*args, **kwargs)

在简化参数后,在表达式中用新内容替换旧内容。

xreplace(rule)

替换表达式中对象的出现。

复制

could_extract_minus_sign

is_hypergeometric

注释

一个张量可以具有由其BSGS提供的任意单项对称性。多项对称性,如黎曼张量的循环对称性(即Bianchi恒等式),则不包括在内。有关如何为一般指标置换群生成BSGS的信息,请参见组合学模块。简单的对称性可以使用内置方法生成。

示例

定义一个二阶对称张量

>>> 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)

注意,同样的事情也可以使用内置的 TensorSymmetry 方法来完成。

>>> sym2 = TensorSymmetry.fully_symmetric(2)
>>> sym == sym2
True
classmethod direct_product(*args)[源代码][源代码]

返回一个 TensorSymmetry 对象,该对象是全(反)对称指标置换群的直接乘积。

注释

(*args) 不同值的一些示例:(1) 向量,等同于 TensorSymmetry.fully_symmetric(1) (2) 具有2个对称指标的张量,等同于 .fully_symmetric(2) (-2) 具有2个反对称指标的张量,等同于 .fully_symmetric(-2) (2, -2) 具有前2个指标可交换且后2个指标反交换的张量 (1, 1, 1) 具有3个指标且无任何对称性的张量

classmethod fully_symmetric(rank)[源代码][源代码]

返回一个完全对称(如果 rank``<0 则为反对称)的 TensorSymmetry 对象,适用于 ``abs(rank) 个指标。

classmethod no_symmetry(rank)[源代码][源代码]

TensorSymmetry 对象,适用于没有对称性的 rank 指标

classmethod riemann()[源代码][源代码]

返回黎曼张量的单色对称性

sympy.tensor.tensor.tensorsymmetry(*args)[源代码][源代码]

返回一个 TensorSymmetry 对象。此方法已弃用,请改用 TensorSymmetry.direct_product().riemann()

注释

例如:[[1]] 向量 [[1]*n] 秩为 n 的对称张量 [[n]] 秩为 n 的反对称张量 [[2, 2]] 黎曼张量的单项槽对称性 [[1],[1]] 向量*向量 [[2],[1],[1] (反对称张量)*向量*向量

请注意,对于形状 [2, 2],我们仅关联了黎曼张量的单项对称性;这是一种符号滥用,因为形状 [2, 2] 通常对应于由单项对称性和循环对称性所表征的不可约表示。

class sympy.tensor.tensor.TensorType(*args, **kwargs)[源代码][源代码]

张量类型的类。已弃用,请改用 tensor_heads()。

参数:
index_types : 张量索引的 TensorIndexType 列表列表
对称性 : 张量对称性 的张量张量的张量对称性
属性:
``index_types``
``symmetry``
``types`` : 无重复的 TensorIndexType 列表列表

方法

__call__(s[, comm])

返回一个 TensorHead 对象或一个 TensorHead 对象列表。

as_content_primitive([radical, clear])

一个存根,允许在计算表达式的内容和基本组件时跳过基本参数(如元组)。

as_dummy()

返回表达式,其中任何具有结构绑定符号的对象都被替换为在其出现的对象中唯一的规范符号,并且仅对交换性具有默认假设为True。

atoms(*types)

返回构成当前对象的原子。

class_key()

类的好顺序。

compare(other)

如果对象在规范意义上小于、等于或大于其他对象,则返回 -1、0、1。

count(query)

计算匹配的子表达式的数量。

count_ops([visual])

用于返回操作计数的 count_ops 的包装器。

doit(**hints)

评估默认情况下不评估的对象,如极限、积分、求和和乘积。

dummy_eq(other[, symbol])

比较两个表达式并处理哑符号。

find(query[, group])

查找所有匹配查询的子表达式。

fromiter(args, **assumptions)

从可迭代对象创建一个新对象。

has(*patterns)

测试是否有任何子表达式匹配任何模式。

has_free(*patterns)

如果 self 包含对象 x 作为自由表达式,则返回 True,否则返回 False。

has_xfree(s)

如果 self 有 s 中的任何一个模式作为自由参数,则返回 True,否则返回 False。

is_same(b[, approx])

如果 a 和 b 结构相同则返回 True,否则返回 False。

match(pattern[, old])

模式匹配。

matches(expr[, repl_dict, old])

用于 match() 的辅助方法,用于在 self 中的通配符符号与 expr 中的表达式之间寻找匹配。

rcall(*args)

通过表达式树递归应用于参数。

refine([assumption])

请参阅 sympy.assumptions 中的 refine 函数。

replace(query, value[, map, simultaneous, exact])

self 中匹配的子表达式替换为 value

rewrite(*args[, deep])

使用定义的规则重写 self

simplify(**kwargs)

请参阅 sympy.simplify 中的 simplify 函数。

sort_key([order])

返回一个排序键。

subs(*args, **kwargs)

在简化参数后,在表达式中用新内容替换旧内容。

xreplace(rule)

替换表达式中对象的出现。

复制

could_extract_minus_sign

is_hypergeometric

class sympy.tensor.tensor._TensorManager[源代码][源代码]

管理张量属性的类。

属性:
comm

方法

clear()

清除 TensorManager。

comm_i2symbol(i)

返回与换组编号对应的符号。

comm_symbols2i(i)

获取与 i 对应的交换组编号。

get_comm(i, j)

返回交换组编号 i, j 的交换参数

set_comm(i, j, c)

设置换向组 i, j 的换向参数 c

set_comms(*args)

为符号 i, j 设置换向组编号 c

注释

张量属于张量交换群;每个群都有一个标签 comm;有预定义的标签:

0 与任何其他张量交换的张量

1 张量自身反对易

2 张量不交换,除了那些 comm=0

其他组可以使用 set_comm 定义;这些组中的张量与 comm=0 的张量可交换;默认情况下,它们不与其他任何组交换。

clear()[源代码][源代码]

清除 TensorManager。

comm_i2symbol(i)[源代码][源代码]

返回与换组编号对应的符号。

comm_symbols2i(i)[源代码][源代码]

获取与 i 对应的交换组编号。

i 可以是一个符号、一个数字或一个字符串。

如果 i 尚未定义,则设置其交换组编号。

get_comm(i, j)[源代码][源代码]

返回交换组编号 i, j 的交换参数

参见 _TensorManager.set_comm

set_comm(i, j, c)[源代码][源代码]

设置换向组 i, j 的换向参数 c

参数:
i, j表示交换组的符号
c组交换数

注释

i, j 可以是符号、字符串或数字,除了 0, 12 分别保留用于交换、反交换张量和与任何其他组不交换的张量,除了与交换张量交换。对于其余情况,使用此方法设置交换规则;默认情况下 c=None

群交换数 c 是根据群交换符号分配的;它可以是

0 通勤

1 反对易

None 无交换性质

示例

GGH 不与自身交换,但彼此之间可以交换;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)
set_comms(*args)[源代码][源代码]

为符号 i, j 设置换向组编号 c

参数:
参数 : (i, j, c) 的序列序列