3
$\begingroup$

So I want to find the sum of odd divisors of a number raised to some power. $i.e.$ I want to find $\sum_{n=1}^\infty\sigma'_{-2k-1}(n)$ where $\sigma'_{-2k-1}(n) = \sum_{d|n, \text{d odd}} d^{-2k-1}$.

How should I go with this? Using DivisorSigma[k,n] just sums up over all the divisors.

Any help is highly appreciated.

$\endgroup$
7
  • 1
    $\begingroup$ Does it help if you remove all powers of 2from your number and sum the full set of divisors? $\endgroup$ Jun 9, 2021 at 13:37
  • 1
    $\begingroup$ For the infinite sum, since $1$ is an odd divisor of all $n$ and $1^{-2k-1}=1$, the sum diverges, no? $\endgroup$
    – Michael E2
    Jun 9, 2021 at 13:37
  • 1
    $\begingroup$ You could just brute force it. Find the divisors, filter out the odds, raise them to the -(2*k+1)th and total: Total[Select[Divisors[n],OddQ]^(-2*k-1)] Probably something more clever out there. $\endgroup$
    – N.J.Evans
    Jun 9, 2021 at 14:53
  • $\begingroup$ @MichaelE2 Yes, you are right. There is some exponential terms as well with very high negative powers which I have not written here. I am mainly interested to know how can I write code for this sum in mathematica. $\endgroup$
    – Kashif
    Jun 9, 2021 at 16:35
  • 1
    $\begingroup$ DivisorSigmaPrime[r_, n_Integer] := DivisorSigma[r, NestWhile[#/2 &, n, EvenQ]] will get you $\sigma_r(n)$. Then Sum[] can be used for the summation. $\endgroup$
    – Michael E2
    Jun 9, 2021 at 16:42

2 Answers 2

6
$\begingroup$

You could find the sum of odd divisors of a number raised to some power in the following way:

DivisorSum[n, #^(-2k-1) &, OddQ]

You can then use Sum[ ] for summation.

$\endgroup$
1
  • $\begingroup$ DivisorSum[] is indeed the appropriate tool to use here. $\endgroup$ Jun 10, 2021 at 2:05
5
$\begingroup$

To incorporate comments, for the sake of completeness: Of the three current suggestions in the comments and answer, Daniel Lichtblau's is fastest:

DivisorSigmaPrime // ClearAll;
DivisorSigmaPrime[r_, n_Integer] := 
  DivisorSigma[r, NestWhile[#/2 &, n, EvenQ]];

It's literally a divide-and-conquer approach, as dividing out twos removes the even divisors.

k = 2;
Table[Total[Select[Divisors[n], OddQ]^(-2*k - 1)], {n, 10000}]; // AbsoluteTiming
Table[DivisorSum[n, #^(-2 k - 1) &, OddQ], {n, 10000}]; // AbsoluteTiming
Table[DivisorSigmaPrime[-2 k - 1, n], {n, 10000}]; // AbsoluteTiming
Clear[n, k];
(*
  {0.253292, Null}  -- @Lusine
  {0.172394, Null}  -- @N.J.Evans
  {0.108652, Null}  -- @Daniel
*)

The differences are greater the more factors there are.

(* no even divisors *)
SeedRandom[0];
k = 2;
n = 2^0 Apply[Times]@Prime[RandomInteger[{10, 1000}, 10]];
DivisorSum[n, #^(-2 k - 1) &, OddQ] - 1 // RepeatedTiming // N[#, 20] &
Total[Select[Divisors[n], OddQ]^(-2*k - 1)] - 1 // RepeatedTiming // N[#, 20] &
DivisorSigmaPrime[-2 k - 1, n] - 1 // RepeatedTiming // N[#, 20] &
Clear[n, k];
(*
  {0.00940233,   1.4631160740223029704*10^-13}  -- @Lusine
  {0.00823647,   1.4631160740223029704*10^-13}  -- @N.J.Evans
  {0.0000936843, 1.4631160740223029704*10^-13}  -- @Daniel
*)

(* many even divisors *)
SeedRandom[0];
k = 2;
n = 2^20 Apply[Times]@Prime[RandomInteger[{10, 1000}, 10]];
DivisorSum[n, #^(-2 k - 1) &, OddQ] - 1 // RepeatedTiming // N[#, 20] &
Total[Select[Divisors[n], OddQ]^(-2*k - 1)] - 1 // RepeatedTiming // N[#, 20] &
DivisorSigmaPrime[-2 k - 1, n] - 1 // RepeatedTiming // N[#, 20] &
Clear[n, k];
(*
  {0.0259015,   1.4631160740223029704*10^-13}  -- @Lusine
  {0.023558,    1.4631160740223029704*10^-13}  -- @N.J.Evans
  {0.000116666, 1.4631160740223029704*10^-13}  -- @Daniel
*)

I didn't find much variation in relative timings if k is changed. (Large n and k leads to lots of bigInt calculations, and all three methods slow down.)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.