1

According to this Mathworld page as well as Wikipedia, you can solve a Pell equation by generating the continued fraction convergents for $\sqrt{N}$. I wanted to do this, so I tried writing a program to solve the following Pell equation:

$p^2 - 13q^2 = 1$

I already knew the answer off the top of my head, $p=649$ and $q=180$. This is the minimal solution in $p$. But when I ran my program, nowhere did I find the $p_n/q_n$ convergent $649/180$. Instead, I found this.

Convergents (p/q) for the square root of 13.

p[0] = 3     q[0] = 1
p[1] = 4     q[1] = 1
p[2] = 7     q[2] = 2
p[3] = 11    q[3] = 3
p[4] = 18    q[4] = 5
p[5] = 119   q[5] = 33
p[6] = 137   q[6] = 38
p[7] = 256   q[7] = 71
p[8] = 393   q[8] = 109
p[9] = 2614  q[9] = 725

I believe these are the correct convergents... I double-checked. But nowhere do I find the correct answer, $p_n/q_n = 649/180$. Could someone tell me what's wrong with my approach? Is my understanding of Pell equations a little off?

ktm5124
  • 429
  • Are you sure that your continued fractions are correct? http://www.maths.surrey.ac.uk/hosted-sites/R.Knott/Fibonacci/cfCALC.html shows for $\sqrt{13}$ the approximations $7/2, 11/3, \ldots, 393/109, 649/180, \ldots$. – Martin R Apr 04 '15 at 02:44
  • You're right, my continued fractions are only right up until 393/109. – ktm5124 Apr 04 '15 at 02:47
  • You placed the second 6 one place early. – Will Jagy Apr 04 '15 at 02:48

1 Answers1

2

$$ \begin{array}{cccccccccccccccccccccccccccccc} & & 3 & & 1 & & 1 & & 1 & & 1 & & 6 & & 1 & & 1 & & 1 & & 1 & & 6 & \\ \frac{0}{1} & \frac{1}{0} & & \frac{3}{1} & & \frac{4}{1} & & \frac{7}{2} & & \frac{11}{3} & & \frac{18}{5} & & \frac{119}{33} & & \frac{137}{38} & & \frac{256}{71} & & \frac{393}{109} & & \frac{649}{180} & & \frac{4287}{1189} \\ \\ -13 & 1 & & -4 & & 3 & & -3 & & 4 & & -1 & & 4 & & -3 & & 3 & & -4 & & 1 & & -4 \end{array} $$

jagy@phobeusjunior:~/old drive/home/jagy$ cd Cplusplus
    jagy@phobeusjunior:~/old drive/home/jagy/Cplusplus$ ./Pell 13


0  form   1 6 -4   delta  -1
1  form   -4 2 3   delta  1
2  form   3 4 -3   delta  -1
3  form   -3 2 4   delta  1
4  form   4 6 -1   delta  -6
5  form   -1 6 4   delta  1
6  form   4 2 -3   delta  -1
7  form   -3 4 3   delta  1
8  form   3 2 -4   delta  -1
9  form   -4 6 1   delta  6
10  form   1 6 -4

 disc   52
Automorph, written on right of Gram matrix:  
109  720
180  1189


 Pell automorph 
649  2340
180  649

Pell unit 
649^2 - 13 * 180^2 = 1 

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

Pell NEGATIVE 
18^2 - 13 * 5^2 = -1 

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

  4 PRIMITIVE 
11^2 - 13 * 3^2 = 4 

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

  -4 PRIMITIVE 
3^2 - 13 * 1^2 = -4 

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

13       13

jagy@phobeusjunior:~/old drive/home/jagy/Cplusplus
Will Jagy
  • 139,541
  • I see. My program must be wrong. It only gets the correct convergents up until 393/109. – ktm5124 Apr 04 '15 at 02:48
  • FWIW, WolframAlpha can handle continued fractions. http://www.wolframalpha.com/input/?i=ContinuedFraction%5BSqrt%5B13%5D%2C+20%5D http://www.wolframalpha.com/input/?i=FromContinuedFraction%5B%7B3%2C1%2C1%2C1%2C1%2C6%2C1%2C1%2C1%2C1%7D%5D I have no idea why the MathWorld pages don't explain how to do what they talk about in Mathematica... – Steve Kass Apr 04 '15 at 02:59
  • @SteveKass, variant of continued fractions that requires no decimal accuracy or cycle detection; I briefly describe the middle part of the method in http://math.blogoverflow.com/2014/08/23/binary-quadratic-forms-over-the-rational-integers-and-class-numbers-of-quadratic-%EF%AC%81elds/ – Will Jagy Apr 04 '15 at 03:03