Rademacher like formula:
ded[h_, k_] := If[k < 3, 0, Sum[m*(FractionalPart[h*m/k] - 1/2), {m, 1, k - 1}]];
omega[k_, n_] := If[k == 1, 1, Sum[If[GCD[h, k] == 1, Cos[(ded[h, k] - 2*h*n)*Pi/k], 0], {h, 1, k - 1}]];
part[n_] := Round[1/(Pi*2*Sqrt[2])*Sum[omega[k, n]*Sqrt[k] * D[Exp[Pi/k*Sqrt[2/3*(nn - 1/24)]]/Sqrt[nn - 1/24], nn] /. nn -> n, {k, 1, Max[5, Sqrt[n]/2]}]];
part[1000] // AbsoluteTiming
(* {0.0156423, 24061467864032622473692149727991} *)
PartitionsP[1000] // AbsoluteTiming
(* {0.0298074, 24061467864032622473692149727991} *)
Observation:
c*Sqrt[n]
terms suffice to compute part(n)
exactly by forcing the error < 1/2
and rounding to the nearest integer. Interesting is a constant c
.
With c = 0.5
is the difference between rounded and real value within the required bounds (but for example with c = 0.3
not!).
c = 0.5;
partfloat[n_] := 1/(Pi*2*Sqrt[2]) * Sum[omega[k, n]*Sqrt[k] *
D[Exp[Pi/k*Sqrt[2/3*(nn - 1/24)]]/Sqrt[nn - 1/24], nn] /. nn -> n, {k, 1,
Max[5, c*Sqrt[n]]}];
dif = Table[N[partfloat[n] - PartitionsP[n], 100], {n, 1, 1000}];
Min[dif]
Max[dif]
(* -0.1924581822178408 *)
(* 0.19346720647243795 *)
ListPlot[dif]
c = 0.3;
dif = Table[N[partfloat[n] - PartitionsP[n], 100], {n, 1, 1000}];
ListPlot[dif]