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


Groups > comp.lang.python > #107587

Re: Optimizing Memory Allocation in a Simple, but Long Function

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Peter Otten <__peter__@web.de>
Newsgroups comp.lang.python
Subject Re: Optimizing Memory Allocation in a Simple, but Long Function
Date Mon, 25 Apr 2016 10:16:24 +0200
Organization None
Lines 28
Message-ID <mailman.66.1461572195.32212.python-list@python.org> (permalink)
References <CAGuRns8KhOFL-a1_a=0hMP=NbktoJw78ih3j4uUSbvkF8bf3pw@mail.gmail.com> <CAPTjJmrQfk20EuoZVMLqKv8F5r=YyKj0nr8iNPw7DWoCEYLmYA@mail.gmail.com> <CAGuRns86c4G5BHX_FF-OBnV_eRVKyngx_Dfp0u7hoHRT0WN++w@mail.gmail.com> <CAPTjJmq5g848-PMTgHOg7sawm+JgA5mSfwDHA-ZZgsmYr6yLCA@mail.gmail.com> <CAGuRns8LsThq3iV-bkdBbg9fZO7s61z4ggBy=YkGDqhaB_J4Xw@mail.gmail.com> <CAGuRns9uvHVBXP79X1Sp8vsW4JpWF-3g1mJoWHOq-cGog61cug@mail.gmail.com> <CAPTjJmpvtP5pj_NiJNXGLmu2QCqSYZNgZjKisRRMRTtzvGHKyQ@mail.gmail.com> <CAHVvXxSwb8=a+b5WQfd3KeXTe8VuL4RMnwu3TSNp8129FJHJGw@mail.gmail.com> <CAGuRns911cXoppsS_8f657UDdCtVFhAzwY7ohafOqrsEuRq7vQ@mail.gmail.com> <CAGuRns9byxLC3pGrkPG8m-qLTzB1+PYxLHNy2=fOHcwWR21x6A@mail.gmail.com> <CAGuRns9yCR8FP9-wV5OYRKUHVtEVMsYgrtQtoB2Up-C4CTOkUw@mail.gmail.com> <nfkjop$tui$1@ger.gmane.org>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Trace news.uni-berlin.de gt1HdrsOprPU6aGD0zPw/QU2qt6xoYCdU3IDeO+Xvn4g==
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'subject:Function': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'rounding': 0.09; 'subject:Long': 0.09; '(python)': 0.16; 'definition.': 0.16; 'precision.': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'somehow.': 0.16; 'surprising': 0.16; 'wrote:': 0.16; '>>>': 0.20; 'programming': 0.22; 'accuracy': 0.23; "i've": 0.25; 'header:User-Agent:1': 0.26; 'example': 0.26; 'header:X-Complaints-To:1': 0.26; 'mostly': 0.27; 'mathematical': 0.27; 'skip:e 30': 0.27; 'strongly': 0.30; 'error.': 0.31; 'post': 0.31; 'point': 0.33; 'url:python': 0.33; 'subject:Simple': 0.33; 'definition': 0.34; 'skip:3 10': 0.35; 'but': 0.36; 'url:org': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'seem': 0.37; 'wrong': 0.38; 'data': 0.39; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'some': 0.40; 'url:3': 0.60; 'your': 0.60; "you'll": 0.61; 'places': 0.64; 'limit': 0.65; 'results': 0.66; 'computers': 0.70; 'desired).': 0.84; 'url:tutorial': 0.91
X-Injected-Via-Gmane http://gmane.org/
X-Gmane-NNTP-Posting-Host p57bd9f11.dip0.t-ipconnect.de
User-Agent KNode/4.13.3
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.22
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <nfkjop$tui$1@ger.gmane.org>
X-Mailman-Original-References <CAGuRns8KhOFL-a1_a=0hMP=NbktoJw78ih3j4uUSbvkF8bf3pw@mail.gmail.com> <CAPTjJmrQfk20EuoZVMLqKv8F5r=YyKj0nr8iNPw7DWoCEYLmYA@mail.gmail.com> <CAGuRns86c4G5BHX_FF-OBnV_eRVKyngx_Dfp0u7hoHRT0WN++w@mail.gmail.com> <CAPTjJmq5g848-PMTgHOg7sawm+JgA5mSfwDHA-ZZgsmYr6yLCA@mail.gmail.com> <CAGuRns8LsThq3iV-bkdBbg9fZO7s61z4ggBy=YkGDqhaB_J4Xw@mail.gmail.com> <CAGuRns9uvHVBXP79X1Sp8vsW4JpWF-3g1mJoWHOq-cGog61cug@mail.gmail.com> <CAPTjJmpvtP5pj_NiJNXGLmu2QCqSYZNgZjKisRRMRTtzvGHKyQ@mail.gmail.com> <CAHVvXxSwb8=a+b5WQfd3KeXTe8VuL4RMnwu3TSNp8129FJHJGw@mail.gmail.com> <CAGuRns911cXoppsS_8f657UDdCtVFhAzwY7ohafOqrsEuRq7vQ@mail.gmail.com> <CAGuRns9byxLC3pGrkPG8m-qLTzB1+PYxLHNy2=fOHcwWR21x6A@mail.gmail.com> <CAGuRns9yCR8FP9-wV5OYRKUHVtEVMsYgrtQtoB2Up-C4CTOkUw@mail.gmail.com>
Xref csiph.com comp.lang.python:107587

Show key headers only | View raw


Derek Klinge wrote:

> I found that the pattern of an additional digit of accuracy corresponding
> to 10*n did not hold as strongly for that value (I can post data if
> desired). I also got some results that seem to contradict the mathematical
> definition. For example try EulersNumber(10**15).LimitMethod(), the
> definition places this limit at e, and yet the (python) answer is >3.035.
> Please let me know if I've fouled up the implementation somehow.

There's nothing wrong with the formula, but floating point numbers have 
limited precision. At some point your calculation will become mostly a 
rounding error.

You'll see the surprising

>>> n = 10**14
>>> (1+1/n)**n
2.716110034087023
>>> n = 10**15
>>> (1+1/n)**n
3.035035206549262

on most modern computers with most programming langagues.
 
https://docs.python.org/3.5/tutorial/floatingpoint.html

has some introductory information.

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


Thread

Re: Optimizing Memory Allocation in a Simple, but Long Function Peter Otten <__peter__@web.de> - 2016-04-25 10:16 +0200

csiph-web