defrule extraction of scalars from symbolic matrix trace



On Dec. 3, Richard Fateman wrote:
-----------------------------------------
>Perhaps simpler
>and special purpose, you can write a program like this....

>simptrace(X) :=   /*  call this only if X looks like tr(mu, ...) and you 
>want to extract scalars. */
>block([A:1, B: substinpart("[",rest(X),0)],
>   for i:1 thru length(B) do

> (  /* set A:  A*  the scalar part of B[i]  ,
       set B[i] : the nonscalar part of B[i] */
>),
>return (A* apply(tr,(cons(first(X),B) )  /* put back  tr(mu, ....    */

>... if this is unclear, please ask.
-------------------------------------------
Thanks for the info on your partition code.

In my dirac package, I had to expand out the mass terms
in things like (here p and q are feynman slashed gamma
matrices)

   tr(p+m,c1*q - M)

and pulled out the scalars by hand 
to get to

 c1*tr(p,q) -M*tr(p) + m*c1*tr(q) - 4*m*M

which simplifies to

 c1*tr(p,q) - 4*m*M

and I used the type of special purpose code
approach you suggest above,
starting with the list of arguments

(%i1) ee : tr(p+m,c1*q - M)$
(%i2) targs : args(ee);
(%o2) [p+m,c1*q-M]

and using a homemade expansion code (in dgexp.mac) 
 which doesn't care about the number of args.

Ted Woollett