Beside I've found answers to similar questions (e.g. this), I can't adapt them to my case.
I am interested in the following sequence of functions $p_{m,n}(t)$, where $m$ and $n$ are integer:
$$ \begin{aligned}p_{m,n}(t)&:=\begin{cases} 0, & \text{if $m<1$ or $n<1$ or $n>m+1$,}\\[4mm]\displaystyle \int_0^t e^{b(t-s)n} q_{m,n}(s) \,ds, & \text{otherwise, where}\end{cases}\\[3mm] q_{m,n}(s)&:= \chi_{m=1}\chi_{n=2}\, b + b n p_{m,n+1}(s)\\[2mm]&\qquad +\chi_{m\geq 2} b n(n-1)\bigl(p_{m-1,n-2}(s)+p_{m-1,n-1}(s)+p_{m-1,n}(s)\bigr)\end{aligned} $$
Here $b>0$ is a parameter and $\chi$ is equal to $1$ if the subscript happens and to $0$ otherwise.
As you may see, the definition is indeed recurrent, since $p_{m,m+1}(\cdot)$ does not really contain the term with $p_{m,m+2}(\cdot)\equiv 0$, and hence can be found recurrently, after this one can find $p_{m,m}(\cdot)$ which depends on $p_{m,m+1}(\cdot)$, and so on down to $p_{m,1}(\cdot)$.
I coded this as follows:
ClearAll[p, b];
$Assumptions = {b > 0};
p[m_, n_] := p[n, m] = If[ m < 1 || n < 1 || n > m + 1, 0 # &,
Module[{s}, Integrate[Exp[(# - s) b n]
(KroneckerDelta[m, 1] KroneckerDelta[n, 2] b
+ b n p[m, n + 1][s] + If[m < 2, 0,
b n (n - 1) (p[m - 1, n - 2][s] + p[m - 1, n - 1][s]
+p[m - 1, n][s])]),
{s, 0, #}] &]];
It works, but very slowly:
In[5]:= p[5, 6][t] // AbsoluteTiming
Out[5]= {83.3974,
15 + 86 E^(b t) - 47350 E^(5 b t) + 5034 E^(6 b t) +
3240 E^(3 b t) (34 + 15 b t) + 10 E^(2 b t) (361 + 30 b t) +
5 E^(4 b t) (-14311 + 21216 b t)}
How can I speed up this?
(Remark: for me the integration variable $s$ looks weird in the module description, but otherwise, I got a mistake, probably because of names conflict at some stage.)
p[m_, n_] := p[n, m] = ...
has a typo. $\endgroup$