Subject: I really don't understand rules and patterns
From: Robert Dodier
Date: Wed, 3 Apr 2013 02:12:47 +0000 (UTC)
On 2013-04-02, Daniel Lakeland <dlakelan at street-artists.org> wrote:
> What is going on here? I want to find sums involving x,y, or z, and an
> index variable, i, j, k and a symbol dq and do something to them. I have
> rules like:
>
> matchdeclare(var,lambda([x],member(x,'[x,y,z])),
> indx,lambda([x],member(x,'[i,j,k])),
> int,integerp);
>
> defrule(recenteridxsum,var+int*dq+indx*dq,[var+indx*dq,int]);
>
> (%i179) recenteridxsum(x+dq*i+dq);
> (%o179) false
>
> This would seem to be wrong. I don't know why it does this though.
To match <stuff> times <constant>, where <constant> is something free of
match variables, the pattern matcher divides by <constant> and inspects
<stuff>. That's not necessarily the same as a purely formal match -- in
this case, dividing <stuff1> times dq + <stuff2> times dq yields
<stuff1> + <stuff2>, which matches neither int nor indx. I'm inclined to
think that's a bug.
The pattern matching code treats "+" and "*" specially, as described in
the documentation for tellsimpafter or matchdeclare (I forget which
one), but that doesn't come into play in this case.
Sorry I can't be more helpful --
Robert Dodier