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


Groups > comp.lang.python > #42359

Re: Why does 1**2**3**4**5 raise a MemoryError?

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 <davea@davea.name>
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 <davea@davea.name>
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 <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.4010.1364715292.2939.python-list@python.org> (permalink)
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

Show key headers only | View raw


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 "<stdin>", line 1, in <module>
> 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

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


Thread

Why does 1**2**3**4**5 raise a MemoryError? morphex <morphex@gmail.com> - 2013-03-30 23:56 -0700
  Re: Why does 1**2**3**4**5 raise a MemoryError? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-31 07:33 +0000
    Re: Why does 1**2**3**4**5 raise a MemoryError? Dave Angel <davea@davea.name> - 2013-03-31 03:48 -0400
    Re: Why does 1**2**3**4**5 raise a MemoryError? morphex <morphex@gmail.com> - 2013-03-31 05:07 -0700
      Re: Why does 1**2**3**4**5 raise a MemoryError? Dave Angel <d@davea.name> - 2013-03-31 08:43 -0400
        Re: Why does 1**2**3**4**5 raise a MemoryError? Roy Smith <roy@panix.com> - 2013-03-31 09:15 -0400
          Re: Why does 1**2**3**4**5 raise a MemoryError? Jason Swails <jason.swails@gmail.com> - 2013-03-31 10:03 -0400
      Re: Why does 1**2**3**4**5 raise a MemoryError? Roy Smith <roy@panix.com> - 2013-03-31 09:04 -0400
      Re: Why does 1**2**3**4**5 raise a MemoryError? Tim Roberts <timr@probo.com> - 2013-04-01 21:45 -0700
        Re: Why does 1**2**3**4**5 raise a MemoryError? Chris Angelico <rosuav@gmail.com> - 2013-04-02 17:16 +1100
        Re: Why does 1**2**3**4**5 raise a MemoryError? Dan Sommers <dan@tombstonezero.net> - 2013-04-02 12:56 +0000
    Re: Why does 1**2**3**4**5 raise a MemoryError? Roy Smith <roy@panix.com> - 2013-03-31 08:59 -0400
  Re: Why does 1**2**3**4**5 raise a MemoryError? Dave Angel <davea@davea.name> - 2013-03-31 03:34 -0400
    Re: Why does 1**2**3**4**5 raise a MemoryError? "Alex" <foo@email.invalid> - 2013-03-31 22:06 +0000
      Re: Why does 1**2**3**4**5 raise a MemoryError? Chris Angelico <rosuav@gmail.com> - 2013-04-01 09:28 +1100
        Re: Why does 1**2**3**4**5 raise a MemoryError? "Alex" <foo@email.invalid> - 2013-04-01 00:39 +0000
          Re: Why does 1**2**3**4**5 raise a MemoryError? Chris Angelico <rosuav@gmail.com> - 2013-04-01 11:58 +1100
          Re: Why does 1**2**3**4**5 raise a MemoryError? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-01 04:16 +0000
            Re: Why does 1**2**3**4**5 raise a MemoryError? Roy Smith <roy@panix.com> - 2013-04-01 07:48 -0400
          Re: Why does 1**2**3**4**5 raise a MemoryError? Nobody <nobody@nowhere.com> - 2013-04-02 08:40 +0100
      Re: Why does 1**2**3**4**5 raise a MemoryError? Chris Angelico <rosuav@gmail.com> - 2013-04-01 09:32 +1100
      Re: Why does 1**2**3**4**5 raise a MemoryError? Dave Angel <davea@davea.name> - 2013-03-31 18:34 -0400

csiph-web