String to Float, without introducing errors

Thomas Passin list1 at tompassin.net
Mon Dec 19 10:02:46 EST 2022


On 12/19/2022 9:10 AM, Peter J. Holzer wrote:
> On 2022-12-19 09:25:17 +1100, Chris Angelico wrote:
>> On Mon, 19 Dec 2022 at 07:57, Stefan Ram <ram at zedat.fu-berlin.de> wrote:
>>> G = Decimal( 6.6743015E-11 )
>>> r = Decimal( 6.371E6 )
>>> M = Decimal( 5.9722E24 )
>>
>> What's the point of using Decimal if you start with nothing more than
>> float accuracy?
> 
> Right. He also interpreted the notation "6.67430(15)E-11" wrong. The
> digits in parentheses represent the uncertainty in the same number of
> last digits. So "6.67430(15)E-11" means "something between 6.67430E-11 -
> 0.00015E-11 and 6.67430E-11 + 0.00015E-11". The r value has only a
> precision of 1 km and I'm not sure how accurate the mass is. Let's just
> assume (for the sake of the argument) that these are actually accurate in
> all given digits.
> 
> So G is between 6.67415E-11 and 6.67445E-11, r is between 6.3705E6 and
> 6.3715E6 and M is between 5.97215E24 and 5.97225E24. If we compute the
> time for those deviations you will find that the differences are many
> orders of magnitude greater than the effect you wanted to show. And that
> still ignores the fact that a vacuum won't be perfect (and collisions
> with a few stray atoms might have a similarly tiny effect), that gravity
> isn't constant while the weight falls (it's getting closer to the center
> of the earth and it's moving past other masses on its way) that Newton's
> law is only an approximation, etc. So while the effect is (almost
> certainly) real, the numbers are garbage.
> 
> I think there's a basic numeracy problem here. This is unfortunately all
> too common, even among scientists. The OP apparently rounded their
> numbers to 8 significant digits (thereby introducing an error of about
> 1E-8) and then insisted that the additional error of 1E-15 introduced by
> the decimal to float conversion was unacceptable, showing IMHO a
> fundamental misunderstanding of the numbers they are working with.
> 
>          hp

In a way, this example shows both things - the potential value of using 
Decimal numbers, and a degree of innumeracy.  It also misses a chance to 
illustrate how to approach a problem in the simplest and most 
informative way.  Here's what I mean -

We can imagine that the input numbers really are exact, with the 
remaining digits filled in with zeros.  Then it might really be the case 
that - if you wanted to do this computation with precision and could 
assume all those other effects could be neglected - using Decimals would 
be a good thing to do. So OK, let's say that's demonstrated.  No need to 
nit-pick it further.

As a physics problem, though, you would generally be interested in two 
kinds of things:

1. Could there be such an effect, and if so would it be large enough to 
be interesting, whether in theory or in practice?
2. Can there be any feasible way to demonstrate the proposed effect by 
measurements?

The first thing one should do is to find a way to estimate the magnitude 
of the effect so it can be compared with some of those other phenomena 
(non-constant gravity, etc) to see if it's worth doing a full 
computation at all, or even spending any more time on the matter.  There 
is likely to be a way to make such an estimate without needing to resort 
to extremely high precision - you would only need to get within perhaps 
an order of magnitude.  Your real task, then, is to find that way.

For example, you would probably be able to estimate the precision needed 
without actually doing the calculation.  That in itself might turn out 
to enough.





More information about the Python-list mailing list