​

​
A Wolfram Notebook on
th
n
Derivatives

Introduction

Derivatives of functions play a fundamental role in calculus and its applications. The function D computes derivatives of various types in the Wolfram Language and is one of the most-used functions in the system.
Starting from the derivative of a function, one can compute derivatives of higher orders to gain further insight into the physical phenomenon described by the function. For example, suppose that the position
s(t)
of a particle moving along a straight line at time
t
is defined as follows.
In[1]:=
s[t_]:=t^5-10t+(1/12)Sin[3t]
Then, the velocity and the acceleration of the particle are given by its first and second derivatives, respectively. The higher derivatives too can be computed easily using D; they also have special names, which can be seen in the following computation.
In[2]:=
{velocity,acceleration,jerk,snap,crackle,pop}=Table[D[s[t],{t,i}],{i,6}];
In[3]:=
Plot[Evaluate[{x[t],velocity,acceleration,jerk,snap,crackle,​​pop}],{t,0,Pi},Exclusions->None,​​PlotLegends->{"position","velocity","acceleration","jerk",​​"snap","crackle","pop"},PlotRange->All]
Out[3]=
Recent versions of the Wolfram Language allow you to compute not just the derivative of any specific order for a function, but also closed-form expressions for derivatives of symbolic order n using D. Such a closed form encodes all the information required to compute higher derivatives of the function.
Here we will give some examples for computing these
th
n
derivatives, starting with an elementary example to illustrate how one might guess a formula for the
th
n
derivative. Next, we create a table of
th
n
derivatives to show that sophisticated special functions are needed to express the closed forms in general. Finally, we show that the calculus of
th
n
derivatives is a generalization of the ordinary calculus of derivatives by exhibiting the sum, product and chain rules for these derivatives.

An Elementary Example

Let us begin by considering the cosine function. Its first four derivatives are given by:
In[4]:=
Table[D[Cos[x],{x,n}],{n,4}]
Out[4]=
{-Sin[x],-Cos[x],Sin[x],Cos[x]}
There is a clear pattern in the table, namely that each derivative may be obtained by adding a multiple of
π/2
to
x
, as shown here.
In[5]:=
Table[Cos[x+(nπ)/2],{n,4}]
Out[5]=
{-Sin[x],-Cos[x],Sin[x],Cos[x]}
D returns exactly this formula for the
th
n
derivative of Cos.
In[6]:=
D[Cos[x],{x,n}]
Out[6]=
Cos
nπ
2
+x
An immediate application of the above closed form would be to compute higher-order derivatives of Cos with blinding speed. D itself uses this method to compute the billionth derivative of Cos in a flash, as shown here.
In[7]:=
D[Cos[x],{x,10^9}]//Timing
Out[7]=
{0.000572,Cos[x]}
Next, we note that, starting from the
th
n
derivative, one can obtain derivatives of symbolic order specified by arbitrary expressions. For example, the
th
(n-1)
derivative of Cos can be obtained by using a replacement rule, as shown here.
In[8]:=
D[Cos[x],{x,n}]/.{n(n-1)}
Out[8]=
Cos
1
2
(-1+n)π+x
This technique can be used to reproduce the pattern of derivatives that led us to guess the closed form for the
th
n
derivative of Cos, as follows.
In[9]:=
Refine[Table[D[Cos[x],{x,n}]/.{n4n+i},{i,1,4}],n∈Integers&&n>=0]
Out[9]=
{-Sin[x],-Cos[x],Sin[x],Cos[x]}
Finally, the closed-form expression for the
th
n
derivative can be used to perform “integration through infinite differentiation” using the following formula.
x
∫
0
f[t]t
∞
∑
n=0
n+1
x
n
(-1)
∂
{x,n}
f[x]
(n+1)!
The formula can be proved, for example, using repeated integration by parts. Applying it to Cos, we recover the integral of this function, as shown here.
In[10]:=
f[t_]:=Cos[t]
In[11]:=
Sum[(x^(n+1)(-1)^nD[f[x],{x,n}])/(n+1)!,{n,0,Infinity}]
Out[11]=
Sin[x]
In[12]:=
Integrate[Cos[t],{t,0,x}]
Out[12]=
Sin[x]

Table of
th
n
Derivatives

The Wolfram Language has a rich variety of mathematical functions, starting from elementary functions, such as Power, to advanced special functions, such as EllipticE. The
th
n
derivatives for many of these functions can be computed in closed form using D. The following table captures the beauty and complexity of these formulas.
In[13]:=
Clear[f];flist={E^x,x^n,Log[x],Sin[x],ArcTan[x],Sinh[x],ArcCosh[x],E^(-x^2/2),​​ChebyshevT[n,x],EllipticE[x]};
In[14]:=
TraditionalFormGridJoinf[x],
∂
{x,n}
f[x],Transposeflist,
∂
{x,n}
#1&/@flist,Background{None,{{None,GrayLevel[0.9]}},{{1,1}Hue[0.6,0.4,1],{1,2}Hue[0.6,0.4,1]}},BaseStyle{FontFamilyTimes,FontSize12},DividersAll,FrameStyleHue[0.6,0.4,0.8],Spacings{2,1}
Out[14]//TraditionalForm=
f(x)
n
∂
f(x)
∂
n
x
x

x

n
x
(n)
n
n≥1
n
x
True
log(x)
n-1
(-1)
(n-1)!
-n
x
n≥1
log(x)
True
sin(x)
sin
πn
2
+x
-1
tan
(x)
π
n-1
2
1-n
x
3

F
2
1
2
,1,1;1-
n
2
,
3-n
2
;-
2
x
sinh(x)

n
(-)
sin
πn
2
-x
-1
cosh
(x)
-
π
n-1
2
x-1
1-n
x
3

F
2

1
2
,
1
2
,1;1-
n
2
,
3-n
2
;
2
x

1-x
n≥1
-1
cosh
(x)
True
-
2
x
2

π
n
2
-n
x
2

F
2
1
2
,1;
1
2
(-n-1)+1,1-
n
2
;-
2
x
2
T
n
(x)
n-1
2
n(n-1)!
n≥1
T
n
(x)
True
E(x)
1
2
π
-n
x
2

F
1
-
1
2
,
1
2
;1-n;x
Some of the entries in the table are rather simple. For example, the first entry states that all the derivatives of the exponential function are equal to the function itself, which generalizes the following result from basic calculus.
These answers agree with the ones obtained if D is used separately for each derivative computation. The results are then simplified.
This closed form can also be expressed in terms of Hermite polynomials, which can be verified in specific cases, as shown here.
The higher derivatives of a function generate oscillations. This remarkable phenomenon is illustrated here using a few derivatives of the Gaussian function considered by us.

The Sum, Product and Chain Rules

The product rule, or the so-called Leibniz rule, gives an answer that is essentially a binomial expansion, expressed as a sum wrapped in Inactive to prevent evaluation.
Finally, there is a form of the chain rule due to the pious Italian priest Francesco Faà di Bruno (1825–1888). This is given by a rather messy expression in terms of BellY, and states that: