Barton (WillisB) suggested using the native complex numbers from Lisp in
Maxima. We've discussed this a bit in private mail, and I thought that
it might be of general interest.
Sometimes Maxima conventions are different from native conventions:
sqrt(-1) == (-1)^(1/2) => %i
(-1)^(1/3) => -1
BUT in Lisp:
(sqrt -1) == (expt -1 1/2) == (expt -1 0.5) => #c(6.1E-17 1.0)
note non-exact (floating) result
(expt -1 1/3) == (expt (float -1) (float 1/3)) => #C(0.50 0.87)
Then again, Maxima conventions are not necessarily consistent:
subst(-1,x,rectform(x^(1/3))) (answer x<0) gives 1/2+sqrt(3)/2*%i
(not surprising of course)
Sometimes Maxima seems more accurate than native complex floats:
(-1.0)^(0.5),numer => %i
(-1.0)^float(1/3),numer => -1.0
but in fact this is a bug... compare:
(-1.0)^(0.50000001),numer => %i
($ratepsilon is being used here, which it shouldn't be, and anyway its
default value is much much too large)
and there is an even more egregious bug lurking in there:
(-1.0)^(0.50001),numer => 1.0 (!!!)
(setting ratepsilon:1.0E-15 does not fix this!!)
In some cases, Maxima is LESS accurate than native complex floats, and
of course much slower:
rt: rectform((-1)^(1/4))
rectform(rt^200) => 1 -- 0.23 sec
rectform(float(rt)^200) => -1.5E13 - 1.6E13 (!!!) -- 0.70 sec
BUT with native complex floats
(expt (expt -1 1/4) 200) => #C(1.0 -2.2E-14) -- 0.00 sec
There is a trick, though...:
rectform(float(rt)^200), maxposex:10; =>
1.000 + 9.8E-16 * %I -- 0.00 sec
MaxPosEx (the largest positive exponent which will be expanded by the
EXPAND command) controls whether rectform's use the trigometric form:
rectform((a+b*%i)^2) => a^2-b^2 + 2*%I*a*c
rectform((a+b*%i)^2),maxposex:0
=> (a^2+c^2) * cos(2 * atan2(c,a)) etc.
Though I hesitate to add yet another global variable controlling
behavior, it looks as though rectform needs its own MaxPosEx.... The
algebraic form is usually easier to simplify, while the trigonometric
form is smaller for exponent > 5 and is consistent with the form used
for non-constant exponents.
In the end, I think Barton is right that complex numbers should be
represented specially, whether it's using something similar to RAT or
using machine numbers. But it would take a lot of work in many parts of
Maxima to make this work properly, I suspect.
-s