bilinear defrule



On Nov. 30, Robert Dodier wrote
-------------------------------------
>On 11/30/10, Edwin Woollett <woollett at charter.net> wrote:

>> matchdeclare ([aa, bb, cc], all);
>>
>> defrule (rbilineara1, xx (aa + bb, cc), map (lambda ([u], xx (u, cc)), 
>> bb));
>> defrule (rbilineara2, xx (cc, aa + bb), map (lambda ([u], xx (cc, u)), 
>> bb));

>> I don't understand why rule rbilineara1 definition in terms
>> of the lambda function doesn't refer to aa as well as bb.
>> How is your definition able to get the job done?

>Well, I just want to match any "+" expression.
>I could write matchdeclare(pp, lambda([e], not atom(e) and op(e) = "+"))
>and then defrule(rfoo, xx(pp, aa), map(lambda([u], xx(u, aa)), pp),
>but I wanted the "+" to appear in the defrule so it's easier to see what
>kind of expression is matched. I would like to write
>defrule(rfoo, xx("+"(aa), cc), ....) but that doesn't seem to work as
>expected; that might be a bug in defrule.

>Since aa and bb match the same things (anything), one of them will
>absorb all of the "+" arguments, and the other will be 0.
>Trial and error suggested that bb is the one that will get all the 
>arguments,
>so I ignored aa.

>Hope this clears it up a little ...
---------------------------
Thanks for the matching explanation. The match 'all' is the wildcard in
this type of programming, in the sense that the Lispless programmer
has little feel for the implications of such a match.

Your suggested explicit alternative, using the
match (not atom and op is plus) is much clearer to me as a
Maxima (only) programmer, and works like it should:

(%i1) load(bilinear);
(%o1) "c:/work5/bilinear.mac"
(%i2) apply1(comm(a + b,c),rbilineara1);
(%o2) comm(b,c)+comm(a,c)
(%i3) apply1(comm(a ,b + c),rbilineara2);
(%o3) comm(a,c)+comm(a,b)

using code file bilinear.mac contents:
-----------------------
declare (bilinear, feature);
bilinearp (e) := featurep (e, bilinear);
declare (comm, bilinear);

matchdeclare (xx, bilinearp);
matchdeclare (aa, all);
matchdeclare(pp, lambda([e], not atom(e) and op(e) = "+"));
defrule(rbilineara1, xx(pp, aa), map(lambda([u], xx(u, aa)), pp));
defrule(rbilineara2, xx(aa, pp), map(lambda([u], xx(aa, u)), pp));
--------------------------------------------

Ted