Finding the nth derivative of functions, in particular y=tan(x)

For $y=\cos2x$

Since $\frac{d y}{d x} = -2 \sin2x$, and $\frac{d^2 y}{d x^2} = -4 \cos2x$, then

$\frac{d^2 y}{d x^2} = -4y$, so

$\frac{d^3 y}{d x^3} = -4\frac{d y}{d x}$, $\frac{d^4 y}{d x^4} = -4\frac{d^2 y}{d x^2}$, etc.

Therefore, the nth differential of $y=\cos2x$ is $\frac{d^n y}{d x^n} = -4 \frac{d^{n-2} y}{d x^{n-2}}, n\geq 2$


For $y=\ln(x)$

Same as above, but this time the differentials are expressed in terms of $x$, not each other.

$ y=\ln(x) \Rightarrow \frac{d y}{d x} = x^{-1} \Rightarrow \frac{d^2 y}{d x^2} = -x^{-2}$, etc.

So for $y=\ln(x)$,

$\frac{d^n y}{d x^n} = (n-1)!(-1)^{n-1}x^{-n}, n\geq 2$


For $y=\tan(x)$

So the question is, does an equation such as that exist for $y=\tan(x)$?

I have tried two approaches:

Differentials of $\tan(x)$ in terms of $y$ and $\frac{dy}{dx}$:

\begin{array}{c} \frac{d y}{d x} & = & 1+y^2 \\ \frac{d^2 y}{d x^2} & = & 2y\frac{d y}{d x} \\ \frac{d^3 y}{d x^3} & = & 4(\frac{d y}{d x})^2 & - & 2\frac{d y}{d x} \\ \frac{d^4 y}{d x^4} & = & 20y(\frac{d y}{d x})^2 & - & 4y\frac{d y}{d x} \\ \frac{d^5 y}{d x^5} & = & 20(\frac{d y}{d x})^3 & + & 68(\frac{d y}{d x})^2 & - & 72 \frac{d y}{d x} \\ \end{array}

There are some patterns you can spot but it didn't seem very promising so I moved on.

Differentials of $\tan(x)$ in terms of other differentials:

\begin{array}{c} \frac{d y}{d x} & = & 1+y^2\\ \frac{d^2 y}{d x^2}& = & 2y\frac{d y}{d x}\\ \frac{d^3 y}{d x^3}& = & 2y\frac{d^2 y}{d x^2} & + & 2(\frac{d y}{d x})^2\\ \frac{d^4 y}{d x^4}& = & 2y\frac{d^3 y}{d x^3} & + & 6\frac{d^2 y}{d x^2}\frac{d^2 y}{d x^2}\\ \frac{d^5 y}{d x^5}& = & 2y\frac{d^4 y}{d x^4} & + & 8\frac{d^3 y}{d x^3}\frac{d y}{d x} & + & 6(\frac{d^2 y}{d x^2})^2\\ \frac{d^6 y}{d x^6}& = & 2y\frac{d^5 y}{d x^5} & + & 10\frac{d^4 y}{d x^4}\frac{d y}{d x} & + & 20\frac{d^3 y}{d x^3}\frac{d^2 y}{d x^2}\\ \frac{d^7 y}{d x^7}& = & 2y\frac{d^6 y}{d x^6} & + & 12\frac{d^5 y}{d x^5}\frac{d y}{d x} & + & 30\frac{d^4 y}{d x^4}\frac{d^2 y}{d x^2} & + & 20(\frac{d^3 y}{d x^3})^2\\ \frac{d^8 y}{d x^8}& = & 2y\frac{d^7 y}{d x^7} & + & 14\frac{d^6 y}{d x^6}\frac{d y}{d x} & + & 42\frac{d^5 y}{d x^5}\frac{d^2 y}{d x^2} & + & 70\frac{d^4 y}{d x^4}\frac{d^3 y}{d x^3}\\ \frac{d^9 y}{d x^9}& = & 2y\frac{d^8 y}{d x^8} & + & 16\frac{d^7 y}{d x^7}\frac{d^1 y}{d x^1} & + & 56\frac{d^6 y}{d x^6}\frac{d^2 y}{d x^2} & + & 112\frac{d^5 y}{d x^5}\frac{d^3 y}{d x^3} & + & 70(\frac{d^4 y}{d x^4})^2\\ \end{array}

Table of coefficients expressed in terms of prime factors:

\begin{array}{c|c c c c c } &1&2&3&4&5\\\hline 2&2\\ 3&2&(2)\\ 4&2&2\times3\\ 5&2&2\times2\times2&(2\times3)\\ 6&2&2\times5&2\times2\times5\\ 7&2&2\times2\times3&2\times3\times5&(2\times2\times5)\\ 8&2&2\times7&2\times3\times7&2\times5\times7\\ 9&2&2\times2\times2\times2&2\times2\times2\times7&2\times2\times2\times2\times7&(2\times5\times7)\\ \end{array}

This is much more exciting. I have worked out formulae up to the third term:

\begin{array}{ c c|c c c} &term& 1 & 2 & 3 & m & last\\ && 2y\frac{d^{n-1} y}{d x^{n-1}} & 2(n-1)\frac{d^{n-2} y}{d x^{n-2}}\frac{d y}{d x} & (n-1)(n-2)\frac{d^{n-3} y}{d x^{n-3}}\frac{d^2 y}{d x^2} & (?)\frac{d^{n-m} y}{d x^{n-m}}\frac{d^{m-1} y}{d x^{m-1}}*^1 & 2(?)\frac{d^{\frac{n-1}{2}} y}{d x^{\frac{n-1}{2}}}*^2\\ \end{array}

$*^1$Note: $(n-m)$ and $(m-1)$ add up to $n-1$, i.e. one less than the differential that is being calculated.

$*^2$ Only appears when $\frac{n-1}{2}$ is a whole number, i.e. for $n$ odd.

The problem I am encountering is that there doesn't seem to be an expression that works for every terms of every differential. Then again I have only calculated up to the 3rd term. Any ideas?

(Also I'd be very interested if you found any other nth differentials of this sort.)


It is a good opportunity to use the Arbogast formula, usually known as Faá di Bruno's formula. To start, let us write $\tan x$ as $$\tan x=\frac{\sin x}{\cos x}=-\mathrm i\frac{\mathrm e^{\mathrm i2x}-1}{\mathrm e^{\mathrm i2x}+1}=-\mathrm i+\frac{2\mathrm i}{\mathrm e^{\mathrm i2x}+1}.$$ Let us then define $g(x)=\mathrm e^{\mathrm i2x}$ and $f(x)=\frac{2\mathrm i}{x+1}-\mathrm i$. We have $\tan x=f(g(x))$ and, for $k\geq1$, $$f^{(k)}(x)=(-1)^kk!\frac{2\mathrm i}{(x+1)^{n+1}} \qquad\text{and}\qquad g^{(k)}(x)=(2\mathrm i)^kg(x).$$ Arbogast - Faá di Bruno's formula gives the $n^{\text{th}}$ derivative (it is a generalization of the chain rule to higher deriative orders). The general formula writes $$\tan^{(n)}x=\sum_{\substack{m_1,\,\dots,\,m_n\\m_1+2m_2+\cdots+nm_n=n}} \frac{n!}{m_1!\dots m_n!}f^{(m_1+\cdots+m_n)}(g(x))\frac{g'(x)^{m_1}}{1!^{m_1}}\cdots\frac{g^{(n)}(x)^{m_n}}{n!^{m_n}}$$ and using explicit form of $f^{(k)}$ and $g^{(k)}$ we have $$\tan^{(n)}x=\sum_{\substack{m_1,\,\dots,\,m_n\\m_1+2m_2+\cdots+nm_n=n}} \frac{n!(m_1+\cdots+m_n)!}{m_1!\dots m_n!} \frac{(-1)^{m_1+\cdots+m_n}2\mathrm i}{(g(x)+1)^{m_1+\cdots+m_n+1}} \frac{(2\mathrm i)^{m_1}g(x)^{m_1}}{1!^{m_1}}\cdots\frac{(2\mathrm i)^{n\cdot m_n}g(x)^{m_n}}{n!^{m_n}}$$ some simplifications yield (with $g(x)/(g(x)+1)=(\mathrm i-\tan x)/2\mathrm i$ and $1/(g(x)+1)=(1-\mathrm i\tan x)/2)$) $$\tan^{(n)}x=n!2^n\mathrm i^{n+1}(1-\mathrm i\tan x)\times\sum_{\substack{m_1,\,\dots,\,m_n\\m_1+2m_2+\cdots+nm_n=n}} \frac{(m_1+\cdots+m_n)!}{m_1!\dots m_n!\,1!^{m_1}\dots n!^{m_n}}\left(\frac{\tan x-\mathrm i}{2\mathrm i}\right)^{m_1+\cdots+m_n}.$$


I actually have two answers for this question. The first is a series I came up with a while back when I was trying to implement the polygamma function and needed a generalized reflection formula. The second I obtained by entering my coefficients into google and looking at the resulting OEIS page.

First formula:

For positive integer n, the n-th derivative of tan(x) can be represented as

$$\sec^2(x) \sum_{k=0}^{n-1} C_{n,k} \tan^k (x)$$

With $C_{n,k}$ being the integer at the n-th row and k-th column of the following table:

image contains a triangle of numbers.  1st row: 1; 2nd row: 0, 2; 3rd row: 2, 0, 6; 4th row: 0, 16, 0, 24; 5th row: 16, 0, 120, 0, 120; 6th row: 0, 272, 0, 960, 0, 720.

(The empty cells represent 0, and are omitted for visual clarity)

The numbers in this triangle can be generated by the recursive definition:

$$C_{n+1,k} = (k+1)(C_{n,k-1}+C_{n,k+1})$$

For the sake of the recurrence relation, all cells outside the triangle are assumed to be 0. In fact, $C_{n,k}$ is 0 for all

•k<0 (left of the triangle)

•k>n (right of the triangle)

•k+n is even (checkerboard pattern)

This was going to be the end of the post, but I then typed in these numbers into google, and an OEIS (online encyclopedia of integer sequences) page came up, which I've linked below:

https://oeis.org/A185896

At some point on the page, it mentions that these polynomials can actually be generated via what are known as Eulerian polynomials. After rearranging some of the variables, I came up with the following formula:

$$ \frac{d^n}{dx^n} \tan(x) = 2\sec^{n+1}(x) \sum _{m=0} ^{n/2-1} (-1)^{m+1-n/2} A(n,m)\sin((n-1-2m)x)$$ for all even n>0

$$ \frac{d^n}{dx^n} \tan(x) = \sec^{n+1}(x) \left( A(n,\frac{n-1}2) + 2 \sum _{m=0} ^{\frac{n-3}2} (-1)^{m+(1-n)/2} A(n,m) \cos((n-1-2m)x) \right)$$ for all odd n>0

Where A(n,m) is another triangle of numbers which, unlike the last one, has an official name: the Eulerian numbers. Also unlike the last triangle of numbers, you can actually generate each row without knowing the numbers on the previous row, via the following formula:

$$A(n,m) = \sum _{k=0} ^{m+1} (-1)^k {n+1\choose k} (m+1-k)^n $$

Both of these formulas have some pros and cons. They both have about the same number of terms. The second formula has the benefit that you don't need to generate all the coefficients for the previous derivatives to find a particular derivative. However, it also has the downside that its coefficients alternate in sign, which could potentially lead to roundoffs errors.

I hope this answers your question. :)