Possible matchdeclare/lambda expression/ruledef bug
Subject: Possible matchdeclare/lambda expression/ruledef bug
From: Robert Dodier
Date: Thu, 21 Feb 2013 22:30:19 +0000 (UTC)
On 2013-02-21, Mike Valenzuela <mickle.mouse at gmail.com> wrote:
> (%i1) matchdeclare(zz, lambda([x], freeof("+", dispform(x,all))))$
> (%i2) matchdeclare(yy, atom)$
> (%i3) defrule (r1, zz + yy, ["Free of addition" = zz, yy = "yy",
> freeof("+", dispform(zz, all)) ] )$
> (%i4) r1(z+y);
>
> (%o4) ["Free of addition"=z+y,0="yy",false]
Well, I think that's to be expected, if one's expectations are adjusted.
The code for "+" and "*" in tellsimpafter and defrule (I forget whether
tellsimp & defmatch do it the same) treats them differently from other
operators. (All commutative n-ary operators should be treated like "*"
and "+" btw. I've been thinking about that for some years now.) Instead
of matching a single argument, the match engine sweeps up all the
arguments which match a match variable according to its predicate, and
that list of matching arguments is returned as "+" or "*" applied to the
list of matching arguments. In this case, zz matches z and it matches y,
and therefore the value returned is "+" applied to [z, y].
I think I made an attempt to explain that in the documentation for
tellsimpafter. Yes, it's convoluted. Sorry about that.
best
Robert Dodier