This is a repost of this challenge, intended to revamp it for looser I/O formats and updated rules
You are to write a program which takes an integer polynomial in \$t\$ as input and outputs the Laplace transform of this polynomial. Some definitions and properties:
- The Laplace transform of a given function \$f(t)\$ is
$$\mathcal{L}\{f(t)\} = F(s) = \int_0^\infty f(t)e^{-st}dt$$
- The Laplace transform of \$f(t) = t^n, \, n = 0, 1, 2, ...\$ is
$$\mathcal{L}\{t^n\} = \frac{n!}{s^{n+1}}$$
- Laplace transforms distribute over addition:
$$\mathcal{L}\{f(t)+g(t)\} = \mathcal{L}\{f(t)\} + \mathcal{L}\{g(t)\}$$
- The Laplace transform of a constant multiplied by a function equals the constant multiplied by the transform:
$$\mathcal{L}\{af(t)\} = a\mathcal{L}\{f(t)\}$$
- An integer polynomial is a polynomial where each term has an integer coefficient, and a non-negative order
An worked example:
$$\begin{align} \mathcal{L}\{3t^4+2t^2+t-4\} & = \mathcal{L}\{3t^4\}+\mathcal{L}\{2t^2\}+\mathcal{L}\{t\}-\mathcal{L}\{4\} \\ & = 3\mathcal{L}\{t^4\}+2\mathcal{L}\{t^2\}+\mathcal{L}\{t\}-4\mathcal{L}\{1\} \\ & = 3\left(\frac{4!}{s^5}\right)+2\left(\frac{2!}{s^3}\right)+\left(\frac{1!}{s^2}\right)-4\left(\frac{0!}{s}\right) \\ & = \frac{72}{s^5}+\frac{4}{s^3}+\frac{1}{s^2}-\frac{4}{s} \end{align}$$
You may take input in a standard representation of a polynomial. Some examples (for \$3x^4+2x^2+x-4\$ as an example) are:
- A list of coefficients.
[-4, 1, 2, 0, 3]
or[3, 0, 2, 1, -4]
- Pairs of coefficients and powers.
[[3, 4], [2, 2], [1, 1], [-4, 0]]
and various different orderings - A string, using whatever variable you like.
3x^4+2x^2+x-4
Similarly, as the output will be a polynomial with negative orders, you may output in similar formats, such as (using \$\mathcal{L}\{3x^4+2x^2+x-4\} = \frac{72}{s^5}+\frac4{s^3}+\frac1{s^2}-\frac4s\$):
- A list of coefficients.
[72, 0, 4, 1, -4]
or[-4, 1, 4, 0, 72]
- Pairs of coefficients and powers.
[[72, -5], [4, -3], [1, -2], [-4, -1]]
and various different orderings (or the positive versions of the powers) - A string, using whatever variable you like.
72s^-5+4s^-3+s^-2-4s^-1
If you have an alternative I/O method you're unsure about, please comment below to ask.
This is code-golf so the shortest code in bytes wins.
[[3, 4], [0, 3], [2, 2], [1, 1], [-4, 0]]
? (Allowing this and the powers being in ascending order would save some languages from extracting indices from the list, for better or worse.) \$\endgroup\$