This is a follow-up of another thread about quasi periodic continued fractions, a.k.a. Hurwitz fractions, with some linear shifts. I seem to have found the pattern of a subclass of them, as given below in the beautiful formulae $(i)-(iv)$. The main question:

Have parametric formulae of this type been obtained before?

For coprime naturals $p\lt q$ let $\tfrac pq=[0;a_1,\dots,a_n]$ with $n$ odd. (Choosing the parity is possible, because there are two ways of writing any $\tfrac pq\ne 1$ as a regular continued fraction, either with $a_n>1$ or with one more partial denominator and $a_n=1$.)

Now define vectors $v:=[a_1,a_2,\dots, a_{n-1},a_n-1,1], \quad\ v^*:=[a_n,a_{n-1},\dots,a_2,a_1-1,1]$. If $a_1=1$ or $a_n=1$, zeros will occur, and we’ll replace a vector $[ \dots, a,0,b, \dots]$ by $[ \dots, a+b,\dots]$ to obtain the standard notation of regular continued fractions.

This definition has the advantage of being 'symmetric' in $v$ and $v^*$. Equivalently, we can define $v$ directly as the vector of $\tfrac pq$ with *even* length; taking the one (again with even length) of $1-\tfrac pq$ and reversing it yields $v^*$.

It is easy to see that, identifying a vector $v$ with the finite continued fraction $[0;v]$, the map $v\mapsto v^*$ yields a well-defined involution of $\mathbb Q\cap(0,1)$. This is crucial for the statements below but makes them somewhat tricky. I don’t see how to apply the standard methods of Hurwitz or Perron to prove those easily. Maybe the expressions of $tanh$ or $tan$ type as below occur as special cases of the hypergeometric series expressions obtained by other authors (e.g. Takao Homatsu or James McLaughlin), but it should be possible to prove them without that heavy machinery.

Notation: Rational numbers like $(\tfrac14-v)$ etc. below are always supposed to be taken $\pmod 1$ so they are between $0$ and $1$, and the leading $0$ of the CF's won't be included in the vectors.

It is well-known that for $s,t \in\mathbb N$,

$ (o)\qquad\boxed{\sqrt{\dfrac ts} \tanh\dfrac1{\sqrt{st}} = \left [0; \overline{ s(4\lambda+1) , t(4\lambda+3)}\ \right] _{\lambda=0}^{\infty}}$.

For coprime naturals $0\lt p\lt q$ and $v,v^*$ as defined above, my findings *can be stated as follows:*

If $s,t \in\mathbb N$, then we have the following regular continued fractions:

$ (i)\qquad\boxed{ \dfrac pq+\dfrac 1q\sqrt{\dfrac ts} \tanh\dfrac1{q\sqrt{st}} =\left [0;\overline{ v, s(4\lambda+1)-1,v^*,t(4\lambda+3)-1 }\ \right ]_{\lambda=0}^\infty}$

and

$ (i')\qquad\boxed{\dfrac pq+\dfrac 1q\sqrt{\dfrac ts} \coth\dfrac1{q\sqrt{st}} =\left [t;\overline{ v, s(4\lambda-1)-1,v^*,t(4\lambda+1)-1}\ \right ]_{\lambda=1}^\infty \\ = 1+\left [\overline{ t(4\lambda+1)-1,v, s(4\lambda+3)-1,v^*}\ \right]_{\lambda=0}^\infty}.$

**Moreover, amazingly the same statements $ (i)$ and $ (i')$ hold if swapping $even\leftrightarrow odd$ and $tanh\leftrightarrow (-tan)$ or $coth\leftrightarrow cot$.**

Note that the map $v\mapsto v^*_{odd}$ yields a different involution in this case, in fact $ v^*_{odd}= 1-v^*_{even}$.

Further, if $q\equiv0\pmod4$ and $s,t$ are positive half-integers, we have

$ (ii)\qquad\boxed{ \dfrac pq +\dfrac1q\sqrt{\dfrac ts} \tanh\dfrac1{q\sqrt{st}} = \left [0; \overline{ v, s(4\lambda+1)+ \epsilon_1- 1, v^\sim, t (4\lambda+3)+ \epsilon_2-1}\ \right] _{\lambda=0}^{\infty}}$

where $ v^\sim =(\tfrac12-v)^*,\epsilon_1=\tfrac12sgn(\tfrac12-v^\sim), \epsilon_2=\tfrac12sgn(\tfrac12- v)$,

and

Finally, if $q\equiv0\pmod8$ and $s,t$ are such that $4s\equiv4t\equiv1\pmod 4$, we have

$ (iii)\qquad\boxed{ \dfrac pq +\dfrac1q\sqrt{\dfrac ts} \tanh\dfrac1{q\sqrt{st}} = \left [0; \overline{ v, s(4\lambda+1) + \epsilon_1- \tfrac34, v^\sim, t (4\lambda+3) + \epsilon_2- \tfrac54}\ \right] _{\lambda=0}^{\infty}}$

where $ v^\sim=(\tfrac34-v)^* ,\epsilon_1=\tfrac12sgn(\tfrac14- v^\sim), \epsilon_2=\tfrac12sgn(\tfrac34- v)$, as well as

if $q\equiv8\pmod{16}$ and $s,t$ are such that $4s\equiv4t\equiv3\pmod 4$, $ (iv)\qquad\boxed{ \dfrac pq +\dfrac1q\sqrt{\dfrac ts} \tanh\dfrac1{q\sqrt{st}} = \left [0; \overline{ v, s(4\lambda+1) + \epsilon_1- \tfrac54, v^\sim, t (4\lambda+3) + \epsilon_2- \tfrac34}\ \right] _{\lambda=0}^{\infty}}$

where $ v^\sim=(\tfrac14-v)^*,\epsilon_1=\tfrac12sgn(\tfrac34- v^\sim), \epsilon_2=\tfrac12sgn(\tfrac14- v)$.

Note that in $(ii)-(iv)$, all the partial denominators are still integers. For $\lambda=0$, terms equal to $0$ or $-1$ may occur that have to be “collapsed” with the neighboring terms to obtain the standard notation.

Corresponding to $(ii)-(iv)$, there are also similar formulae for $coth$, e.g.,

if $q\equiv0\pmod4$ and $s,t$ are positive half-integers,

$ (ii’)\qquad\boxed{ \dfrac pq +\dfrac1q\sqrt{\dfrac ts} \coth\dfrac1{q\sqrt{st}}\\ =1+ \left [ \overline{ t(4\lambda+1)+ \epsilon_1- 1, \tfrac12-v, s (4\lambda+3)+ \epsilon_2-1,v^*}\ \right] _{\lambda=0}^{\infty}}$,where $\epsilon_1=\tfrac12sgn(v-\tfrac12),\epsilon_2=\tfrac12sgn(v^*-\tfrac12)$.

The switching to $(-\tan)$ and $\cot$ still works for $(ii)$ and $(ii’)$, whereas for $(iii)$ and $(iv)$, this yields a ‘bifurcation’ with the four different vectors $v,(\tfrac34+v)^*, \tfrac12+v,(\tfrac14+v)^*$ occurring in each period. BTW, going from $(i)$ to $(ii)$ and from there to $(iii)$ and $(iv)$, you can see another kind of bifurcation, viz. from $-1$ to $-1\pm\tfrac12$ to $-1\pm\tfrac12\pm\tfrac14$. *Those bifurcations seem in fact very frequent when modifying the parameters $p,q,s,t$ in certain ways and might give indications towards a better understanding of the general form of such Hurwitz fractions. Indeed, playing around with them feels somewhat like zooming into the Mandelbrot set at different places...*

I'm wondering if the classes $(o)-(iv)$ are essentially the only quasi periodic continued fractions of $tanh$ type which have exactly 1 or 2 shifts.

By "essentially" I mean up to aperiodic onsets and up to cyclic permutations within the (quasi) periodic part.

Expressions "of $tanh$ type" are those that can be written in the form $\frac{a\tanh(1/r)+b}{c\tanh(1/r)+d}$ with $ r^2\in\mathbb N$ and $a,b,c,d\in\mathbb N_0$ such that $ad-bc\ne0$.

Many more things can of course be conjectured about the CF of $f(p,q,s,t):=\dfrac pq +\dfrac1q\sqrt{\dfrac ts}\tanh\dfrac1{q\sqrt{st}}$ where $s,t$ are positive rationals such that $q^2st\in\mathbb N$ (which is *a priori* necessary for the CF to be Hurwitzian). The two following should not be too hard to prove for any number of shifts:

The CF of $f(p,q,s,t)$ has no aperiodic onset (if allowing possible $0$ and $-1$ entries in the first period, as mentioned above after $(iv)$ )

If $f(p,q,s,t)=\left [0; \overline{ v_1,a_1\lambda+b_1,v_2,a_2\lambda+b_2, ...,v_k,a_k\lambda+b_k}\ \right]_{\lambda=0}^{\infty}$, then the rationals defined by the vectors $v_1,...,v_k$ all have denominators that divide the $lcm$ of $q$ and the denominators of $s,t$. (Some of the $v_i$ can be absent.)