fnormal in maple (version 7, anyway)



On September 01, 2008, Stavros Macrakis wrote:

> For this sort of application, you probably want to restrict the
> normalization to floats (not rationals, which should be exact) and also 
> look
> for nearby rationals.  You could also get more sophisticated about 
> bfloats.
>
> float_chop(ex):=
> if floatnump(ex) then
>     if abs(ex) < 1.0e-14 then 0
>     else ratsimp(ex)                         -- depends on ratepsilon
>  elseif mapatom(ex) then ex
>  else map(float_chop,ex)$
>
> ratepsilon: 5.0e-15$   /* default is 2.0e-8, which is much too big */
>
> This also converts things like 0.33333333333333 => 1/3, 1.000000000000001 
> =>
> 1, etc.  Of course, it also converts sqrt(2.0) and float(%pi) to rational
> approximations....
>
I would like  to restrict the transformation to floats and
  complex numbers whose elements are floats in rectform
   format , so that

expr : exp( float(%i*2*%pi));  -->
1.0-2.4492127076447545E-16*%i   --->

is transformed to 1.0, ie., left as a float.

As it stands, your code has the behavior

(%i16) expr : exp( float(%i*2*%pi));
(%o16) 1.0-2.4492127076447545E-16*%i
(%i17) [floatnump(expr),mapatom(expr) ];
(%o17) [false,false]
(%i18) float_chop(expr);
`rat' replaced 1.0 by 1/1 = 1.0
(%o18) 1

Ted Woollett

Ted Woollett