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