# How to compute a multi-round convolution? [duplicate]

I am trying to do a n-round of convolution of a function. The code is posted as below. But it is not working. Is there a solution?

p[x_] := 1/(x + 1)*UnitStep[x]
p1[x_] := Convolve[p[y], p[y], y, x]
p2[x_] := Convolve[p[y], p1[y], y, x]


p1 succeeded. But the output of p2 only repeats the question as follows:

Convolve[UnitStep[y]/(1 + y),
Convolve[UnitStep[y]/(1 + y), UnitStep[y]/(1 + y), y, y], y, x]


Using partial memoization:

Clear[p];
p[0] = Function[x, 1/(x + 1)*UnitStep[x]];
p[n_Integer?Positive] := p[n] =
Function[x, Evaluate@Convolve[p[n - 1][y], p[0][y], y, x]]

p[0][x]
(*    UnitStep[x]/(1 + x)    *)

p[1][x]
(*    ((-I \[Pi] + Log[-1 - x] + Log[1 + x]) UnitStep[x])/(2 + x)    *)

p[2][x]
(*    -(1/(3 (3 + x)))(2 \[Pi]^2 + 3 I \[Pi] Log[-2 - x] +
3 I \[Pi] Log[1 + x] + 3 Log[-1 - x] Log[1/(2 + x)] +
3 Log[1 + x] Log[1/(2 + x)] - 3 I \[Pi] Log[(1 + x)/(2 + x)] -
3 Log[1 + x] Log[2 + x] - 3 PolyLog[2, -1 - x] -
6 PolyLog[2, 1/(2 + x)] + 6 PolyLog[2, (1 + x)/(2 + x)] +
3 PolyLog[2, 2 + x]) UnitStep[x]                                  *)

Plot[{p[0][x], p[1][x], p[2][x]}, {x, 0, 2}]


• Could you please give the references for the following commands? Thank you. (1) Function; (2) p[n_Integer?Positive] (3) Evaluate@
– Hans
Commented Apr 23, 2021 at 21:37
• @Hans - In Mathematica, highlight the symbol/command that you do not understand and press F1 for help. Commented Apr 24, 2021 at 1:59

There are two issues: do you have the form right, and is the integral (the convolution) solvable. Let's do the first one by picking a really simple example, like p[x]:=UnitStep[x]. You can see that your code fails. Because of the way things are defined, you need to change the variables, or they get all messed up. Note that this works:

p[x_] := UnitStep[x]
p1[x_] := Convolve[p[y], p[y], y, x]
p2[x_] := Convolve[p[z], p1[z], z, x]
p3[x_] := Convolve[p[w], p2[w], w, x]

{p[x],p1[x],p2[x],p3[x]}


Now change p[x] to your desired function... you'll see it works fine for p1[x] and p2[x]. I got bored waiting to see if p3[x] would finish. But at some point, this is going to fail because the functions are getting too hard to integrate in closed form.

• I do not see any substantive difference between your code and mine.
– Hans
Commented Apr 23, 2021 at 20:45
• The difference is in the arguments y,x for p1, z,x for p2 and w,x for p3. The way you have the arguments, the recursive calls get confused whereas by using new variables, it works. But anyway, Roman's solution is more general. Commented Apr 24, 2021 at 21:33
• But z for p2 and w for p3 are local variables. They should not be used outside of the definition of p2[x_] and p3[x_], right? The choice of symbols for the local variables should be irrelevant to invocation of the function. Is it not right?
– Hans
Commented Apr 25, 2021 at 18:10
• Sorry Hans, but that is incorrect. If you run your code, p2[x] does not evaluate. If you run my code, it evaluates fine. (Be sure to Clear[] the definitions in between). Commented Apr 25, 2021 at 18:48