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....
-s
On Mon, Sep 1, 2008 at 2:39 PM, Edwin Woollett <woollett at charter.net> wrote:
> ...This behaves like Chop(expr) in Mathematica, a feature very useful
> when combining symbolic with floating point calculations....
>