[Maxima] Complex components and kindp
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
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,
but ask the user.
One further observation of me is that the function kindp is strange:
/* At first a fresh symbol. That's OK. */
(%i1):lisp (kindp '$z '$complex)
/* We declare the symbol Complex. OK */
(%i2) :lisp (kindp '$z '$complex)
/* Now we declare another symbol real. OK */
(%i3) :lisp (kindp '$x '$real)
/* But this symbol is also Complex. ??? */
(%i3) :lisp (kindp '$x '$complex)
/* The same with an integer.
kindp gives true for integer, real, complex. ???
(%i6) :lisp (kindp '$n '$integer)
(%i6) :lisp (kindp '$n '$real)
(%i6) :lisp (kindp '$n '$complex)
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
featurep has the same problem, see also BugSF.
More information about the Maxima