float and bfloat issues



Am Sonntag, den 17.01.2010, 17:33 +0100 schrieb Dieter Kaiser:
> Am Sonntag, den 17.01.2010, 10:14 -0500 schrieb Raymond Toy:
> > These were sent to me by Jim FitzSimons, who wrote the bigfloat
> > implementation of elliptic integrals that I translated into Lisp.
> > 
> > bfloat(sqrt(%i)) -> 1.0b0*(-1)^(1/4)
> > 
> > Should this be more like .707+.707*%i?
> > 
> > Another issue is
> > 
> > float(polarform(sqrt(1+%i))) -> 1.18*2.718^(%i*%pi/8)
> > 
> > But
> > 
> > bfloat(polarform(sqrt(1+%i))) -> 1.18*(3.82b-1*%i+9.23b-1)
> > 
> > Not sure which is the correct answer.  In some ways, the float result is
> > better since it preserves the polarform, but doesn't float the phase
> > part.  The bfloat result is better since everything is a bfloat, but the
> > polarform is converted to rectangular.
> 
> Yes, I think we have a lot of more inconsistencies because the numerical
> evaluation of the power function is not implemented as complete as might
> be necessary. 
> 
> At first, the power function evaluates numerically for float and
> bigfloat values as base or exponent. But not for complex values. This is
> not the convention we have for the numerical evaluation of functions. 
> 
> On the other side some specific cases (the sqrt function and the exp
> function) have been implemented to evaluate numerically for complex
> numbers too. This causes inconsistencies. 
> 
> I think at first we should implement a more complete and consistent
> numerical evaluation for the power function. A lot of problems might
> vanish if we do so.

My last comment is not fully correct. The numerical evaluation of the
power function does not change anything for the reported examples with
the function float and bigfloat.

It might be necessary to implement the routines $float and $bigfloat
more consistent.

I have tested code to evaluate the power function for a complex
argument. I think these examples should all evaluate to a numerical
value as is shown here:

(%i38) (1.0+%i)^2;
(%o38) 2.0 %i
(%i39) (1.0b0+%i)^2;
(%o39) 2.0b0 %i
(%i40) (1.0+%i)^(1/3);
(%o40) .2905145555072514 %i + 1.084215081491351
(%i41) (1.0b0+%i)^(1/3);
(%o41) 2.905145555072515b-1 %i + 1.084215081491351b0
(%i42) (1+%i)^(1.0*%i);
(%o42) .1548717524642468 %i + .4288290062943679
(%i43) (1+%i)^(1.0b0*%i);
(%o43) 1.548717524642468b-1 %i + 4.288290062943679b-1

We can avoid a lot of extra calls to rectform and float or bfloat if we
implement the numerical evaluation for a complex base or exponent too.
Furthermore I think it is much more consistent when the power function
behaves like other functions too.

We get no problem with the testsuite.

Dieter Kaiser