I'm interested in using Mathematica's symbolic manipulation to obtain, for a particular function $f$, derivatives of arbitrary order evaluated at zero. Normally I'd use the D command, but $f$ depends on a function $h$ that I can only define implicitly. More precisely, given a constant $a$ and two functions $g$ and $R$, I'd like to calculate $f^{(n)}(0)$ for any given $n$, where

$f(s) := g(a+ h(s)) \, h'(s)$

and $h$ is a function satisfying $h(0) = 0$ and $R(a+h(s))=-s$ for all $s$.

On paper I can of course use implicit differentiation on the last equation and substitute accordingly to obtain the derivatives of $f$ that I'd like in terms of those of $g$ and $R$, but this is eventually quite tedious, so I was looking to automate it. Is there a way to accomplish this in Mathematica?

I've written some pseudocode for a particular example, with the part I'm stuck on denoted by ???. Ideally, I'd like the code defining $h(s)$ to be independent of the particular choice of $a$, $g$ and $R$ so that I don't have to rewrite it if I change the former. Help is greatly appreciated!

(* Example definitions of a, n, g, and R *)
a = 1;
n = 5;
g[s_] := Exp[-s];
R[s_] := Log[s]-s+1;

(* Implicit definition of h[s_] goes here *)

(* Define f, take nth derivative, evaluate at 0 *)
f[s_] := g[a + h[s]] h'[s];
D[f[s], {s, n}]/.s->0

Edit: example R was poorly chosen, sorry!

  • $\begingroup$ Dt[] is useful if you want to do implicit differentiation. $\endgroup$ Jun 30, 2015 at 0:28
  • $\begingroup$ Thanks! Replacing D above by Dt, I get closer to what I'd like with the various derivatives of h appearing in the output, but can I also get Mathematica to compute those too from an implicit definition? $\endgroup$
    – sourisse
    Jun 30, 2015 at 0:44
  • $\begingroup$ Don't forget the @user if you want to make sure the person you're replying to gets pinged. (The author of a post always gets pinged.) $\endgroup$
    – Michael E2
    Jun 30, 2015 at 0:49
  • $\begingroup$ Well, you can use Solve[] afterwards if need be. $\endgroup$ Jun 30, 2015 at 0:50

1 Answer 1


Is this what you want?

Clear[Derivative, h];

h[0] = 1;  (* to avoid division by zero with OP's example R *)

Derivative[1][h][s_] := Block[{Derivative},
  h'[\[FormalS]] /. 
      D[R[a + h[\[FormalS]]] == - \[FormalS], \[FormalS]], 
      h'[\[FormalS]]] /. \[FormalS] -> s
Derivative[n_][h][s_] := 
  D[Derivative[n - 1][h][\[FormalS]], \[FormalS]] /. \[FormalS] -> s;

(*  (1 + h[s])/h[s]  *)

(*  (1 + h[s])/h[s]^2 - (1 + h[s])^2/h[s]^3  *)

(*  2  *)

(*  -2  *)

D[f[s], {s, 5}] /. s -> 0
(*  -(38798/E^2)  *)

(Those formal symbols look bad on the site, but they seem the best choice for the code. Or one could use Module to create a unique local symbol for each call.)

  • $\begingroup$ This is great, thank you! $\endgroup$
    – sourisse
    Jun 30, 2015 at 1:15
  • $\begingroup$ @sourisse You're welcome. You might want to read this answer, mathematica.stackexchange.com/a/15620, in case you need to undo some mistake and have to undefine the derivative(s). $\endgroup$
    – Michael E2
    Jun 30, 2015 at 1:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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