Complex mode for $sign



Because I had a look on more support for Complex and negative Real values for
the Log function I studied the functions for Complex components: cabs (or abs),
carg, realpart, imagpart, conjugate, sign (or signum). These functions are
completed by rectform, polarform and atan2. The functions for Complex Components
are important for symbolically calculations with Complex values but have known
problems.

At last, I ended up with a known error of the testsuite (not reported as a bug)
which seems to be very simple, but is in my opinion a fundamental error, because
it shows clearly the problems of handling Complex values within Maxima:

(%i2) declare(z,complex);
(%o2) done;
(%i3) abs(z^2);
(%o3) z^2;

The reason for this bug is the function $sign which is called by csign. This
function allways return $pz for an even exponent. $sign does not take care for
Complex values. (cabs does the above example better, but has problems too).

I think $sign was only designed for Real values. But it is called with a simple
extension by csign for general values. That does not work general enough to
support Complex values. So I tried to extend $sign with a Complex mode which
detect additionally complex and imaginary expressions. (It is not easy to write
a separat sign routine for Complex expressions, because Complex values can arise
from expressions which look pure real).

The complex mode is switched on with the global variable complexsign which is
still present in the code, but not used. So it is possible to write a routine

(defun $csign (x)
  (let ((complexsign t))
    ($sign x)))

With complexsign is set to false Maxima don't regocnize the Complex mode and all
run as known including the testsuite. But switching the Complex mode on csign
gives the following results:

(%i2) declare(z,complex);
(%o2) done
(%i3) csign(z);
(%o3) complex
(%i4) csign(10*z*x+y);
(%o4) complex
(%i5) csign((10*z*x+y)^2);
(%o5) complex
(%i6) csign(%i);
(%o6) imaginary
(%i7) csign(2*%i*x);
(%o7) imaginary
(%i8) csign(2*%i*x+y);
(%o8) complex
(%i9) csign((2*%i*x+y)^3);
(%o9) complex
(%i10) csign(sqrt(-1)+10);
(%o10) complex
(%i11) csign(sqrt(-1));
(%o11) imaginary
(%i12) csign(sqrt(-1)^3);
(%o12) imaginary

I have allready found extensions to $sign to detected Complex and Imaginary
expressions within mplus, mtimes and mexpt expressions. There is further work
necessary, but perhaps the concept is right.

Next I had a look at the functions abs and cabs to benefit from a function which
handle Complex values better. But it isn't as easy as it should be. The biggest
problem is that both routines have problems with Complex values. It seems to me
that the deficiencies of these functions are quite well balanced out.

At the end I think there should no longer exist a separat function cabs, because
abs should include the correct and complete handling of Complex values.

Dieter Kaiser