0

Say I have a number $n$, and want to find the expression of $\sqrt{n}$ as a regular continued fraction. How would I do such a thing systematically?
A naive computer algorithm wouldn't work, due to floating point errors.

J. Doe
  • 1
  • 1
    The algorithm is described here : https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Continued_fraction_expansion – Peter Jan 24 '19 at 18:33
  • It doesn't always produce a **regular** continued fraction. for example when $S=7$ – J. Doe Jan 24 '19 at 18:48
  • Then, please show what the algorithm gives and what would be the correct result. – Peter Jan 24 '19 at 18:51
  • Is $n$ assumed to be a positive integer? – hardmath Jan 24 '19 at 18:54
  • 1
    it gives $a=\sqrt4=2$, $r=3$ (because $S=7=\lfloor\sqrt7\rfloor^2+3=4+3$), and that means $\sqrt7=2+\frac3{4+\frac3{4+\frac3{4+\frac3{...}}}}$, while the desired result is one in which the first element is $\lfloor\sqrt7\rfloor=2$, and all the numerators are 1. And yes, $n$ is a positive integer. – J. Doe Jan 24 '19 at 19:07
  • 1
    Maybe, you have chosen the wrong algorithm. I have not further checked the site, but I still think that the algorithm for a regular continued fraction should be present. – Peter Jan 24 '19 at 19:09
  • 2
    See the algorithm for which Wikipedia uses $\sqrt{114}$ as an example. – Misha Lavrov Jan 24 '19 at 19:10
  • The same Question was asked previously (see [here](https://math.stackexchange.com/questions/265690/continued-fraction-of-a-square-root)) but unfortunately has an Accepted Answer that provides an example instead of a proper algorithm. For that reason I'd like to see someone write a full Answer here with the details of a proposed *integer* algorithm. The previously linked Wikipedia article *does provide* such an algorithm, so this is not an imponderable task. – hardmath Jan 24 '19 at 19:20
  • Thank you, it works perfectly :) but why is $d_{n+1}$ always an integer? You'd intuitively think $d_n$ doesn't necessarily devide $S-m_{n+1}^2$. – J. Doe Jan 24 '19 at 19:27

0 Answers0