Comment #1 on issue 3510 by Franck.Dernoncourt: implement Stirling numbers
http://code.google.com/p/sympy/issues/detail?id=3510

You might want to use dynamic programming instead, which is by faster. Computing n=k=100 takes forever using your code and is immediate (< 1 second) using dynamic programming.

(just an example quickly extracted from my code)

Code:

cache_size= 10
cache = [[0 for j in range(cache_size)]  for i in range(cache_size)]

def generate_cache():
    cache[0][0] = 1
    for i in range(1, cache_size):
        for j in range(1, cache_size):
            cache[i][j]=cache[i-1][j-1] + j* cache[i-1][j]

def main():
    generate_cache()
    for i in range(0, cache_size):
        print cache[i]

if __name__ == "__main__":
    main()


Output:
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 1, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 1, 1, 0, 0, 0, 0, 0, 0, 0]
[0, 1, 3, 1, 0, 0, 0, 0, 0, 0]
[0, 1, 7, 6, 1, 0, 0, 0, 0, 0]
[0, 1, 15, 25, 10, 1, 0, 0, 0, 0]
[0, 1, 31, 90, 65, 15, 1, 0, 0, 0]
[0, 1, 63, 301, 350, 140, 21, 1, 0, 0]
[0, 1, 127, 966, 1701, 1050, 266, 28, 1, 0]
[0, 1, 255, 3025, 7770, 6951, 2646, 462, 36, 1]

--
You received this message because you are subscribed to the Google Groups 
"sympy-issues" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy-issues?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to