Simple expression for Partition function, $P(n)$, for $n\le20$

280 Views Asked by At

I know there are various forms to express the function $P(n)$, the number of partitions for an integer $n$, e.g. see some of the formulas referenced on Wolfram.

But say I only care about the first ~$10-20$ numbers ($P(n)$ for $n \lt$ ~$20$).

E.g. from OEIS:, the sequence (up to $n=20$): $$1, 1, 2, 3, 5, 7, 11, 15, 22, 30, 42, 56, 77, 101, 135, 176, 231, 297, 385, 490$$

But is there a "relatively simple" exact closed form expression for the first $10-20$ values of $n$? Relatively simple meaning e.g. an expression for $P(n)$, $n \le$ ~$10-20$, that someone could calculate reasonably quickly on a basic calculator (products and sums okay, but e.g. no Bessel functions or something). Also, no approximate solutions, only exact solutions.

2

There are 2 best solutions below

0
On

Yes, it is possible to calculate a closed form, but it is not so nice. Anyway the calculation is relative simple, and once it is calculated you just need to apply the formula, so here it is (the explanation of the theory below is much larger than the code required to use it):

Let us define the constant $P = 1.366611510803...$ as a Mills-like constant such that the partition function $P(n)=f(P,n)$ for $n=[1..20]$. The constant $P$ is obtained by the encapsulation of the elements of the partition function elements $P(n)$ into integers $E_n$ of $[N,(N+1)^2]$ intervals. As a result, the function $f(P,n)$ is a representing function of the first elements of the partition function for $n=[1..20]$, so $P(n)=f(P,n), n \in [1..20]$.

This constant is such that:

$P(n)=f(P,n)=\lfloor E^{2^n} \rfloor -(\lfloor E^{2^{n-1}} \rfloor)^2+\frac{\lvert n-(\frac{1}{2}) \rvert}{(\frac{1}{2})-n}$

for $n=[1..20]$ provides $P(n)$ in the same growing order.

I am using a method of my own (I asked about it some weeks ago but unfortunately still was not answered).

The constant has a lot of decimal places, but if you are using PARI/GP you can calculate it and use it and it will provide the exact values of $P(n)$ for $n=[1,20]$.

This is the manual method to generate the constant $P$ (it is much better described in my original question applied to other encapsulation problem):

$E_1=P(1)=1$ encapsulating the next value $P(2)=1$ into $E_1^2+P(2)+1=1+1+1=3$.

$E_2=3^2=9$ encapsulating the next value $P(3)=2$ into $E_2^2+P(3)+1=9+2+1=12$.

$E_3=12^2=144$ encapsulating the next value $P(4)=3$ into $E_3^2+P(4)+1=144+3+1=148$.

... up to:

$E_{20}=E_{19}^2$ encapsulating the next value $P(20)=490$ into $E_{20}^2+P(20)+1$.

Then using same theory as Mills' constant, our constant is $P=E_{20}^{(\frac{1}{2^{20}})} = 1.366611510803...$.

You will require a good amount of decimal places to have enough precision to use it and obtain the values, but it works and can be used for calculations.

For instance in PARI/GP first you calculate up to $E_{20}$, then calculate the constant $P$ with $E_{20}$, and then you can apply the formula to obtain the exact values of $P(1)..P(20)$ from that moment (so for instance you can store the value of the constant $P$ in a library and build a function to use it):

\p200000;
P1=1
E1=1
P2=1
E2=E1^2+P2+1
P3=2
E3=E3^2+P3+1
P4=3
E4=E4^2+P4+1
P5=5
E5=E5^2+P5+1
P6=7
E6=E6^2+P6+1
P7=11
E7=E1^7+P7+1
P8=15
E8=E8^2+P8+1
P9=22
E9=E9^2+P9+1
P10=30
E10=E10^2+P10+1
P11=42
E11=E11^2+P11+1
P12=56
E12=E12^2+P12+1
P13=77
E13=E13^2+P13+1
P14=101
E14=E14^2+P14+1
P15=135
E15=E15^2+P15+1
P16=176
E16=E16^2+P16+1
P17=231
E17=E17^2+P17+1
P18=297
E18=E18^2+P18+1
P19=385
E19=E19^2+P19+1
P20=490
E20=E20^2+P20+1
P=E20^(1/(2^E20))

And then you can use $P$ as follows:

P20=floor(P^(2^20))-(floor(P^(2^19)))^2-1
P19=floor(P^(2^19))-(floor(P^(2^18)))^2-1
P18=floor(P^(2^18))-(floor(P^(2^17)))^2-1
P17=floor(P^(2^17))-(floor(P^(2^16)))^2-1
P16=floor(P^(2^16))-(floor(P^(2^15)))^2-1
P15=floor(P^(2^15))-(floor(P^(2^14)))^2-1
P14=floor(P^(2^14))-(floor(P^(2^13)))^2-1
P13=floor(P^(2^13))-(floor(P^(2^12)))^2-1
P12=floor(P^(2^12))-(floor(P^(2^11)))^2-1
P11=floor(P^(2^11))-(floor(P^(2^10)))^2-1
P10=floor(P^(2^10))-(floor(P^(2^9)))^2-1
P09=floor(P^(2^9))-(floor(P^(2^8)))^2-1
P08=floor(P^(2^8))-(floor(P^(2^7)))^2-1
P07=floor(P^(2^7))-(floor(P^(2^6)))^2-1
P06=floor(P^(2^6))-(floor(P^(2^5)))^2-1
P05=floor(P^(2^5))-(floor(P^(2^4)))^2-1
P04=floor(P^(2^4))-(floor(P^(2^3)))^2-1
P03=floor(P^(2^3))-(floor(P^(2^2)))^2-1
P02=floor(P^(2^2))-(floor(P^(2^1)))^2-1
P01=floor(P^(2^1))-(floor(P^(2^0)))^2+1

Be aware that $f(P,1)$ ($P01$ in the code) is an special case and that is the reason of the correction term $+\frac{\lvert n-(\frac{1}{2}) \rvert}{(\frac{1}{2})-n}$.

1
On

The partition numbers $P(n)$ for $1\le n\le21$ can be calculated quickly and easily using the recurrence $$P(n)=P(n-1)+P(n-2)-P(n-5)-P(n-7)+P(n-12)+P(n-15)$$ with boundary conditions $P(0)=1$ and $P(n)=0$ for $n\lt0.$

This is a truncated form of formula (20) on that Wolfram page you linked to. The sequence $1,\ 2,\ 5,\ 7,\ 12,\ 15$ is easily remembered as $1,\ 2,\ 2+3,\ 3+4,\ 3+4+5,\ 4+5+6.$