A very small error in float?



The explanation is that floating-point arithmetic is not associative in
general. This is a property of floating-point arithmetic, not a property of
Maxima.

When you factor a number, you reorganize its calculation.  For example,
factor(3/5) is represented as (1/5)*3 instead of 3/5, just as factor(10/21)
is represented as (1/3)*(1/7)*2*5.  And float(1/5)*float(3) - float(3/5) =>
-1e-16.

I suppose it could equally well represent factor(10/21) as (2*5)/(3*7)
(mquotient internally), but for most applications it doesn't matter.  And in
any case you will still run into the non-associativity problem, even for
integers:

    float(23^12*37^30) - float(factor(23^12*37^30)) => 3.7e47

to see that it's not *factor* that's the problem:

    float(23^12*37^30) - float(23^12)*float(37^30) => 3.7e47

                -s

On Wed, Mar 23, 2011 at 09:42, Esben Byskov <eb at civil.aau.dk> wrote:

>  *Hi maxima list,
>
> The outcome of the session below is somewhat disturbing,
> I think.  Maybe there is a valid explanation.
> *
> Maxima 5.23.2 http://maxima.sourceforge.net
> using Lisp CLISP 2.44.1 (2008-02-23)
> Distributed under the GNU Public License. See the file COPYING.
> Dedicated to the memory of William Schelter.
> The function bug_report() provides bug reporting information.
> (%i1) r: 735/25;
>                                       147
> (%o1)                                 ---
>                                        5
> (%i2) float(r);
> (%o2)                                29.4
> (%i3) fr: factor(r);
>                                         2
>                                      3 7
> (%o3)                                ----
>                                       5
> (%i4) ffr: float(fr);
> (%o4)                          29.40000000000001
>
> *Best regards,
>
> Esben Byskov
> *
>
> Esben Byskov, Ph.D., Dr.Techn.
> Professor Emeritus of Structural Analysis
> Department of Civil Engineering
> Aalborg University
> Sohngaardsholmsvej 57
> DK-9000 Aalborg
> Denmark
>
> Phone:   +45 3963 7328
> e-mail:  eb at civil.aau.dk
>
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>
>