Pell's equation for n = 2 and six of its integer solutions
Pell's equation is any Diophantine equation of the form

x^2ny^2=1\,
where n is a given positive nonsquare integer and integer solutions are sought for x and y. In Cartesian coordinates, the equation has the form of a hyperbola; solutions occur wherever the curve passes through a point whose x and y coordinates are both integers, such as the trivial solution with x = 1 and y = 0. Joseph Louis Lagrange proved that, as long as n is not a perfect square, Pell's equation has infinitely many distinct integer solutions. These solutions may be used to accurately approximate the square root of n by rational numbers of the form x/y.
This equation was first studied extensively in ancient India, starting with Brahmagupta, who developed the chakravala method to solve Pell's equation and other quadratic indeterminate equations in his Brahma Sphuta Siddhanta in 628, about a thousand years before Pell's time. His Brahma Sphuta Siddhanta was translated into Arabic in 773 and was subsequently translated into Latin in 1126. Bhaskara II in the 12th century and Narayana Pandit in the 14th century both found general solutions to Pell's equation and other quadratic indeterminate equations. Solutions to specific examples of the Pell equation, such as the Pell numbers arising from the equation with n = 2, had been known for much longer, since the time of Pythagoras in Greece and to a similar date in India. The name of Pell's equation arose from Leonhard Euler's mistakenly attributing its study to John Pell.^{[1]} Euler was aware of the work of Lord Brouncker, the first European mathematician to find a general solution of the equation, but apparently confused Brouncker with Pell.
For a more detailed discussion of much of the material here, see Lenstra (2002) and Barbeau (2003).
History
As early as 400 BC in India and Greece, mathematicians studied the numbers arising from the n = 2 case of Pell's equation,

x^2  2y^2=1
and from the closely related equation

x^2  2y^2 = 1
because of the connection of these equations to the square root of two.^{[2]} Indeed, if x and y are positive integers satisfying this equation, then x/y is an approximation of √2. The numbers x and y appearing in these approximations, called side and diameter numbers, were known to the Pythagoreans, and Proclus observed that in the opposite direction these numbers obeyed one of these two equations.^{[2]} Similarly, Baudhayana discovered that x = 17, y = 12 and x = 577, y = 408 are two solutions to the Pell equation, and that 17/12 and 577/408 are very close approximations to the square root of two.
Later, Archimedes approximated the square root of 3 by the rational number 1351/780. Although he did not explain his methods, this approximation may be obtained in the same way, as a solution to Pell's equation.^{[2]}
Around AD 250, Diophantus considered the equation

a^2 x^2+c=y^2,
where a and c are fixed numbers and x and y are the variables to be solved for. This equation is different in form from Pell's equation but equivalent to it. Diophantus solved the equation for (a,c) equal to (1,1), (1,−1), (1,12), and (3,9). AlKaraji, a 10thcentury Persian mathematician, worked on similar problems to Diophantus.
In Indian mathematics, Brahmagupta discovered that

(x_1^2  Ny_1^2)(x_2^2  Ny_2^2) = (x_1x_2 + Ny_1y_2)^2  N(x_1y_2 + x_2y_1)^2 = (x_1x_2  Ny_1y_2)^2  N(x_1y_2  x_2y_1)^2
(see Brahmagupta's identity). Using this, he was able to "compose" triples (x_1, y_1, k_1) and (x_2, y_2, k_2) that were solutions of x^2  Ny^2 = k, to generate the new triple

(x_1x_2 + Ny_1y_2 \,,\, x_1y_2 + x_2y_1 \,,\, k_1k_2) and (x_1x_2  Ny_1y_2 \,,\, x_1y_2  x_2y_1 \,,\, k_1k_2).
Not only did this give a way to generate infinitely many solutions to x^2  Ny^2 = 1 starting with one solution, but also, by dividing such a composition by k_1k_2, integer or "nearly integer" solutions could often be obtained. For instance, for N=92, Brahmagupta composed the triple (10, 1, 8) (since 10^2  92(1^2) = 8) with itself to get the new triple (192, 20, 64). Dividing throughout by 64 gave the triple (24, 5/2, 1), which when composed with itself gave the desired integer solution (1151, 120, 1). Brahmagupta solved many Pell equations with this method; in particular he showed how to obtain solutions starting from an integer solution of x^2  Ny^2 = k for k = ±1, ±2, or ±4.^{[3]}
The first general method for solving the Pell equation (for all N) was given by Bhaskara II in 1150, extending the methods of Brahmagupta. Called the chakravala (cyclic) method, it starts by composing any triple (a,b,k) (that is, one which satisfies a^2  Nb^2 = k) with the trivial triple (m, 1, m^2  N) to get the triple (am + Nb, a+bm, k(m^2N)), which can be scaled down to

\left( \frac{am+Nb}{k} \,,\, \frac{a+bm}{k} \,,\, {m^2N} \right).
When m is chosen so that (a+bm)/k is an integer, so are the other two numbers in the triple. Among such m, the method chooses one that minimizes (m²N)/k, and repeats the process. This method always terminates with a solution (proved by Lagrange in 1768). Bhaskara used it to give the solution x=1766319049, y=226153980 to the notorious N = 61 case.^{[3]}
The general theory of Pell's equation, based on continued fractions and algebraic manipulations with numbers of the form P+Q\sqrt{a}, was developed by Lagrange in 1766–1769.^{[4]}
Solutions
Fundamental solution via continued fractions
Let \tfrac{h_i}{k_i} denote the sequence of convergents to the continued fraction for \sqrt{n}. Then the pair (x_{1},y_{1}) solving Pell's equation and minimizing x satisfies x_{1} = h_{i} and y_{1} = k_{i} for some i. This pair is called the fundamental solution. Thus, the fundamental solution may be found by performing the continued fraction expansion and testing each successive convergent until a solution to Pell's equation is found.
As Lenstra (2002) describes, the time for finding the fundamental solution using the continued fraction method, with the aid of the Schönhage–Strassen algorithm for fast integer multiplication, is within a logarithmic factor of the solution size, the number of digits in the pair (x_{1},y_{1}). However, this is not a polynomial time algorithm because the number of digits in the solution may be as large as √n, far larger than a polynomial in the number of digits in the input value n (Lenstra 2002).
Additional solutions from the fundamental solution
Once the fundamental solution is found, all remaining solutions may be calculated algebraically as

x_k + y_k \sqrt n = (x_1 + y_1 \sqrt n)^k.
Equivalently, we may calculate subsequent solutions via the recurrence relations

\displaystyle x_{k+1} = x_1 x_k + n y_1 y_k,

\displaystyle y_{k+1} = x_1 y_k + y_1 x_k.
An alternative method to solving, once finding the first nontrivial solution, one could take the original equation x^2  ny^2 = 1 and factor the left hand side as a difference of squares, yielding (x + y\sqrt n)(x  y\sqrt n) = 1. Once in this form, one can simply raise each side of the equation to the kth power, and recombining the factored form to a single difference statement. The solution s will be of the form (xs)^k + n\cdot(ys)^k = 1.
Concise representation and faster algorithms
Although writing out the fundamental solution (x_{1},y_{1}) as a pair of binary numbers may require a large number of bits, it may in many cases be represented more compactly in the form

x_1+y_1\sqrt n = \prod_{i=1}^t (a_i + b_i\sqrt n)^{c_i}
using much smaller coefficients a_{i}, b_{i}, and c_{i}.
For instance, Archimedes' cattle problem may be solved using a Pell equation, the fundamental solution of which has 206545 digits if written out explicitly. However, instead of writing the solution as a pair of numbers, it may be written using the formula

x_1+y_1\sqrt n=u^{2329},
where

u = x'_1+y'_1\sqrt{4729494} \, = x'_1+y'_1\sqrt{609\cdot7766} \,
and \scriptstyle x'_1 and \scriptstyle y'_1 only have 45 and 41 decimal digits, respectively. Alternatively, one may write even more concisely

u = (300426607914281713365\sqrt{609}+84129507677858393258\sqrt{7766})^2.
(Lenstra 2002).
In fact, it equivalent to solve the Pell equation x^24729494y^2=1.
Methods related to the quadratic sieve approach for integer factorization may be used to collect relations between prime numbers in the number field generated by √n, and to combine these relations to find a product representation of this type. The resulting algorithm for solving Pell's equation is more efficient than the continued fraction method, though it still does not take polynomial time. Under the assumption of the generalized Riemann hypothesis, it can be shown to take time

\exp O(\sqrt{\log N\log\log N}),
where N = log n is the input size, similarly to the quadratic sieve (Lenstra 2002).
Quantum algorithms
Hallgren (2007) showed that a quantum computer can find a product representation, as described above, for the solution to Pell's equation in polynomial time. Hallgren's algorithm, which can be interpreted as an algorithm for finding the group of units of a real quadratic number field, was extended to more general fields by Schmidt & Völlmer (2005).
Example
As an example, consider the instance of Pell's equation for n = 7; that is,

x^2  7 y^2 = 1
The sequence of convergents for the square root of seven are

h / k (Convergent)

h^{2} −7k^{2} (Pelltype approximation)

2 / 1

−3

3 / 1

+2

5 / 2

−3

8 / 3

+1

Therefore, the fundamental solution is formed by the pair (8, 3). Applying the recurrence formula to this solution generates the infinite sequence of solutions

(1, 0); (8, 3); (127, 48); (2024, 765); (32257, 12192); (514088, 194307); (8193151, 3096720); (130576328, 49353213); ... (sequence A001081 (x) and A001080 (y) in OEIS)
The smallest solution can be very large. For example, the least solution to x^2313y^2 = 1 is (32188120829134849, 1819380158564160), and this is the equation which Frenicle challenged Wallis to solve.^{[5]} (For the records, see A033316 (n), A033315 (x), and A033319 (y))
The smallest solution of Pell equations
The following is a list of the smallest solution to x^{2}  ny^{2} = 1 with n ≤ 128. For square n, there are no solutions except (1, 0). (sequence A002350 (x) and A002349 (y) in OEIS, or A033313 (x) and A033317 (y) (for nonsquare n))
n

x

y

n

x

y

n

x

y

n

x

y

1





33

23

4

65

129

16

97

62809633

6377352

2

3

2

34

35

6

66

65

8

98

99

10

3

2

1

35

6

1

67

48842

5967

99

10

1

4





36





68

33

4

100





5

9

4

37

73

12

69

7775

936

101

201

20

6

5

2

38

37

6

70

251

30

102

101

10

7

8

3

39

25

4

71

3480

413

103

227528

22419

8

3

1

40

19

3

72

17

2

104

51

5

9





41

2049

320

73

2281249

267000

105

41

4

10

19

6

42

13

2

74

3699

430

106

32080051

3115890

11

10

3

43

3482

531

75

26

3

107

962

93

12

7

2

44

199

30

76

57799

6630

108

1351

130

13

649

180

45

161

24

77

351

40

109

158070671986249

15140424455100

14

15

4

46

24335

3588

78

53

6

110

21

2

15

4

1

47

48

7

79

80

9

111

295

28

16





48

7

1

80

9

1

112

127

12

17

33

8

49





81





113

1204353

113296

18

17

4

50

99

14

82

163

18

114

1025

96

19

170

39

51

50

7

83

82

9

115

1126

105

20

9

2

52

649

90

84

55

6

116

9801

910

21

55

12

53

66249

9100

85

285769

30996

117

649

60

22

197

42

54

485

66

86

10405

1122

118

306917

28254

23

24

5

55

89

12

87

28

3

119

120

11

24

5

1

56

15

2

88

197

21

120

11

1

25





57

151

20

89

500001

53000

121





26

51

10

58

19603

2574

90

19

2

122

243

22

27

26

5

59

530

69

91

1574

165

123

122

11

28

127

24

60

31

4

92

1151

120

124

4620799

414960

29

9801

1820

61

1766319049

226153980

93

12151

1260

125

930249

83204

30

11

2

62

63

8

94

2143295

221064

126

449

40

31

1520

273

63

8

1

95

39

4

127

4730624

419775

32

17

3

64





96

49

5

128

577

51

Connections
Pell's equation has connections to several other important subjects in mathematics.
Algebraic number theory
Pell's equation is closely related to the theory of algebraic numbers, as the formula

x^2  n y^2 = (x + y\sqrt n)(x  y\sqrt n)
is the norm for the ring \mathbb{Z}[\sqrt{n}] and for the closely related quadratic field \mathbb{Q}(\sqrt{n}). Thus, a pair of integers (x, y) solves Pell's equation if and only if x + y \sqrt{n} is a unit with norm 1 in \mathbb{Z}[\sqrt{n}]. Dirichlet's unit theorem, that all units of \mathbb{Z}[\sqrt{n}] can be expressed as powers of a single fundamental unit (and multiplication by a sign), is an algebraic restatement of the fact that all solutions to the Pell equation can be generated from the fundamental solution. The fundamental unit can in general be found by solving a Pelllike equation but it does not always correspond directly to the fundamental solution of Pell's equation itself.
Chebyshev polynomials
Demeyer (2007) mentions a connection between Pell's equation and the Chebyshev polynomials: If T_{i} (x) and U_{i} (x) are the Chebyshev polynomials of the first and second kind, respectively, then these polynomials satisfy a form of Pell's equation in any polynomial ring R[x], with n = x^{2} − 1:

T_i^2  (x^21) U_{i1}^2 = 1. \,
Thus, these polynomials can be generated by the standard technique for Pell equations of taking powers of a fundamental solution:

T_i + U_{i1} \sqrt{x^21} = (x + \sqrt{x^21})^i. \,
It may further be observed that, if (x_{i},y_{i}) are the solutions to any integer Pell equation, then x_{i} = T_{i} (x_{1}) and y_{i} = y_{1}U_{i − 1}(x_{1}) (Barbeau, chapter 3).
Continued fractions
A general development of solutions of Pell's equation x^2ny^2 = 1 in terms of continued fractions for \sqrt{n} can be presented, as the solutions x and y are approximates to the square root of n and thus are a special case of continued fraction approximations for quadratic irrationals.
The relationship to the continued fractions implies that the solutions to Pell's equation form a semigroup subset of the modular group. Thus, for example, if p and q satisfy Pell's equation, then

\begin{pmatrix} p & q \\ nq & p \end{pmatrix}
is a matrix of unit determinant. Products of such matrices take exactly the same form, and thus all such products yield solutions to Pell's equation. This can be understood in part to arise from the fact that successive convergents of a continued fraction share the same property: If p_{k−1}/q_{k−1} and p_{k}/q_{k} are two successive convergents of a continued fraction, then the matrix

\begin{pmatrix} p_{k1} & p_{k} \\ q_{k1} & q_{k} \end{pmatrix}
has determinant (−1)^{k}.
Størmer's theorem applies Pell equations to find pairs of consecutive smooth numbers. As part of this theory, Størmer also investigated divisibility relations among solutions to Pell's equation; in particular, he showed that each solution other than the fundamental solution has a prime factor that does not divide n.
As Lenstra (2002) describes, Pell's equation can also be used to solve Archimedes' cattle problem.
The negative Pell equation
The negative Pell equation is given by

x^2  ny^2 = 1 (eq.1)
It has also been extensively studied; it can be solved by the same method of using continued fractions and will have solutions when the period of the continued fraction has odd length. However we do not know which roots have odd period lengths so we do not know when the negative Pell equation is solvable. But we can eliminate certain n since a necessary but not sufficient condition for solvability is that n is not divisible by a prime of form 4m+3. Thus, for example, x^{2}3py^{2} = 1 is never solvable, but x^{2}5py^{2} = 1 may be, such as when p = 13 or 17 (of course, p needs to be with the form 4m+1), though not when p = 41.
Number n which x^{2}ny^{2} = 1 is solvable are

1, 2, 5, 10, 13, 17, 26, 29, 37, 41, 50, 53, 58, 61, 65, 73, 74, 82, 85, 89, 97, 101, 106, 109, 113, 122, 125, 130, 137, 145, 149, 157, 170, 173, 181, 185, 193, 197, 202, 218, 226, 229, 233, 241, 250, ... (sequence A031396 in OEIS)
The solutions of x (while n is in this sequence) are listed in A130226.
These ns are divisible neither by 4 nor by a prime of the form 4m + 3, but these conditions are not sufficient  the counterexamples are listed in A031398. In fact, if and only if the period length of the continued fraction for \sqrt{n} ( A003285) is odd, than x^{2}ny^{2} = 1 is solvable.
Cremona & Odoni (1989) demonstrate that the proportion of squarefree n divisible by k primes of the form 4m+1 for which the negative Pell equation is solvable is at least 40%. If it does have a solution, then it can be shown that its fundamental solution leads to the fundamental one for the positive case by squaring both sides of eq. 1,

(x^2  ny^2)^2 = (1)^2 \,
to get,

(x^2 + ny^2)^2  n(2xy)^2 = 1. \,
Or, since ny^{2} = x^{2}+1 from eq.1, then,

(2x^2 + 1)^2  n(2xy)^2 = 1 \,
showing that fundamental solutions to the positive case are bigger than those for the negative case.
Transformations
I. The related equation,

u^2  dv^2 = \pm 2 \, (eq.2)
can be used to find solutions to the positive Pell equation for certain d. Legendre proved that all primes of form d = 4m + 3 solve one case of eq.2, with the form 8m + 3 solving the negative, and 8m + 7 for the positive. Their fundamental solution then leads to the one for x^{2}−dy^{2} = 1. This can be shown by squaring both sides of eq. 2,

(u^2  dv^2)^2 = (\pm 2)^2 \,
to get,

(u^2 + dv^2)^2  d(2uv)^2 = 4. \,
Since dv^2 = u^2 \mp 2 from eq.2, then,

(2u^2 \mp 2)^2  d(2uv)^2 = 4 \,
or simply,

(u^2 \mp 1)^2  d(uv)^2 = 1 \,
showing that fundamental solutions to eq.2 are smaller than eq.1. For example, u^{2}3v^{2} = 2 is {u,v} = {1,1}, so x^{2} − 3y^{2} = 1 has {x,y} = {2,1}. On the other hand, u^{2} − 7v^{2} = 2 is {u,v} = {3,1}, so x^{2} − 7y^{2} = 1 has {x,y} = {8,3}.
II. Another related equation,

u^2  dv^2 = \pm 4 \, (eq.3)
can also be used to find solutions to Pell equations for certain d, this time for the positive and negative case. For the following transformations,^{[6]} if fundamental {u,v} are both odd, then it leads to fundamental {x,y}.
1. If u^{2} − dv^{2} = −4, and {x,y} = {(u^{2} + 3)u/2, (u^{2} + 1)v/2}, then x^{2} − dy^{2} = −1.
Ex. Let d = 13, then {u,v} = {3, 1} and {x,y} = {18, 5}.
2. If u^{2} − dv^{2} = 4, and {x,y} = {(u^{2} − 3)u/2, (u^{2} − 1)v/2}, then x^{2} − dy^{2} = 1.
Ex. Let d = 13, then {u,v} = {11, 3} and {x,y} = {649, 180}.
3. If u^{2} − dv^{2} = −4, and {x,y} = {(u^{4} + 4u^{2} + 1)(u^{2} + 2)/2, (u^{2} + 3)(u^{2} + 1)uv/2}, then x^{2} − dy^{2} = 1.
Ex. Let d = 61, then {u,v} = {39, 5} and {x,y} = {1766319049, 226153980}.
Especially for the last transformation, it can be seen how solutions to {u,v} are much smaller than {x,y}, since the latter are sextic and quintic polynomials in terms of u.
Notes

^ Lettre IX. Euler à Goldbach, dated August 10, 1750 in: P. H. Fuss, ed., Correspondance Mathématique et Physique de Quelques Célèbres Géomètres du XVIIIeme Siècle … (Mathematical and physical correspondence of some famous geometers of the 18th century), vol. 1, (St. Petersburg, Russia: 1843), pp. 3539 ; see especially page 37. From page 37: "Pro hujusmodi quaestionibus solvendis excogitavit D. Pell Anglus peculiarem methodum in Wallisii operibus expositam." (For solving such questions, the Englishman Dr. Pell devised a singular method [which is] shown in Wallis' works.)

^ ^{a} ^{b} ^{c} .

^ ^{}a ^{b}

^ "Solution d'un Problème d'Arithmétique", in , vol. 1, pp. 671–731, 1867.Oeuvres de LagrangeJ.A. Serret (Ed.),

^ Prime Curios!: 313

^ A Collection of Algebraic Identities: Pell Equations.
References

Barbeau, Edward J. (2003), Pell's Equation, Problem Books in Mathematics, SpringerVerlag, .

Whitford, Edward Everett (1912), The Pell equation (Phd Thesis), Columbia University

Cremona, John E.; Odoni, R. W. K. (1989), "Some density results for negative Pell equations; an application of graph theory", Journal of the London Mathematical Society. Second Series 39 (1): 16–28, .

Demeyer, Jeroen (2007), Diophantine Sets over Polynomial Rings and Hilbert’s Tenth Problem for Function Fields, Ph.D. thesis, .

. Originally published 1977.

Hallgren, Sean (2007), "Polynomialtime quantum algorithms for Pell’s equation and the principal ideal problem", Journal of the ACM 54 (1): Art. No. 4, .

.

Pinch, R. G. E. (1988), "Simultaneous Pellian equations", Math. Proc. Cambridge Philos. Soc. 103 (1): 35–46, .

Schmidt, A.; Vollmer, U. (2005), "Polynomial time quantum algorithm for the computation of the unit group of a number field", .

Wildberger, N.J., Divine Proportions : Rational Trigonometry to Universal Geometry, Wild Egg Books, Sydney, 2005.
Further reading
External links
This article was sourced from Creative Commons AttributionShareAlike License; additional terms may apply. World Heritage Encyclopedia content is assembled from numerous content providers, Open Access Publishing, and in compliance with The Fair Access to Science and Technology Research Act (FASTR), Wikimedia Foundation, Inc., Public Library of Science, The Encyclopedia of Life, Open Book Publishers (OBP), PubMed, U.S. National Library of Medicine, National Center for Biotechnology Information, U.S. National Library of Medicine, National Institutes of Health (NIH), U.S. Department of Health & Human Services, and USA.gov, which sources content from all federal, state, local, tribal, and territorial government publication portals (.gov, .mil, .edu). Funding for USA.gov and content contributors is made possible from the U.S. Congress, EGovernment Act of 2002.
Crowd sourced content that is contributed to World Heritage Encyclopedia is peer reviewed and edited by our editorial staff to ensure quality scholarly research articles.
By using this site, you agree to the Terms of Use and Privacy Policy. World Heritage Encyclopedia™ is a registered trademark of the World Public Library Association, a nonprofit organization.