summertime hacking; making maxima 10X faster or more
Subject: summertime hacking; making maxima 10X faster or more
From: Richard Fateman
Date: Mon, 17 Jul 2006 14:35:53 -0700
15 years ago I wrote a bunch of patches to the Maxima / Macsyma simplifier
using hash coding and memorization, to make it much faster. 10X or more -
replacing
exponential-time routines with constant-time routines!
Maxima 5.9.3 http://maxima.sourceforge.net
(%o3) true
(%i4) showtime:all$
Evaluation took 00.40 seconds (00.40 elapsed)
(%i6) m1:sum(z[i],i,0,200)$
Evaluation took 2.22 seconds (2.22 elapsed)
(%i7) m2:sum(z[i],i,0,200)$
Evaluation took 2.16 seconds (2.16 elapsed)
(%i8) m1-m2;
Evaluation took 00.50 seconds (00.50 elapsed)
(%o8)
0
(%i9) m1+m2$
Evaluation took 0.00 seconds (0.00 elapsed)
(%i10) %o9-m1-m2;
Evaluation took 0.10 seconds (0.10 elapsed)
(%o10)
0
(%i11) m10:m1+sum(z[i],i,201,500)$
Evaluation took 7.00 seconds (7.00 elapsed)
(%i12) m20:m2+sum(z[i],i,201,500)$
Evaluation took 5.09 seconds (5.09 elapsed)
(%i13) m10-m20;
Evaluation took 0.29 seconds (0.29 elapsed)
(%o13)
0
LOAD IN THE PATCH FILE
(%i14) load("c:\\lisp\\newsimp.o");
......
now redo the same stuff as above.
(%i15) m1:sum(z[i],i,0,200)$
Evaluation took 00.20 seconds (00.20 elapsed) // 10X faster
(%i16) m2:sum(z[i],i,0,200)$
Evaluation took 00.20 seconds (00.20 elapsed) // 10X faster
(%i17) m1-m2;
Evaluation took 0.00 seconds (0.00 elapsed) // infty faster (0 vs 0.5 sec)
.....
(%i10) m10:m1+sum(z[i],i,201,500)$
Evaluation took 00.50 seconds (00.50 elapsed) // 14X faster
(%i11) m20:m2+sum(z[i],i,201,500)$
Evaluation took 00.40 seconds (00.40 elapsed)
(%i12) m10-m20; // infty faster (0 vs 0.29 sec)
Evaluation took 0.00 seconds (0.00 elapsed)
(%o12) 0
HERE ARE SOME OTHER TESTS ...
he newsimp programs should be even faster for
adding these (larger!) expressions.
(%i13) r[0]:0$
(%i14) r[i]:=r(r[i-1])$
(%i16) h1:sum(r[i],i,0,200)$
Evaluation took 75.96 seconds (75.96 elapsed) // vs 400 sec.. 5X faster
similar for h2.
computing h1-h2 with newsimp takes 0 seconds vs. 9.3 sec ..
..............
Why not use newsimp all the time?
Some bugs, some may be peculiar to GCL, though. There may be
interactions with other pieces of code in maxima. I've disabled some
of the "expand" features -- you should almost always be using ratsimp
or ratexpand, anyway. Tellsimp, at least on plus and times
is also disabled; could be fixed. I played with using (complex 0 1) instead
of the atom %i. When Macsyma was written, lisp did not have rational
numbers or complexes. Now it has both.
The code is in http://www.cs.berkeley.edu/~fateman/temp/newsimp.cl and
can be compiled and read in to maxima 5.9.3.
I've mentioned all this before ,but readers of this mailing list who have
joined recently
may not be aware of this code, and they may want to learn more about
the guts of maxima's simplifier. If so they may benefit from looking at the
code,
and especially the extra comments inserted in the source file.
RJF