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:

    If Los Angeles has been called “the capital of crackpots” and “the metropolis of isms,” the native Angeleno can not fairly attribute all of the city’s idiosyncrasies to the newcomer—at least not so long as he consults the crystal ball for guidance in his business dealings and his wife goes shopping downtown in beach pajamas.
    —For the State of California, U.S. public relief program (1935-1943)

    The last public hanging in the State took place in 1835 on Prince Hill.... On the fatal day, the victim, a man named Watkins, peering through the iron bars of his cell, and seeing the townfolk scurrying to the place of execution, is said to have remarked, ‘Why is everyone running? Nothing can happen until I get there.’
    —Administration for the State of Con, U.S. public relief program (1935-1943)