通过自动引入时间变量或以任何其他方式简化非常长的符号表达式

发布于 2024-12-29 10:24:51 字数 572 浏览 2 评论 0原文

在尝试解决符号数学问题后,我得到了大约 17000 个字符的表达式。我正在使用 Matlab 的符号工具箱,但我愿意接受任何建议(Mathematica,无论什么)。

出于显而易见的原因,我不会将表达式直接复制粘贴到问题中。 这里是一个链接

运行 Matlab 命令 simplifysimple,甚至尝试 collect 也没有改善情况(有些人得到了情况更糟)。

但我想知道,我不关心表达式是否使用时间参数逐步计算。比如:

 z1 = a^2*y1;
 %Now the expression can be simplified by using z1 as alias!
 z1+z1^2 ....

是否有一种自动方法可以使用时间变量进行逐步简化?此外,您能想到的任何其他方法都是可行的。

After attempting to solve a symbolic math problem, I got an expression with about 17000 characters. I am using the symbolic toolbox for Matlab, but I am open to any suggestion (Mathematica, whatever).

For obvious reasons, I won't copy-paste the expression straight into the question. Here is a link instead.

Running the Matlab commands simplify and simple, and even attempts to collect didn't improve the situation (Some got it worse).

But I am wondering, I don't care if the expression is evaluated in steps, with temporal parameters. Something like:

 z1 = a^2*y1;
 %Now the expression can be simplified by using z1 as alias!
 z1+z1^2 ....

Is there an automatic method to get such a step-by-step simplification with temporal variables? Also, any other method that you can think of is plausible.

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

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

发布评论

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

评论(2

丑丑阿 2025-01-05 10:24:51

可以尝试公共子表达式消除(CSE)。这是一个摘自

让mathematica用另一个方程简化表达式

InputForm[Experimental`OptimizeExpression[(3 + 3*a^2 + Sqrt[5 + 6*a + 5*a^2] +
      a*(4 + Sqrt[5 + 6*a + 5*a^2]))/6]]

==>

Out[206]//InputForm=
Experimental`OptimizedExpression[Block[{Compile`$1, Compile`$3, Compile`$4, 
   Compile`$5, Compile`$6}, Compile`$1 = a^2; Compile`$3 = 6*a; 
   Compile`$4 = 5*Compile`$1; Compile`$5 = 5 + Compile`$3 + Compile`$4; 
   Compile`$6 = Sqrt[Compile`$5]; (3 + 3*Compile`$1 + Compile`$6 + 
     a*(4 + Compile`$6))/6]]

Might try common subexpression elimination (CSE). Here is an example cribbed from

Get mathematica to simplify expression with another equation

InputForm[Experimental`OptimizeExpression[(3 + 3*a^2 + Sqrt[5 + 6*a + 5*a^2] +
      a*(4 + Sqrt[5 + 6*a + 5*a^2]))/6]]

==>

Out[206]//InputForm=
Experimental`OptimizedExpression[Block[{Compile`$1, Compile`$3, Compile`$4, 
   Compile`$5, Compile`$6}, Compile`$1 = a^2; Compile`$3 = 6*a; 
   Compile`$4 = 5*Compile`$1; Compile`$5 = 5 + Compile`$3 + Compile`$4; 
   Compile`$6 = Sqrt[Compile`$5]; (3 + 3*Compile`$1 + Compile`$6 + 
     a*(4 + Compile`$6))/6]]
烟凡古楼 2025-01-05 10:24:51

正如我在评论中所写,Mathematica 的简化工具似乎比 Matlab 中的类似命令更有效。
鉴于您似乎是 Matlab 用户,因此我在这里向您详细说明如何使用 Mathematica 的两个简化命令。
如果您将长表达式定义为

longExpression = (x3^2*(y2+y3-a*y1-a*y2-2*a*y3-...

那么您可以使用

Simplify[longExpression]  
and 
FullSimplify[longExpression]

最后一个会产生一个漂亮而清晰的表达式,它只有 1535 个字符(听起来很多,但没有那么多变量)。
也许这足以简化您的问题。如果没有,请告诉我们。

As I wrote in my comment, it seems that Mathematica’s simplification tools are more efficient than similar commands in Matlab.
Since it seems that you are a Matlab user, I give you here a detailed instruction how to use just two of the simplification commands of Mathematica.
If you define your long expression as

longExpression = (x3^2*(y2+y3-a*y1-a*y2-2*a*y3-...

Then you can use

Simplify[longExpression]  
and 
FullSimplify[longExpression]

The last produces a nice and clear expression which has just 1535 characters (sounds much, but there are not so many variables).
Perhaps this is enough simplification for your problem. If not, then let us know.

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