id	summary	reporter	owner	description	type	status	priority	milestone	component	resolution	keywords	cc	work_issues	upstream	reviewer	author	merged	dependencies	stopgaps
8342	Efficient Arbitrary Sequence Generator	colah	colah	"{{{
def construct_sequence(base,f):
    """"""
    Returns a function that gives sequence terms, building off past calls.
    
    Input:
       - `base` -- the base case(s) of the sequence.
       - `f`    -- the recursive description of the sequence; it takes a sequence referencing function and returns a function that will, given n, return the nth term.

    Output:
       A function that, given n, returns the nth term in the sequence.
    
    Examples:
       sage: fib = construct_sequence([1,1], lambda t: lambda n : t(n-1) + t(n-2)) #The Fibonacci sequence

       sage: hof = construct_sequence([1,1], lambda t: lambda n : t(n-t(n-1)) + t(n-t(n-2))) #The Hofstadter Q sequence
       sage: [hof(n) for n in range(100)] # List of 100 terms
    """"""
    b = {}
    for i in range(len(base)):
        b[i] = base[i]
    def get_term(n):
        if n in b.keys(): return b[n]
        else:
            b[n] = f(get_term)(n)
            return b[n]
    return get_term
}}}
"	enhancement	needs_work	minor	sage-wishlist	numerical		sequence, generator			N/A		colah			
