3

Is there a formula for determining the upper bound for the length of the cycle for the continued fraction expansion of $\sqrt{D}$? I am attempting to expand for $D=4097280036$ and have tried up to 3500 loops but no luck. Does the repetitive cycle have even longer length? Or might I have made a calculation error? Note that I am using bigint-like calculations so that should be OK and indeed for other values for $D$ it all works fine so I guess I just bumped into an extraordinary long cycle.

Anyway - is there a formula in D stating what the (theoretical) upper bound for the cycle length is? And how often one lands up in these very long cycles?

Maestro13
  • 1,960

3 Answers3

2

You may or may not have made calculation errors. I have put two methods on this site that make no errors at all, one I learned from Prof. Lubin. In both cases, i do not believe that I wrote code for oversize integers. However, it will not take me long to do so.

Continued fraction of $\sqrt{67} - 4$

The other aspect is that the cycle length can not be longer than $$ \sqrt D \log D $$

I asked for more detail at https://mathoverflow.net/questions/264315/cycle-length-and-total-count-of-gauss-reduced-indefinite-binary-quadratic-forms

Apparently your number is $$ 64010^2 - 8^2 $$

Working program with GMP in C++, here is beginning and the end. Note that we get primitive representations ( $x,y $ not printed) for $x^2 - n y^2 = 64, 256, 1024, 4096, 16384, 65536.$

========================

4097280036 2^2 3 10667 32009

0. 64009  ;   pell  diff:   -127955  
1.   1  ;   pell  diff:   64  
2. 1999  ;   pell  diff:   -39999  
3.   3  ;   pell  diff:   24013  
4.   4  ;   pell  diff:   -103847  
5.   1  ;   pell  diff:   256  
6. 499  ;   pell  diff:   -33987  
7.   3  ;   pell  diff:   78025  
8.   1  ;   pell  diff:   -32000  
9.   3  ;   pell  diff:   30061  
10.   3  ;   pell  diff:   -97415  
11.   1  ;   pell  diff:   1024  
12. 124  ;   pell  diff:   -32439  
13.   3  ;   pell  diff:   91573  
14.   1  ;   pell  diff:   -8000  
15.  15  ;   pell  diff:   31753  
16.   3  ;   pell  diff:   -94187  
17.   1  ;   pell  diff:   4096  
18.  30  ;   pell  diff:   -63107  
19.   1  ;   pell  diff:   64905  
20.   1  ;   pell  diff:   -500  
21. 255  ;   pell  diff:   67965  
22.   1  ;   pell  diff:   -60023  
23.   1  ;   pell  diff:   16384  
24.   7  ;   pell  diff:   -38435  
25.   3  ;   pell  diff:   23785  
26.   5  ;   pell  diff:   -8000  
27.  15  ;   pell  diff:   98965  
28.   1  ;   pell  diff:   -24023  
29.   4  ;   pell  diff:   46365  
30.   2  ;   pell  diff:   -57047  
31.   1  ;   pell  diff:   65536  
32.   1  ;   pell  diff:   -29387  

===============================

12998.   1  ;   pell  diff:   -29387  
12999.   3  ;   pell  diff:   65536  
13000.   1  ;   pell  diff:   -57047  
13001.   1  ;   pell  diff:   46365  
13002.   2  ;   pell  diff:   -24023  
13003.   4  ;   pell  diff:   98965  
13004.   1  ;   pell  diff:   -8000  
13005.  15  ;   pell  diff:   23785  
13006.   5  ;   pell  diff:   -38435  
13007.   3  ;   pell  diff:   16384  
13008.   7  ;   pell  diff:   -60023  
13009.   1  ;   pell  diff:   67965  
13010.   1  ;   pell  diff:   -500  
13011. 255  ;   pell  diff:   64905  
13012.   1  ;   pell  diff:   -63107  
13013.   1  ;   pell  diff:   4096  
13014.  30  ;   pell  diff:   -94187  
13015.   1  ;   pell  diff:   31753  
13016.   3  ;   pell  diff:   -8000  
13017.  15  ;   pell  diff:   91573  
13018.   1  ;   pell  diff:   -32439  
13019.   3  ;   pell  diff:   1024  
13020. 124  ;   pell  diff:   -97415  
13021.   1  ;   pell  diff:   30061  
13022.   3  ;   pell  diff:   -32000  
13023.   3  ;   pell  diff:   78025  
13024.   1  ;   pell  diff:   -33987  
13025.   3  ;   pell  diff:   256  
13026. 499  ;   pell  diff:   -103847  
13027.   1  ;   pell  diff:   24013  
13028.   4  ;   pell  diff:   -39999  
13029.   3  ;   pell  diff:   64  
13030. 1999  ;   pell  diff:   -127955  
13031.   1  ;   pell  diff:   1  
13032. 128018  :   { sqrt( 4097280036 ) - 64009 } / 1

==========================

Will Jagy
  • 139,541
2

Pretty sure there is no formula, but there are some estimates and numerical experiments here: http://www.albany.edu/~mb533919/ART12%20(revised).pdf

Lukas Geyer
  • 18,259
2

There are no easy lower bounds as the length is very small for numbers such as $\sqrt{n^2+1}$ or $\sqrt{n^2+2}$. There is an upper bound mentioned by Will Jagy, which is $\sqrt D \log D$.

However, Will Jagy is wrong; you did not do a mistake. The period length of the continued fraction of $\sqrt{4097280036}$ is astonishing $13032$, much more than what you tried!

Sage code:

def continued_fraction_complete(x) :
    iteratives = dict()
    coefficients = list()
    while x not in iteratives :
        iteratives[x] = len(coefficients)
        a = floor(x)
        coefficients.append(a)
        x = 1/(x-a)
    return tuple(coefficients[:iteratives[x]]), tuple(coefficients[iteratives[x]:])

D = 4097280036
K.<b> = QuadraticField(4097280036)
p0,p1 = continued_fraction_complete(b)
print len(p0), len(p1)

Output: 1 13032 (pre-period and period)

yo'
  • 4,506
  • What are you using to find the cycle length? – Will Jagy Jun 12 '17 at 22:34
  • SageMath. Should I share the code? (It won't be easy as it's a part of my own large library, but I can write a shorter code, it's not rocket science to write it.) I can also say for instance that the largest coefficients are 128018, 6400, 6400, 5565, 5565, 5120, 5120, 4000, 4000, ... – yo' Jun 12 '17 at 22:35
  • It's alright, I made a copy of Lubin's method with GMP, mostly I had to comment out printing steps as the numbers get too large to print. But I kept the count of steps. – Will Jagy Jun 12 '17 at 22:42
  • @WillJagy And I used the ability of Sage to compute floor on arbitrary quadratic numbers :-) Anyway, it's 1am and I'm off, bye! – yo' Jun 12 '17 at 22:43
  • Thanks - I extended the loop and found the end of the cycle now. And found that principal solution for the corresponding Pell equation has 6751 / 6747 digits :-) – Maestro13 Jun 13 '17 at 07:11