The exponential generating function (e.g.f.) of a sequence \$a_n\$ is defined as the formal power series \$f(x) = \sum_{n=0}^{\infty} \frac{a_n}{n!} x^n\$.
When \$a_0 = 0\$, we can apply the exponential function \$\exp\$ on this formal power series:
\$\begin{align} \exp(f(x)) &= \sum_{n=0}^{\infty} \frac{1}{n!} f(x)^n \\ &= \sum_{n=0}^{\infty} \frac{1}{n!} \left(\sum_{m=1}^{\infty} \frac{a_m}{m!} x^m\right)^n \\ &= \sum_{n=0}^{\infty} \frac{b_n}{n!} x^n \\ \text{where} \\ b_0 &= 1 \\ b_n &= \sum_{k=1}^n \binom{n-1}{k-1} a_k b_{n-k} \text{ when } n>0 \end{align}\$
This is the exponential generating function of the sequence \$b_n\$. If all \$a_n\$ are integers, then all \$b_n\$ are also integers. So this is a tranformation of integer sequences.
It seems that OEIS call this the Exponential transform. But I can't find a reference to its definition.
Here are some examples on OEIS:
- A001477 (the nonnegative integers, \$0,1,2,3,4,\dots\$) -> A000248 (\$1,1,3,10,41,\dots\$)
- A001489 (the nonpositive integers, \$0,-1,-2,-3,-4,\dots\$) -> A292952 (\$1, -1,-1,2,9,\dots\$)
- A000045 (Fibonacci numbers, \$0,1,1,2,3,\dots\$) -> A256180 (\$1,1,2,6,21,\dots\$)
- A160656 (\$0\$ and the odd primes, \$0,3,5,7,11,\dots\$) -> A353079 (\$1,3,14,79,521,\dots\$)
- A057427 (\$0,1,1,1,1,\dots\$) -> A000110 (Bell numbers, \$1,1,2,5,15,\dots\$)
Task
Given a finite integer sequence, compute its Exponential transform.
The length of the input sequence is always greater than \$0\$. Its \$0\$th term is always \$0\$. You can omit the leading \$0\$ in the input.
If the input sequence has length \$n\$, you only need to output the first \$n\$ terms of the output sequence.
Input and output can be in any reasonable format, e.g., a list, an array, a polynomial, a function that takes \$i\$ and returns the \$i\$th term (0-indexed or 1-indexed), etc.
You may also take the input sequence and an integer \$i\$, and output the \$i\$th term (0-indexed or 1-indexed) of the output sequence.
This is code-golf, so the shortest code in bytes wins.
Example Python code
This example code uses the above recurrence formula. There are other formulas that might give shorter answers.
import math
def exponential_transform(a):
b = [0] * len(a)
b[0] = 1
for i in range(1, len(a)):
b[i] = sum(math.comb(i-1, j-1) * a[j] * b[i - j] for j in range(1, i + 1))
return b
Testcases
[0, 0, 0, 0, 0] -> [1, 0, 0, 0, 0]
[0, 1, 0, -1, 0, 1, 0, -1] -> [1, 1, 1, 0, -3, -8, -3, 56]
[0, 1, 2, 3, 4, 5, 6, 7] -> [1, 1, 3, 10, 41, 196, 1057, 6322]
[0, -1, -2, -3, -4, -5, -6, -7] -> [1, -1, -1, 2, 9, 4, -95, -414]
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55] -> [1, 1, 2, 6, 21, 86, 404, 2121, 12264, 77272, 525941]
[0, 3, 5, 7, 11, 13, 17, 19] -> [1, 3, 14, 79, 521, 3876, 31935, 287225]
[0, 1, 1, 1, 1, 1] -> [1, 1, 2, 5, 15, 52]
[0, 1, 2, 5, 15, 52] -> [1, 1, 3, 12, 60, 358]
[0, 1, 3, 12, 60, 358] -> [1, 1, 4, 22, 154, 1304]
[0, 1, 4, 22, 154, 1304] -> [1, 1, 5, 35, 315, 3455]
[0, 1, 5, 35, 315, 3455] -> [1, 1, 6, 51, 561, 7556]
1+
in the comment means though. There's also a wiki page for sequence transforms but many aren't documented yet. \$\endgroup\$