why the inconsistency?

Christos TZOTZIOY Georgiou tzot at sil-tec.gr
Wed Oct 1 06:19:43 EDT 2003


On Tue, 30 Sep 2003 14:24:51 -0700, rumours say that John Baxter
<news.collectivize at scandaroon.com> might have written:

>> I didn't reply earlier since Tim --how uncommon-- covered the subject
>> better (he also corrected my +1 omission/misteak), but I believe you
>> should have said: 'conveniently ignoring what "work correctly" means in
>> a given context'... ;-)
>
>"Work" and "work correctly" seem equivalent when one is speaking of 
>computer programs.  Not so in lots of other contexts.

Ah, yes.  I get what you say, but I don't think they seem equivalent in
the domain of floating point arithmetic (which is the point here - no
pun intended).  See the following:

Naive target:
    sum 1000 numbers chosen so, that they add up to 100.

Naive answer:
    # the following code is guaranteed to work
    # it is not guaranteed to work correctly
    s = 0
    for x in xrange(1000):
        s += 0.1

Naive output interpretation:
    print s
    100.0

Real output:
    print repr(s)
    99.999999999998593

So, unless we are just nitpicking (and in which case I will gladly drop
the subject), the "computer program" above "works" but does not "work
correctly".  Python does what I told it to do, and while my logic
theoretically is flawless, it doesn't practically take account of the
limitations of computer floating point arithmetic.  This final
subsentence makes the difference between "works" and "works correctly"
in this thread.

Cheers,
-- 
TZOTZIOY, I speak England very best,
Ils sont fous ces Redmontains! --Harddix




More information about the Python-list mailing list