## 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}}
```

3Maybe

`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.'s ennui – 2016-02-18T06:32:27.080@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 – 2016-02-18T07:11:19.930

1No need to apologize! You are fortunate here that

Mathematicahas the necessary stuff for the computations you want to do. Give me a few, and I'll write something up. – J. M.'s ennui – 2016-02-18T07:14:48.130FWIW, your inner sum equals

– Chip Hurst – 2016-06-02T18:10:55.163`JordanTotient[k, n]`

but unfortunately that function is not inMathematica.