|
From: Eduardo O. <edu...@gm...> - 2025-07-20 13:41:40
|
Ouch! You're right!
One way to fix my "bug" is to run my function defined by `defmatch'
inside a `block([x],...)', i.e., change this:
matchdeclare(x, all);
defmatch(isx2_, x^2);
isx2 (o) := not atom(isx2_(o));
isx2_body(o) := isx2(o) and rhs(isx2_(o)[1]);
to:
matchdeclare(x, all);
defmatch(isx2__, x^2);
isx2_ (o) := block([x], isx2__(o));
isx2 (o) := not atom(isx2_(o));
isx2_body(o) := isx2(o) and rhs(isx2_(o)[1]);
Thanks!!!
Eduardo
On Sun, 20 Jul 2025 at 10:09, Richard Fateman <fa...@gm...> wrote:
>
> without looking at this in detail, it seems likely that you are using
> the name x for two conflicting purposes. It is not a good idea to use
> x as a pattern variable and as a symbol in your expression, since defmatch
> not only returns an equation x=something, it also binds x globally to
> something.
>
> If seems you are trying to define a function something like this:
> vv(h):=if atom(h) then false else if op(h)="^" and part(h,2)=2 then
> part(h,1)
>
> Good luck
> RJF
>
>
>
> On Sun, Jul 20, 2025 at 8:36 AM Eduardo Ochs <edu...@gm...>
> wrote:
>
>> 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
>> _______________________________________________
>> Maxima-discuss mailing list
>> Max...@li...
>> https://lists.sourceforge.net/lists/listinfo/maxima-discuss
>>
>
|