]> Continued Fractions - The Pell Equation

The Pell Equation

The equation

x 2 Dy 2 =1

over the integers for some nonsquare positive D is known as the Pell equation. We consider a slighty more general variant of the equation:

x 2 Dy 2 =±1

Theorem: If D is a nonsquare positive integer whose continued fraction expansion has a repeating portion of k terms, then p k,q k is a solution of

x 2 Dy 2 =(1 ) k

Proof: Let D=[a 1 ;a 2 ,...] and x i=[a i;a i+1 ,...]. We have x 2 =x k+2 which means

D=x k+2 p k+1 +p kx k+2 q k+1 +q k=x 2 p k+1 +p kx 2 q k+1 +q k

and x 2 =1 /(Da 1 ), whence

D=p k+1 +p k(Da 1 )q k+1 +q k(Da 1 )

Rearranging, and equating rational and irrational parts yields

q k+1 a 1 q kp k = 0 p k+1 a 1 p kq kD = 0

Eliminating a 1 :

p kq k+1 +q kp k+1 +p k 2 Dq k 2 =0  

Theorem: If p,q is a solution of x 2 Dy 2 =±1 and p,q are coprime then p/q is a convergent of D.

Proof: If D>3 , then

pqD=1 (p+qD)q<1 2 q 2

and the result follows from a theorem on the accuracy of convergents. We can explicitly verify the cases D=2 ,3 .

Theorem: If the rth convergent of D gives a solution of x 2 Dy 2 =±1 then kr where k is the number of terms in the period of the expansion.

Proof: Define x k=[a k;a k+1 ,...]. It is enough to show x r+2 =x 2 when the rth convergent gives a solution of the Pell equation: if P,Q are the smallest positive integers such that P 2 DQ 2 =±1 , then from the previous theorem, P/Q is the Rth convergent for some R, and we would have x R+2 =x 2 , and also k=R (otherwise we would have a smaller solution than P,Q since x k+2 =x 2 ).

We replace ±1 with (1 ) r in the equation since odd convergents are less than D while even convergents are greater.

We have

D=p rx r+1 +p r1 q rx r+1 +q r1

which rearranges to

(p rDq r)x r+1 =p r1 +Dq r1

Applying p r 2 Dq r 2 =(1 ) r gives

x r+1 =D+(1 ) r(Dq rq r1 p rp r1 )

That is, x r+1 is D plus some integer. From our work on periodic continued fractions, we must have x 2 =x r+2  

Theorem: The expansion of D for a nonsquare positive integer D has the form

[a 1 ;a 2 ,a 3 ,a 4 ,...,a 4 ,a 3 ,a 2 ,2 a 1 ,...]

with a 2 ,a 3 ,...,2 a 1 repeating.

Proof: Considering the relationship between Euclid's algorithm and the computation of convergents, or directly from the recurrence relation, we have

q k+1 q k=[a k+1 ;a k,...,a 2 ]

In the proof of our first theorem on Pell equations, we found

q k+1 a 1 q kp k=0

if p k,q k is a solution. Since a 1 +p kq k=[2 a 1 ;a 2 ,...,a k], we have

[a k+1 ;a k,...,a 2 ]=[2 a 1 ;a 2 ,...,a k] 

If x,y and x,y are solutions to x 2 Dy 2 =±1 , observe x>x if and only if y>y. We use this in the following proof.

Theorem: If p,q is the smallest positive solution of the equation x 2 Dy 2 =±1 , then all positive solutions p n,q n are given by

(p+qD) n=p n+Dq n

where n is odd for when the minus sign is chosen, and any integer when the plus sign is chosen.

Proof: Since (pqD) n=p nDq n, we find (p 2 Dq 2 ) n=p n 2 Dq 2 , thus p n,q n indeed satisfies the equation if p,q does.

First suppose the plus sign is chosen, and we have a standard Pell equation. Suppose r,s is a solution such that

(p+qD) m<r+sD<(p+qD) m+1

for some m. Divide through by p m+q mD to obtain

1 <t+uD<p+qD

where t+uD=(r+sD)(p mq mD).

Replacing D with D and multiplying shows that t,u is a (not necessarily positive) solution of the Pell equation. If t,u>0 then we have a smaller positive solution, contradicting the minimality of p,q.

We have t>0 because r>sD and p m>q mD, as they are solutions of the Pell equation. We observe u has the same sign as

(p msq mr)(p ms+q mr)=p m 2 s 2 q m 2 r 2 =s 2 (Dq m 2 +1 )q m 2 (Ds 2 +1 )=s 2 q m 2

Since s>q m we are done.

For the minus sign variant of the equation, we argue similarly, with m and m+2 where m is odd.