Solution (source code)

= Solution

Since $g(0)=0$, only the first three positive powers of $g$ contribute through degree three. The <composition coefficients of power series> follow by using $g^2=g_1^2x^2+2g_1g_2x^3+O(x^4)$ and $g^3=g_1^3x^3+O(x^4)$ in $f_0+f_1g+f_2g^2+f_3g^3+\cdots$. Hence
$$
\boxed{f(g(x))=f_0+f_1g_1x+(f_1g_2+f_2g_1^2)x^2+(f_1g_3+2f_2g_1g_2+f_3g_1^3)x^3+O(x^4).}
$$
Here $f_m$ and $g_m$ are coefficients of the <power series>, rather than raw <derivatives>; their definitions already contain any factorial factors.