Mathematica:非交换乘法下的下标简化

发布于 2024-10-17 04:09:14 字数 578 浏览 2 评论 0原文

在 Mathematica 7.0+ 中使用下标[变量,整数],我有以下形式的表达式:

a_-4 ** b_1 ** a_-4 ** b_-4 ** a_1 ** c_-4 ** c_1 ** c_5

我想简化这个表达式。

规则:
* 具有相同下标的变量不交换,
* 具有不同下标的变量可以交换。

我需要一种方法来简化表达式并组合相似的术语(如果可能);输出应该类似于:

(a_-4)^2 ** b_-4 ** c_-4 ** b_1 ** a_1 ** c_1 ** c_5

我需要的最重要的事情是按下标对表达式中的术语进行排序,同时保留有关哪些通勤和哪些不通勤的规则。 (我想做的)第二件事是在顺序正确后合并相似的术语。我至少需要按以下方式对上面的表达式进行排序:

a_-4 ** a_-4 ** b_-4 ** c_-4 ** b_1 ** a_1 ** c_1 ** c_5,

即交换具有不同下标的变量,同时保留具有相同下标的变量的非通信性质。

欢迎所有想法,谢谢。

Using Subscript[variable, integer] in Mathematica 7.0+, I have expressions of the following form:

a_-4 ** b_1 ** a_-4 ** b_-4 ** a_1 ** c_-4 ** c_1 ** c_5

I would like to simplify this expression.

Rules:
* Variables with the same subscript to don't commute,
* variables with different subscripts do commute.

I need a way to simplify the expression and combine like terms (if possible); the output should be something like:

(a_-4)^2 ** b_-4 ** c_-4 ** b_1 ** a_1 ** c_1 ** c_5

The most important thing I need is to order the terms in the expression by subscripts while preserving the rules about what commutes and what does not. The second thing (I would like) to do is to combine like terms once the order is correct. I need to at least order expressions like above in the following way:

a_-4 ** a_-4 ** b_-4 ** c_-4 ** b_1 ** a_1 ** c_1 ** c_5,

that is, commute variables with different subscripts while preserving the non-communicative nature of variables with the same subscripts.

All ideas are welcome, thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

人│生佛魔见 2024-10-24 04:09:14

前几天我引用了一本图书馆笔记本来回答相关问题。

http://library.wolfram.com/infocenter/Conferences/325/

< a href="https://stackoverflow.com/questions/4974251/how-to-expand-the-arithematics-of- Differential-operators-in-mathematica">如何扩展mathematica中微分运算符的算术

我会抄一些相关的代码。我首先(再次)提到我将定义并使用我自己的非交换运算符,以避免内置 NonCommutativeMultiply 带来的模式匹配问题。另外,我将使用 a[...] 而不是 Subscript[a,...] 以便于使用 ascii 表示法和 Mathematica 输入/输出的剪切粘贴。

我们将某些“基本”实体分类为标量或变量,后者是具有交换限制的事物。我并没有尽可能地考虑这一点,而只是将标量定义为相当明显的“非变量”。

variableQ[x_] := MemberQ[{a, b, c, d}, Head[x]]
scalarQ[x_?NumericQ] := True
scalarQ[x_[a_]^n_. /; !variableQ[x[a]]] := True
scalarQ[_] := False

ncTimes[] := 1
ncTimes[a_] := a
ncTimes[a___, ncTimes[b___, c___], d___] := ncTimes[a, b, c, d]
ncTimes[a___, x_ + y_, b___] := ncTimes[a, x, b] + ncTimes[a, y, b]
ncTimes[a___, n_?scalarQ*c_, b___] := n*ncTimes[a, c, b]
ncTimes[a___, n_?scalarQ, b___] := n*ncTimes[a, b]
ncTimes[a___, x_[i_Integer]^m_., x_[i_]^n_., b___] /; 
  variableQ[x[i]] := ncTimes[a, x[i]^(m + n), b]
ncTimes[a___, x_[i_Integer]^m_., y_[j_Integer]^n_., b___] /; 
  variableQ[x[i]] && ! OrderedQ[{x, y}] := (* !!! *)
    ncTimes[a, y[j]^n, x[i]^m, b]

我将使用您的输入表单,只需稍微修改一下,因此我们将转换 ** 表达式以使用 ncTimes。

Unprotect[NonCommutativeMultiply];
NonCommutativeMultiply[a___] := ncTimes[a]

这是你的例子。

In[124]:= 
    a[-4] ** b[1] ** a[-4] ** b[-4] ** a[1] ** c[-4] ** c[1] ** c[5]

Out[124]= ncTimes[a[-4]^2, a[1], b[1], b[-4], c[-4], c[1], c[5]]

这种看似费力的方法的一个优点是您可以轻松定义换向器。例如,我们已经(隐含地)应用了这一点来制定上述规则。

commutator[x_[a_], y_[b_]] /; x =!= y || !VariableQ[x[a] := 0

一般来说,如果您有换向器规则,例如

ncTimes[a[j],a[i]] == ncTimes[a[i],a[i]]+(j-i)*a[i]

每当 j > 时, i,那么你可以规范化,比如在所有表达式中将 a[i] 放在 a[j] 之前。为此,您需要修改标记为 (!!!) 的规则以考虑此类换向器。

我应该补充一点,我在任何意义上都没有完全测试上述代码。

丹尼尔·利希布劳
沃尔夫勒姆研究公司

I cited a library notebook the other day for a related question.

http://library.wolfram.com/infocenter/Conferences/325/

How to expand the arithematics of differential operators in mathematica

I'll crib some relevant code. I first mention (again) that I'm going to define and work with my own noncommutative operator, to avoid pattern matching headaches from built-in NonCommutativeMultiply. Also I will use a[...] instead of Subscript[a,...] for ease of ascii notation and cut-paste of Mathematica input/output.

We will classify certain "basic" entities as scalars or variables, the latter being the things that have commutation restrictions. I am not taking this nearly as far as one might go, and am only defining scalars to be fairly obvious "non-variables".

variableQ[x_] := MemberQ[{a, b, c, d}, Head[x]]
scalarQ[x_?NumericQ] := True
scalarQ[x_[a_]^n_. /; !variableQ[x[a]]] := True
scalarQ[_] := False

ncTimes[] := 1
ncTimes[a_] := a
ncTimes[a___, ncTimes[b___, c___], d___] := ncTimes[a, b, c, d]
ncTimes[a___, x_ + y_, b___] := ncTimes[a, x, b] + ncTimes[a, y, b]
ncTimes[a___, n_?scalarQ*c_, b___] := n*ncTimes[a, c, b]
ncTimes[a___, n_?scalarQ, b___] := n*ncTimes[a, b]
ncTimes[a___, x_[i_Integer]^m_., x_[i_]^n_., b___] /; 
  variableQ[x[i]] := ncTimes[a, x[i]^(m + n), b]
ncTimes[a___, x_[i_Integer]^m_., y_[j_Integer]^n_., b___] /; 
  variableQ[x[i]] && ! OrderedQ[{x, y}] := (* !!! *)
    ncTimes[a, y[j]^n, x[i]^m, b]

I'll use your input form only slightly modified, so we'll convert ** expressions to use ncTimes instead.

Unprotect[NonCommutativeMultiply];
NonCommutativeMultiply[a___] := ncTimes[a]

Here is your example.

In[124]:= 
    a[-4] ** b[1] ** a[-4] ** b[-4] ** a[1] ** c[-4] ** c[1] ** c[5]

Out[124]= ncTimes[a[-4]^2, a[1], b[1], b[-4], c[-4], c[1], c[5]]

An advantage to this seemingly laborious method is you can readily define commutators. For example, we already have (implicitly) applied this one in formulating the rules above.

commutator[x_[a_], y_[b_]] /; x =!= y || !VariableQ[x[a] := 0

In general if you have commutator rules such as

ncTimes[a[j],a[i]] == ncTimes[a[i],a[i]]+(j-i)*a[i]

whenever j > i, then you could canonicalize, say by putting a[i] before a[j] in all expressions. For this you would need to modify the rule marked (!!!) to account for such commutators.

I should add that I have not in any sense fully tested the above code.

Daniel Lichtblau
Wolfram Research

穿透光 2024-10-24 04:09:14

这是您正在寻找的东西吗

Sort

这些类型的规则可以概括(例如,为非交换对象添加交换规则,使其处理非数字索引等...)并打包到 NCMSort 例程中。您还可以通过定义唯一的 NCMOrder 函数在一次传递中进行排序来优化它,例如

NCMSort[expr_] := expr /. a_NonCommutativeMultiply :> a[[NCMOrder[a]]]

旁白:
我在生成 arXiv:1009.3298 的结果时使用了这样的过程 - 笔记本将随(即将发布)更长的论文。

Is this the type of thing you are looking for

Sort

These types of rules can be generalised (e.g. add commutation rules for noncommuting objects, make it handle nonnumeric indices, etc...) and packaged up into a NCMSort routine. You can also optimize it by doing the sorting in a single pass by defining a unique NCMOrder function, e.g.

NCMSort[expr_] := expr /. a_NonCommutativeMultiply :> a[[NCMOrder[a]]]

An aside:
I used such a process in generating the results of arXiv:1009.3298 -- the notebook will be distributed with the (soon to be released) longer paper.

初雪 2024-10-24 04:09:14

您可以使用 NCAlgebra 做您想做的事情。在您的示例中:

<< NC`
<< NCAlgebra`
expr = Subscript[a, -4] ** Subscript[b, 1] ** Subscript[a, -4] ** Subscript[b, -4] ** Subscript[a, 1] ** Subscript[c, -4] ** Subscript[c, 1] ** Subscript[c, 5]
rule = {(Subscript[x_, i_] ** Subscript[y_, j_] /; i > j) -> Subscript[y, j] ** Subscript[x, i]}NCReplaceRepeated[expr, rule]
NCReplaceRepeated[expr, rule]

生成

Subscript[a, -4] ** Subscript[a, -4] ** Subscript[b, -4] ** Subscript[c, -4] ** Subscript[b, 1] ** Subscript[a, 1] ** Subscript[c, 1] ** Subscript[c, 5]

它在这里看起来不太好,但 Subscripts 将在笔记本上很好地呈现。

You can do what you want using NCAlgebra. In the case of your example:

<< NC`
<< NCAlgebra`
expr = Subscript[a, -4] ** Subscript[b, 1] ** Subscript[a, -4] ** Subscript[b, -4] ** Subscript[a, 1] ** Subscript[c, -4] ** Subscript[c, 1] ** Subscript[c, 5]
rule = {(Subscript[x_, i_] ** Subscript[y_, j_] /; i > j) -> Subscript[y, j] ** Subscript[x, i]}NCReplaceRepeated[expr, rule]
NCReplaceRepeated[expr, rule]

produces

Subscript[a, -4] ** Subscript[a, -4] ** Subscript[b, -4] ** Subscript[c, -4] ** Subscript[b, 1] ** Subscript[a, 1] ** Subscript[c, 1] ** Subscript[c, 5]

It does not look so nice here but Subscripts will render nicely on a Notebook.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文