Simplifying a very long symbolic expression by automatically introducing temporal variables or in any other way

北城以北 提交于 2019-12-04 05:39:14
Daniel Lichtblau

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!