[Question]
  [
The *Dirichlet convolution* is a special kind of *convolution* that appears as a very useful tool in number theory. It operates on the set of [*arithmetic functions*](https://en.wikipedia.org/wiki/Arithmetic_function).
### Challenge
Given two arithmetic functions \$f,g\$ (i.e. functions \$f,g: \mathbb N \to \mathbb R\$) compute the *Dirichlet convolution* \$(f \* g): \mathbb N \to \mathbb R\$ as defined below.
### Details
* We use the convention \$ 0 \notin \mathbb N = \{1,2,3,\ldots \}\$.
* The Dirichlet convolution \$f\*g\$ of two arithmetic functions \$f,g\$ is again an arithmetic function, and it is defined as $$(f \* g)(n) = \sum\_\limits{d|n} f\left(\frac{n}{d}\right)\cdot g(d) = \sum\_{i\cdot j = n} f(i)\cdot g(j).$$ (Both sums are equivalent. The expression \$d|n\$ means \$d \in \mathbb N\$ divides \$n\$, therefore the summation is over the natural *divisors* of \$n\$. Similarly we can subsitute \$ i = \frac{n}{d} \in \mathbb N, j =d \in \mathbb N \$ and we get the second equivalent formulation. If you're not used to this notation there is a step by step example at below.) Just to elaborate (this is not directly relevant for this challenge): The definition comes from computing the product of [Dirichlet series](https://en.wikipedia.org/wiki/Dirichlet_series): $$\left(\sum\_{n\in\mathbb N}\frac{f(n)}{n^s}\right)\cdot \left(\sum\_{n\in\mathbb N}\frac{g(n)}{n^s}\right) = \sum\_{n\in\mathbb N}\frac{(f \* g)(n)}{n^s}$$
* The input is given as two [black box functions](https://codegolf.meta.stackexchange.com/a/13706/24877). Alternatively, you could also use an infinite list, a generator, a stream or something similar that could produce an unlimited number of values.
* There are two output methods: Either a function \$f\*g\$ is returned, or alternatively you can take take an additional input \$n \in \mathbb N\$ and return \$(f\*g)(n)\$ directly.
* For simplicity you can assume that every element of \$ \mathbb N\$ can be represented with e.g. a positive 32-bit int.
* For simplicity you can also assume that every entry \$ \mathbb R \$ can be represented by e.g. a single real floating point number.
### Examples
Let us first define a few functions. Note that the list of numbers below each definition represents the first few values of that function.
* the multiplicative identity ([A000007](https://oeis.org/A000007)) 
$$\epsilon(n) = \begin{cases}1 & n=1 \\ 0 & n>1 \end{cases}$$
`1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...`
* the constant unit function ([A000012](https://oeis.org/A000012))$$ \mathbb 1(n) = 1 \: \forall n $$
`1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ...`
* the identity function ([A000027](https://oeis.org/A000027)) 
$$ id(n) = n \: \forall n $$
`1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, ...`
* the Möbius function ([A008683](https://oeis.org/A008683))
$$ \mu(n) = \begin{cases} (-1)^k & \text{ if } n \text{ is squarefree and } k \text{ is the number of Primefactors of } n \\ 0 & \text{ otherwise } \end{cases} $$
`1, -1, -1, 0, -1, 1, -1, 0, 0, 1, -1, 0, -1, 1, 1, 0, -1, 0, -1, ...`
* the Euler totient function ([A000010](https://oeis.org/A000010)) 
$$ \varphi(n) = n\prod\_{p|n} \left( 1 - \frac{1}{p}\right) $$
`1, 1, 2, 2, 4, 2, 6, 4, 6, 4, 10, 4, 12, 6, 8, 8, 16, 6, 18, 8, ...`
* the Liouville function ([A008836](http://oeis.org/A008836)) 
$$ \lambda (n) = (-1)^k $$ where \$k\$ is the number of prime factors of \$n\$ counted with multiplicity
`1, -1, -1, 1, -1, 1, -1, -1, 1, 1, -1, -1, -1, 1, 1, 1, -1, -1, -1, ...`
* the divisor sum function ([A000203](http://oeis.org/A000203)) 
$$\sigma(n) = \sum\_{d | n} d $$
`1, 3, 4, 7, 6, 12, 8, 15, 13, 18, 12, 28, 14, 24, 24, 31, 18, 39, 20, ...`
* the divisor counting function ([A000005](http://oeis.org/A000005))
$$\tau(n) = \sum\_{d | n} 1 $$
`1, 2, 2, 3, 2, 4, 2, 4, 3, 4, 2, 6, 2, 4, 4, 5, 2, 6, 2, 6, 4, 4, 2, 8, ...`
* the characteristic function of square numbers ([A010052](http://oeis.org/A010052))
$$sq(n) = \begin{cases} 1 & \text{ if } n \text{ is a square number} \\ 0 & \text{otherwise}\end{cases}$$
`1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, ...`
Then we have following examples:
* \$ \epsilon = \mathbb 1 \* \mu \$
* \$ f = \epsilon \* f \: \forall f \$
* \$ \epsilon = \lambda \* \vert \mu \vert \$
* \$ \sigma = \varphi \* \tau \$
* \$ id = \sigma \* \mu\$ and \$ \sigma = id \* \mathbb 1\$
* \$ sq = \lambda \* \mathbb 1 \$ and \$ \lambda = \mu \* sq\$
* \$ \tau = \mathbb 1 \* \mathbb 1\$ and \$ \mathbb 1 = \tau \* \mu \$
* \$ id = \varphi \* \mathbb 1 \$ and \$ \varphi = id \* \mu \$
The last for are a consequence of the [Möbius inversion](https://en.wikipedia.org/wiki/M%C3%B6bius_inversion_formula): For any \$f,g\$ the equation \$ g = f \* 1\$ is equivalent to \$f = g \* \mu \$.
### Step by Step Example
This is an example that is computed step by step for those not familiar with the notation used in the definition. Consider the functions \$f = \mu\$ and \$g = \sigma\$. We will now evaluate their convolution \$\mu \* \sigma\$ at \$ n=12\$. Their first few terms are listed in the table below.
$$\begin{array}{c|ccccccccccccc}
f & f(1) & f(2) & f(3) & f(4) & f(5) & f(6) & f(7) & f(8) & f(9) & f(10) & f(11) & f(12)
\\ \hline
\mu & 1 & -1 & -1 & 0 & -1 & 1 & -1 & 0 & 0 & 1 & -1 & 0 
\\
\sigma & 1 & 3 & 4 & 7 & 6 & 12 & 8 & 15 & 13 & 18 & 12 & 28
\\
\end{array}$$
The sum iterates over all natural numbers \$ d \in \mathbb N\$ that divide \$n=12\$, thus \$d\$ assumes all the natural divisors of \$n=12 = 2^2\cdot 3\$. These are \$d =1,2,3,4,6,12\$. In each summand, we evaluate \$g= \sigma\$ at \$d\$ and multiply it with \$f = \mu\$ evaluated at \$\frac{n}{d}\$. Now we can conclude
$$\begin{array}{rlccccc}
(\mu \* \sigma)(12) &= \mu(12)\sigma(1) &+\mu(6)\sigma(2) &+\mu(4)\sigma(3) &+\mu(3)\sigma(4) &+\mu(2)\sigma(6) &+\mu(1)\sigma(12)
\\
&= 0\cdot 1 &+ 1\cdot 3 &+ 0 \cdot 4 &+ (-1)\cdot 7 &+ (-1) \cdot 12 &+ 1 \cdot 28
\\
&= 0 & + 3 & 1 0 & -7 & - 12 & + 28 
\\
&= 12 \\
& = id(12)
\end{array}$$
  
[Answer]
# [Lean](https://leanprover.github.io/), ~~108~~ ~~100~~ ~~95~~ ~~78~~ 75 bytes
```
def d(f g:_->int)(n):=(list.iota n).foldr(λd s,ite(n%d=0)(s+f d*g(n/d))s)0
```
[Try it online!](https://tio.run/##TYxNCsIwFIT3PcWACO/5U9uFm0C8igTzUgPhFUzozVx5h16ppropDHzMBzNJnC6LlwBPAYO5n29RC5OysZRiLm0ci4NyG8bkXzR/PPIpFiHde9sx5WOdHgbSi2fO3P2@5jdIYaCucEV9hLGIAQqLHuUpWiEpC7qm2cnkEvy6qumvW/EYZWvW@lfLFw "Lean – Try It Online")
[More testcases with all of the functions.](https://tio.run/##pVSxjhoxEO35ipGSKPaez2EpkciPRDlk1t7FkvHC2heljARC1GlSXpso9VVcdenhH/ZHyHgNKw5xoCiVNX4zb2bf@K1Rwu70ZFpWHoQp1KgSfKqH2jovbKYcSOEFt8LzaaUnaidVDpLkUPSHtx@19ZRY2h8Qo53nuvQCLOV5aWRFNmsJjmmviH0nB11K3A2WJgWxHySljnZ3psyEAW1z/RUS6A9AdjqBf/MIxEIfsCvFA7sEUOdgYQAp@LGyeCjjFHRjwdMrBc1YtpT3U7A8F5kvKxfryW1K79o7bpQt/PiYc7s8x5mjMMrzTFQSyD7ItfGqwmwUKSsbmVCFFq6ELcIFbWiff2/Wz@tz1GcniqPMz@ZH0Rv6t/YmpftBUHiQDKLolLv7SSRZ/AfJ0TBu9tpyuJtV/q6HO7InO@q8UV9w00e93iOY9iifiCmu@zJO0tgO6uX30I9eSc9K9U8Fm6fL@HZ5GY8rvcIxv4IvLuNuFq0hRm54/rUjAgQhS2PmRPhsnPYgePVEDgxHZWmwqlOvvoGEerWC074M0K24y@LgSq@cz4TDX0K/Sca384L0zw94cUED/yeyeWTIl6DKlHWAbOcs@DtBRZo4wHtPJPuva/PQgpi3aGJcKgtGiEQRD4tOIG1wNzviSUNGjFj4OSSoX2RdxGGahJQFU7STxQ7LA7pdHhog/vnwhBuVhDFHagSr1A8/cwZF/fCLtcKj7nT3Fw)
[Answer]
# [Haskell](https://www.haskell.org/), 46 bytes
```
(f!g)n=sum[f i*g(div n i)|i<-[1..n],mod n i<1]
```
[Try it online!](https://tio.run/##FcixDkAwFAXQ3VdciaEVJE2MfIl0KNV6oY8oJv9eccazmLjO25aScLmX3Mc7DA5UemHpAYPkS109qKZhXYXd/tUpnYIhRg@7Z8BxEl8oIMwY83hPk4Rq2/QB "Haskell – Try It Online")
Thanks to flawr for -6 bytes and a great challenge! And thanks to H.PWiz for another -6!
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 17 bytes
Of course Mathematica has a built-in. It also happens to know many of the example functions. I've included some working examples.
```
DirichletConvolve
```
[Try it online!](https://tio.run/##lYu7CsIwGEb3PkVA6BTQCI6BinVroegYMqT1r/0hF8htEZ89tugLyLccDuczKi5gVMRJlZmXFj1Oi4Z4cTY7naEMHm1sZnFNGvywoLCSkhYzBufvyQhLCSP16lYwsvonZ8dfL2bRoUsZtYZOmfGhttt5DE3vYMQU@rQJS3ey3jc3ZZ8gTpLzF6OH796yKh8 "Wolfram Language (Mathematica) – Try It Online")
[Answer]
# [Python 3](https://docs.python.org/3/), 59 bytes
```
lambda f,g,n:sum(f(d)*g(n//d)for d in range(1,n+1)if 1>n%d)
```
[Try it online!](https://tio.run/##TcyxCoMwEAbgV7lFuNNAOEoXoT5Jl8iZNFB/JU0Hnz4uDm7f9O1H/Wx4NHu92zesswWKLjmMv//KkU36xPDeJG6FjDKoBKSF1WFQyZF0QmfS9pJR2fg6MKqju/Up0k4 "Python 3 – Try It Online")
[Answer]
# [Add++](https://github.com/cairdcoinheringaahing/AddPlusPlus), 51 bytes
```
D,g,@~,$z€¦~¦*
D,f,@@@,@b[VdF#B]dbRzGb]$dbL$@*z€g¦+
```
[Try it online!](https://tio.run/##S0xJKSj476KTkZpTkFqk4@Cgo/KoaY1@CpDIrAISh5bZJoUqc7noFGRk6jjopLgpO8U6BTgGgVRVQzTVpiT5qBxaph3PBVRWklgKVObmY6gN4mWmADkgRn5eKpBlCLQoXcehTkcFYnTdoWVaQMk0oLUOOg5J0WFg41OSgqrck2JVQMY6aIFUpgNN/6@SZpeZYgc0yM7QiMufC8gFOskOaB@Y/x8A "Add++ – Try It Online")
Takes two pre-defined functions as arguments, plus \$n\$, and outputs \$(f \* g)(n)\$
## How it works
```
D,g,		; Define a helper function, $g
	@~,	; $g takes a single argument, an array, and splats that array to the stack
		; $g takes the argument e.g. [[τ(x) φ(x)] [3 4]]
		; STACK : 			[[τ(x) φ(x)] [3 4]]
	$z	; Swap and zip:			[[3 τ(x)] [4 φ(x)]]
	€¦~	; Reduce each by execution:	[[τ(3) φ(4)]]
	¦*	; Take the product and return:	τ(3)⋅φ(4) = 4
D,f,		; Define the main function, $f
	@@@,	; $f takes three arguments: φ(x), τ(x) and n (Let n = 12)
		; STACK:			[φ(x) τ(x) 12]
	@	; Reverse the stack:		[12 τ(x) φ(x)]
	b[V	; Pair and save:		[12]			Saved: [τ(x) φ(x)]
	dF#B]	; List of factors:		[[1 2 3 4 6 12]]
	dbR	; Copy and reverse:		[[1 2 3 4 6 12] [12 6 4 3 2 1]]
	z	; Zip together:			[[[1 12] [2 6] [3 4] [4 3] [6 2] [12 1]]]
	Gb]	; Push Saved:			[[[1 12] [2 6] [3 4] [4 3] [6 2] [12 1]] [[τ(x) φ(x)]]]
	$dbL	; Number of dividors:		[[[τ(x) φ(x)]] [[1 12] [2 6] [3 4] [4 3] [6 2] [12 1]] 6]
	$@*	; Repeat:			[[[1 12] [2 6] [3 4] [4 3] [6 2] [12 1]] [[τ(x) φ(x)] [τ(x) φ(x)] [τ(x) φ(x)] [τ(x) φ(x)] [τ(x) φ(x)] [τ(x) φ(x)]]]
	z	; Zip:				[[[τ(x) φ(x)] [1 12]] [[τ(x) φ(x)] [2 6]] [[τ(x) φ(x)] [3 4]] [[τ(x) φ(x)] [4 3]] [[τ(x) φ(x)] [6 2]] [[τ(x) φ(x)] [12 1]]]
	€g	; Run $g over each subarray:	[[4 4 4 6 4 6]]
	¦+	; Take the sum and return:	28
```
[Answer]
# [R](https://www.r-project.org/), 58 bytes
```
function(n,f,g){for(i in (1:n)[!n%%1:n])F=F+f(i)*g(n/i)
F}
```
[Try it online!](https://tio.run/##XZDBioMwEIbPO0@RPQiZVmmzR9FTwfPCHksLsSY6YCZFk70s@@xWe2jR0wwfP98M/zA1NNCt6004ef4VRTbZyLdAniWnNm3xz/pBkiAWUuWM509Oknm5YFVWeysJd63kAyFU/5MJ@qPIxNuAZCWXpUIlTD8acYTIFDYZBdRsEIOLC@LoajOMee68qSmOcO9oxU3s5/ndEfTa1c32vMwUXl9h70yrZwojtU6LlehnQRB03H6yCsydHBFg1ZlUX6mL6dOJ0wM "R – Try It Online")
Takes `n`, `f`, and `g`. Luckily the `numbers` package has quite a few of the functions implemented already.
If vectorized versions were available, which is possible by wrapping each with `Vectorize`, then the following 45 byte version is possible:
# [R](https://www.r-project.org/), 45 bytes
```
function(n,f,g,x=1:n,i=x[!n%%x])f(i)%*%g(n/i)
```
[Try it online!](https://tio.run/##dVBNi4MwED03vyJ7EDIl0qZHqaf@gYWFvZQtRB11wEwWTRbpn3dtDy0echqY9zFv3rg0NFLdDxgunv/kOV/ayHUgz4p1qzs9l6ZgTeV8/eAsm3@gVQTZPusUHwgWDHZ3zuU31sGPdEf1lgO1isvSgJE4TCiPICJTSNINCGqSKINwcYtydBWOU1E4jxXFCcRvTwkKxmGdnz2BGKyrmnRqlRu4vXTeYWfXLYiJOmdlwv7rAYIINqYf2HDXdo@rqdjUr8xJu6ifl2D5Bw "R – Try It Online")
[Answer]
# [APL (Dyalog Classic)](https://www.dyalog.com/), 20 bytes
```
{(⍺⍺¨∘⌽+.×⍵⍵¨)∪⍵∨⍳⍵}
```
with `⎕IO←1`
[Try it online!](https://tio.run/##bVE9b9swEN35K7jJiuBWlOQ0CaDJ/yMAG9kuEckfoAWoaDO1KIy2DroU6dKlS4wuGYIsAboo/4R/xH1HSgkDBCRP7x6P9053clkOi/eyXMyGZ6XUWp3tzeVPtTBffoj9GPbDwGzvsdud2fwy3/9Frx6uzPYOu92FZvOX8GZntrcAF/v9ZKnpkcjJZfVcra17wVQBYL7@YVVtwSekE7y9cSe2tscxf872yFq2fKe8DIInWBnOISwdEZMh/whLHAKII1bK6m0hX5D2bS/X495/xjCtZpWfKYXeG1JJSG/ERQpB8hJYVGZ3KohMj3kSs7X0e0D1p90/ZDYZ1U444yOHmV55D1yD4m49Ic9jbD3RtvVmc/0aI7zEPMKW5iSOT4LFeWC@fQ6mUpUngZ2UjQ8wvZxmxse8qgPHTXOwfDyYIlsWtTcj1PBwFR3gk0YJ7EEYcLP9zWut5jM@HTRhng1HTdSc4v604VJzOeeTRlbLcvKk4waCxB@rOuy0bGdzDBgFoEkdq4rcXvhVuUhVgKOCe3b1mNanHZdXNWi96kjk7//VCyWY48rXgr4ryYsD4dQpavgf "APL (Dyalog Classic) – Try It Online")
Easy to solve, hard to test - generally not my type of challenge. Yet, I enjoyed this one very much!
`{` `}` defines a dyadic operator whose operands `⍺⍺` and `⍵⍵` are the two functions being convolved; `⍵` is the numeric argument
`∪⍵∨⍳⍵` are the divisors of `⍵` in ascending order, i.e. unique (`∪`) of the LCMs (`∨`) of `⍵` with all natural numbers up to it (`⍳`)
`⍵⍵¨` apply the right operand to each
`⍺⍺¨∘⌽` apply the left operand to each in reverse
`+.×` inner product - multiply corresponding elements and sum
---
[The same in ngn/apl](https://tio.run/##bVLBTsJAEL3vV@yNlop224Jg0l8hQaFKJCBtDxjlBCFErdGD0UNNiBeJMSGN4SJ4wXv7D/sjdabdBpqY3Z28eZ19M92ZxkWn1D3txjH3Az55uJK49w17M@fTF373o@z/PnNvCXszl/n0A/F0zhTufQEcEhIt4RaDYJPwxxkqsCFpNwHwmzcSrhMwgu8qZXSzSI@a2AyrNM9mKLEkmuQkGNVgGXAqYPEwFQ36VVisAoBVSbj6N/OuzbJlOPNzDIlGOSEdkh1iCg2TlSnTIRt6GlgoK9k6Q1KvUU0l0Th3H6vXxR8YiRpWjtig5RQTp5@7kr6QKtYW7XjEwpc3FGmzKCcNkxVo5LKoy4pWxEZR7r3Shn3cdu2GfUmtLrV6NnXPWtRpnfS6Teq2HHePWtJANo1SeaAM6rqi1QeEuKjMp@8HNhYlhiMZAFY74vdPwBZ65wV@OxaO1Wh3CjaMhhQtTZwJPwjXssu9TyJZJsyLH1jChQDokx9I1xCRcSMTWu4H0VgQ7aYJPdgRgQgYMBjXx5lgnH6qs2XClQmz5wdOP7s0FrVsYwCZ0J0dZUw1ycVEkzSXCInjPw) looks better because of Unicode identifiers, but takes 2 additional bytes because of 1-indexing.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 9 bytes
```
ÆDṚÇ€ḋÑ€Ʋ
```
[Try it online!](https://tio.run/##y0rNyan8f7gtzUdX61iXQeCxifZAnsvDnbMOtz9qWvNwR/fhiUD62CagaDGX0ZH9//8bGgEA "Jelly – Try It Online")
Line at the top is the main line of \$f\$, line at the bottom is the main line of \$g\$. \$n\$ is passed as an argument to this function.
[Answer]
# [Swift 4](https://developer.apple.com/swift/), ~~74 70~~ 54 bytes
```
{n in(1...n).map{n%$0<1 ?f(n/$0)*g($0):0}.reduce(0,+)}
```
[Try it online!](https://tio.run/##fYw9DsIwFINncoo3FOkFSkgkFsrfzClQ1TRVhj5VIYWhykEYEFfkBiGBncWWrc@@3q3xm2hGasBqvABVcCbPYXXMDhObudaPjoBYYOzLvZ@vxz9SZfJWOzBwSKcldMnzaPerdYpxIrCESghBXPT1MNG8kHsFJ4O0LiRfdJi0kkG4Vo9Ni7Jc8hAHZ8mjRrXlPH4A "Swift 4 – Try It Online")
[Answer]
# JavaScript (ES6), 47 bytes
Takes input as `(f)(g)(n)`.
```
f=>g=>h=(n,d=n)=>d&&!(n%d)*f(n/d)*g(d)+h(n,d-1)
```
[Try it online!](https://tio.run/##dZDNjoJAEITvPEV7kHSD/Jl4MRnMJsYbT7DZbFgHkQUHBTQx8d3ZZgDl4M5lSHXVV0P/xre43lfZuXFUKZN2J9qDCFMRHgWqhRSKRChNc4ZqLsk6oPL4SlGSfezmTkBtkZXXW1YUCQhQIEJAVsGyALessAtyvpfUjXII2bMBH9Y8gTkLG9j2Hhs4toaAP1gBD3JWiQgVGafyJ7vWwGfsiCbsQLM7nG13wL7l8YBIOzqq5uk@0wQnmvA7fH2B4Qx4e4Zs4X/w3RVxLCAjk4lqsub@9ASG4XnAUQGvFVgw@ox9qeqySNyiTPHTdd2PqorvuFzRl3uKz4jfC1D64Tt85gnHOL9Lb4RI10yXPCzD4u7/Svw3JX2MsL682O0f "JavaScript (Node.js) – Try It Online")
### Examples
```
liouville =
n => (-1) ** (D = (n, k = 2) => k > n ? 0 : (n % k ? D(n, k + 1) : 1 + D(n / k, k)))(n)
mobius =
n => (M = (n, k = 1) => n % ++k ? k > n || M(n, k) : n / k % k && -M(n / k, k))(n)
sq =
n => +!((n ** 0.5) % 1)
identity =
n => 1
// sq = liouville * identity
console.log([...Array(25)].map((_, n) => F(liouville)(identity)(n + 1)))
// liouville = mobius * sq
console.log([...Array(20)].map((_, n) => F(mobius)(sq)(n + 1)))
```
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 108 bytes
```
#define F float
F c(F(*f)(int),F(*g)(int),int n){F s=0;for(int d=0;d++<n;)if(n%d<1)s+=f(n/d)*g(d);return s;}
```
Straightforward implementation, shamelessly stolen from [Leaky Nun's Python answer](https://codegolf.stackexchange.com/a/176109/56453).
Ungolfed:
```
float c(float (*f)(int), float (*g)(int), int n) {
    float s = 0;
    for(int d = 1; d <= n;++d) {
        if(n % d == 0) {
            s += f(n / d) * g(d);
        }
    }
    return s;
}
```
[Try it online!](https://tio.run/##jZT/TtswEMf/bp7iBkJLaEqbFtim0EmoardKTJooTJMYqkLiFEv5URoHsaH@NYT2BnuS/TWeAd5hL9Ld2Umb0AqQkth39n389dkXtzZy3dk6j9wg9RjsJcLj8db5e63kCvgZ@mbrHvN5xKAHfhA7QuuBq/f0Td/QeSQME7ujrIsfiIzrHiTthu3HE/KCh32vWt2LbIP7erTh7VlGUm1jt@4ZmyPdM@wJE@kkgsSeznrAxgkP4khXMLjWKtlwBO02WLY2RQVxxJYnZGPcWxFLQ/U6dM6ZI4CH44CFLBKO4HGUAEqFWJyzCfhp5CrfGXOdNGHQfx2CiGMInB/fsQM@H6UTBnEqKCxMAyfR8gx1Pnb3j4b9T58PdAKZsLW1ZVDe0JhrSmhVF72XTpCy5OQU2nA9HH7ZH@4ffhgMh1MbMtHZhAhqYJ3aU00r8MPUBMuEWvY2VLOwGkUjG1oYeWMUkeNznk9rymdbfndlR32thmqU@618rF1pWGSVeIETnnlOSWa5WciqLXkeOWtWCZ3wUajILSnojZLQVIJ28G0pReRqUkt7yd6WpcZa79CmDTVLbOGkhRy0CpnYzpdT21cefHYKnt2yzos8641CZ6W5wmlo85t11B0cZXfKN2Fk0k3CahIsEY/dWCTdr/2j4eC40@kOBoYNLMB7zK640OVAb79/cHzYNTS6kZLQA31zktUwkOEXjby6YVFVWKVXY@YK5uGqsbC1Sl7tHKhGsdlrY9FBtcplQCWfj8M40cCICgai5epKufLhnuYzX7WJrcIr4wnSfX3tZMM7nS8OGz6cYSESacP/Fq0hxixLk9RKvZ6VVDEBNDLV6CkOZmmj/4VMUOjwSL@MuSeFjFOR6GuUNHj4Q1uFf79@w/3dGq0jDyn7fZn0izKByrTZoEEVSfPKlJ9IebiVmIebBSa74bIm5Y18ksIpr4h6LIZjEjLSy5QgiBjWkhAiyR09yUgukHH/d4mBZZD/DZ6HYDxC7iQkuVhQcgLthIhP7@ZmfjoFITKTUsHzMixK6c1SSmWg5IQvO5XbxyIolfJcn9eAwfMzKYqQ4cRZrWH1fZ79Bw "C (gcc) – Try It Online")
[Answer]
## F#, 72 bytes
```
let x f g n=Seq.filter(fun d->n%d=0){1..n}|>Seq.sumBy(fun d->f(n/d)*g d)
```
Takes the two functions `f` and `g` and a natural number `n`. Filters out the values of `d` that do not naturally divide into `n`. Then evaluates `f(n/d)` and `g(d)`, multiples them together, and sums the results.
[Answer]
# [Pari/GP](http://pari.math.u-bordeaux.fr/), 32 bytes
```
(f,g,n)->sumdiv(n,d,f(n/d)*g(d))
```
[Try it online!](https://tio.run/##Hcs7DoAgDADQqzi2pqDs6kUIg6ZKGKgEP5N3r8b9vTLXZGJRbsZGYaNIgmY6rszpBiGmDaRjbCMwopaa5ATPID@gvK9Luo7vPDIY76x1fQioLw "Pari/GP – Try It Online")
There is a built-in `dirmul` function, but it only supports *finite* sequences.
[Answer]
# APL(NARS), 47 chars, 94 bytes
```
{(m⍵[1])×n⍵[2]}{+/⍺⍺¨{k←⍳⍵⋄(⍵÷b),¨b←k/⍨0=k∣⍵}⍵}
```
where m and n are the function one has to use (this because i don't know how
to call one array of function in one function in APL).
Using the example above the multiplication of Mobius function (here it is 12π) and sum of divisors
function (here it is 11π) for value 12 that multiplication would be:
```
  {(12π⍵[1])×11π⍵[2]}{+/⍺⍺¨{k←⍳⍵⋄(⍵÷b),¨b←k/⍨0=k∣⍵}⍵}12
12
```
if one has to calculate some other value:
```
  {(12π⍵[1])×11π⍵[2]}{+/⍺⍺¨{k←⍳⍵⋄(⍵÷b),¨b←k/⍨0=k∣⍵}⍵}1002
1002
  {(12π⍵[1])×11π⍵[2]}{+/⍺⍺¨{k←⍳⍵⋄(⍵÷b),¨b←k/⍨0=k∣⍵}⍵}1001
1001
  {(12π⍵[1])×11π⍵[2]}{+/⍺⍺¨{k←⍳⍵⋄(⍵÷b),¨b←k/⍨0=k∣⍵}⍵}20000x
20000 
```
One can see if for example the first 2000 number the function result is the identity
```
  (⍳2000)≡{(12π⍵[1])×11π⍵[2]}{+/⍺⍺¨{k←⍳⍵⋄(⍵÷b),¨b←k/⍨0=k∣⍵}⍵}¨⍳2000
1
```
]