# Recursive Dirichlet convolutions and sum errors

I only have an informal knowledge of mathematical at best, learned entirely from modifying premade programs, and reading the documentation of functions, so I apologize if my question should be obvious or inane. Currently, I'm trying to mess around with Dirichlet powers of arithmetic functions, and to do this I'm using Mathematica. I have the following code, but I keep getting errors about various objects not being able to be used as iterators.

f[1, x_] := MoebiusMu[x];
f[n_, x_] := DirichletConvolve[f[1, d], f[n - 1, d], d, x];
Table[f[i, 2], {i, 0, 5}]


I assume that this is caused by the effectively nested DirichletConvolutions, as I've run into similar errors in the past, and fixed them by making sure that the iterators had different names for each layer, but I don't think that's a viable solution here. Furthermore, based on the errors, I assume that this runs deeper into the implementation of the DirichletConvolution function with Sum. How can I fix this?

I hope this helps. This is certainly not a stupid question as it depends on some subtle behaviour that took me some time to figure out.

A simple problem first. You don't define f[0,x] so you have an infinite recursion. I've modified it so that it only recurses for n>1 (and changed the lower limit on the table).

The other problem is that Mathematica gets confused by the fact that the same symbol d is reused at different levels of recursion. The way round this is to use Module to declare it as a local variable.

With these fixes, I get

f[1, x_] := MoebiusMu[x];
f[n_ /; n > 1, x_] :=
Module[{d}, DirichletConvolve[f[1, d], f[n - 1, d], d, x]];

Table[f[i, 2], {i, 1, 5}]
(* {-1, -2, -3, -4, -5} *)

• Thanks, this was helpful! For some reason, it never occurred to me that Mathematica would have different levels of scope. Also, the end result was certainly not what I was expecting. – tox123 May 31 at 18:50