Double Sum Involving Condition

I would like to compute the dimensions of some small free nilpotent Lie algebras. However, I am totally new to this and I could not figure out how to write the double sum which gives the dimension of the free nilpotent Lie algebra $L(c,n)$ of step $c$ with $n$ generators.

Long story short, I would like to learn how I can write the sum

$$\dim L(c,n) = \sum_{m=1}^{c}\frac{1}{m}\sum_{d \mid m}\mu(d)n^{m/d}$$

where $\mu$ is the Möbius function, in Mathematica.

-
Maybe diml[c_, n_] := Block[{j}, Sum[DirichletConvolve[MoebiusMu[j], n^j, j, m]/m, {m, c}]]? If this does what you want, I'll write an answer. – J. M. Feb 18 at 6:32
@J.M. Hello. I tried this with some known values and it produced the correct values. I am sorry, since I do not know much about Mathematica this is the only way of me knowing that it works. Thank you! So please go ahead and write an answer, – Can Hatipoglu Feb 18 at 7:11
No need to apologize! You are fortunate here that Mathematica has the necessary stuff for the computations you want to do. Give me a few, and I'll write something up. – J. M. Feb 18 at 7:14
Welcome to Mathematica.SE! 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – Louis Feb 18 at 7:32
FWIW, your inner sum equals JordanTotient[k, n] but unfortunately that function is not in Mathematica. – Chip Hurst Jun 2 at 18:10

A story of incremental improvement

Let's look at the OP's original expression again, for reference:

$$\sum_{m=1}^{c}\frac{1}{m}\sum_{d \mid m}\mu(d)n^{m/d}$$

Most people here are familiar with Sum[], and would not have much trouble translating the outer summation into Mathematica syntax. The inner part,

$$\sum_{d \mid m}\mu(d)n^{m/d}$$

is not terribly familiar to those who do not do much number theory. What this basically is saying is that the terms of the sum are indexed over the divisors of $m$. Appropriately enough, Mathematica does have a Divisors[] function. The inner sum can thus be written as

Sum[MoebiusMu[d] n^(m/d), {d, Divisors[m]}]


Summing over the divisors of a number, however, is so common a number-theoretic operation that Mathematica has seen it fit to provide a DivisorSum[] function. Thus, the inner sum can also be written as

DivisorSum[m, MoebiusMu[#] n^(m/#) &]


The story does not end here. The operation

$$\sum_{d \mid m}f(d)g(m/d)$$

frequently turns up in number-theoretic and other contexts, that it has been given a special name: Dirichlet convolution. Mathematica, fortunately, also provides a function for evaluating convolutions, called DirichletConvolve[]. Thus, the inner sum is most compactly expressed as

DirichletConvolve[MoebiusMu[j], n^j, j, m]


The function in the OP can now be implemented like so:

diml[c_Integer?Positive, n_Integer?Positive] := Block[{j},
Sum[DirichletConvolve[MoebiusMu[j], n^j, j, m]/m, {m, c}]]


or, using formal symbols as suggested by The Doctor,

diml[c_Integer?Positive, n_Integer?Positive] :=
Sum[DirichletConvolve[MoebiusMu[\[FormalJ]], n^\[FormalJ], \[FormalJ], m]/m, {m, c}]


(They look messy here on SE, but should look nice when pasted into Mathematica.)

Here is the function in action:

Table[diml[c, n], {c, 5}, {n, 5}]
{{1, 2, 3, 4, 5}, {1, 3, 6, 10, 15}, {1, 5, 14, 30, 55},
{1, 8, 32, 90, 205}, {1, 14, 80, 294, 829}}

-
Thank you for introducing me to DirichletConvolve and for this instructive answer . This is my vote :) – ubpdqn Feb 18 at 8:55

Please see J.M.'s answer (in comments) using DirichletConvolve. I would vote for this as an answer.

l[c_, n_] :=Module[{r = Range[c]},
Total[(1/r) Total /@MapThread[MoebiusMu@#1 n^(#2/#1) & ,{Divisors /@ r, r}]]]


I will happily delete and vote for JM answer.

-

I like J.M.'s answer and voted for it. However, it's hard to format comments, so I've posted this as an answer instead. Rather than using Block[{j},...], you can use formal symbols instead, used to represent a formal parameter that will never be assigned a value. Moreover, if you enter

DivisorSum[m, Function[d, MoebiusMu[d] n^(m/d)]] // TraditionalForm


you will see that Mathematica uses formal symbols automatically. Also, in many cases, I prefer to use the "map notation" for Function instead of # and &. For example,

is executable code for this function.

Finally, in TraditionalForm notation, the sum can be expressed as

which corresponds nicely to the original sum posted in the question. However, using DirichletConvolve should be more efficient.

-