using tellsimp for sorting



 >  On 8/24/2010 12:13 PM, Piotr S?omski wrote:
 >> Hello.
 >>
 >> The sorting problem.
 >>
 >> We have a product of terms s[i,j] eg:
 >> s[3,2] . s[2,2] . s[2,1] . s[3,3]
 >> I use dot product because I need reorder this terms using my own rules.
 >> And the rules are such that terms should be sorted by first index 
but order of second index must be intact.
 >> So above product after sorting shoul look like:
 >> s[2,2] . s[2,1] . s[3,2] . s[3,3]
 >>
 >> I wrote some code using examples from this forum:
 >>
 >> greaterthan(i,j):=integerp(j) and is(i>j)$
 >> matchdeclare([ii,jj],integerp)$
 >> matchdeclare(i,integerp,j,greaterthan(i))$
 >> tellsimp(s[i,ii].s[j,jj],s[j,jj].s[i,ii])$
 > You have written a rule that deal only with  dot products of 2 items.
 > You need a rule or rules that work for any number of terms.
 >
 > Note that a.b.c   is  the same as
 >
 > "."(a,b,c).   A function of 3 arguments.
 >
 >
 > I suggest that you do this...
 >
 > K:  s[3,2] . s[2,2] . s[2,1] . s[3,3]
 >
 > L: subst("[",".", K);
 >
 > sort(L, lambda([p,q], is (inpart(p,1)< inpart(q,1))));
 >
 > subst(".", "[", %).
 >
 > of course there is not much reason to use "." here.  You could just 
use lists.
 >
 >
 > Pattern matching is not very useful for functions of arbitrary 
numbers of variables
 > in Maxima.
 > RJF

Thanx for replay.

Now suppose I have sorted some product, say s[2,2] . s[2,1] . s[3,2] . 
s[3,3] and I need to apply following rules to it:

matchdeclare([k,kk],integerp)$
tellsimp(s[k,kk].s[k,kk],1)$
tellsimp(s[k,1].s[k,2],( %i*s[k,3]))$
tellsimp(s[k,1].s[k,3],(-%i*s[k,2]))$
tellsimp(s[k,2].s[k,1],(-%i*s[k,3]))$
tellsimp(s[k,2].s[k,3],( %i*s[k,1]))$
tellsimp(s[k,3].s[k,1],( %i*s[k,2]))$
tellsimp(s[k,3].s[k,2],(-%i*s[k,1]))$

(btw these are rules for multiplying Pauli matrices).
But I run into the same problem. Only 2 rightmost terms are taken.
s[2,2] . s[2,1] . s[3,2] . s[3,3] turns to  %i*(s[2,2] . s[2,1] . s[3,1])
I found that adding

matchdeclare([W,X,Y,Z],subvarp)$
simp:false$
tellsimp(W.(Y.Z),(W.Y).Z)$
simp:true$

forces Maxima to work for three rightmost term in the product.
I'd be happy to construct a rule that work for 4 terms also.

Piotr Slomski