1
$\begingroup$

If I evaluate D[f[g[x]],{x,5}], I'll get a result containing derivatives of f and g, explained here. But suppose that I have explicit formulae for the derivatives $g^{n}(x)$, for $n=1,2,\ldots$. How can I substitute these into my result, so that my result doesn't contain $g$ (or its derivatives), except for terms of the form $f^{n}(g(x))$? (Without copying and pasting manually.)

I've tried Solve and Reduce, but it doesn't actually substitute the function, and Replace doesn't work on this type of problem. Any help would be greatly appreciated.

$\endgroup$

1 Answer 1

6
$\begingroup$

Define the known explicit formulae for the derivatives $g^{(n)}(x)$:

dg[1, x_] = x^2;
dg[2, x_] = x^77;
dg[3, x_] = Cos[x];
dg[4, x_] = Sin[x];
dg[5, x_] = -2;

Evaluate something and substitute, remembering that the full form of a derivative is given in terms of the Derivative head:

D[f[g[x]], {x, 5}] /. Derivative[n_][g][x_] :> dg[n, x]

(*    -2*f'[g[x]] + 10*x^77*Cos[x]*f''[g[x]] +
      5*x^2*Sin[x]*f''[g[x]] + 15*x^156*f'''[g[x]] +
      10*x^4*Cos[x]*f'''[g[x]] + 10*x^83*f''''[g[x]] +
      x^10*f'''''[g[x]]                                   *)
$\endgroup$
1
  • $\begingroup$ This looks just like what I was after. Thank you so much. $\endgroup$
    – AGibbs
    Commented Oct 3, 2022 at 15:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.