Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.074 X-Spam-Evidence: '*H*': 0.85; '*S*': 0.00; 'interpreter': 0.05; 'raises': 0.09; 'subject:Why': 0.09; 'python': 0.11; '2.7.3': 0.16; '488': 0.16; 'calculates': 0.16; 'digits.': 0.16; 'dump': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'mind.': 0.24; 'gets': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; "doesn't": 0.30; 'skip:( 20': 0.30; '"",': 0.31; '>>>>': 0.31; 'sep': 0.31; 'anyone': 0.31; 'file': 0.32; '(most': 0.33; 'sense': 0.34; 'done': 0.36; 'doing': 0.36; "didn't": 0.36; 'subject:?': 0.36; 'to:addr:python-list': 0.38; 'recent': 0.39; 'does': 0.39; 'realize': 0.39; 'to:addr:python.org': 0.39; 'enough': 0.39; 'expression': 0.60; 'today,': 0.61; 'first': 0.61; 'more': 0.64; 'different': 0.65; 'here': 0.66; 'received:74.208': 0.68; 'ocean.': 0.84; 'received:74.208.4.194': 0.84; 'power,': 0.91; 'hand,': 0.93 Date: Sun, 31 Mar 2013 03:34:31 -0400 From: Dave Angel User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130308 Thunderbird/17.0.4 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Why does 1**2**3**4**5 raise a MemoryError? References: <8e43bc87-e822-4bb3-b9ef-ccd489da8bf3@googlegroups.com> In-Reply-To: <8e43bc87-e822-4bb3-b9ef-ccd489da8bf3@googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:l1dPuz7Hj6SpSiPJgkuHMMxQJpUnwW307CukbEeR+Ed JVRwptewIr5UJDV9Kft5gbQF023HNwuDZot5OdnWxj4iVL60Yj HEfWgFDJpYqzWTbKaNq1LoKTWFNoL3hTY3WsTyizTOQc228FVr zoo68ocXMNCxx6zU3rebgw1jKMIj/i37xNzSVBt1bDwDHgo3Fy VSjJz/pDSwf5oJspcbRaTOd6NNjRY6zaegOxT87ym0JDt688Ew Xd2dUSO6BzpS0We+eYXEsCPG32jOzPN7FE3+9wwTN6bzjr6jHU uQu2gHyH5Umw9dzNkXP1e+CCOpRcpjYtO3XfT+tHv/fR2mGpA= = X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 47 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1364715292 news.xs4all.nl 6979 [2001:888:2000:d::a6]:42769 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:42359 On 03/31/2013 02:56 AM, morphex wrote: > Hi. > > I was just doodling around with the python interpreter today, and here is the dump from the terminal: > > morphex@laptop:~$ python > Python 2.7.3 (default, Sep 26 2012, 21:53:58) > [GCC 4.7.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> 1**2 > 1 >>>> 1**2**3 > 1 >>>> 1**2**3**4 > 1L >>>> 1**2**3**4**5 > Traceback (most recent call last): > File "", line 1, in > MemoryError >>>> > > Does anyone know why this raises a MemoryError? Doesn't make sense to me. > > Perhaps you didn't realize that the expression will be done from right to left. So first it calculates 4**5 which is 1024 Then it calculates 3**1024, which has 488 digits. then it calculates 2 to that power, which is a number large enough to boggle the mind. That number's storage needs makes a few gigabytes seem like a molecule in the ocean. Anyway, it never gets around to doing the 1** part. On the other hand, perhaps you wanted to do a different calculation: >>> ((((1**2)**3)**4)**5) 1 -- DaveA