title: What technical limitations prevent the calculation of Graham's number in python?
body: <p>Assuming that the computer running this program has an infinite amount of memory, I'm interested in where Python will break when running the following:</p>
  
  <p>For fun, I implemented <a href="https://en.wikipedia.org/wiki/Hyperoperation" rel="nofollow noreferrer">hyperoperators</a> in python as the module <a href="https://github.com/thoppe/python-hyperoperators" rel="nofollow noreferrer"><code>hyperop</code></a>. One of my examples is Graham's number:</p>
  
  <pre><code>def GrahamsNumber():
      # This may take awhile...
      g = 4
      for n in range(1,64+1):
          g = hyperop(g+2)(3,3)
      return g
  </code></pre>
  
  <p>The condensed version of the class <code>hyperop</code> looks like this:</p>
  
  <pre><code>def __init__(self, n):
      self.n = n
      self.lower = hyperop(n - 1)
  
  def _repeat(self, a, b):
      if self.n == 1:
          yield a
  
      i = 1
      while True:
          yield a
          if i == b:
              break
          i += 1
  
  def __call__(self, a, b):
      return reduce(lambda x, y: self.lower(y, x), self._repeat(a, b))
  </code></pre>
  
  <p>Essentially the library is just a recursive fold-right operation, with a special definition for the <a href="https://github.com/thoppe/python-hyperoperators/blob/master/hyperop/hyperop.py" rel="nofollow noreferrer">base case of n=1</a>. Originally <code>__call__</code> was beautifully golfed as:</p>
  
  <pre><code>return reduce(lambda x, y: self.lower(y, x), [a,]*b)
  </code></pre>
  
  <p>However, <a href="https://stackoverflow.com/questions/22114088/overflowerror-python-int-too-large-to-convert-to-c-long/22114284#22114284">it turns out that you can't make a list with more elements than the size of a C long</a>. That was a fun limitation that most Python programmers probably don't encounter in their normal day-to-day and it inspired the following question.</p>
  
  <blockquote>
    <p>Where, if at all, will the <code>hyperop</code> calculation fail due to a <em>technical limitation of python</em> (specifically <a href="https://www.python.org/downloads/release/python-2710/" rel="nofollow noreferrer">2.7.10</a>)?  </p>
  </blockquote>