From: mstankus@oba.ucsd.edu (Mark Stankus)
Newsgroups: sci.math.symbolic
Subject: Re: an example of comparative CAS programming
Date: 22 Nov 92 04:23:06 GMT
Organization: Mathematics @ UCSD

In article <dzpqj3g@lynx.unm.edu> jpg@spectre.unm.edu (Jeffrey P. Golden) writes:
>Reply-To: jpg@macsyma.com
>
>Given all the recent messages about comparative programming in 
>the various CAS, I thought the following might be elucidating.
>
>Barry Simon, "Symbolic Math: Problems and Solutions", 
>Notices of the AMS, Vol. 39, No. 7, pp. 700-710, Sept. 1992 
>has the following problem:
>
>  9.  Rule based algebra
>  Consider the Clifford algebra in 10 variables, that is the 
>  complex algebra with ten generators, s0,...,s9 obeying
>          si sj + sj si = 0 if i is different from j
>          si si = 1
>  That is multiplication is NOT commutative (but is assumed
>  associative).  Compute (s0+s1+....+s9)^5
>  NOTE: This must be done with general methods - it is cheating 
>  to use the invariance of the Clifford algebra under orthogonal 
>  transformations.
>
>The article gives the following solutions provided by the 
>respective CAS vendors:
>
>-------------------------------------------------------------------------
>
>Derive Problem 9.  A solution was provided with 55 lines of function
>definition of which the following is typical:
>ADD_AUX(u,v,j,k):=~
> IF(j=0,HEAD(v,k),~
>    IF(k=0,HEAD(u,j),~
>       IF(SIMILAR(ELEMENT(u,j),ELEMENT(v,k)),~
>          APPEND(ADD_AUX(u,v,j-1,k-1),~
>  ADDSIMILAR(ELEMENT(ELEMENT(u,j),1)+ELEMENT(ELEMENT(v,k),1),ELEMENT(u,j))),~
>          IF(BEFORE(ELEMENT(u,j),ELEMENT(v,k)),~
>             APPEND(ADD_AUX(u,v,j,k-1),[ELEMENT(v,k)]),~
>             APPEND(ADD_AUX(u,v,j-1,k),[ELEMENT(u,j)])))))
>Anyone who thinks you can't program with just an IF statement
>should look at this.  It's awkward but certainly doable!  The
>answer, by the way is 100 times the sum of the sigmas.
>
>Maple Problem 9: Here's the code to set up the rule based algebra:
>   s.(0..9):
>   readlib(commutat):
>   for i from 0 to 9 do
>    for j from i+1 to 9 do
>     &*(s.j,s.i) := -&*(s.i,s.j);
>    od;
>    &*(s.i,s.i) := 1;
>   od:
>
>   &^ := proc(a,n) local t;
>   t := 1;
>   to n do
>    if type(t,constant) then t := t*a
>    else t := expand(t&*a)
>    fi
>   od;
>   t
>   end:
>
>   q9 := sum('s.k',k=0..9);
>   a9:=q9&^5;
>
>Mathematica Problem 9
>  (* rulesfor  Clifford algebra *)
>  ncm[s[i_],s[j_]] := -ncm[s[j], s[i]]/;i > j
>  ncm[s[i_], s[i_]] := 1
>  (* rules for non-commutative multiplication *)
>  (* - behavior of multiplication of integers *)
>  ncm[a_?NumberQ, b_?NumberQ, c___] := ncm[a b, c]
>  (* - distributivity of addition *)
>  ncm[m___, a_Plus,b_Plus, n___] :=
>          ncm[m, Distribute[tmp[a,b],Plus]/.tmp -> ncm, n]
>  (*  - associativity *)
>  ncm[a___, ncm[r___], b___] := ncm[a, r, b]
>  (* here's the expression *)
>  expr = Plus @@ Map[s, Range[1,9]]
>  (* and here's the power.  Note the output form involves ncm; this could 
>   be formatted to look cleaner for one's individual purposes. *)
>  expr^5/.
>        x_^n_ :> Fold[ncm, x, Table[x, {n - 1}]]
>
>Reduce Problem 9: Shows simple elegance of the Reduce language.
>   operator s;
>   noncom s;
>   for all i,j such that i>j let s(i)*s(j)=-s(j)*s(i);
>   for all i let s(i)*s(i) = 1;
>   xxx := for i:=0:9 sum s(i);
>   xxx^2;
>   xxx*ws^2;
>
>-------------------------------------------------------------------------
>
>Macsyma (from Macsyma Inc.) has a built in package ATENSOR for 
>working with Clifford algebras, but here's an alternative solution 
>done with Macsyma 417, going back to basic principles and using 
>pattern matching:
>
>
>(c1) matchdeclare([i,j],integerp)$
>
>(c2) tellsimpafter(s[i]^^2,1)$
>
>(c3) tellsimpafter(s[i].s[j],-s[j].s[i],i>j)$
>
>(c4) /* optional: */  compile_rule(all)$
>
>(c5) factor(expand(sum(s[i],i,0,9)^^5));
>
>(d5)    100 (s  + s  + s  + s  + s  + s  + s  + s  + s  + s )
>              9    8    7    6    5    4    3    2    1    0
>
>-------------------------------------------------------------------------
>
>
>You should of course make your own judgments but I don't find the 
>Derive, Maple, or Mathematica solutions to be elegant.  
>
>One easily sees the price one pays with Maple due to its lack of 
>pattern matching - notice all the enumerated assignments that are 
>being made!  I don't know if a better solution is possible with 
>Maple VR2.
>
>And notice all the extra stuff that's required in the Mathematica 
>solution!
>
>I think the Reduce solution would be the most elegant if it weren't 
>for the     xxx^2;  xxx*ws^2;   .  Does the simpler  xxx^5; 
>not work, or is this circumlocution done just for the sake of 
>efficiency?
>
>But I also think the Macsyma solution is pretty elegant too.
>
>
>From: Jeffrey P. Golden <jpg@macsyma.com>
>Organization: Macsyma Inc.
>Reply-To: jpg@macsyma.com

It is true that the Mathematica solution required some code. On the
other hand, we have developed an add-on to mathematica (which
is long, but does a significant amount) which is available
through anonymous ftp (instructions below).

If you get a copy of this program, please send us your name
so that we can keep track of our users for bug reports,
modifications to the program, etc.

Mark Stankus

(****************************************************************************)


                               NCALGEBRA

                              Version 0.1



(****************************************************************************)

     Thanks you for your interest in NCAlgebra.  This message contains the
     information necessary for you to use anonymous ftp to transfer the 
     files from our site to yours. The ONLY thing which you have to
     do to get the NCAlgebra package is to follow the following sample
     terminal session. 

     NCAlgebra is at osiris.ucsd.edu, in the pub/ncalg directory.  Below 
     is a record of an actually ftp session. What the user types is 
     underlined.  Quoted expressions describe what should be typed.
     (e.g., where you see "Any thing will do.", you may type anything
     you want). Ignore all timing data.

     Note: If you are unfamiliar with ftp, then note that after the
     command "mget *", the computer will respond with the prompt 
     "mget CEEP?". You should hit the return key to indicate that 
     you do indeed want to get the file CEEP. The computer will then
     prompt you for the next file and you must hit the return key 
     again. Even though there are about thirty files, the whole
     process should take less than five minutes.
     
     
     BELOW IS A SAMPLE SESSION. IF YOU FOLLOW IT, THEN YOU WILL BE
     ABLE TO GET A COPY OF THE NCALGEBRA PACKAGE.

     YOU CAN HAVE YOUR LOCAL COMPUTER "GURU" FOLLOW THE BELOW 
     INSTRUCTIONS AND INSTALL NCALGEBRA AS AN OFFICIAL MATHEMATICA
     PACKAGE. ONCE THIS IS DONE, EVERYONE USING THE COMPUTER MAY
     USE NCALGEBRA.



          % ftp 128.54.18.1
            -------------------
     
          Connected to 128.54.18.1.
     
          220 osiris FTP server (SunOS 4.0) ready.
     
     
          Name (128.54.18.1:dhurst): anonymous
                                     ---------
     
          331 Guest login ok, send ident as password.
     
          Password: "Any thing will do." 
                    --------------------
     
          230 Guest login ok, access restrictions apply.
     
          ftp> cd pub/ncalg 
               -------------
                                               
          250 CWD command successful.          
     
          ftp> mget *  
               ------
     
          mget CEEP?  "You just hit the <Return> key."
                      --------------------------------
     
          200 PORT command successful.
     
          150 ASCII data connection for CEEP (128.54.18.8,3053) (453 bytes).
     
          226 ASCII Transfer complete.
     
          local: CEEP remote: CEEP
     
          474 bytes received in 0.0043 seconds (1.1e+02 Kbytes/s)

          mget CONTENTS? "Just keep on hitting that <Return> key until ... "
                         ---------------------------------------------------
          ftp> 
     
          ftp> bye  
               ---
          221 Goodbye.
      

     
     We have included a file called "ListofFilesAndSizes" in the directory
     so that you can compare filenames and filesizes by Kilobyte blocks.
     
     This can be accomplished by typing the following UNIX commands,
     
          ls -s -1 > MyFiles; diff MyFiles ListofFilesAndSizes
     
     If what you have is identical to what we have, there should be NO
     output from the diff command.  If there is a difference, then try
     ftp again. If the difference is "small", talk to a local expert.

     We are interested in knowing who has NCAlgebra, so that 
     we are able to inform them that new versions of the code 
     are available, etc. PLEASE send us a email message so 
     that we know that you are using the program.

     The documentation for NCAlgebra is contained in the file
     NCDOCUMENT. Printing out this file to a printer is the best 
     first step.
     
     We can email NCAlgebra, if necessary.
     
               Email any questions, comments or requests to 
       
     
                          ncalg@osiris.ucsd.edu
     
      
     
     
-- 
mstankus
mstankus@oba