# Integer solutions of $3a^2 - 2a - 1 = n^2$

I've got an equation $3a^2 - 2a - 1 = n^2$, where $a,n \in \mathbb{N}$.

I put it in Wolfram Alpha and besides everything else it gives integer solution: see here.

For another equation (say, $3a^2 - 2a - 2 = n^2$, where $a,n \in \mathbb{N}$) Wolfram Alpha does not provide integer solutions: here.

1. How does Wolfram Alpha determine existence of the integer solutions?
2. How does it find them?
3. What should I learn to be able to do the same with a pencil and a piece of paper (if possible)?

-
You should remember that generally the way to reduce a problem involving a quadratic polynomial with a first-degree term to a problem involving a quadratic polynomial with no first-degree term is completing the square. –  Michael Hardy Jul 21 '11 at 21:18

I believe Pell's Equation (and variants) would be useful.

The first one can be recast as

$$9a^2 - 6a - 3 = 3n^2$$ i.e.

$$(3a-1)^2 - 4 = 3n^2$$

You are looking for solutions to

$$x^2 - 3y^2 = 4$$ such that $x = -1 \mod 3$.

There are standard techniques to solve Pell's equation and variants (see the wiki page linked above and mathworld page here: http://mathworld.wolfram.com/PellEquation.html) and I am guessing Wolfram Alpha is using one of them.

For the second I believe we get

$$x^2 - 3y^2 = 7$$

which does not have solutions, considering modulo $4$ (as pointed out by Adrián Barquero).

-
Beat me to it! +1, this is perfect. –  Eric Naslund Jul 21 '11 at 18:43
That the quadratic equation $x^2 - 3y^2 = 7$ has no solutions in integers can be seen by reducing modulo $4$ also. –  Adrián Barquero Jul 21 '11 at 19:05
Thank you for your help! –  kishkin Jul 21 '11 at 19:22
@Adrian: Indeed... Thanks! –  Aryabhata Jul 21 '11 at 20:58

Lagrange showed how to reduce a general binary quadratic Diophatine equation to Pell form.

$$\rm a\ x^2 + b\ xy + c\ y^2 + d\ x + e\ y + f\ =\ 0$$

reduces to a Pell equation as follows: put $\rm\ D = b^2-4ac,\ E = bd-2ae,\ F = d^2-4af\:.\$ Then

$$\rm D\ Y^2\ =\ (D\ y + E)^2 + D\ F - E^2,\quad\quad Y\ =\ 2ax + by + d$$

Therefore if we put $\rm\quad\ \ X\: =\: D\ y + E,\quad\ \ N\: =\: E^2 - D\ F\quad\ \$ we obtain the Pell equation

$$\rm X^2 - D\ Y^2\ =\ N$$

Now you can apply standard techniques for solving Pell equations. They are a bit too complex to describe here. However, you can obtain complete step-by-step descriptions of the solution to any Pell equation using Dario Alpern's Quadratic two integer variable equation solver. For some recent optimizations of Lagrange's algorithm see this paper H. C. Williams et al. A new look at an old equation.

-
Thank you for mentioning Lagrange method. –  kishkin Jul 21 '11 at 19:22

The first one can also be easely reduced to pytagorean one:

$$3a^2 - 2a - 1= 4a^2-(a^2+2a+1) \,.$$

Thus

$$n^2+(a+1)^2=(2a)^2 \,.$$

-
This is an interesting observation, but it is not enough. The above Pythagorean equation is in fact a Pythagorean equation with a side condition, namely that $1$ more than half the hypotenuse is one of the legs. True, we have a method for generating the integer solutions of $x^2+y^2=z^2$. However, it may take substantial further work to satisfy the "side condition." –  André Nicolas Jul 21 '11 at 22:33