Behavior of defmatch



On 2013-08-14, Wilhelm Haager <wilhelm.haager at htlstp.ac.at> wrote:

>   (%i2) matchdeclare([xx,yy],numberp,rr,lambda([u],numberp(u) and u > 
> 0));
>   (%o2) done
>
> There is no match with the "+" sign in the expression:
>
>   (%i3) defmatch(circlep,(y-yy)^2 + (x-xx)^2 = rr);
>   (%o3) circlep
>   (%i4) circlep((y-3)^2+(x-2)^2 = 25);
>   (%o4) false

For "+" and "*" expressions, the generated pattern matching function
might try to extract terms via arithmetic operations (as shown by :lisp
#'$circlep) rather than purely syntactic operations. Putting aside the
question of whether a pattern matcher should use any arithmetic, the
generated function fails to match while a similar function with some
other operator (named "my+" here) succeeds.

(%i2) matchdeclare([xx,yy],numberp,rr,lambda([u],numberp(u) and u > 0)) $
(%i3) infix ("my+", 100, 100);
(%o3) "my+"
(%i4) defmatch(circlep,(y-yy)^2 my+ (x-xx)^2 = rr) $
(%i5) circlep((y-3)^2 my+ (x-2)^2 = 25);
(%o5) [rr = 25,xx = 2,yy = 3]

>   (%i5) defmatch(circlep1,(x-xx)^2 - (y-yy)^2 = rr);
>   (%o5) circlep1
>   (%i6) circlep1((x-2)^2-(y-3)^2 = 25);
>   (%o6) [rr = 25,yy = 3,xx = 2]

I didn't look at this case in detail. My first guess is that the
asymmetry of "-" helps.

best

Robert Dodier