Implementation of a function $csign



I have reported some work on a function $csign which work like $sign but handles
complex expressions more complete.

I have checked out the code.

Because the $sign function is very important for a lot of other code I tried to
be very carefully and have implemented the new function $csign in a way which
change nothing. This is done by introducing the flag *complexsign*.

The function $csign binds the variable *complexsign* to T and calls the $sign
function. $csign gives exactly the same results as $sign for the examples in the
test file rtest_sign.mac. In addition the following can be done with $csign:

(%i6) declare(z,complex,[j,k,l,m],imaginary)$
(%i7) csign(z);    /* a complex symbol */
(%o7) complex
(%i8) csign(j);    /* an imaginary symbol */
(%o8) imaginary
(%i9) csign(%i);
(%o9) imaginary
(%i10) csign(%i*j); /* multiplicaton of imaginary symbols */
(%o10) neg
(%i11) csign(%i*j*k);
(%o11) imaginary
(%i12) csign(%i*j*k*l);
(%o12) pos
(%i13) csign(1+%i);  /* Complex numbers */
(%o13) complex
(%i14) csign((1+%i)^2);
(%o14) complex
(%i15) csign((1+1/j)^2); /* an imaginary symbol in the expression */
(%o15) complex
(%i16) csign((1+1/j)^n);
(%o16) complex
(%i17) csign(infinity); /* infinity is complex */
(%o17) complex
(%i18) csign(%e^z);     /* Exponentiation */
(%o18) complex
(%i19) csign(%e^%i);
(%o19) complex
(%i20) csign(%e^j);
(%o20) complex
(%i21) csign(%e^(x+%i*y));
(%o21) complex

When a function is declared to be complex $csign works too:

(%i4) csign(conjugate(z));
(%o4) complex
(%i5) csign(conjugate(x)); /* x is real */
(%o5) pnz
(%i6) csign(conjugate(x+%i*y));
(%o6) complex

The sin function is not declared to be complex:

(%i7) csign(sin(x+%i*y));
(%o7) pnz
(%i8) declare(sin,complex)$  /* we declare it to be complex */
(%i9) csign(sin(x+%i*y));
(%o9) complex

But now csign can not detect that the sin function is real for a real argument:

(%i10) csign(sin(x));
(%o10) complex

This can be improved declaring the function to be real valued. Here an example
for the functions realpart and imagpart:

(%i11) csign(realpart(z));
(%o11) pnz
(%i12) csign(imagpart(z));
(%o12) pnz

To do this all more consistent a look at the implementation of features for
functions have to be done. These features have to be implemented more complete
and consistent.

At first, I have used the function $csign to implement complete and correct
support for the functions: abs, rectform, realpart, imagpart, carg, signum (e.g.
abs(z^2) does not simplify for z complex, no unnessary questions from rectform,
realpart, ...). This code works too.

This implementation is perhaps not very elegant. But it was my aime not to
change anything which works. To get more elegant code I think we have to rewrite
the whole code of $sign.

I hope $csign will be useful and will work in code which has to check for
complex expressions. Improvements of the code and suggestions are welcome.

If you are interessed and $csign works as expected I will prepare to commit the
implementation of the functions for the complex components.

Dieter Kaiser

P.S. We get some compiler warnings with CLISP 2.44 for the file compar.lisp.
These warnings are not caused by the changes for $csign.