TITLE: Is there a Faa di Bruno-like formula for composition of three functions?
QUESTION [10 upvotes]: Faa di Bruno's formula (MathWorld, Wikipedia) gives the kth derivative of f(g(t)) as a sum over set partitions.  (I'm not sure how well-known the combinatorial interpretation is; for example see a 2006 paper of Michael Hardy).
Is there a similar formula for the kth derivative of f(g(h(t))), i. e. of a threefold composition?  One has, I think,
${d^2 \over dt^2} f(g(h(t))) = f^{\prime\prime}(g(h(t))) g^\prime(h(t))^2 (h^\prime(t))^2 + f^\prime(g(h(t))) g^{\prime\prime}(h(t)) h^{\prime}(t)^2$
$ + f^\prime(g(h(t))) g^\prime(h(t)) h^{\prime\prime}(t)$
but I am not even sure this is right (computation is tricky!) and I do not know how to generalize this.

REPLY [5 votes]: I would like to provide an analytically explicit answer. For simplicity, just take f,g,h smooth functions from $\mathbb R$ into itself. Then we have
\begin{align*}
\frac{(h\circ g\circ f)^{(p)}}{p!}=\sum_{\substack{p_1+\dots+p_q=p\\q\ge 1, p_j\ge 1}}
\frac{(h\circ g)^{(q)}}{q!}
\prod_{1\le j\le q}\frac{f^{(p_j)}}{p_j!}
\\
=
\sum_{\substack{p_1+\dots+p_q=p\\q\ge 1, p_j\ge 1}}
\sum_{\substack{q_1+\dots+q_r=q\\r\ge 1, q_k\ge 1}}
\frac{h^{(r)}}{r!}
\prod_{1\le k\le r}\frac{g^{(q_k)}}{q_k!}
\prod_{1\le j\le q}\frac{f^{(p_j)}}{p_j!},
\end{align*}
where of course the derivatives of $h$ (resp. $g$) are evaluated at $(g\circ f)(x)$ (resp. $f(x)$). Alphabetical order may help the reader to complete an expression for the higher order derivatives of the composition of $N$ functions.

REPLY [5 votes]: Similarly to Theo's answer, I think the best way to write such combinatorial formulas is in terms of trees (rather than multiindices or even set partitions). I explained that in my article "Feynman diagrams in algebraic combinatorics" in Sém Lothar. Combin.  49 (2002/04), Art. B49c.
See in particular Eq. 13 for composition of $n$ functions.