defrule extraction of scalars from symbolic matrix trace
Subject: defrule extraction of scalars from symbolic matrix trace
From: Richard Fateman
Date: Fri, 03 Dec 2010 12:00:28 -0800
Not everything has to be done with patterns. In particular,
defrule(r1, ....)
simplify defines a function r1.
Sometimes it is better to write functions yourself, rather than having
defrule write them for you. For a (probably more "advanced" than necessary
discussion of this issue, see
http://www.cs.berkeley.edu/~fateman/papers/partition.pdf )
If the idea is to take tr( mu, ..stuff..) and change it to A*tr(mu,
...B...) where
A=product of all scalar multiples of yada yada and B is the stuff with
the scalars removed, then
you could use the partition program in that paper, or something like it.
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.
RJF
On 12/3/2010 11:30 AM, Robert Dodier wrote:
> There's no way to apply a user-defined rule to a function with a
> variable number of arguments.
> There is some code (PART+ and PART*) which handles "+" and "*" separately
> from other operators. I've often thought about generalizing that so
> it could have other n-ary and/or commutative operators,
> but haven't made any progress on it.
>
> At this point I think the only solution is to write a
> simplification function in Lisp.
>
> best, Robert Dodier
>
> On 11/30/10, Edwin Woollett<woollett at charter.net> wrote:
>> 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:
>> --------------------------------------
>> load (multiadditive)$
>>
>> declare(tr, multiadditive);
>>
>> 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:
>>
>> (%i1) load(tr);
>> (%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
>>
>> _______________________________________________
>> Maxima mailing list
>> Maxima at math.utexas.edu
>> http://www.math.utexas.edu/mailman/listinfo/maxima
>>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima