patterns and rules



Thanks to everyone who answered my question about how to
collect/collecttermsl,ratsimp etc.

Now I want to do a more complete ordering and I think I have to figure
out how to use patterns to do it...  I want to figure this stuff out
anyway.

But I've noticed that the documentation seems to be missing.

Anyway here is what I want:
I want to be able to suggest a hirarchy of terms to collect, in other
words I want to:

1. ratsimp with one list of coefficients
2. take a different set of terms and apply individually to each sums
collected, including the terms^0 sum.
3. of course it makes sense that the number of levels of this be
arbitrary.

For instance say I had the following expression:

 sol1:
g14*(g03*(g22*g41+g31*g32)+g13*(-g12*g41-g21*g32)+g23*(-g12*g31-g21*g22+2
*g11*g13))
+g04*(g23*(g12*g41+g21*g32)-g03*g32*g41-g11*g23^2)+g13*g23*(-g22*g41-g31*
g32)+g13^2*g32*g41
+g05*(g13*(g12*g31+g21*g22)-g03*g22*g31+g04*(g03*g11-g12*g21)-g11*g13^2)+
g22*g23^2*g31+g14^2*(g12*g21-g03*g11)
-g13*g23*g32+g03*g14*g32+g22*g23^2-g12*g14*g23-g03*g05*g22+g05*g12*g13;

(C16) ratsimp(sol1,g11,g21,g31,g41);
(D16)
((g13^2-g03*g04)*g32+(g04*g12-g13*g22)*g23+g03*g14*g22-g12*g13*g14)*g41
+g31*((g03*g14-g13*g23)*g32+g22*g23^2-g12*g14*g23-g03*g05*g22+g05*g12*g13)
+g21*((g04*g23-g13*g14)*g32-g14*g22*g23+g05*g13*g22+g12*g14^2-g04*g05*g12)
+(g03*g14-g13*g23)*g32+g11*(-g04*g23^2+2*g13*g14*g23-g03*g14^2-g05*g13^2+
g03*g04*g05)+g22*g23^2-g12*g14*g23-g03*g05*g22+g05*g12*g13


What I want to be able to do would look like:

(C??) simprecursive(sol1,[g11,g21,g31,g41],[g12,g22,g32,g42]);

(D??) g41*(g12*(g04*g23-g13*g14) + g22*(g03*g14-g13*g23) + g32*(-g03*g04 + g13^2))
+ g31*(g12*(g13*g05-g14*g23) + g32*(g03*g14-g13*g23) + g22*(-g03*g05 + g23^2))
+ g21*(g22*(g13*g05-g14*g23) + g32*(g04*g23-g13*g14) + g12*(-g04*g05 + g14^2))
+ g11*(g13*g14*g23*2-g03*g14^2-g04*g23^2 + g05*(g03*g04-g13^2))
+ g22*(g23^2-g03*g05)+g12*(g05*g13-g14*g23)

see, the sums are organized by the second list and the remaining item
are ordered by the second list.

By the way I used ratsimp instead of collecttermsl because you have to
expand before collecttermsl will do what I want.
ratsimp(sol1,g11,g21,g31,g41) seems to be the same as
collecttermsl(expand(sol1),[g11,g21,g31,g41]);

I've programmed in scheme before, and a bit in mathematica so I'm sure I
can do this, but I don't seem to have enough information.

Joshua Scholar