TITLE: When is $8x^2-4$ a square number?
QUESTION [16 upvotes]: I asked an earlier question on when $32x+32$ is a square number (here) and I got a very clear answer.
Now I am looking to solve for which $x$ the equation $8x^2-4$ results in a square number. When I am trying to solve it I get: $y^2=4(2x^2-1)$ so if we put $y=2w$ then $2x^2-1 = w^2$ and therefore $x=\sqrt{\frac{w^2+1}{2}}$ which is correct.
Only now I need to check when $\frac{w^2-1}{2}$ is a square which goes on recursively. I am looking for Integer solutions for $x$ and $w$. How can I solve this?

REPLY [3 votes]: Continued Fraction Approach
Suppose $2q^2-1=p^2$. Then
$$
\left(\sqrt2-\frac pq\right)\left(\sqrt2+\frac pq\right)=\frac1{q^2}\tag{1}
$$
Thus,
$$
\left|\sqrt2-\frac pq\right|\lt\frac1{2q^2}\tag{2}
$$
The only rational approximations that are this good are Continued Fraction approximations. The continued fraction for $\sqrt2$ is $(1;2,2,2,2,\dots)$. Using the table below, where each column below the line is the sum of the the number above that column times previous column plus the column preceding that:
$$
\begin{array}{c|c}
&&1&2&2&2&2&2&2\\\hline
0&1&1&3&7&17&41&99&239\\
1&0&1&2&5&12&29&70&169
\end{array}\tag{3}
$$
the first several convergents for this continued fraction are
$$
\color{#00A000}{\frac11},\frac32,\color{#00A000}{\frac75},\frac{17}{12},\color{#00A000}{\frac{41}{29}},\frac{99}{70},\color{#00A000}{\frac{239}{169}},\cdots\tag{4}
$$
Under- and over-estimates alternate, Thus, the green entries are under-estimates.
Since the numerators and denominators follow the recurrence
$$
(S^2-2S-1)a=0\tag{5}
$$
where $S$ is the shift operator $Sa_n=a_n+1$, and $(x^2-2x-1)(x^2+2x-1)=x^4-6x^2+1$, the numerators and denominators must also satisfy
$$
(S^4-6S^2+1)a=0\tag{6}
$$
Therefore, the recurrence for every other numerator and denominator is
$$
a_n=6a_{n-2}-a_{n-4}\tag{7}
$$

Thus, if we start out with $a_1=1$ and $a_2=5$, then compute successive terms with
  $$
a_n=6a_{n-1}-a_{n-2}\tag{8}
$$
  we get all integers so that $8a_n^2-4=4(2a_n^2-1)$ is a square.


Notes
$(1)$: If $q\ne0$, this is equivalent to $2q^2-1=p^2$.
$(2)$: Since $p\ge q$, we actually have $\left|\sqrt2-\frac pq\right|\le\frac1{(1+\sqrt2)q^2}\lt\frac1{2q^2}$. The claim about rational approximations is Theorem $5.6$ from this paper.
$(3)$: This table was generated as described in the preceding paragraph. It is simply using the Wallis Algorithm, in particular Corollary $2.2$, from this paper.
$(4)$: This list simply collects the convergents from table $(3)$ and colors the under-estimates green.
$(5)$: This equation is an operator-based restatement of $a_n=2a_{n-1}+a_{n-2}$.
$(6)$: Any sequence that satisfies the constraint in $(5)$ also satisfies this equation.
$(7)$: This is a restatement of $(6)$, which is a relation among every other element of the sequence. This gives us a recurrence on the numerators and denominators of the under-estimates.
$(8)$: Describe the sequence of denominators for the under-estimates.