2

What is the continued fraction representation of $\log a \over \log b$? Both $a, b$ are integers $>1$.

Wolfram gives expressions for $\log(1+z)$ as well as $\log({1+z\over1-z})$, but does not give any explanation for their derivation.

The Handbook of Continued Fractions for Special Functions is excellent but its exposition does not seem to help with the fact that there are two arguments to the expression, not one.

My goal is to produce successive rational approximations to $\log a \over \log b$. I could produce successive rational expressions for $\log a$ and $\log b$ independently and divide to produce an approximation to the ratio, but that approximation is not optimal. Some Mathematica tests using exhastive search for the first few ideal rational approximations show the ratio method is vastly inferior to the optimal answer that treats the values simultaneously.

3 Answers3

3

If you know how to get the simple continued fraction of $n/m$ using the subtractive extended Euclidean algorithm, you do essentially the same thing except instead of subtraction you use division. If you want to find good rational approximations to $\log x/\log y,$ use this algorithm.

First, initial values are $x_0 = x>1, y_0 = y>1$ and $a_0=1, b_0=0, c_0=0, d_0=1.$ For every $n\ge0$ we have that $x_n = x^{a_n}/y^{b_n},$ $y_n = y^{d_n}/x^{c_n}.$ Now if $x_n=y_n$ then we stop since $x^{a_n+c_n}=y^{b_n+d_n}$ and $\log x/\log y=(b_n+d_n)/(a_n+c_n).$ Otherwise, suppose $x_n<y_n.$ Then let $x_{n+1}=x_n,\; y_{n+1}=y_n/x_n,\;$ and $\;y_{n+1}=y^{d_n+b_n}/x^{a_n+c_n}.$ So now we get that $a_{n+1}=a_n,$ $b_{n+1}=b_n,$ $c_{n+1}=c_n+a_n,$ $d_{n+1}=d_n+b_n.$ Note that $y_{n+1}>1$ because $x_n<y_n.$

Similarly if $x_n>y_n,$ with the roles of $x$ and $y$ reversed. Explicitly, let $x_{n+1}=x_n/y_n,\; y_{n+1}=y_n\;$ and $\;x_{n+1}=x^{a_n+c_n}/y^{b_n+d_n}.$ So now we get that $a_{n+1}=a_n+c_n,$ $b_{n+1}=b_n+d_n,$ $c_{n+1}=c_n,$ $d_{n+1}=d_n.$ Note that $x_{n+1}>1$ because $x_n>y_n.$

For all $n\ge0$, the mediant of $\frac{b_n}{a_n}$ and $\frac{d_n}{c_n}$ is $\frac{b_n+d_n}{a_n+c_n}\approx \frac{\log x}{\log y}=\log_y x$ and $\;x_n>1,\;y_n>1.$ This implies that $0<\log_y x_n = a_n\log_y x-b_n,\; 0<b_n<a_n\log_y x$ and $0<b_n/a_n<\log_y x.$ Similar reasoning gives $0<\log_y x<d_n/c_n.$

For an example, let $x=2,y=10.$ Then, $x_4=1.6=2^4/10^1,$ $y_4=1.25=10^1/2^3$ giving $\log_{10}2 \approx (1+1)/(4+3)=2/7$ and next $x_5=1.28=2^7/10^2,$ $y_5=1.25=10^1/2^3$ giving $\log_{10}2\approx (2+1)/(7+3)=3/10=.300.$ Next approximation is $4/13=.307\dots\;$ and so on.

(Note) Shanks' algorithm from 1954 is closely related except he finds just the simple continued fraction partial quotients. The algorithm I describe gives rational bounds at each stage using only one division per step. These bounds are $\;b_n/a_n<\log_y x<d_n/c_n\;$ for all $n$.

Somos
  • 37,457
  • 3
  • 35
  • 85
  • This is so simple and elegant.. clearly the right way to proceed. And now I have more to learn about the generalizations like Shanks' algorithm, thanks! – Diane Wilbor Nov 01 '17 at 20:34
  • but this is no formular, it's a good algo for computer programs though – athos May 09 '18 at 05:39
  • This is really nice work here. – ness Jul 10 '24 at 12:18
  • 1
    @ness Did you tried the subtractive extended Euclidean algorithm? This is just the same except with division instead of subtraction. – Somos Jul 10 '24 at 12:32
  • I am looking at it, but don't understand the connection from that to this – ness Jul 10 '24 at 14:04
  • I am still trying to understand why this works. I've read Shank's paper and I've read about the extended euclidean algorithm, but I'm still stuck. Any other things I could focus on to understand this? – ness Oct 20 '24 at 10:46
  • @ness I have added more information. What part don't you understand? – Somos Oct 20 '24 at 12:38
  • I am able to write a program that will compute successive approximations of logx/logy using your algorithm above. I just don't understand why it works. https://tinyurl.com/sagewssagews – ness Oct 20 '24 at 12:43
  • @ness It works for the same reason that the Euclidean algorithm works. The bounding interval $;b_n/a_n<\log_y x<d_n/c_n;$ gets smaller as $n$ increases. – Somos Oct 20 '24 at 12:46
  • I still don't understand, but will try reading about the Euclidean algorithm and Extended Euclidean Algorithm again. – ness Oct 20 '24 at 12:59
  • The extended euclidean algroithm helps us find that gcd(a,b)=c. We can unwind this info to find out which particular linear combination of a and b make c. I don't understand the connection between this process and finding tighter and tighter bounds around $log_yx$. – ness Oct 20 '24 at 13:56
  • 1
    @ness Here is a suggestion for you to try. Use the extended Euclidean algorithm on $13$ and $21$. Then compare with my algorithm for $2^{13}$ and $2^{21}$. You should be able to notice the direct connection between the two algorithms. – Somos Oct 20 '24 at 16:17
  • <3<3<3 Thank you. I will try this tomorrow – ness Nov 04 '24 at 03:15
2

This is not quite an answer, but also way too big for a comment.

Euler made a powerful observation, that $a_0+a_0a_1+a_0a_1a_2+\dots+a_0a_1a_2\dots a_n$ equals

$$\cfrac{a_0}{1- \cfrac{a_1}{1+a_1- \cfrac{a_2}{1+a_2- \cfrac{\ddots}{\ddots- \cfrac{a_{n-1}}{1+a_{n-1}- \cfrac{a_n}{1+a_n}}}}}}$$

Using this and taking $n\to\infty$, one can show that if $x=1+\sum_{i=1}^{\infty}\left(\prod_{j=1}^ia_i\right)$ then

$$x=\cfrac{1}{1- \cfrac{a_1}{1+a_1- \cfrac{a_2}{1+a_2- \cfrac{a_3}{1+a_3-\ddots}}}}$$

This, together with an application of an equivalence transformation, is what's behind Euler's celebrated continued fraction representation for $e^z$ $(z>0)$:

$$e^z=\cfrac{1}{1-\cfrac{z}{1+z-\cfrac{z}{2+z-\cfrac{2z}{3+z-\cfrac{3z}{4+z-\ddots}}}}}$$


The expression for $\log\left(\frac{1+z}{1-z}\right)$ comes from the power series

$$\log\left(\frac{1+z}{1-z}\right)=2\sum_{n=0}^\infty\frac{z^{2n+1}}{2n+1},$$

using the same principle as above. Indeed, we can write

\begin{align} \log\left(\frac{1+z}{1-z}\right) &=2z\left(1+\frac{z^2}3+\frac{z^4}5+\dots\right)\\ &=2z\left(1+\frac{z^2}3+\frac{z^2}{3}\frac{z^2}{5/3}+\dots\right) \end{align}

and apply an equivalence transformation at the end to tidy things up.


The continued fraction representation for $\log(1+z)$ is a bit more complicated. It comes from Gauss's continued fraction representations for hypergeometric functions. Indeed, for $|z|<1$ we have

\begin{align} \log(1+z)=\sum_{n=1}^\infty \frac{(-1)^{n-1}}nz^n &=z\sum_{m=0}^\infty \frac{(-1)^m}{m+1}z^m\\ &=z\sum_{m=0}^\infty\frac{(-z)^m}{m!}\frac{(1)_m(1)_m}{(2)_m}\\ &=z\,\,{}_2F_1(1,1,;2;-z) \end{align}

This yields a continued fraction representation for $\log(1+z)$ that is still valid outside of the branch cut, ie, outside $(-\infty,-1)$.


If you don't mind $\log b$ showing up, there's an obvious formula. Taking $a^*=a-1$ we get that $\frac{\log a }{\log b}=\frac1{\log b} \log(1+a^*)$ must equal

\begin{align} \frac1{\log b}\cdot &\cfrac{a^*}{1+ \cfrac{a^*}{2+ \cfrac{a^*}{3+ \cfrac{4a^*}{4+ \cfrac{4a^*}{5+ \cfrac{9a^*}{6+ \cfrac{9a^*}{7+\ddots}}}}}}}\\ =&\cfrac{a^*}{\log b+ \cfrac{a^*\log b}{2+ \cfrac{a^*}{3+ \cfrac{4a^*}{4+ \cfrac{4a^*}{5+ \cfrac{9a^*}{6+ \cfrac{9a^*}{7+\ddots}}}}}}} \end{align}

If you're not happy with $\log b$ showing up near $a^*$, you can instead write

\begin{align} &\cfrac{a^*}{\log b+\frac1{\frac1{\log b}}\cdot \cfrac{a^*}{2+ \cfrac{a^*}{3+ \cfrac{4a^*}{4+ \cfrac{4a^*}{5+ \cfrac{9a^*}{6+ \cfrac{9a^*}{7+\ddots}}}}}}}\\ = &\cfrac{a^*}{\log b+ \cfrac{a^*}{\frac{2}{\log b}+ \cfrac{a^*}{3\log b+\frac1{\frac1{\log b}}\cdot \cfrac{4a^*}{4+ \cfrac{4a^*}{5+ \cfrac{9a^*}{6+ \cfrac{9a^*}{7+\ddots}}}}}}} \end{align}

Proceeding in this manner, we get

$$\cfrac{a^*}{\log b+ \cfrac{a^*}{\frac{2}{\log b}+ \cfrac{a^*}{3\log b+ \cfrac{4a^*}{\frac4{\log b}+ \cfrac{4a^*}{5\log b+ \cfrac{9a^*}{\frac6{\log b}+ \cfrac{9a^*}{7\log b+\ddots}}}}}}}$$

Fimpellizzeri
  • 23,321
  • Indeed, too big for a comment. It sure gives excellent intuition and a flavor for manipulating these infinite sequences. Thanks! – Diane Wilbor Nov 01 '17 at 20:36
1

If $a = b+z $ with $|z| < b$, then you can write $$ \dfrac{\log(b+z)}{\log(b)} = 1 + \dfrac{z}{b \log b + \dfrac{z}{ \frac{2}{\log (b)} + \dfrac{z}{3 b \log(b) + \dfrac{z}{ \frac{2}{2\log (b)} + \dfrac{z}{5 b \log(b) + \dfrac{z}{ \frac{2}{3\log(b)} + \ldots}}}}}}$$

Robert Israel
  • 470,583