Thomas D. Dean on Mon, 04 Dec 2023 08:03:14 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

number of ways of writing a nonnegative integer n as a sum of 3 squares (zero being allowed).


Sorry if this too far off topic.

I have been looking at OEIS, A005875, and can not understand their counting. I can see the Pari code and understand how it works.

OEIS calls this "number of ways of writing a nonnegative integer n as a sum of 3 squares (zero being allowed)." or "Number of ordered triples (i, j, k) of integers such that n = i^2 + j^2 + k^2." So, i,j,and, k should be considered distinct even if they are numerically equal?

If there is only one member in the vector of integers st N=a^2+b^2+c^2
Pari returns 6 permutations.
foreach([[1,2,3]],x,forperm(x,v,print(v)))

If there are two members in the vector of integers st N=a^2+b^2+c^2
Pari returns 12 permutations.
foreach([[1,2,3],[4,5,6]],x,forperm(x,v,print(v)))

A005875(n)=if(n<0,0,polcoeff(sum(k=1,sqrtint(n),2*x^k^2,1+x*O(x^n))^3,n))

sumsquares(n,k)=
{
   my(bd=sqrtint(n),s=[]);
   forvec(x=vector(k,i,[0,bd]),
         if(n==sum(i=1,k,x[i]^2),
            s=setunion(s,[vecsort(x)]);
           );
   );
   s;
}

for(i=0,30,print(i,"\t",6*#sumsquares(i,3),"\t",A005875(i)));

If I consider each of a,b,c to be distinct even though the are not numberically:
N [a,b,c]
0 [0,0,0] -> 6 OEIS says 1 What about ordered tripes?
1 [0,0,1] -> 6 OEIS says 6 OK
2 [0,1,1] -> 6 OEIS says 12 - How do they get this?
3 [1,1,1] -> 6 OEIS says 8 - ?
4 [0,0,2] -> 6 OEIS says 6 OK
5 [0,1,2] -> 6 OEIS says 24??
6 [1,1,2] -> 6 OEIS says 24??
7 none
8 [0,2,2] -> 6 OEIS says 12
...
25 [0,0,5] [0,3,4] -> 12 OEIS says 30?
26 [0,1,5] [1,3,4] -> 12 OEIS says 72?

What am I missing? Can someone explain this to me?

Tom Dean