home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / sci / math / symbolic / 3074 < prev    next >
Encoding:
Internet Message Format  |  1992-11-21  |  9.5 KB

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!sun-barr!ames!pacbell.com!network.ucsd.edu!sdcc12!oba!mstankus
  2. From: mstankus@oba.ucsd.edu (Mark Stankus)
  3. Newsgroups: sci.math.symbolic
  4. Subject: Re: an example of comparative CAS programming
  5. Message-ID: <41417@sdcc12.ucsd.edu>
  6. Date: 22 Nov 92 04:23:06 GMT
  7. References: <dzpqj3g@lynx.unm.edu>
  8. Sender: news@sdcc12.ucsd.edu
  9. Organization: Mathematics @ UCSD
  10. Lines: 274
  11. Nntp-Posting-Host: oba.ucsd.edu
  12.  
  13. In article <dzpqj3g@lynx.unm.edu> jpg@spectre.unm.edu (Jeffrey P. Golden) writes:
  14. >Reply-To: jpg@macsyma.com
  15. >
  16. >Given all the recent messages about comparative programming in 
  17. >the various CAS, I thought the following might be elucidating.
  18. >
  19. >Barry Simon, "Symbolic Math: Problems and Solutions", 
  20. >Notices of the AMS, Vol. 39, No. 7, pp. 700-710, Sept. 1992 
  21. >has the following problem:
  22. >
  23. >  9.  Rule based algebra
  24. >  Consider the Clifford algebra in 10 variables, that is the 
  25. >  complex algebra with ten generators, s0,...,s9 obeying
  26. >          si sj + sj si = 0 if i is different from j
  27. >          si si = 1
  28. >  That is multiplication is NOT commutative (but is assumed
  29. >  associative).  Compute (s0+s1+....+s9)^5
  30. >  NOTE: This must be done with general methods - it is cheating 
  31. >  to use the invariance of the Clifford algebra under orthogonal 
  32. >  transformations.
  33. >
  34. >The article gives the following solutions provided by the 
  35. >respective CAS vendors:
  36. >
  37. >-------------------------------------------------------------------------
  38. >
  39. >Derive Problem 9.  A solution was provided with 55 lines of function
  40. >definition of which the following is typical:
  41. >ADD_AUX(u,v,j,k):=~
  42. > IF(j=0,HEAD(v,k),~
  43. >    IF(k=0,HEAD(u,j),~
  44. >       IF(SIMILAR(ELEMENT(u,j),ELEMENT(v,k)),~
  45. >          APPEND(ADD_AUX(u,v,j-1,k-1),~
  46. >  ADDSIMILAR(ELEMENT(ELEMENT(u,j),1)+ELEMENT(ELEMENT(v,k),1),ELEMENT(u,j))),~
  47. >          IF(BEFORE(ELEMENT(u,j),ELEMENT(v,k)),~
  48. >             APPEND(ADD_AUX(u,v,j,k-1),[ELEMENT(v,k)]),~
  49. >             APPEND(ADD_AUX(u,v,j-1,k),[ELEMENT(u,j)])))))
  50. >Anyone who thinks you can't program with just an IF statement
  51. >should look at this.  It's awkward but certainly doable!  The
  52. >answer, by the way is 100 times the sum of the sigmas.
  53. >
  54. >Maple Problem 9: Here's the code to set up the rule based algebra:
  55. >   s.(0..9):
  56. >   readlib(commutat):
  57. >   for i from 0 to 9 do
  58. >    for j from i+1 to 9 do
  59. >     &*(s.j,s.i) := -&*(s.i,s.j);
  60. >    od;
  61. >    &*(s.i,s.i) := 1;
  62. >   od:
  63. >
  64. >   &^ := proc(a,n) local t;
  65. >   t := 1;
  66. >   to n do
  67. >    if type(t,constant) then t := t*a
  68. >    else t := expand(t&*a)
  69. >    fi
  70. >   od;
  71. >   t
  72. >   end:
  73. >
  74. >   q9 := sum('s.k',k=0..9);
  75. >   a9:=q9&^5;
  76. >
  77. >Mathematica Problem 9
  78. >  (* rulesfor  Clifford algebra *)
  79. >  ncm[s[i_],s[j_]] := -ncm[s[j], s[i]]/;i > j
  80. >  ncm[s[i_], s[i_]] := 1
  81. >  (* rules for non-commutative multiplication *)
  82. >  (* - behavior of multiplication of integers *)
  83. >  ncm[a_?NumberQ, b_?NumberQ, c___] := ncm[a b, c]
  84. >  (* - distributivity of addition *)
  85. >  ncm[m___, a_Plus,b_Plus, n___] :=
  86. >          ncm[m, Distribute[tmp[a,b],Plus]/.tmp -> ncm, n]
  87. >  (*  - associativity *)
  88. >  ncm[a___, ncm[r___], b___] := ncm[a, r, b]
  89. >  (* here's the expression *)
  90. >  expr = Plus @@ Map[s, Range[1,9]]
  91. >  (* and here's the power.  Note the output form involves ncm; this could 
  92. >   be formatted to look cleaner for one's individual purposes. *)
  93. >  expr^5/.
  94. >        x_^n_ :> Fold[ncm, x, Table[x, {n - 1}]]
  95. >
  96. >Reduce Problem 9: Shows simple elegance of the Reduce language.
  97. >   operator s;
  98. >   noncom s;
  99. >   for all i,j such that i>j let s(i)*s(j)=-s(j)*s(i);
  100. >   for all i let s(i)*s(i) = 1;
  101. >   xxx := for i:=0:9 sum s(i);
  102. >   xxx^2;
  103. >   xxx*ws^2;
  104. >
  105. >-------------------------------------------------------------------------
  106. >
  107. >Macsyma (from Macsyma Inc.) has a built in package ATENSOR for 
  108. >working with Clifford algebras, but here's an alternative solution 
  109. >done with Macsyma 417, going back to basic principles and using 
  110. >pattern matching:
  111. >
  112. >
  113. >(c1) matchdeclare([i,j],integerp)$
  114. >
  115. >(c2) tellsimpafter(s[i]^^2,1)$
  116. >
  117. >(c3) tellsimpafter(s[i].s[j],-s[j].s[i],i>j)$
  118. >
  119. >(c4) /* optional: */  compile_rule(all)$
  120. >
  121. >(c5) factor(expand(sum(s[i],i,0,9)^^5));
  122. >
  123. >(d5)    100 (s  + s  + s  + s  + s  + s  + s  + s  + s  + s )
  124. >              9    8    7    6    5    4    3    2    1    0
  125. >
  126. >-------------------------------------------------------------------------
  127. >
  128. >
  129. >You should of course make your own judgments but I don't find the 
  130. >Derive, Maple, or Mathematica solutions to be elegant.  
  131. >
  132. >One easily sees the price one pays with Maple due to its lack of 
  133. >pattern matching - notice all the enumerated assignments that are 
  134. >being made!  I don't know if a better solution is possible with 
  135. >Maple VR2.
  136. >
  137. >And notice all the extra stuff that's required in the Mathematica 
  138. >solution!
  139. >
  140. >I think the Reduce solution would be the most elegant if it weren't 
  141. >for the     xxx^2;  xxx*ws^2;   .  Does the simpler  xxx^5; 
  142. >not work, or is this circumlocution done just for the sake of 
  143. >efficiency?
  144. >
  145. >But I also think the Macsyma solution is pretty elegant too.
  146. >
  147. >
  148. >From: Jeffrey P. Golden <jpg@macsyma.com>
  149. >Organization: Macsyma Inc.
  150. >Reply-To: jpg@macsyma.com
  151.  
  152. It is true that the Mathematica solution required some code. On the
  153. other hand, we have developed an add-on to mathematica (which
  154. is long, but does a significant amount) which is available
  155. through anonymous ftp (instructions below).
  156.  
  157. If you get a copy of this program, please send us your name
  158. so that we can keep track of our users for bug reports,
  159. modifications to the program, etc.
  160.  
  161. Mark Stankus
  162.  
  163. (****************************************************************************)
  164.  
  165.  
  166.                                NCALGEBRA
  167.  
  168.                               Version 0.1
  169.  
  170.  
  171.  
  172. (****************************************************************************)
  173.  
  174.      Thanks you for your interest in NCAlgebra.  This message contains the
  175.      information necessary for you to use anonymous ftp to transfer the 
  176.      files from our site to yours. The ONLY thing which you have to
  177.      do to get the NCAlgebra package is to follow the following sample
  178.      terminal session. 
  179.  
  180.      NCAlgebra is at osiris.ucsd.edu, in the pub/ncalg directory.  Below 
  181.      is a record of an actually ftp session. What the user types is 
  182.      underlined.  Quoted expressions describe what should be typed.
  183.      (e.g., where you see "Any thing will do.", you may type anything
  184.      you want). Ignore all timing data.
  185.  
  186.      Note: If you are unfamiliar with ftp, then note that after the
  187.      command "mget *", the computer will respond with the prompt 
  188.      "mget CEEP?". You should hit the return key to indicate that 
  189.      you do indeed want to get the file CEEP. The computer will then
  190.      prompt you for the next file and you must hit the return key 
  191.      again. Even though there are about thirty files, the whole
  192.      process should take less than five minutes.
  193.      
  194.      
  195.      BELOW IS A SAMPLE SESSION. IF YOU FOLLOW IT, THEN YOU WILL BE
  196.      ABLE TO GET A COPY OF THE NCALGEBRA PACKAGE.
  197.  
  198.      YOU CAN HAVE YOUR LOCAL COMPUTER "GURU" FOLLOW THE BELOW 
  199.      INSTRUCTIONS AND INSTALL NCALGEBRA AS AN OFFICIAL MATHEMATICA
  200.      PACKAGE. ONCE THIS IS DONE, EVERYONE USING THE COMPUTER MAY
  201.      USE NCALGEBRA.
  202.  
  203.  
  204.  
  205.           % ftp 128.54.18.1
  206.             -------------------
  207.      
  208.           Connected to 128.54.18.1.
  209.      
  210.           220 osiris FTP server (SunOS 4.0) ready.
  211.      
  212.      
  213.           Name (128.54.18.1:dhurst): anonymous
  214.                                      ---------
  215.      
  216.           331 Guest login ok, send ident as password.
  217.      
  218.           Password: "Any thing will do." 
  219.                     --------------------
  220.      
  221.           230 Guest login ok, access restrictions apply.
  222.      
  223.           ftp> cd pub/ncalg 
  224.                -------------
  225.                                                
  226.           250 CWD command successful.          
  227.      
  228.           ftp> mget *  
  229.                ------
  230.      
  231.           mget CEEP?  "You just hit the <Return> key."
  232.                       --------------------------------
  233.      
  234.           200 PORT command successful.
  235.      
  236.           150 ASCII data connection for CEEP (128.54.18.8,3053) (453 bytes).
  237.      
  238.           226 ASCII Transfer complete.
  239.      
  240.           local: CEEP remote: CEEP
  241.      
  242.           474 bytes received in 0.0043 seconds (1.1e+02 Kbytes/s)
  243.  
  244.           mget CONTENTS? "Just keep on hitting that <Return> key until ... "
  245.                          ---------------------------------------------------
  246.           ftp> 
  247.      
  248.           ftp> bye  
  249.                ---
  250.           221 Goodbye.
  251.       
  252.  
  253.      
  254.      We have included a file called "ListofFilesAndSizes" in the directory
  255.      so that you can compare filenames and filesizes by Kilobyte blocks.
  256.      
  257.      This can be accomplished by typing the following UNIX commands,
  258.      
  259.           ls -s -1 > MyFiles; diff MyFiles ListofFilesAndSizes
  260.      
  261.      If what you have is identical to what we have, there should be NO
  262.      output from the diff command.  If there is a difference, then try
  263.      ftp again. If the difference is "small", talk to a local expert.
  264.  
  265.      We are interested in knowing who has NCAlgebra, so that 
  266.      we are able to inform them that new versions of the code 
  267.      are available, etc. PLEASE send us a email message so 
  268.      that we know that you are using the program.
  269.  
  270.      The documentation for NCAlgebra is contained in the file
  271.      NCDOCUMENT. Printing out this file to a printer is the best 
  272.      first step.
  273.      
  274.      We can email NCAlgebra, if necessary.
  275.      
  276.                Email any questions, comments or requests to 
  277.        
  278.      
  279.                           ncalg@osiris.ucsd.edu
  280.      
  281.       
  282.      
  283.      
  284. -- 
  285. mstankus
  286. mstankus@oba 
  287.