def recurrence_memo(initial):
 cache = initial
 def decorator(f):
  @wraps(f)
  def g(n):
   L = len(cache)
   if (n <= (L - 1)):
    return cache[n]
   for i in range(L, (n + 1)):
    cache.append(f(i, cache))
   return cache[(-1)]
  return g
 return decorator

def recurrence_memo ( initial ) : cache = initial def decorator ( f ) : @ wraps ( f ) def g ( n ) : L = len ( cache ) if ( n <= ( L - 1 ) ) : return cache [ n ] for i in range ( L , ( n + 1 ) ) : cache . append ( f ( i , cache ) ) return cache [ ( - 1 ) ] return g return decorator
memo decorator for sequences defined by recurrence see usage examples e .