简化和重新排列mathematica中的非交换变量

发布于 2024-09-27 16:44:45 字数 1143 浏览 1 评论 0 原文

简而言之,我有一个表达式,其中包含 p1p2q1q2 之间的乘法,并且 I' d 喜欢使用 [qi,pi]=ii*hb,其中 i={1,2} 将表达式转换为对称形式 (pi^ a*qi^b+qi^b*pi^a)/2

例如,对于 p2*q2*p2^2 我得到 (p2*q2^3+q2^3*p2)/2 + 1/2*ii*p2^2* hb 使用简化和一些替换。但是我无法简化 q2*q1^2*p2 尽管我已经指定了规则 q2*p2-> (p2*q2+q2*p2)/2 +ii/2*hb 并且具有 1 和 2 的变量可交换。

更详细地说,这里是 Mathematica 代码(我使用 量子包)。

该代码在索引为 1 或 2 时有效,但在使用两个索引时无效:

p2*q2*q1*q2 给出 p2*q1*q2^2, p2*q2*q2 可以进一步简化,但由于有 q1,Mathematica 不会这样做。

更详细地说:我正在尝试编写一个 Mathematica 代码,可以在 附录(本文中的方程A2)这是我正在使用的代码。后一个文件中的代码与上面的代码有点不同,因为我无法让上面的代码也运行,但它是理想的。

最后,我想将最终代码用于其他类型的哈密顿量,最高可达四次方甚至更高。

我希望有人建议我如何学习如何编写一个可以为我进行有针对性的简化的包。

In short, I have an expression that contains multiplications between p1, p2, q1 and q2, and I'd like to use [qi,pi]=ii*hb, where i={1,2} to get the expression to a symmetric form (pi^a*qi^b+qi^b*pi^a)/2.

So for example, for p2*q2*p2^2 I get (p2*q2^3+q2^3*p2)/2 + 1/2*ii*p2^2*hb using simplification and some replacements. But I cannot simplify q2*q1^2*p2 although I have specified a rule q2*p2-> (p2*q2+q2*p2)/2 +ii/2*hb and that variables with 1s and 2s commute.

In more detail, here is the Mathematica code (I use the quantum package).

The code works when the index is either 1 or 2 but doesn't work when both indexes are used:

p2*q2*q1*q2 gives p2*q1*q2^2, p2*q2*q2 can further be simplified but since there is q1, Mathematica doesn't do it.

In even more detail: I'm trying to write a Mathematica code that can get equations in appendix (eq. A2) in this paper
and this is the code that I'm using. The code in latter file is a little different from the code above because I couldn't get the code above to run as well but it would be ideal.

In the end I'd like to use the final code for other kind of Hamiltonians up to 4th power or even higher.

I'd love an advice how I can learn how to write a package that can do targeted simplifications for me.

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

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

发布评论

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

评论(1

紫罗兰の梦幻 2024-10-04 16:44:45

如果您只是使用规则来简化(并且我假设您的意思是使用 Replace[]),那么如果您要替换的模式存在但不准确,则可能会出现问题正确的形式。例如,您的 Replace[q2*q1^2*p2,q2*p2->(p2*q2+q2*p2)/2] 示例在这种情况下不会执行任何操作(请注意编写 q2*p2*q1^2 也无济于事,因为 Mathematica 在开始评估之前对所有输入进行排序,

我过去在 Mathematica 中遇到过类似的简化问题,并且有两种策略取得了相当的成功。很抱歉我无法给您具体的解决方案,我希望这些可以帮助您解决问题。

解决方案 1:您必须编写自己的 ReplaceUnordered[form,rule] 函数来解析 。 form 的所有不同顺序,以实现 rule 的可能应用。这可以通过 Permutations[] 和使用 HoldForm[ 来完成。 ]

解决方案 2:使用 Simplify[] 具体使用选项 ComplexityFunction 来创建非对称表达式。更“昂贵”,以及选项 TransformationFunctions 来指定您自己的简化规则。

这里 (pdf) 是对 Mathematica 的简短介绍以及它的构建和评估过程。

额外的奖励解决方案:使用 FORM 这是一种专门为解决您的问题而编写的语言正在拥有。

编辑:额外额外奖励(可能非常简单)解决方案:正如 rcollier 指出的SymmetricReduction[]可能会很容易地做你想做的事。

还有一件事是为了路上:当我不得不用非交换变量进行计算时
我使用了这个包,其中包含Grassmann的代数和微积分变量。



If you are just using rules to simplify (and I'm assuming that you mean that you use Replace[]) then there can be problems if the pattern you want to replace is present but not in the exact correct form. E.g., your example of Replace[q2*q1^2*p2,q2*p2->(p2*q2+q2*p2)/2] which will do nothing in this case (Note that writing q2*p2*q1^2 won't help either since Mathematica sorts all input before starting evaluation.

I have in the past encountered similar simplification problems with Mathematica and there are two strategies that have yielded reasonable success. I'm sorry I can't give you a specific solution, I hope these help you figure it out.

Solution 1: You have to write your own ReplaceUnordered[form,rule] function that parses through all the different orderings of form for possible applications of rule. This can be done with Permutations[] and the use of HoldForm[].

Solution 2: Use Simplify[]. Specifically use the option ComplexityFunction to make non-symmetrical expressions more "expensive", and the option TransformationFunctions to specify your own simplification rules.

Here (pdf) is a nice short(ish) introduction to Mathematica and it's constructs and the evaluation process.

Extra Bonus Solution: Use FORM which is a language written specifically to solve the problem you are having.

EDIT: Extra Extra Bonus (possibly very easy) Solution: As rcollier pointed out SymmetricReduction[] might do what you want very easily.

And one more for the road: When I have had to do calculations with non-commutative variables
I have used this package which contains algebra and calculus for Grassmann variables.



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