home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / sci / math / symbolic / 3073 < prev    next >
Encoding:
Text File  |  1992-11-21  |  4.7 KB  |  147 lines

  1. Newsgroups: sci.math.symbolic
  2. Path: sparky!uunet!spool.mu.edu!umn.edu!news.cs.indiana.edu!lynx!spectre.unm.edu!jpg
  3. From: jpg@spectre.unm.edu (Jeffrey P. Golden)
  4. Subject: an example of comparative CAS programming
  5. Message-ID: <dzpqj3g@lynx.unm.edu>
  6. Date: Sun, 22 Nov 92 00:35:09 GMT
  7. Organization: Dept. of Math & Stat, University of New Mexico, Albuquerque
  8. Lines: 137
  9.  
  10. Reply-To: jpg@macsyma.com
  11.  
  12. Given all the recent messages about comparative programming in 
  13. the various CAS, I thought the following might be elucidating.
  14.  
  15. Barry Simon, "Symbolic Math: Problems and Solutions", 
  16. Notices of the AMS, Vol. 39, No. 7, pp. 700-710, Sept. 1992 
  17. has the following problem:
  18.  
  19.   9.  Rule based algebra
  20.   Consider the Clifford algebra in 10 variables, that is the 
  21.   complex algebra with ten generators, s0,...,s9 obeying
  22.           si sj + sj si = 0 if i is different from j
  23.           si si = 1
  24.   That is multiplication is NOT commutative (but is assumed
  25.   associative).  Compute (s0+s1+....+s9)^5
  26.   NOTE: This must be done with general methods - it is cheating 
  27.   to use the invariance of the Clifford algebra under orthogonal 
  28.   transformations.
  29.  
  30. The article gives the following solutions provided by the 
  31. respective CAS vendors:
  32.  
  33. -------------------------------------------------------------------------
  34.  
  35. Derive Problem 9.  A solution was provided with 55 lines of function
  36. definition of which the following is typical:
  37. ADD_AUX(u,v,j,k):=~
  38.  IF(j=0,HEAD(v,k),~
  39.     IF(k=0,HEAD(u,j),~
  40.        IF(SIMILAR(ELEMENT(u,j),ELEMENT(v,k)),~
  41.           APPEND(ADD_AUX(u,v,j-1,k-1),~
  42.   ADDSIMILAR(ELEMENT(ELEMENT(u,j),1)+ELEMENT(ELEMENT(v,k),1),ELEMENT(u,j))),~
  43.           IF(BEFORE(ELEMENT(u,j),ELEMENT(v,k)),~
  44.              APPEND(ADD_AUX(u,v,j,k-1),[ELEMENT(v,k)]),~
  45.              APPEND(ADD_AUX(u,v,j-1,k),[ELEMENT(u,j)])))))
  46. Anyone who thinks you can't program with just an IF statement
  47. should look at this.  It's awkward but certainly doable!  The
  48. answer, by the way is 100 times the sum of the sigmas.
  49.  
  50. Maple Problem 9: Here's the code to set up the rule based algebra:
  51.    s.(0..9):
  52.    readlib(commutat):
  53.    for i from 0 to 9 do
  54.     for j from i+1 to 9 do
  55.      &*(s.j,s.i) := -&*(s.i,s.j);
  56.     od;
  57.     &*(s.i,s.i) := 1;
  58.    od:
  59.  
  60.    &^ := proc(a,n) local t;
  61.    t := 1;
  62.    to n do
  63.     if type(t,constant) then t := t*a
  64.     else t := expand(t&*a)
  65.     fi
  66.    od;
  67.    t
  68.    end:
  69.  
  70.    q9 := sum('s.k',k=0..9);
  71.    a9:=q9&^5;
  72.  
  73. Mathematica Problem 9
  74.   (* rulesfor  Clifford algebra *)
  75.   ncm[s[i_],s[j_]] := -ncm[s[j], s[i]]/;i > j
  76.   ncm[s[i_], s[i_]] := 1
  77.   (* rules for non-commutative multiplication *)
  78.   (* - behavior of multiplication of integers *)
  79.   ncm[a_?NumberQ, b_?NumberQ, c___] := ncm[a b, c]
  80.   (* - distributivity of addition *)
  81.   ncm[m___, a_Plus,b_Plus, n___] :=
  82.           ncm[m, Distribute[tmp[a,b],Plus]/.tmp -> ncm, n]
  83.   (*  - associativity *)
  84.   ncm[a___, ncm[r___], b___] := ncm[a, r, b]
  85.   (* here's the expression *)
  86.   expr = Plus @@ Map[s, Range[1,9]]
  87.   (* and here's the power.  Note the output form involves ncm; this could 
  88.    be formatted to look cleaner for one's individual purposes. *)
  89.   expr^5/.
  90.         x_^n_ :> Fold[ncm, x, Table[x, {n - 1}]]
  91.  
  92. Reduce Problem 9: Shows simple elegance of the Reduce language.
  93.    operator s;
  94.    noncom s;
  95.    for all i,j such that i>j let s(i)*s(j)=-s(j)*s(i);
  96.    for all i let s(i)*s(i) = 1;
  97.    xxx := for i:=0:9 sum s(i);
  98.    xxx^2;
  99.    xxx*ws^2;
  100.  
  101. -------------------------------------------------------------------------
  102.  
  103. Macsyma (from Macsyma Inc.) has a built in package ATENSOR for 
  104. working with Clifford algebras, but here's an alternative solution 
  105. done with Macsyma 417, going back to basic principles and using 
  106. pattern matching:
  107.  
  108.  
  109. (c1) matchdeclare([i,j],integerp)$
  110.  
  111. (c2) tellsimpafter(s[i]^^2,1)$
  112.  
  113. (c3) tellsimpafter(s[i].s[j],-s[j].s[i],i>j)$
  114.  
  115. (c4) /* optional: */  compile_rule(all)$
  116.  
  117. (c5) factor(expand(sum(s[i],i,0,9)^^5));
  118.  
  119. (d5)    100 (s  + s  + s  + s  + s  + s  + s  + s  + s  + s )
  120.               9    8    7    6    5    4    3    2    1    0
  121.  
  122. -------------------------------------------------------------------------
  123.  
  124.  
  125. You should of course make your own judgments but I don't find the 
  126. Derive, Maple, or Mathematica solutions to be elegant.  
  127.  
  128. One easily sees the price one pays with Maple due to its lack of 
  129. pattern matching - notice all the enumerated assignments that are 
  130. being made!  I don't know if a better solution is possible with 
  131. Maple VR2.
  132.  
  133. And notice all the extra stuff that's required in the Mathematica 
  134. solution!
  135.  
  136. I think the Reduce solution would be the most elegant if it weren't 
  137. for the     xxx^2;  xxx*ws^2;   .  Does the simpler  xxx^5; 
  138. not work, or is this circumlocution done just for the sake of 
  139. efficiency?
  140.  
  141. But I also think the Macsyma solution is pretty elegant too.
  142.  
  143.  
  144. From: Jeffrey P. Golden <jpg@macsyma.com>
  145. Organization: Macsyma Inc.
  146. Reply-To: jpg@macsyma.com
  147.