Message Boards Message Boards

Improve speed while using Simplify[ ]?

time = TimeUsed[];
Simplify[-((3 t)/4) - 3/8 t Sin[ x[1] + x[2] + x[3] +... +  x[18] + x[19] + x[20]] + 3/8 (2 + Sin[x[1] + x[2] + x[3] + ...+ x[18] + x[19] + x[20]])];
TimeUsed[] - time
results:   0.07

time = TimeUsed[];
Simplify[-((3 t)/4) - 3/8 t Sin[ x[1] + x[2] + x[3] +... +  x[13] + x[14] + x[15]] + 3/8 (2 + Sin[x[1] + x[2] + x[3] + ...+ x[13] + x[14] + x[15]])];
TimeUsed[] - time
results:   22.2

The second procedure is obviously more simple than the first procedure, why the running time of the second procedure (i.e. 22s) is much more than the first procedure (i.e. 0.07), and how to improve the second procedure?

POSTED BY: Xiaoxu Zhong
3 Replies
  1. There might be some caching involved.
  2. Use AbsoluteTiming

Without the full expression I can not give it a try....

POSTED BY: Sander Huisman

What about the following approach:

In[1]:= Simplify[ (-3 t)/4 - (3 t)/8 y + 3/8 (2 + y)] /. 
  y -> Sin[Sum[x[i], {i, 15}]] // AbsoluteTiming

Out[1]= {0.000174964, -(3/
   8) (-1 + t) (2 + 
    Sin[x[1] + x[2] + x[3] + x[4] + x[5] + x[6] + x[7] + x[8] + x[9] +
       x[10] + x[11] + x[12] + x[13] + x[14] + x[15]])}
Posted 7 years ago

Thanks, this approach works, I guess maybe it is the algorithms related to the simplify in mathematica that caused this problem. But I wonder whether there is a instruction that can modify this problem, i.e. the time cost to calculate increases with the number of x[i] increases?

POSTED BY: Updating Name
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract