It’s slow! But why does it work at all? This is so obscure that I’m spoiling it for you up front. The number of ways to partition n into four triangular numbers, counting 0s and permutations, equals the sum of the divisors of 2n+1. The generating function for the triangular numbers is
Slash dot means substitute. It is amazing that Series still can’t figure out how many terms it needs of an infinite sum. So 19 is prime because the coefficient of q^9 is 20, the number of ways to express 9 as the sum of four triangular numbers:
In[]:=
Sum[(#q)^Binomial[n,2],{n,∞}]&/@(abcd)
Out[]=
EllipticTheta2,0,
aq
EllipticTheta2,0,
bq
EllipticTheta2,0,
cq
EllipticTheta2,0,
dq
16
1/8
(aq)
1/8
(bq)
1/8
(cq)
1/8
(dq)
In[]:=
Expand@SeriesCoefficient[%,{q,0,9}]
Out[]=
6
a
3
b
+
3
a
6
b
+
6
a
3
c
+
3
a
3
b
3
c
+
6
b
3
c
+
3
a
6
c
+
3
b
6
c
+
6
a
bcd+a
6
b
cd+ab
6
c
d+
6
a
3
d
+
3
a
3
b
3
d
+
6
b
3
d
+
3
a
3
c
3
d
+
3
b
3
c
3
d
+
6
c
3
d
+
3
a
6
d
+
3
b
6
d
+abc
6
d
+
3
c
6
d
E.g., a^6 d^3 says 9 = 6+0+0+3. 0, 1, 3, and 6 are triangular numbers.