(initial)
return decorator
Memo decorator for sequences defined by recurrence

    See usage examples e.g. in the specfun/combinatorial module
Memo decorator for sequences defined by recurrence
Memo decorator for sequences defined by recurrence
def recurrence_memo(initial):
    """
    Memo decorator for sequences defined by recurrence

    See usage examples e.g. in the specfun/combinatorial module
    """
    cache = initial

    def decorator(f):
        @wraps(f)
        def g(n):
            L = len(cache)
            if n <= L - 1:
                return cache[n]
            for i in xrange(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 xrange ( L , n + 1 ) : cache . append ( f ( i , cache ) ) return cache [ - 1 ] return g return decorator