Decimal vs float

Kay Schluehr kay.schluehr at gmx.net
Sun Jan 22 09:18:38 EST 2006


Tim Peters wrote:
> [Kay Schluehr]
> > I concur and I wonder why CAS like e.g. Maple that represent floating
> > point numbers using two integers [1] are neither awkward to use nor
> > inefficient.
>
> My guess is that it's because you never timed the difference in Maple
> -- or, perhaps, that you did, but misinterpreted the results.  You
> don't give any data, so it's hard to guess which.
>
> BTW, why do you think Maple's developers added the UseHardwareFloats option?

For no good reason at least not as a public interface. But since the
value of UseHardwareFloats is deduced from the accuracy ( Digits
environment variable ) a programmer has seldom to deal explicitely with
UseHardwareFloats. That means he pays for accuracy only, what is the
essential numerical information. I guess an analogy is the use of
integers in Python with the differerence that precision is replaced by
the amount of absolute value. The solution is so nice that I wonder why
floats and decimals could not be unified in a similar way?

> > According to the Python numeric experts one has to pay a
> > high tradeoff between speed and accuracy.  But as it seems it just
> > compares two Python implementations ( float / decimal ) and does not
> > compare those to approaches in other scientific computing systems.
>
> It's easy to find papers comparing the speed of HW and SW floating
> point in Maple.  Have you done that, Kay?

O.K. you are right here.

> For example, read:
>
>     "Symbolic and Numeric Scientific Computation in Maple"
>     K.O. Geddes, H.Q. Le
>     http://www.scg.uwaterloo.ca/~kogeddes/papers/ICAAA02.ps
>
> Keith Geddes is a key figure in Maple's history and development, and
> can hardly be accused of being a Python apologist ;-)  Note that
> Example 1.5 there shows a _factor_ of 47 speed gain from using HW
> instead of SW floats in Maple, when solving a reasonably large system
> of linear equations.  So I'll ask again ;-):  why do you think Maple's
> developers added the UseHardwareFloats option?
>
> While that paper mentions the facility only briefly, Geddes and Zheng
> give detailed analyses of the tradeoffs in Maple here:
>
>     "Exploiting Fast Hardware Floating Point in High Precision Computation"
>     http://www.scg.uwaterloo.ca/~kogeddes/papers/TR200241.ps
>
> If you're uncomfortable reading technical papers, one bottom line is
> that they show that the time required by Maple to do a floating-point
> multiplication in software "is at least 1000 times larger" than doing
> the same with UseHardwareFloats set to true (and Digits:=15 in both
> cases).

No, it's perfect, Tim. Thanks for the links.

> > By the way one can also learn from Maple how accuracy can be adjusted
> > practically. I never heard users complaining about that.
>
> It's easy to change the number of digits of precision in Python's
> decimal module.

If I remember correctly it was Steve Holden who complained that
explaining accuracy by means of the decimal module would be a non issue
for beginners in Python. I have nothing to complain here ( o.k. nesting
two levels deep to set prec is less nice than having Digits offered by
the CAS immediately. But this is more cosmetic ).

Kay




More information about the Python-list mailing list