# Why does the solution of a Pell's equation equal zero?

A Pell's equation is given in the following way:

$nx^2 + 1 = y^2$

According to mathematical rules and the website http://www-groups.dcs.st-and.ac.uk/~history/HistTopics/Pell.html it can also be written like this:

$y^2 - nx^2 = 1$

The equation Bhaskara II uses as an example is:

$y^2 - 61x^2 = 1$

So you have to find x and y. A solution I found was $x = 226153980, y = 1766319049$. I tested the correctness of the result with the first version of the Pell's equation (see above):

$61x^2 + 1 = y^2$

$61 * 226153980 + 1 = 1766319049^2 \Rightarrow y = 1766319049$

So the result is correct. Now let's try it with the second way of writing it:

$y^2 - 61x^2 = 1$

$1766319049^2 - 61 * 226153980^2 = 0 \neq 1$ (According to Google)

So the first equation proves the correctness and the second one? What's wrong with my logic or approach that the obviously correct solution equals 0?

-
–  deinst Dec 12 '11 at 15:48
Looks like a google rounding error. –  Thomas Andrews Dec 12 '11 at 15:48
Yes, it looks like google isn't doing arbitrary-precision arithmetic - if you just enter "61*226153980^2," it gives a response of $3.11988298 × 10^{18}$. –  Thomas Andrews Dec 12 '11 at 15:54
Thank you! It really seems like the precision arithmetic is the problem here. My little C++ program also confirmed me that the result is 1. However, it's always nice to learn things. And this time I learned: Don't trust Google or the calculator for big numbers. ;) –  Paul Engstler Dec 12 '11 at 15:56
@Paul Engstler: If we casually use a calculator or computer to subtract two large nearly equal numbers, the answer cannot be trusted. –  André Nicolas Dec 12 '11 at 18:26

Well, it seems Google is wrong, for if I paste the same line in my haskell interpreter, I get 1. Although I'm surprised about it, it probably means google does some rounding when numbers get too large.

-
I just tested it with Python and my calculator. Python fails completely (probably it misinterprets the results data type) and my calculator shows 0. I'm going to test it now with C++. –  Paul Engstler Dec 12 '11 at 15:52
I wonder which version of Python you are using and what statement you are executing? On Python 2.6.1, 17663190492 - 61*2261539802 gives the correct result 1L. –  user12861 Dec 12 '11 at 17:48
@Paul: Maybe you used ^ in Python, it means xor (not exponentiation) –  sdcvvc Dec 12 '11 at 19:03
Yes, I tested it some minutes later with pow. That worked. I know that "^" exists in other languages. But whatever. Thank you. :) –  Paul Engstler Dec 12 '11 at 20:05

It should be easy to see that Google is wrong in this instance by looking at the last digit of what your answer should be. The first number ends in 9 which, when squared, will end in 1. And you're subtracting a multiple of 10. So just by simple inspection, the answer should have a last digit of 1.

-

I did not notice this one at the time. Start with $$29718^2 - 61 \cdot 3805^2 = -1.$$ Then use this version of BRAHMAGUPTA'S IDENTITY that is easily verified by hand, $$\left( a^2 - 61 b^2 \right)^2 = \left( a^2 + 61 b^2 \right)^2 - 61 \left( 2 a b\right)^2,$$ using $$a = 29718, \; \; b = 3805.$$ We find $$a^2 + 61 b^2 = 1,766,319,049$$ and $$2 a b = 226,153,980.$$ So $$1766319049^2 - 61 \cdot 226153980^2 = \left( -1 \right)^2 = 1$$ after erasing the commas.

-