Am Dienstag, den 26.07.2011, 19:08 +0200 schrieb Dieter Kaiser:
> Am Dienstag, den 26.07.2011, 06:11 -0500 schrieb Barton Willis:
> > Generally these stricter defaults involve calling sign or csign inside a
> > simplifying function. This leads to undocumented behavior:
> >
> > (%i71) m : matrix([abs(x), log(exp(sqrt(x)))],[5,7]);
> > (%o71) matrix([abs(x),sqrt(x)],[5,7])
> >
> > (%i74) m : matrix([log(exp(sqrt(x))),abs(x)],[7,5]);
> > (%o74) matrix([sqrt(x),x],[7,5])
> >
> > The order matrix elements are simplified isn't documented. Another example
> >
> > (%i85) m : matrix([abs(x), if x > 0 then log(exp(sqrt(x))) else 42],[5,7]);
> > (%o85) matrix([abs(x),if x>0 then sqrt(x) else 42],[5,7])
> >
> > (%i86) m : matrix([if x > 0 then log(exp(sqrt(x))) else 42, abs(x)],[7,5]);
> > (%o86) matrix([if x>0 then sqrt(x) else 42,x],[7,5])
> >
> > Finally, sign & csign are somewhat slow functions (speed depends on fact database).
>
> I will add more comments about the topic of this thread. But first, a
> look at the reported bug of this posting. It is very interesting bug and
> it is an old bug. The examples of this posting do not show the bug in
> Maxima versions before 5.22, but the origin of the bug is very old.
>
> First, an example with the current Maxima version. The problem is, that
> the sign of the second call in a compound expression or in a list
> depends on the first expression.
>
> Maxima version: 5.24post
> Maxima build date: 17:6 7/26/2011
> Host type: i686-pc-linux-gnu
> Lisp implementation type: SBCL
> Lisp implementation version: 1.0.45
>
> These are the expected results:
>
> (%i1) sign(sqrt(x));
> (%o1) pz
> (%i2) sign(x);
> (%o2) pnz
>
> A compound statement with a wrong result for the sign of x:
>
> (%i3) (sign(sqrt(x)), sign(x));
> (%o3) pz
>
> A list with a wrong result for the sign of x:
>
> (%i6) [sign(sqrt(x)), sign(x)];
> (%o6) [pz, pz]
>
> Again the wrong results with Maxima 5.10:
>
> Maxima version: 5.10.0
> Maxima build date: 21:56 3/14/2011
> host type: i686-pc-linux-gnu
> lisp-implementation-type: SBCL
> lisp-implementation-version: 1.0.45
>
> (%i2) (sign(sqrt(x)), sign(x));
> (%o2) pz
> (%i3) [sign(sqrt(x)), sign(x)];
> (%o3) [pz, pz]
>
> In the examples from this posting the columns of the matrices are
> evaluated and simplified like a list. In Maxima 5.22 a call to the
> function csign was included for the log function, the second call to
> csign is from the abs function. The function csign behaves similar to
> the function sign and has the same bug. The second call gives a wrong
> result. The problem is easy to see when tracing the function csign.
>
> I suppose that the origin of the bug are some global variables in the
> function sign which have old values from a first call.
>
> The bug is not related to the functionality of the log function, but the
> extension of the functionality shows an old bug.
A further remark:
The error is in the function sign-mexpt. This function writes facts into
the actual context, using the functions tdpos, tdneg, tdzero, tdpn, and
tdpz. The function meval* kills these facts after finishing an
evaluation. But for evaluating the columns of a matrix or a list the
function meval is mapped over the elements. Therefore the facts from a
previous call of a sign function are still present in a second call.
Two solutions might be possible:
1. Map the function meval* over the elements of a list or a compound
statement.
2. Create a local context when entering the function sign-mexpt to store
temporary facts.
I would prefer the second approach.
Dieter Kaiser