How does `DirichletConvolve` relate to Dirichlet convolution?

Consider the following code

f[n_, p_] := n^p
g[n_, p_] := n*p
    
DirichletConvolve[f[n, p], g[n, p], n, 4]

First, we define two functions f and g. Then we compute their Dirichlet convolution.

The third argument in the Dirichlet convolution tells us that n is the function argument for which we want to do the convolution. p on the other hand is a parameter that happens to exist in the functions but is not related to the convolution. Changing the last line to

DirichletConvolve[f[n, p], g[n, p], p, 4]

means that we are using p as the variable for the convolution, whereas n now is some parameter.

Finally, the 4 says that we want to evaluate the resulting function at 4. If you want to evaluate this function at the general position m you use

DirichletConvolve[f[n, p], g[n, p], n, m]

Mathematical Way

Let me write this in a mathematical way: We have two functions

$$ f \colon \mathbb{N} \times \mathbb{N} \longrightarrow \mathbb{N} \\ (n,p) \longmapsto n^p $$

and

$$ g \colon \mathbb{N} \times \mathbb{N} \longrightarrow \mathbb{N} \\ (n,p) \longmapsto n\cdot p $$

Now DirichletConvolve[f[n, p], g[n, p], n, m] evaluates

$$ (f*g)(m, p) = \sum_{d \mid m} f(d, p) g \left(\frac{m}{d}, p\right) $$

whereas DirichletConvolve[f[n, p], g[n, p], p, m] evaluates

$$ (f*g)(m, p) = \sum_{d \mid m} f(p, d) g \left(p, \frac{m}{d}\right) $$

Example from the Documentation

If the functions f and g do not have any parameters, this looks like:

f[n_] := n (* or any other function depending only on n *)
g[n_] := n

DirichletConvolve[f[n], g[n], n, m]

This example is equivalent to the one from the documentation

DirichletConvolve[n, n, n, m]

We convolve the identity map with itself and evaluate it at m.


Let f,g be arithmetical functions.

Then (f*g)(n), where * is Dirichlet Multiplication or Convolution is equal to:

DirichletConvolve[f[j],g[j],j,n]

and also:

DivisorSum[n,f[#]g[n/#]&]

So for example,

DivisorSigma[0,n]=DirichletConvolve[1,1,j,n]

I only recently tweeted about this to @WolframResearch https://twitter.com/ndroock1/status/1273593486491693062