# [Maxima] Complex components and kindp

Dieter Kaiser drdieterkaiser at web.de
Sat Aug 2 18:37:19 CDT 2008

```I had a look at a Log function which don't take all values as positve real but
can simplify correct for negative real and complex values too.

By this way I get in some trouble with the functions for the Complex components:
carg, cabs, realpart, imagpart, signum, conjugate, atan2. When doing complete
Complex arithmetic all functions are very important and should simplify
correctly.

Signum is only implemented for real values and knows nothing about Complex
values. The wrong handling of Complex values by carg is a known bug. A big
problem is that sometimes the functions don't use consistently the given facts,

One further observation of me is that the function kindp is strange:

(%i2) kill(all);
(%o0) done

/* At first a fresh symbol. That's OK. */

(%i1):lisp (kindp '\$z '\$complex)
NIL

/* We declare the symbol Complex. OK */
(%i1) declare(z,complex);
(%o1) done

(%i2) :lisp (kindp '\$z '\$complex)
T

/* Now we declare another symbol real. OK */
(%i2) declare(x,real);
(%o2) done
(%i3) :lisp (kindp '\$x '\$real)
T

/* But this symbol is also Complex. ??? */

(%i3) :lisp (kindp '\$x '\$complex)
T

/* The same with an integer.
kindp gives true for integer, real, complex. ???

(%i5) declare(n,integer);
(%o5) done
(%i6) :lisp (kindp '\$n '\$integer)
T
(%i6) :lisp (kindp '\$n '\$real)
T
(%i6) :lisp (kindp '\$n '\$complex)
T

So if we would write correct code to detect a symbol which is declared Complex
we could do the following test:

(and (kindp '\$z '\$complex) (not (kindp '\$real)) (not (kindp 'integer))

But I observed further that '\$rational also declares a value to be real and
complex. Furthermore an '\$irrational value is '\$real and '\$complex too. So the
above test is not complete. I have not tested all possibilities, but it is
necessary to find all them to get correct tests.

This behaviour of kindp seems to be nice in view of the algebraic structure of
the numbers. But for writing code I think this is not very useful. The function