Maxima: compiling with cmucl, sbcl and gcl.



Hello,

After looking at the example posted recently, I still can't tell what
is going on. With the matrix dAconndt as posted, the function
mysimprec seems to run in a timely fashion. Maybe someone
else can try this.

I get mysimprec run times from 1.5 s (for GCL) to about 4 s
(SBCL) to about 5 s (for Clisp). These are all using current
CVS Maxima (i.e. 5.12 + changes) on a Linux system w/ 450 MHz cpu.

I changed length(string(...)) to slength(string(...)) in mysimprec.
It triggers an error otherwise; I don't see how it could have
succeeded before. I also threw in calls to elapsed_run_time
which is a recently added function (because showtime:true
didn't show the time when I ran load("mysimprec.mac")).

By the way when I run the program, it loops one more time and
produces a different (and slightly shorter) result.

I'll be interested to hear what are the run times on other systems.

Robert Dodier

PS. Here is my script in extenso. I ran it with load("/tmp/mysimprec.mac").

$ cat /tmp/mysimprec.mac
mysimprec(s):=block(
          [indexlist,sx,nf,listsimpf,nsx,nmin,simpf,sxnew],
          listsimpf:[fullratsimp,trigsimp,factor,trigreduce,
                     dividethru],nf:length(listsimpf),sx:s,
          nmin:slength(string(sx)),indexlist:[],
          print ("mysimprec: initial length of string(sx) =", nmin),
          for i1 thru nf do
              (simpf:listsimpf[i1],sxnew:apply(simpf,[sx]),
               nsx:slength(string(sxnew)),
               print ("mysimprec: after applying", simpf, "length of
string(sxnew) =", nsx),
               if nsx < nmin
                   then (indexlist:endcons(simpf,indexlist),
                         sx:sxnew,nmin:nsx)),display(indexlist),
          return(sx))$

dividethru(a):=block([num,den,quo,result],
           if not atom(a) and op(a) = "//"
               then (num:part(a,1),den:part(a,2),
                     quo:divide(num,den),
                     result:quo[2]/den+quo[1]) else result:a,
           return(result))$

dAconndt : matrix([0,a*dphi*kon*cos(phi)/2],[0,a*dphi*kon*sin(phi)/2],
                 [0,
                  a*sin(delta3)*kon
                   *(ddelta3*cos(delta3)*Lo1-ddelta3*sin(delta3)*Lc)
                   /(2*(sin(delta3)*Lo1+cos(delta3)*Lc)^2)
                   -a*ddelta3*cos(delta3)*kon
                    /(2*(sin(delta3)*Lo1+cos(delta3)*Lc))],
                 [0,
                  -ddelta3*sin(delta3)*kon*Lc
                   /(2*(sin(delta3)*Lo1+cos(delta3)*Lc))
                   -cos(delta3)*kon*Lc
                               *(ddelta3*cos(delta3)*Lo1
                                -ddelta3*sin(delta3)*Lc)
                    /(2*(sin(delta3)*Lo1+cos(delta3)*Lc)^2)],
                 [0,
                  kon*(2*ddelta3*cos(delta3)*Lo1-ddelta3*sin(delta3)*Lc)
                   /(2*(sin(delta3)*Lo1+cos(delta3)*Lc))
                   -kon*(ddelta3*cos(delta3)*Lo1-ddelta3*sin(delta3)*Lc)
                       *(2*sin(delta3)*Lo1+cos(delta3)*Lc)
                    /(2*(sin(delta3)*Lo1+cos(delta3)*Lc)^2)],
                 [0,
                  kon*(8*ddelta3*cos(delta3)*sin(delta3)*Lo1^2
                      -4*ddelta3*sin(delta3)^2*Lc*Lo1
                      +4*ddelta3*cos(delta3)^2*Lc*Lo1)
                   /(4*(sin(delta3)*Lo1+cos(delta3)*Lc)
                      *sqrt(4*sin(delta3)^2*Lo1^2
                             +4*cos(delta3)*sin(delta3)*Lc*Lo1+Lc^2))
                   -kon*(ddelta3*cos(delta3)*Lo1-ddelta3*sin(delta3)*Lc)
                       *sqrt(4*sin(delta3)^2*Lo1^2
                              +4*cos(delta3)*sin(delta3)*Lc*Lo1+Lc^2)
                    /(2*(sin(delta3)*Lo1+cos(delta3)*Lc)^2)],
                 [0,
                  -kon*Lc*(ddelta3*cos(delta3)*Lo1-ddelta3*sin(delta3)*Lc)
                   /(2*(sin(delta3)*Lo1+cos(delta3)*Lc)^2)],[0,0],[0,0])$

t0 : elapsed_run_time ()$
dAconndt_result : mysimprec (dAconndt)$
t1 : elapsed_run_time ()$
print ("time to compute mysimprec = ", t1 - t0)$

grind (dAconndt_result)$

dAconndt_expected : matrix([0,a*dphi*kon*cos(phi)/2],[0,a*dphi*kon*sin(phi)/2],
                 [0,
                  -a*ddelta3*kon*Lc/(2*(sin(delta3)^2*Lo1^2
                                       +2*cos(delta3)*sin(delta3)*Lc*Lo1
                                       -sin(delta3)^2*Lc^2+Lc^2))],
                 [0,
                  -ddelta3*kon*Lc*Lo1/(2
                                      *(sin(delta3)^2*Lo1^2
                                       +2*cos(delta3)*sin(delta3)*Lc*Lo1
                                       -sin(delta3)^2*Lc^2+Lc^2))],
                 [0,
                  ddelta3*kon*Lc*Lo1/(2
                                     *(sin(delta3)^2*Lo1^2
                                      +2*cos(delta3)*sin(delta3)*Lc*Lo1
                                      -sin(delta3)^2*Lc^2+Lc^2))],
                 [0,
                  ddelta3*kon*Lc
                         *(2*sin(delta3)*Lo1^2+cos(delta3)*Lc*Lo1
                                              +sin(delta3)*Lc^2)
                   /(2*(sin(delta3)^2*Lo1^2+2*cos(delta3)*sin(delta3)*Lc*Lo1
                                           -sin(delta3)^2*Lc^2+Lc^2)
                      *sqrt(4*sin(delta3)^2*Lo1^2
                             +4*cos(delta3)*sin(delta3)*Lc*Lo1+Lc^2))],
                 [0,
                  -ddelta3*kon*Lc*(cos(delta3)*Lo1-sin(delta3)*Lc)
                   /(2*(sin(delta3)^2*Lo1^2+2*cos(delta3)*sin(delta3)*Lc*Lo1
                                           -sin(delta3)^2*Lc^2+Lc^2))],[0,0],
                 [0,0])$

print ("length of string(dAconndt_result) = ", slength (string
(dAconndt_result)))$
print ("length of string(dAconndt_expected) = ", slength (string
(dAconndt_expected)))$


Here is an example output (SBCL).

(%i1) load ("/tmp/mysimprec.mac");
mysimprec: initial length of string(sx) = 1116
mysimprec: after applying fullratsimp length of string(sxnew) =
                                                             986
mysimprec: after applying trigsimp length of string(sxnew) = 788
mysimprec: after applying factor length of string(sxnew) = 751
mysimprec: after applying trigreduce length of string(sxnew) =
                                                             747
mysimprec: after applying dividethru length of string(sxnew) =
                                                             747
     indexlist = [fullratsimp, trigsimp, factor, trigreduce]

time to compute mysimprec =  4.66
matrix([0,a*dphi*kon*cos(phi)/2],[0,a*dphi*kon*sin(phi)/2],
       [0,
        a*ddelta3*kon*Lc/(cos(2*delta3)*Lo1^2
                         -Lo1^2-2*sin(2*delta3)*Lc*Lo1
                         -cos(2*delta3)*Lc^2-Lc^2)],
       [0,
        ddelta3*kon*Lc*Lo1/(cos(2*delta3)*Lo1^2
                           -Lo1^2-2*sin(2*delta3)*Lc*Lo1
                           -cos(2*delta3)*Lc^2-Lc^2)],
       [0,
        -ddelta3*kon*Lc*Lo1/(cos(2*delta3)*Lo1^2
                            -Lo1^2-2*sin(2*delta3)*Lc*Lo1
                            -cos(2*delta3)*Lc^2-Lc^2)],
       [0,
        (-2*ddelta3*sin(delta3)*kon*Lc*Lo1^2
         -ddelta3*cos(delta3)*kon*Lc^2*Lo1
         -ddelta3*sin(delta3)*kon*Lc^3)
         /(((cos(2*delta3)-1)*Lo1^2-2*sin(2*delta3)*Lc*Lo1
                                   +(-cos(2*delta3)-1)*Lc^2)
          *sqrt(-2*cos(2*delta3)*Lo1^2+2*Lo1^2
                                      +2*sin(2*delta3)*Lc*Lo1
                                      +Lc^2))],
       [0,
        (ddelta3*cos(delta3)*kon*Lc*Lo1
         -ddelta3*sin(delta3)*kon*Lc^2)
         /((cos(2*delta3)-1)*Lo1^2-2*sin(2*delta3)*Lc*Lo1
                                  +(-cos(2*delta3)-1)*Lc^2)],
       [0,0],[0,0])$
length of string(dAconndt_result) =  747
length of string(dAconndt_expected) =  751
(%o1)                  /tmp/mysimprec.mac
(%i2) build_info();

Maxima version: 5.12.0cvs
Maxima build date: 19:57 7/9/2007
host type: i686-pc-linux-gnu
lisp-implementation-type: SBCL
lisp-implementation-version: 1.0