First of all, and since this is my first question in this forum, I would like to specify that I am not a professional mathematician (but a philosophy teacher); I apologize by advance if something is wrong in my question.

I enjoy doing numerical computations on my leisure time, and at the end of the last summer, I was working on some personal routines related to the world of ISC. With the help of these pieces of code, I detected algorithmically several identities, among which the following one $$ \tanh z = \operatorname*{K}_{n=1}^{\infty} \frac{1 + \left((n-1) \frac{\pi}{4} z^{-1}\right)^2}{(2n-1) \frac{\pi}{4} z^{-1}} \tag{1} \label{1} $$

The previous notation is the one I use; I find it convenient and it can be found for instance in Continued Fractions with Applications by Lorentzen & Waadeland, but I know that some people don't like it; it has to be read the following way: $$ a_0 + \operatorname*{K}_{n=1}^{\infty} \frac{b_n}{a_n} = a_0 + \cfrac{b_1}{a_1 + \cfrac{b_2}{a_2 + \cfrac{b_3}{a_3 + \dotsb}}} $$

This continued fraction is nice when used for computing the hyperbolic tangent of numbers like $\pi/4$ and other simple multiples of $\pi$ since it will only involve integer numbers in the expansion of the continued fraction.

Of course I browsed a little in order to see what was known about it, for example here, but I didn't find anything similar. I also sent it to several professional mathematicians, who told me that it could be difficult to recognize easily whether this continued fraction was equivalent to some other identity or not.

I haven't myself the required skills to study further this expression, but I would be very happy to know more about it: is it something well-known? Is it something that comes trivially from some other identity? Is it (who knows?) something new?

Edit 1: I posted myself an answer to the question by thinking something new was found; but it happened to be related to the precision in the computation. For that reason I may delete this answer in the future.

Edit 2: In this edit I am going to explain more how I came up with the identity and to add a code that can be used to test the identity.

I will not post my C code here because it is too long but I can really share it if someone wants it. Basically: I coded in the end of last summer a program in C computing very quickly millions of random continued fractions; each one was computed up to its 36th convergent; convergence was checked by looking at the difference between 35th and 36th convergent. Any quadratic value was discarded as not interesting for my purpose. Remaining values were matched against all non-quadratic values in Shamos's catalogue of real numbers by computing the PSLQ vector for $[z,1,S]$ (where $z$ was a continued fraction and $S$ a number from Shamos's book). I used a personal hygienic C macro for the pslq algorithm that I share here. The precision when computing the PSLQ algorithm on double-precision numbers was "poor" (about 12 digits) but I focused on speed for this project. Whenever an interesting result was returned by the PSLQ algorithm (low norm of the returned vector), the continued fraction was computed a second time with the dd type from D.H. Bailey's libqd library (about 32 exact digits only but much quicker than any arbitrary precision library; furthermore precision in Shamos's book is only 20 digits). If the coefficients previously returned by the PSLQ algorithm were able to find again the relation with at least 17 exact digits, current parameters were printed. I made this program run for several weeks on three cores of a Raspberry Pi 2 (which is rather slow but which can compute long tasks without getting warm). Results had to be later generalized "by hand" when similar values were noticed by me. What I finally got was much more than I could expect. Above is one of these results.

Below is some code for Maxima (using the bfloat types):

/* Set the precision of the computation with bfloat numbers */
fpprec: 1024$

/* compute the n-th convergent of the continued fraction at x */
K(x,n) :=  block([ a,b,p1:1,p2:0,q1:0,q2:1],
  for k:1 thru n do (
    /* compute the k-th partial denominator as a */
    /* compute the k-th partial numerator as b */
    /* compute the k-th convergent as p2/q2 */
    p:a*p2+b*p1, q:a*q2+b*q1,
    /* shift values for simulating the matrix operation */
    p1:p2, p2:p, q1:q2, q2:q), p/q);

You can try it online by using this link (just change the value at the end of the code once the page will be loaded).

In a future edit I will add some plots illustrating the convergence of the continued fraction in \eqref{1} when the number of partial numerators (denominators) goes to infinity.

Edit 3:

Here is a plot showing the convergence of the continued fraction compared to the classical one for $\tanh$. The abscissa is the rank of the convergent (the last value of $n$ in the formula above):

enter image description here

Thomas Baruchel
  • 973
  • 7
  • 22
  • I don't know much about this area but $\tanh(0)=0$, and the right hand side looks to be either undefined or different from 0 to me when $z=0$. – rVitale Nov 05 '15 at 20:52
  • 1
    You are right; it is actually undefined for z=0; however a quick numerical computation let me check than the convergence is very good around 0. Computing up to n=512 with a precision of 1024 digits during the computation leads to ~400 exact decimal digits for z=1e-6 for instance. – Thomas Baruchel Nov 05 '15 at 20:59
  • Welcome to math.SE! Nice question! You can use LaTeX directly in the question; no need to embed the formulas as images. – Hans Lundmark Nov 06 '15 at 08:38
  • Since you have Lorentzen & Waadeland, have you looked at appendix A, eqs. (2.5.3) or (2.5.5) for $\tan\frac{z\pi}{4}$, with suitable substitutions and equivalence transformations? – ccorn Nov 07 '15 at 22:53
  • @Anatoly I have an excellent convergence for z=$\pi$. – Thomas Baruchel Nov 08 '15 at 19:19
  • What does represent the vertical axes in the plot? $tanh(x)$ when $x$ is large? How large? If you just want to put a single plot, instead of plotting for just one value of $x$, It would be better to plot the [MSE](https://en.wikipedia.org/wiki/Mean_squared_error) over a large number of values of $x$, for example 10000 equispaced values in $[-13, 13]$. If $y_i = tan(x_i)$ and $\hat {y}_i = f(x_i)$, where $f$ is your new expression, then the MSE could be computed as $$\text{MSE} = \frac{1}{N}\sum_{i=1}^{N} (y_i - \hat{y}_i)^2$$ – Carlos H. Mendoza-Cardenas Nov 16 '15 at 12:40
  • @Carlos Mendoza Sorry for that; vertical axes is log(abs(tanh(1)-K(1,n))) where K(x,n) is continued fraction evaluated at x up to rank n, in other words K(x,n) is the nth convergent of the continued fraction for x=1. As said in the post, n being itself the horizontal axes. – Thomas Baruchel Nov 16 '15 at 14:50
  • 1
    http://functions.wolfram.com/ElementaryFunctions/Tanh/10/0001/ – Alex Dec 17 '15 at 00:28
  • @Alex I am not so familiar with continued fractions; does that expansion transform easily into the one in this post? – Justpassingby Dec 17 '15 at 09:08
  • @Justpassingby - I didn't spend time yet to answer your question... I hoped Thomas will investigate this. – Alex Dec 19 '15 at 19:26
  • @Alex fair enough I'll see it when something gets posted here, then :-) – Justpassingby Dec 19 '15 at 21:22
  • @Alex I am not sure this is the same continued fraction; your link is actually the same I gave in my post and if I remember well, this continued fraction is what I called "classical c.f." in my plot above (with a different convergence as far as I can see). Unless some unexpected transformation can go from one to the other, it looks like values like $\pi/4$ give continued fractions with integer (or rational) coefficient with my formula while they give continued fractions involving $\pi$ with the classical formula. – Thomas Baruchel Dec 19 '15 at 21:44
  • There is also Pi/4 continued fraction expression given by Kevin Brown http://www.mathpages.com/home/kmath381.htm – Alex Dec 20 '15 at 23:00

1 Answers1


Your continued fraction is a very special case of the general continued fraction for the quotient of gamma functions conjectured in this post,see corollary (iii)

Edited: It is also a special case of the hyperbolic


Incidentally, note its trigonometric companion,


as discussed in this comment.

  • 2,763
  • 14
  • 32
  • @Nicco: For comparison, I added the general trigonometric version that you found. – Tito Piezas III May 17 '16 at 16:26
  • @Nicco: I just realized that since the [hyperbolic tangent](https://en.wikipedia.org/wiki/Hyperbolic_function#Standard_analytic_expressions) is, $$\tanh(x) = \frac{e^{2x}-1}{e^{2x}+1}$$ while the [tangent](https://en.wikipedia.org/wiki/Trigonometric_functions#Relationship_to_exponential_function_and_complex_numbers) is, $$\tan(x) = (-i)\frac{e^{2\,i\,x}-1}{e^{2\,i\,x}+1}$$ I think these two cfracs can be combined into a superfamily. – Tito Piezas III May 17 '16 at 18:46
  • @ Tito Piezas III :The full generalisation is found in this [post](http://www.math.stackexchange.com/questions/1739431/conjectured-general-continued-fraction-for-the-quotient-of-gamma-functions) – Nicco May 17 '16 at 21:57
  • @ Tito Piezas III :Entry 18 of ramanujan in your [blogpost](https://sites.google.com/site/tpiezas/0017) is a special case of the trigonometric version when $z=-1$ and $m=1$ – Nicco May 22 '16 at 20:26