You are on page 1of 8

Pell’s equations

Written by Dmitry Badziahin for the MaPS Correspondence Program

Introduction
Consider the following Diophantine equation (Recall: Diophantine equations are equations where
all solutions are required to be integers).
Example 1.
x2 − 2y 2 = 1. (∗)
First of all, notice that it is enough to only consider its non-negative solutions because if (x, y)
is a solution then (±x, ±y) are automatically solutions too.
By playing a little bit with the equation, we can find small solutions: (x, y) = (1, 0), (3, 2). By
playing a bit more, we may find a slightly bigger solution (17, 12), enthusiastic searchers will find
an even bigger pair (99, 70). This data gives us some evidence that probably the equation has
infinitely many solutions and that they are quite rare. But of course, before we can state this for
sure, it needs to be rigorously verified.
The equation (∗) from the first example is a particular case of Pell’s equations. They were first
mentioned in ancient India and Greece around 400BC. The first method to solve Pell’s equations
was found by Indian mathematicians Brahmagupta and Bhaskara in the 12th century. Later, in
the 17th century it was rediscovered in Europe with works of Fermat, Euler and Lagrange. Finally,
the complete theory of Pell’s equations was developed by Lagrange in 1766–1769.
Definition 1. The Diophantine equation

x2 − dy 2 = 1,

where d is an integer parameter which is not a perfect square, is called the Pell’s equation.
Definition 2. By generalised Pell’s equation we call the equation of the form

x2 − dy 2 = k

where d, k are integer parameters and d is not a perfect square.


As we will see, to find a complete solution of the Pell’s equations we need to get some knowledge
from several branches of Mathematics, including algebraic number theory and Diophantine
approximation.
Exercise 1. This exercise shows that for perfect squares d, the Pell’s equation is much easier to
solve and its solutions behave completely differently to the case when d is not a perfect square.
Find all integer solutions of the equation

x2 − 4y 2 = 45.

1
Bits of algebraic number theory

Consider the set of quadratic surds a + b 2, where a and b are integers. Or, written formally,
√ √
Z[ 2] := {a + b 2 : a, b ∈ Z}.

Notice that we can add, subtract and multiply numbers from Z[ 2] and still get the results
from the same set. Indeed,
√ √ √
(a1 + b1 2) + (a2 + b2 2) = (a1 + a2 ) + (b1 + b2 ) 2;
√ √ √
(a1 + b1 2)(a2 + b2 2) = (a1 a2 + 2b1 b2 ) + (a1 b2 + a2 b1 ) 2.

In other words, we can add, subtract and multiply numbers from Z[ 2], like we do with integer
numbers! By the way, the sets which can be equipped with an addition, subtraction and multi-
plication operations that share the same properties as integer numbers, are called rings. We will
dig deeper into them in one of the later√notes. In some cases we can divide one quadratic surd by
another and still get an element in Z[ 2], in the other cases we can not, again as in the case of
integer numbers. √ √
The upshot is: the set Z[ 2] of quadratic surds a + b 2 shares many properties with the set
Z of integers. However it has some extra interesting properties that integers do not have!
√ √ √
Definition 3. A conjugate of a number α = a + b 2 ∈ Z[ 2] is the number ᾱ = a − b 2.
If you are familiar with the complex numbers, you may compare this notion of conjugates with
the conjugates of complex numbers.
It appears that conjugate numbers satisfy some useful properties.
√ √
Property 1. For any two numbers α = a1 + a2 2 and β = b1 + b2 2 the following equations are
satisfied:
α + β = ᾱ + β̄;
αβ = ᾱβ̄.
Exercise 2. Verify these two properties of conjugate numbers
√ √
Definition 4. A norm of a number α = a + b 2 ∈ Z[ 2] is the number N (α) = α · ᾱ.
By expanding α, we get
√ √
N (α) = (a + b 2)(a − b 2) = a2 − 2b2 .

This equation shows us that firstly, N (α) is always integer and secondly, it looks suspiciously
similar to the left hand side of equation
√ (∗)! Therefore the problem from Example 1 can be
rephrased as follows: find all α ∈ Z[ 2] such that N (α) = 1. Now we are almost ready to generate
infinitely many solutions of that equation.

Proposition 1. For any α and β from Z[ 2] we have N (αβ) = N (α)N (β).
Proof. Indeed, one has

N (αβ) = αβαβ = αβ ᾱβ̄ = αᾱβ β̄ = N (α)N (β).

2

We have
√ already found√ that N (3 + 2 2) = 1 and this gives
√ us an infinite
√ series of solutions:
N ((3 + 2 2)n ) = N (3 + 2 2)n = 1n = 1! In particular, (3 +
√ 3 2 2)2
= 17 +
√ 12 2, which
√ gives us the

solution (17, 12) of (∗). Further computations give (3+2 2) = (17+12 2)(3+2 2) = 99+70 2
and hence (99, 70) is another solution of the equation. Generally, if (x, y) is a solution of (∗) then
we compute √ √ √
(x + y 2)(3 + 2 2) = (3x + 4y) + (3y + 2x) 2,
and therefore ((3x + 4y), (2x + 3y)) is also a solution of
√ (∗). √
Finally, notice that there is nothing
√ special about 2 in the
√ definition of Z[ 2] and the same
arguments will work for any set Z[ d] of quadratic surds a + b d where d is not a perfect square.
Exercise 3. Find an infinite series of integer solutions of the Diophantine equation

x2 − 10y 2 = 1.

Leaving no solutions behind


Now we know that if we find one solution of the Pell’s equation, we can generate an infinite series
of solutions. To complete the theory of Pell’s equations we need to establish two things:

1. Verify that we have enumerated all solutions of the equation;

2. Find one solution which will then allow us to generate all other solutions.

In this section we address the first problem. Our initial search of solutions of (∗) suggests that
the method from the previous section enumerates all solutions of that equation. But we still need
to rigorously verify it. √
The idea is: if a multiplication by 3 + 2 2 generates a bigger solution from already found
solution (x, y), then applying the inverse procedure should perhaps lead to a smaller solution. By
keeping this idea in mind, we will show that any solution (x, y) of (∗), where x and y are big
enough, must be generated from a smaller solution.
We first estimate: √ √
√ (x − y 2)(x + y 2) 1
x−y 2= √ = √ .
x+y 2 x+y 2
1
Denote its right hand side by  and observe that  < and  < x1 . In other words, we have that

y 2 √
the RHS is very close to zero and so
√ x/y is a√very good rational approximation of 2.
Now we use the equation (3 − 2 2)(3 + 2 2) = 1 to get:

x+y 2 √ √ √
√ = (x + y 2)(3 − 2 2) = (3x − 4y) + (3y − 2x) 2.
3+2 2
x−
Substitute y = √
2
into the first term to get

x− √ √
3x − 4y = 3x − 4 · √ = (3 − 2 2)x + 2 2.
2
This expression is always positive. Also it is less than x if
√ √ √ √
(3 − 2 2)x + 2 2 6 x ⇐⇒ 2 2 6 (2 2 − 2)x.

3
or (since  < x1 )

2 2 2
x > √ ≈ 3.414.
2 2−2
The conclusion from these calculations is; any solution (x, y) of (∗) with x > 2√can be generated
from another solution (x0 , y 0 ) with the smaller x0 by the multiplication by 3 + 2 2 process.
Now we are done! It is obvious that the only solution
√ of (∗)√in nonnegative (x, y) with x 6 1 is
(1, 0). For any other solution (x, y) we divide x + y 2 by 3 + 2 2 to generate smaller and smaller
solutions until we end up with the solution (x0 , y0 ), x0 6 1, which must√ nbe (1, 0). Therefore all
the solutions of this equations are generated from the numbers (3 + 2 2) , n ∈ N!
With enough care, the same calculations may be applied to any Pell’s equation x2 − dy 2 = 1
and the following statement may be verified:
Proposition 2. Let d be a positive integer which is not a perfect square. Let (x1 , y1 ) be the solution
of x2 − dy 2 = 1 with the smallest possible x1 such
√ that x1 > 1. Then all solutions of this Pell’s
equation are generated by the numbers (x1 + y1 d)n , n ∈ N.
Exercise 4. Verify the proposition for the equation x2 − 3y 2 = 1, i.e. find “the smallest” solution
(x√
1 , y1 ) of this equation and verify that all the other solutions are generated by the numbers (x1 +
y1 3)n , n ∈ N.

Generalised Pell’s equations


Consider the generalised Pell’s equations. Unlike the standard ones, they may or may not have
integer solutions. But if they have one solution there are infinitely many of them. A general hint
here would be to try look for one solution and if you are not successful, then try to show that the
equation has no solutions. Let’s look at a couple of examples.
Example 2. Solve the following equation in integer numbers:

x2 − 3y 2 = 2.

After checking small numbers and not finding a solution, let’s try to prove that the equation
has no solutions. A good technique here is the modular arithmetic. If we look at the equation
modulo 3, we derive
x2 ≡ 2 (mod 3).
A quick check (or Fermat’s Little Theorem) shows that there are no squares which are congruent
to 2 modulo 3. Therefore the equation does not have solutions. 
Exercise 5. Solve the following equations in integers:

x2 − 5y 2 = 2;

x2 − 11y 2 = 3.
Example 3. Solve the equation in integer numbers:

x2 − 2y 2 = 7. (∗∗)

4
A quick check reveals the solution (3, 1). After we find it, we can proceed in a similar way
as for the classical Pell’s equation
√ and present an infinite series of solutions! (x, y) is a solution
of (∗∗) if and only if N (x + y 2) = 7. But
√ √
N ((x + y 2)(3 + 2 2))
is also equal to 7. Therefore as before, ((3x + 4y), (2x + 3y)) is another solution of the equation.
This observation gives an infinite series of solutions (3, 1), (13, 9), (75, 53), (437, 309), . . .
As the next step, we need to check if this series exhausts all the solutions of the equation.
Warning: unlike the standard Pell’s equations, the extended ones may have several infinite series
of solutions, so it is always worth checking. Consider a solution (x, y). We get
√ 7
x − 2y = √ =: .
x + 2y
Observe that  < x7 . Now we compute

x+y 2 √
√ = (3x − 4y) + (3y − 2x) 2.
3+2 2
x−
As we saw before, for y = √
2
the term 3x − 4y is always positive and is less than x if
√ √
2 2 6 (2 2 − 2)x.
Since  < x7 , this implies

14 2
x2 > √ ≈ 23.899.
2 2−2
The conclusion is that any solution (x, y) of (∗∗) with x√> 5 can be generated from another solution
(x0 , y 0 ) with smaller x0 by the multiplication by 3 + 2 2 process. Manual search of the solutions
with x 6 4 gives us only one pair (x, y) = (3, 1).
It looks like we are done? Not really! Indeed, all pairs (x, y) are generated by (x0 , y 0 ) with
a smaller x0 . But what about y 0 , maybe it becomes negative? If that happens then (x, y) is not
generated by anything we wrote before. Let’s check:

0 (3 − 2 2)x − 3
y = 3y − 2x = √ .
2
We get y 0 > 0 if x > 3√
3−2 2
or in view of  < x7 , that follows from
21
x2 > √ ≈ 122.397.
3−2 2
Therefore in fact we need to manually check the solutions (x, y) with x up to 11. Doing that
reveals one more series of solutions: (5, 3), (27, 19), (157, 111), . . . 
Remark. In √fact, you can check that the solution (5, 3) is generated from (3, −1) by multipli-
cation by 3 + 2 2.
Exercise 6. Solve the equation in integers:
x2 − 10y 2 = 9.
Exercise 7. An integer number is called a triangle number if it can be written as m(m+1) 2
for
some positive integer m. An integer number is called a square number if it can be written as m2
for some positive integer m. Show that there are infinitely many integers which are triangular and
square at the same time.

5
Extension. Finding the smallest solution of the Pell’s equation
Now, the remaining thing is to find “the smallest” solution of the Pell’s equation. For our model
equation (∗) that was easy. We very quickly found it by inspection. However, for some Pell’s
equations these solutions may become really huge. For example, the first non-trivial solution of

x2 − 61y 2 = 1

is (1766319049, 226153980) which is impossible to find by inspection (at least without computer
assistance). Moreover, for the moment we even do not know if such a solution exists at all. Maybe
for some values of d there are no non-trivial solutions of the Pell’s equation?
In fact, one can show that nontrivial solutions of pell’s equations always exist. Moreover there
are methods which allow to find the solutions like one for d = 61, with pen and paper. Here we
only outline the steps of how to do that. The rigorous proofs would require us to dig into the
theory of Diophantine approximation and continued fractions. We encourage enthusiastic readers
to explore this theory themselves.
Example 4. Find a pair of positive integers x, y such that

x2 − 13y 2 = 1.
√ √
The key point here is an observation: since we have (x − 13y)(x + 13y) = 1 then
√ 1
x− 13y = √
x+ 13y
In other words,
x √

1 1
y(x + √13y) < √13y 2 .
− 13 =
y

In other words, x/y is a very good rational approximation of 13. Such a good
√ rational approxi-
mations can be found with help of the continued fraction expansion of 13.
The continued fraction expansion of a real number x is an expression of the form
1
x = a0 + . (◦)
1
a1 + 1
a2 + a3 +···

where a0 is integer and all other terms a1 , a2 , . . . , an , . . . , are positive integers. For convenience,
we denote this expansion by [a0 ; a1 , a2 , . . .]. The terms a0 , a1 , . . . are called partial quotients of
x. √
Let’s compute the continued fraction expansion √ of 13. The fraction on the right hand side
of (◦) is clearly smaller than 1, therefore a0 = [ 13] = 3. Then we compute
√ √
1 13 + 3 13 + 3
[a1 ; a2 , a3 , . . .] = √ = √ √ = .
13 − 3 ( 13 − 1)( 13 + 3) 4

13+3
We transform our problem to finding a continued fraction expansion of 4
and can proceed as
before. "√ # √ √
13 + 3 13 + 3 13 − 1
a1 = = 1; −1= ;
4 4 4

6
√ √
4 4( 13 + 1) 13 + 1
[a2 ; a3 , a4 , . . .] = √ = = ;
13 − 1 12 3
"√ # √ √
13 + 1 13 + 1 13 − 2
a2 = = 1; −1= ;
3 3 3
√ √
3 3( 13 + 2) 13 + 2
[a3 ; a4 , a5 , . . .] = √ = = ;
13 − 2 9 3
"√ # √ √
13 + 2 13 + 2 13 − 1
a3 = = 1; −1= ;
3 3 3
√ √
3 3( 13 + 1) 13 + 1
[a4 ; a5 , a6 , . . .] = √ = = ;
13 − 1 12 4
"√ # √ √
13 + 1 13 + 1 13 − 3
a4 = = 1; −1= ;
4 4 4

4 4( 13 + 3) √
[a5 ; a6 , a7 , . . .] = √ = = 13 + 3.
13 − 3 4
Now we compute that a5 = 6 and notice √ that the pattern starts repeating: [a6 ; a7 , a8 , . . .] =
[a1 ; a2 , a3 , . . .]. Therefore we can write 13 = [3; 1, 1, 1, 1, 6, 1, 1, 1, 1, 6, 1, 1, 1, 1, 6, . . .].
The same process applies to any other real number x.The resulting continued fraction expansion
may be finite or infinite. And of course it is not always periodic as in our case.
It is known that all very good rational approximations of x come from “cutting the tail” of its
continued fraction expansion. Formally, given x = [a0 ; a1 , a2 , . . . , ], the n’th convergent of x is
a rational number
pn
cn = = [a0 ; a1 , . . . , an ].
qn

Let’s find the convergents of 13:
1
c0 = [3] = 3; c1 = [3; 1] = 3 + = 4;
1
1 7
c2 = [3; 1, 1] = 3 + 1 = .
1+ 1
2
Computing further convergents in this way becomes quite cumbersome. But luckily, there is a
quicker way.
Theorem 1. The numerators pn and denominators qn of the convergents of x = [a0 ; a1 , a2 , . . .]
can be computed by the following recurrent formulae:
p−1 = 1; p0 = a0 ; pn+1 = an+1 pn + pn−1 ;
q−1 = 0; q0 = 1; qn+1 = an+1 qn + qn−1 .
Equipped with this theorem, we can quickly compute many convergents. We write the results
in the following table:
an 3 1 1 1 1 6 1 1 1 1
pn 3 4 7 11 18 119 137 256 393 649
qn 1 1 2 3 5 33 38 71 109 180

7
Theorem 2 (Legendre). If

x − p 1
< 2
q 2q
p
then q
is a convergent of x.

Recall that the solution (x, y) of our Pell’s equation satisfies 13 − xy < √13y 1
2 therefore

Legendre
√ theorem applies. It is sufficient to search for solutions (x, y) among the convergents of
13. In other words, the solutions of the Pell’s equation x2 − 13y 2 = 1 are among entries of the
table above for pn , qn . The good thing about that table is that the entries pn and qn grow very
quickly, therefore instead of checking hundreds, thousands or even millions or more pairs (x, y) we
are left with dozens of candidates.
Finally, we check the candidates (pn , qn ) from the table above and get 6492 − 13 · 1802 = 1.
That gives us the solution (649, 180). 
Remark.
√ One could find the solution
√ (649, 180) slightly quicker
√ by noticing that
N (18 + 5 13) = −1. Then N ((18 + 5 13)2 ) = N (649 + 180 13) = (−1)2 = 1.
Exercise 8. Show that the Pell’s equation

x2 − dy 2 = 1

always has a solution in positive integer (x, y). You may use the following property of convergents:
for all α ∈ R and for all convergents pn /qn of α,

α − pn < 1 .

qn qn2

You might also like