Looking for an explanation of unusual behavior in Divisors[] function

I have defined the function that counts the number of square divisors of input integer x. The function is

NumberOfSquareDivisors[H_]:=Length[Select[Divisors[H],Not@*SquareFreeQ]];

Now when computing the average number of square divisors cases at H = 10000000 I get

N[Sum[NumberOfSquareDivisors[i],{i,1,10000000}]/10000000]

Divisors::argx: Divisors called with 0 arguments; 1 argument is expected.

When tested for smaller values, say 10^3, 10^4, 10^5, 10^6 I get the proper sum. So at 10^7 the Divisors function is claiming that it is called with zero arguments. How can this occur?

Is this an error in Mathematica or something else?

I have tested this on two difference computers using the latest version of Mathematica.

• does SetSystemOptions["SymbolicSumThreshold" -> 10000000]; N[Sum[NumberOfSquareDivisors[i], {i, 1, 10000000}]/10000000] work?
– kglr
Sep 4, 2020 at 4:04
• Yes that did work. Now I am at work using the cloud and the calculation exceed my time limit, but this tells me that it was computing the sum without the error. Sep 4, 2020 at 4:08

1 Answer

When the length of the sum exceeds 10^6, Sum will try to compute the result symbolically. This symbolic computation fails miserably for your function, generating errors. You can see this for smaller values by setting a system option:

SetSystemOptions["SymbolicSumThreshold"->1000];

Sum[NumberOfSquareDivisors[i],{i,1,1001}]


Divisors::argx: Divisors called with 0 arguments; 1 argument is expected.

0

Clearly, trying to perform a symbolic sum of a user defined function is unlikely to work. You can avoid this by raising the threshold:

SetSystemOptions["SymbolicSumThreshold"->Infinity];

Sum[NumberOfSquareDivisors[i],{i,1,10^7}]


However, I don't have the patience to wait for this to finish. You can reset to the default with:

SetSystemOptions["SymbolicSumThreshold"->10^6];

• That makes sense, however it was unexpected. At least I get an error/warning condition. I do use user defined functions with sums in many cases, however, the sum limits are usually small so I have not seen this condition until now. Sep 4, 2020 at 4:18