Function Repository Resource:

ChainD

Source Notebook

Get the derivative with respect to a function

Contributed by: Carl Woll

ResourceFunction["ChainD"][f, g]

gives the partial derivative of f with respect to g, where both f and g are functions of the same variable.

ResourceFunction["ChainD"][f, {g, n}]

gives the nth derivative.

ResourceFunction["ChainD"][f, g1,g2,]

gives the partial derivative of f with respect to g1 followed by the partial derivative with respect to g2, etc.

Details and Options

Only derivatives with respect to univariate functions are supported.
When differentiating with respect to multiple functions, each function must be a univariate function, but they need not be functions of the same variable.
Derivatives with respect to different functions are, in general, not commutative.
A symbolic inverse of the function g(x) is not required.
Derivatives with respect to functions are obtained using the relation .

Examples

Basic Examples (2) 

Derivative of x4 with respect to x2:

In[1]:=
ResourceFunction["ChainD"][x^4, x^2]
Out[1]=

Derivative of a more complicated function:

In[2]:=
Simplify @ ResourceFunction["ChainD"][x^5/Sqrt[x^3 + y^2], {x^3, 2}]
Out[2]=

Scope (2) 

It is not necessary to be able to symbolically invert g(x):

In[3]:=
Simplify @ ResourceFunction["ChainD"][x^2, BesselJ[2, x]]
Out[3]=

It is not possible to symbolically invert BesselJ[2,x]:

In[4]:=
Solve[BesselJ[2, x] == z, x]
Out[4]=

Derivative of a multivariate function with respect to functions of each of the variables:

In[5]:=
ResourceFunction["ChainD"][Sin[x y^2], x^2, y^2]
Out[5]=

Possible Issues (2) 

When using ChainD with multiple functions, the result in general depends on the order of derivatives:

In[6]:=
ResourceFunction["ChainD"][x^8, x^4, x^2]
Out[6]=
In[7]:=
ResourceFunction["ChainD"][x^8, x^2, x^4]
Out[7]=

Derivatives with respect to heads of functions are not supported:

In[8]:=
ResourceFunction["ChainD"][f[x], f]
Out[8]=

Publisher

Carl Woll

Version History

  • 2.0.0 – 28 February 2020
  • 1.0.0 – 23 October 2019

License Information