Simplification of a very long symbolic expression by automatically entering temporary variables or in any other way

After trying to solve a symbolic mathematical problem, I got an expression with about 17,000 characters. I use the symbolic toolbox for Matlab, but I'm open to any suggestion (Mathematica, whatever).

For obvious reasons, I will not copy-paste the expression directly into the question. Here is the link instead .

Running Matlab simplify and simple commands, and even collect attempts did not improve the situation (some got worse).

But I wonder, I don't care if the expression is evaluated step by step, with time parameters. Sort of:

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

Is there an automatic way to get this step-by-step simplification using temporary variables? Also, any other method you can think of is plausible.

+6
source share
2 answers

You might be trying to eliminate common subexpression (CSE). Here is an example taken from

Get math to simplify expressions using 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]] 
+5
source

As I wrote in my commentary, it seems that Mathematicas simplification tools are more efficient than similar commands in Matlab. Since it seems that you are a Matlab user, I give you detailed instructions on how to use only two Mathematica simplification commands. 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 latter produces a good and clear expression that has only 1535 characters (sounds a lot, but not so many variables). Perhaps this is quite a simplification of your problem. If not, let us know.

+1
source

Source: https://habr.com/ru/post/907183/


All Articles