Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #39471

Re: Confusing math problem

Path csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.013
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'float': 0.05; '22,': 0.09; 'calculating': 0.09; 'whichever': 0.09; 'result.': 0.15; '53-bit': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'how,': 0.16; 'nearest': 0.16; 'one-element': 0.16; 'operation,': 0.16; 'skip:{ 30': 0.16; 'wrote:': 0.17; 'comparing': 0.17; 'integer': 0.17; 'skip:{ 20': 0.17; '>>>': 0.18; 'feb': 0.19; 'error.': 0.21; 'subject:problem': 0.22; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'set.': 0.27; 'message-id:@mail.gmail.com': 0.27; "doesn't": 0.28; 'received:209.85.212': 0.28; 'chris': 0.28; 'initial': 0.28; '>>>>': 0.29; 'case,': 0.29; "i'm": 0.29; 'fri,': 0.30; 'problem.': 0.32; 'print': 0.32; 'to:addr:python-list': 0.33; "can't": 0.34; 'received:google.com': 0.34; 'done': 0.34; 'consistent': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'explain': 0.36; 'but': 0.36; 'should': 0.36; 'does': 0.37; 'being': 0.37; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'gives': 0.39; 'to:addr:python.org': 0.39; 'help': 0.40; 'matter': 0.61; 'different': 0.63; 'show': 0.63; 'results': 0.65; 'talking': 0.66; 'power': 0.74; '"oh,': 0.84; '2013': 0.84; 'mac.': 0.84; 'route': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=2yaCwx37XpDhwARqbg0qkH0k4azqPiqczwfpVjlq1os=; b=WyKhBmqr4NFCgiQWTWUQHu5jvO/8ETcNVumNPdtduRKq/KpRnVsQg0fUEjXYYrEypR Bb76dCF5r4oqQCJRVhQ70iQ9mY7cVNXognlej7NRQqhtFP/BRzTaSrxGpnbdxFTHt6ev 0EwAPsjuN8xbY+qK6l4064b2+oh6JKzUz4w15tDLgkfe7KJzMMvBv6uPWJp0BfFPkWWN GiKIblOKzkFsTnnxqr2v7e9pRFxWpy/FaKJ+oAeBL6EwXapnGrSj0lGYNSLrZzdsAoLc PGLHDL+FpEX82ZlqPOlrfZUCPOIrOc4fFYtXX7KVlhu8BAJ6nPIQ18cICSAs9G0liUyu z9yA==
MIME-Version 1.0
X-Received by 10.52.22.194 with SMTP id g2mr29718568vdf.91.1361484696276; Thu, 21 Feb 2013 14:11:36 -0800 (PST)
In-Reply-To <aonjmqFqplbU1@mid.individual.net>
References <kg5sog$lfb$1@dont-email.me> <512682B3.8070909@davea.name> <51268867.1000800@davea.name> <mailman.2199.1361481815.2939.python-list@python.org> <aonjmqFqplbU1@mid.individual.net>
Date Fri, 22 Feb 2013 09:11:35 +1100
Subject Re: Confusing math problem
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2205.1361484698.2939.python-list@python.org> (permalink)
Lines 33
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1361484698 news.xs4all.nl 6984 [2001:888:2000:d::a6]:44242
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:39471

Show key headers only | View raw


On Fri, Feb 22, 2013 at 8:59 AM, Peter Pearson <ppearson@nowhere.invalid> wrote:
> On Fri, 22 Feb 2013 08:23:27 +1100, Chris Angelico <rosuav@gmail.com> wrote:
>> In theory, a float should hold the nearest representable value to the
>> exact result. Considering that only one operation is being performed,
>> there should be no accumulation of error. The integer results show a
>> small number (618) of collisions, eg 2**16 and 4**8; why should some
>> of those NOT collide when done with floating point? My initial thought
>> was "Oh, this is comparing floats for equality", but after one single
>> operation, that should be not a problem.
>
> Does this help explain it?
>
>>>> print hex(int(math.pow(3,60))); print hex(3**60)
> 0x88f924eeceeda80000000000L
> 0x88f924eeceeda7fe92e1f5b1L
>

I understand how the inaccuracy works, but I'm expecting it to be as
consistent as Mr Grossmith's entertainments. It doesn't matter that
math.pow(3,60) != 3**60, but the number of collisions is different
when done with floats on the OP's Mac. Here's what I'm talking about:

>>> set((3**60,9**30,27**20))
{42391158275216203514294433201}
>>> set((math.pow(3,60),math.pow(9,30),math.pow(27,20)))
{4.23911582752162e+28}

Note how, in each case, calculating three powers that have the same
real-number result gives a one-element set. Three to the sixtieth
power can't be perfectly rendered with a 53-bit mantissa, but it's
rendered the same way whichever route is used to calculate it.

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Confusing math problem "Schizoid Man" <schiz_man@21stcentury.com> - 2013-02-21 19:33 +0000
  Re: Confusing math problem Dave Angel <davea@davea.name> - 2013-02-21 15:25 -0500
    Re: Confusing math problem "Schizoid Man" <schiz_man@21stcentury.com> - 2013-02-21 22:39 +0000
      Re: Confusing math problem Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-02-21 22:53 +0000
        Re: Confusing math problem "Schizoid Man" <schiz_man@21stcentury.com> - 2013-02-21 23:41 +0000
          Re: Confusing math problem Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-02-22 00:04 +0000
          Re: Confusing math problem Ian Kelly <ian.g.kelly@gmail.com> - 2013-02-21 17:19 -0700
    Re: Confusing math problem "Schizoid Man" <schiz_man@21stcentury.com> - 2013-02-21 23:39 +0000
  Re: Confusing math problem Ian Kelly <ian.g.kelly@gmail.com> - 2013-02-21 13:42 -0700
  Re: Confusing math problem Chris Angelico <rosuav@gmail.com> - 2013-02-22 07:46 +1100
    Re: Confusing math problem "Schizoid Man" <schiz_man@21stcentury.com> - 2013-02-21 22:44 +0000
      Re: Confusing math problem Chris Angelico <rosuav@gmail.com> - 2013-02-22 11:29 +1100
      Re: Confusing math problem Dave Angel <davea@davea.name> - 2013-02-21 21:19 -0500
  Re: Confusing math problem Dave Angel <davea@davea.name> - 2013-02-21 15:49 -0500
  Re: Confusing math problem Chris Angelico <rosuav@gmail.com> - 2013-02-22 08:23 +1100
    Re: Confusing math problem Peter Pearson <ppearson@nowhere.invalid> - 2013-02-21 21:59 +0000
      Re: Confusing math problem Chris Angelico <rosuav@gmail.com> - 2013-02-22 09:11 +1100
      Re: Confusing math problem Dave Angel <davea@davea.name> - 2013-02-21 17:33 -0500
      Re: Confusing math problem Chris Angelico <rosuav@gmail.com> - 2013-02-22 10:15 +1100
    Re: Confusing math problem Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-22 09:16 +0000
      Re: Confusing math problem Serhiy Storchaka <storchaka@gmail.com> - 2013-02-22 13:48 +0200
  Re: Confusing math problem Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-22 09:27 +0000

csiph-web