# Methods for solving Pell's equation?

It is known that the minimum solution of Pell's equation $x^2-dy^2=\pm1$ can be found from the continued fraction expansion of $\sqrt d$. Are there other methods for finding the minimum (or any other) solutions?

-
I've done some editing here, I hope I have captured the spirit. – Gerry Myerson Dec 4 '10 at 5:40
I occasionally have to solve a Pell equation, and my method is almost invariably this: I fire up pari and just loop over the positive integers searching for some! The computer almost always finds two or three almost instantly, from which I can read off the fundamental unit and the degree 2 recurrence relation generating the solutions! – Kevin Buzzard Dec 4 '10 at 8:17
I guess my method would be called "Brute force and Ignorance". Given the speed of modern computers, there's a lot to be said for it. – Kevin Buzzard Dec 4 '10 at 9:51
Step 1. Build a scalable fault-tolerant quantum computer. Step 2. Use the algorithm of Hallgren: Polynomial-time quantum algorithms for Pell's equation and the principal ideal problem, STOC, 2002. Step 3: profit! – Steve Huntsman Dec 4 '10 at 12:41
Just ran across this thread. I confess to using Kevin's usual method too on occasion, but if you're already firing up pari you should use its built-in function quadunit(x) (taking x=4d). Try telling gp for(d=1,100,if(!issquare(d),print([d,(quadunit(4*d))]))) – Noam D. Elkies May 28 '11 at 4:30

The basic and classical methods, apart from brute force, are

• continued fraction expansions (regular, nearest integer, etc.) or, equivalently, some form of reduction theory for indefinite binary quadratic forms;

• computing many elements of small norm in a quadratic number field, which often is a lot more effective; the technique used here is also used for factoring integers.

For a detailed algorithmic description see Jacobson & Williams (Solving the Pell Equation) or Buchmann & Vollmer (Binary Quadratic Forms).

In addition, you can compute a power of the fundamental unit from the class number formulas, which essentially consists in taking norms of suitable cyclotomic units. Kronecker has shown how to solve the Pell equation using elliptic and modular functions, and Girstmair (Kronecker's solution of the Pell equation on a computer {Kroneckers Lösung der Pellschen Gleichung auf dem Computer], Math. Semesterber. 53, 45-64 (2006)) has shown that it can be made to work in practice.

You can also imitate the theory of descent on elliptic curves; I have sketched connections with classical tricks in some preprints on higher descent on Pell conics.

-

Another nice reference on this problem (and non-CF methods to solve it) is Lenstra's 2002 notices survey, "Solving the Pell Equation".

-

Any algorithm for computing fundamental units of a real quadratic number field $\mathbb{Q}(\sqrt{D})$ can be used for solving Pell's equation. (You might have to do a bit of work to convert the result, but that can be done in polynomial time...)

See for example M. Jacobson, H. Williams: Solving the Pell Equation. Springer, 2009.

-

It is really the same method, but see my answer at

The one thing I would add here is that, if the main concern is the length of the period, the continued fraction digits are the absolute values of my $\delta$'s, so sometimes the continued fraction period is half the cycle length.

-

Just to add another method to the collection: Let $\Delta = \sigma + 4 m$, be the fundamental discriminant of a quadratic field, where $\sigma \in \{ 0, 1 \}$. Let $(x / z , y / z)$ be a rational solution of the Pell conic $x^2 + \sigma x y - m y^2 = 1$, with $\text{gcd}(x, y) = 1$, and let $\beta \equiv x \cdot y^{-1} \pmod{z}$. Assume that $q_1 = (t_1, u_1)$, $q_2 = (t_2, u_2)$ satisfy $z t^2 + (2 \beta + \sigma ) t u + \frac{\beta^2 + \sigma \beta - m}{z} u^2 = 1$ in rational integers, then $\nu (q_2 , q_1 ) =$ I am trying to write a matrix times a vector: $(z t_1 + (\beta + \sigma ) u_1, \beta t_1 + \frac{\beta^2 + \sigma \beta - m}{z} u_1,- u_1,t_1 ) (t_2, u_2)$ satisfies the Pell conic in rational integers. I learned about the map $\nu$ from Franz Lemmermeyer, his articles and book `Binary quadratic forms'. There is a bijection between the integer points $(t, u)$ and the primitive integer points $(T, U)$ of $z T^2 + (2 x + \sigma y) T U + z U^2 = y^2$. Given a primitive integer point $(T, U)$, we also have a primitive integer point $(U, T)$. Using this bijection, given an integer point $(t_1, u_1)$, we obtain another point $(t_2, u_2) = (\kappa t_1 + \kappa' u_1, y t_1 - \kappa u_1)$, where $\kappa = \frac{x - \beta y}{z}$, and $\kappa' = \frac{(2 \beta + \sigma ) x - (\beta^2 + m ) y}{z^2}$. The points $(t_1, u_1), (t_2, u_2)$ are used with $\nu$ to obtain an integer point of the Pell conic. In particular, letting $\gamma = \frac{\beta^2 + \sigma \beta - m}{z}$, $( x t^2 + (z \kappa' + \sigma \kappa + y \gamma ) t u + ((\beta + \sigma ) \kappa' - \kappa \gamma ) u^2, y t^2 - 2 \kappa t u - \kappa' u^2 )$. One must check that $T \not= U$, equivalently that $y t \not= (\kappa + 1) u$, for otherwise this method will not work. This follows from "Arithmetic of Pell surfaces", Acta Arith., 146, (2011), no. 1, 1--12.

-