8

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.

Andrey Rubshtein
  • 20,795
  • 11
  • 69
  • 104
  • 1
    @Mr. Wizard Agreed. I nearly bought you one, until I looked at the price tag (they inflate everything...) – Daniel Lichtblau Jan 30 '12 at 02:00
  • @Daniel I haven't decided if I should thank you or press charges. O_o – Mr.Wizard Jan 30 '12 at 04:15
  • I can’t compare it directly with Matlab (I do not have this program), but it seems that Mathematica’s Simplify and FullSimplify are more efficient than similar commands in Matlab. After Simplify your expression has 2192 and after FullSimplify it has just 1535 characters. Perhaps this is enough simplification for you or it would be a good new starting point for further attempts of simplification. – partial81 Jan 30 '12 at 09:53
  • Thanks for the feedback! One main point of your question is about a simplification with temporal variables. I totally ignored this in my answer. So, in my opinion my comment stays just a comment and not an answer. But perhaps you can persuade me with some arguments ;-) Maybe your expression is after Mathematica’s simplification simple enough, then my comment would be in deed a (random-)answer. – partial81 Jan 30 '12 at 13:04

2 Answers2

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]]
Community
  • 1
  • 1
Daniel Lichtblau
  • 6,854
  • 1
  • 23
  • 30
2

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.

partial81
  • 495
  • 6
  • 14