From: Eduardo O. <edu...@gm...> - 2025-07-20 12:36:45
|
Hi list, I was trying to write some programs using `defmatch' but I was getting some strange behaviors that SEEMED to be related to subexpressions being modified in ways that I didn't expect... I still don't understand what is going on but I finally got something that is easy to reproduce. The program is below, and I tested it both with a recent Maxima with "maxima --no-init" and with a Maxima 5.44 with "/usr/bin/maxima --userdir=/tmp" with a /tmp/ that is empty enough, and I got the same error. Note that in the last line the (x-2)^2+(y+3)^2 = 4 is not only reordered to (y+3)^2+(x-2)^2 = 4 but it is also changed to: (y+3)^2+(x-4)^2 = 4 I am attaching a screenshot. I edited the whitespace and the line breaks in the bash/Maxima window a bit, but besides that I didn't change anything else. Here is the program: display2d : false; matchdeclare(x, all)$ defmatch(isx2_, x^2)$ isx2 (o) := not atom(isx2_(o))$ isx2_body(o) := isx2(o) and rhs(isx2_(o)[1])$ sqrtp_ (o) := if isx2(o) then isx2_body(o) else sqrt(o)$ sqrtn_ (o) := if isx2(o) then -isx2_body(o) else sqrt(o)$ sqrtp (o) := map('sqrtp_,o)$ sqrtn (o) := map('sqrtn_,o)$ o0 : (x-2)^2+(y+3)^2=4; part(o0,1,1); o : o0 - part(o0,1,1); /* (x-2)^2 = 4-(y+3)^2 */ o : sqrtp(o); /* x-2 = sqrt(4-(y+3)^2) */ part(o,1,2); o : o - part(o,1,2); /* x = sqrt(4-(y+3)^2)+2 */ define(g1(y), rhs(o)); /* g1(y):=sqrt(4-(y+3)^2)+2 */ o0 : (x-2)^2+(y+3)^2=4; /* (y+3)^2+(x-4)^2 = 4 */ Cheers, Eduardo Ochs http://anggtwu.net/eev-maxima.html |