Pentagonal Number Theorem - Example Program

Example Program

Here is a simple Python program which computes p(n), the number of partitions, using the recurrence resulting from the pentagonal number theorem.

pentagonal = lambda n : n*(3*n-1)/2 def generalised_pentagonal(n): # 0, 1, -1, 2, -2 if n < 0: return 0 if n%2 == 0: return pentagonal(n/2+1) else: return pentagonal(-(n/2+1)) pt = for n in range (1, 1000+1): r = 0 f = -1 i = 0 while 1: k = generalised_pentagonal(i) if k > n: break if i%2==0: f = -f r += f*pt i += 1 pt.append(r) print pt

Read more about this topic:  Pentagonal Number Theorem

Famous quotes containing the word program:

    These native villages are as unchanging as the woman in one of their stories. When she was called before a local justice he asked her age. “I have 45 years.” “But,” said the justice, “you were forty-five when you appeared before me two years ago.” “SeƱor Judge,” she replied proudly, drawing herself to her full height, “I am not of those who are one thing today and another tomorrow!”
    State of New Mexico, U.S. public relief program (1935-1943)

    The blacksmith dropped his hammer, the carpenter his plane, the mason his trowel, the farmer his sickle, the baker his loaf, and the tapster his bottle. All were off for the mines, some on horses, some on carts, and some on crutches, and one went in a litter.
    —For the State of California, U.S. public relief program (1935-1943)