# [Maxima] simplification of abs

Barton Willis willisb at unk.edu
Tue Sep 28 10:45:33 CDT 2010

```I checked in a revised simpabs; examples

OK--nounform for abs(log(x))

(%i21) abs(log(x));
(%o21)  abs(log(x))

OK, but %pi would be better:

(%i22) subst(x=-1,%);
(%o22) abs(log(- 1))

Not wrong, but nonideal :(

(%i23) rectform(%);
(%o23) abs(log(- 1))

Well, map rectform does it (should this really be required?)

(%i24) map(rectform,%);
(%o24) %pi

Much better:

(%i25) declare(z,complex);
(%o25) done

(%i26) abs(log(-z));
(%o26)  abs(log(- z))

Better--previously was 2 * %pi

(%i27) subst(z=-1,%);
(%o27)   0

The testsuite and share testsuite run OK--(fixed only a few minor
regressions).
I thank Dieter for helping me with all this.

--Barton

maxima-bounces at math.utexas.edu wrote on 09/24/2010 03:28:17 PM:

>
> Am Freitag, den 24.09.2010, 15:00 -0500 schrieb Barton Willis:
> > I think the general simplifier for abs does some things that it
> shouldn't. Example:
> >
> >  (%i1) abs(log(x));
> >  (%o1) sqrt(log(abs(x))^2+atan2(0,x)^2)
> >
> > Surely, (%o1) causes trouble for limit, integrate, solve, ...
> Another problem with (%o1) is
> >
> >  (%i2) subst(x=%i,%);
> >  (%o2) sqrt(atan2(0,%i)^2)
> >
> > Rectform and related functions will *not* simplify %o2 to %pi/2.
> Changing log to plog and all is well:
> >
> >  (%i4) abs(plog(x));
> >  (%o4) abs(plog(x))
> >
> >  (%i5) subst(x=%i,%);
> >  (%o5) %pi/2
> >
> > A related bug (maybe this is more of a problem with carg, not abs)
> >
> >  (%i6) declare(z,complex);
> >  (%o6) done
> >
> >  (%i7) abs(log(-z));
> >  (%o7) sqrt(log(abs(z))^2+(carg(z)+%pi)^2)
> >
> > Wrong: Should be 0, not 2 pi:
> >
> >  (%i8) subst(z=-1,%);
> >  (%o8) 2*%pi
> >
> >  (%i9) abs(log(1));
> >  (%o9) 0
>
> Yes, the problem is that we call the function cabs in the simplifier of
> abs. cabs is called every time an expression seems to be complex. The
> call of cabs is present since the initial revision of Maxima. Older
> versions have not the reported problems, but we have improved other code
> of Maxima to handle complex expressions more completely. This causes now
> the problems with the abs function, because Maxima has more knowledge
> about expressions and functions which are complex, e.g.
>
> (%i1) csign(log(x));
> (%o1) complex
>
> but
>
> (%i2) csign(plog(x));
> (%o2) pnz
>
> We have to redesign the function abs without a call of cabs to get the
> desired results.
>
> Dieter Kaiser
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima

```