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

  • $\begingroup$ 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$. $\endgroup$ Nov 5, 2015 at 20:52
  • 1
    $\begingroup$ 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. $\endgroup$ Nov 5, 2015 at 20:59
  • $\begingroup$ Welcome to math.SE! Nice question! You can use LaTeX directly in the question; no need to embed the formulas as images. $\endgroup$ Nov 6, 2015 at 8:38
  • $\begingroup$ 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? $\endgroup$
    – ccorn
    Nov 7, 2015 at 22:53
  • 1
    $\begingroup$ functions.wolfram.com/ElementaryFunctions/Tanh/10/0001 $\endgroup$
    – Alex
    Dec 17, 2015 at 0:28

1 Answer 1


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.

  • $\begingroup$ @Nicco: For comparison, I added the general trigonometric version that you found. $\endgroup$ May 17, 2016 at 16:26
  • $\begingroup$ @Nicco: I just realized that since the hyperbolic tangent is, $$\tanh(x) = \frac{e^{2x}-1}{e^{2x}+1}$$ while the tangent 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. $\endgroup$ May 17, 2016 at 18:46
  • $\begingroup$ @ Tito Piezas III :The full generalisation is found in this post $\endgroup$
    – Nicco
    May 17, 2016 at 21:57
  • $\begingroup$ @ Tito Piezas III :Entry 18 of ramanujan in your blogpost is a special case of the trigonometric version when $z=-1$ and $m=1$ $\endgroup$
    – Nicco
    May 22, 2016 at 20:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .