# Pell's equation

Please enter a positive nonsquare integer $N$: ; or select one of the suggested values:

The fundamental solution to the Diophantine equation ${x}^{2}-{y}^{2}=1$ is given by $x =$ and $y =$.

Try entering the following equalities in your Javascript console:

Note that $\frac{x}{y}$ is a fractional approximation of $\sqrt{N}$ with $|xy−N|≤1y(x+⌊N⌋y)=1≤10−$

The continued fraction algorithm provides the best rational approximations of $\sqrt{N}$: $=$

In the previous formula, the same pattern is repeated indefinitely and the initial sequence is (incidentally, note that the first and last elements satisfy the equality $=2×$ while the other elements form a palindrome). The values of $x$ and $y$ above were actually obtained by truncating the continued fraction to $= = x y$

Alternatively, these values can be obtained by the Chrakravala method:

where the following rules are used:

• The integer square root of $N$ is defined as $⌊\sqrt{N}⌋$.
• Given integers $x_1,y_1,k_1,\lambda$ scaling down by $\lambda$ is done by $\left\{\left\{\left\{\left\{\left\{\left(\lambda x_1\right)\right\}^2 - N \left\{\left(\lambda y_1\right)\right\}^2\right\}\right\} = \left\{\lambda^2k_1\right\}\right\}\right\} \implies \left\{x_1^2 - Ny_1^2 = k_1\right\}$.
• Given integers $x_1,y_1,k_1,x_2,y_2,k_2$ the samāsa operation is applying Brahmagupta's identity: $\left\\left\{ \begin\left\{gathered\right\} \left\{x_1^2 - Ny_1^2 = k_1\right\} \\ \left\{x_2^2 - Ny_2^2 = k_2\right\} \end\left\{gathered\right\} \implies \left\{\left\{\left\left( x_1x_2 + \left\{Ny_1y_2\right\} \right\right)^2 - N\left\left(x_1y_2+x_2y_1\right\right)^2\right\} = \left\{k_1k_2\right\} \right\} \right.$
• In particular, given $x_1,y_1,k_1$, Bhaskara's minimization is to take $\left\{x_2 = m\right\}, \left\{y_2 = 1\right\}, \left\{k_2 = m^2 - N\right\}$ where $m > 0$ is chosen such that $\left\{\frac\left\{x_1+\left\{my_1\right\}\right\}\left\{k_1\right\}\right\} \in \mathbb Z$ and $\left|m^2 - N \right|$ is minimal.