# [Maxima] defrule extraction of scalars from symbolic matrix trace

Edwin Woollett woollett at charter.net
Tue Nov 30 15:32:56 CST 2010

```If the symbolic matrix trace has the notation
tr (mu, a*nu,rh,b*la,....) with (mu,nu,rh,la,..)
declared nonscalars and (a,b,c,d,...) declared
scalars, I would like to pull out all scalars so
that the above becomes
a*b*tr (mu,nu,rh,la,...),

and, of course, tr (a*mu) --> a*tr(mu).
I have tried pulling out scalars using an adaptation
of Robert Dodier's defrule method in commutators.mac
but eventually I have the problem that the number of
args of tr is arbitrary ( >=1).

So I am looking for a way of dealing with such arbitrariness.
So far, I have the code:
--------------------------------------

matchdeclare (aa, scalarp);
matchdeclare (bb, nonscalarp);
matchdeclare (cc, all);

defrule (rm1, tr (aa * bb), aa * tr (bb));
defrule (rm2, tr (aa * bb, cc), aa * tr (bb, cc));
defrule (rm3, tr (cc, aa * bb), aa * tr (cc, bb));

declare ([a,b,c,d,x,y,z], scalar)\$

declare ([la,mu,nu,rh,ta,si,al,be], nonscalar)\$

---------------------
and the partially successful output:

(%o1) "c:/work5/tr.mac"

(%i2) tr (mu,nu);
(%o2) tr(mu,nu)

(%i3) tr (mu,nu+rh);
(%o3) tr(mu,rh)+tr(mu,nu)

(%i4) tr (a*mu);
(%o4) tr(a*mu)

(%i5) apply1 (tr (a*mu),rm1);
(%o5) a*tr(mu)

(%i6) apply1 (tr (a*mu,nu),rm2);
(%o6) a*tr(mu,nu)

(%i7) apply1 (tr (a*mu,nu,rh),rm2);
(%o7) tr(a*mu,nu,rh)

(%i8) apply1 (tr (mu,a*nu),rm3);
(%o8) a*tr(mu,nu)

(%i9) apply1 (tr (la,mu,a*nu),rm3);
(%o9) tr(la,mu,a*nu)

(%i10) apply1 (tr (mu,a*nu,rh),rm3);
(%o10) tr(mu,a*nu,rh)

---------------------------
It looks like I need a replacement for
matchdeclare (cc, all); that deals with
the arbitrary number of args problem.

Ted Woollett

```