\documentclass[a4paper]{article}
\usepackage{mathtools}
\usepackage{amsfonts}
\usepackage{listings}
\begin{document}
\title{Special Pythagorean Triples}
\author{Amit Yaron}
\date{Sep 25, 2024}
\maketitle
\begin{abstract}
A pythagorean triple is an ordered set of integers a,b,c such that
$a^2+b^2=c^2$ . Generating triples in which $c-b=1$ is easy. Another
type of a Pythagorean triple is that in which $b-a=1$. One of them is
$(a,b,c)=(20,21,29)$. In this article I will show a formula for those
triples.
\end{abstract}
\section{Let's Get Started}
Be a,b,c three positive integers, such that:\\
\[
\begin{cases}
a^2+b^2=c^2\\
b-a=1
\end{cases}
\]
The variable $b$ can be eliminated. so:\\
\begin{align}
&a^2+(a+1)^2=c^2\Rightarrow\nonumber\\
\Rightarrow & a^2+a^2+2a+1=c^2\Rightarrow\nonumber\\
\Rightarrow & 2a^2+2a+1=c^2\Rightarrow\nonumber\\
\Rightarrow & 4a^2+4a+2=2c^2\Rightarrow\nonumber\\
\Rightarrow & 4a^2+4a+1+1=2c^2\Rightarrow\nonumber\\
\Rightarrow & (2a+1)^2+1=2c^2\Rightarrow\nonumber\\
\Rightarrow & (2a+1)^2-2c^2=-1
\end{align}
Now, let us plug:
\[
\begin{cases}
x=2a+1\\
y=c
\end{cases}
\]
into (1), and we'll get that:
\begin{equation}x^2-2y^2=-1\end{equation}
Equation (2) is not Pell's equation for Pell's equation is:
\begin{equation*}x^2-ny^2=1\end{equation*}
Where $x,y$ are integer variables and $n$ is a non-square constant integer.
Equation (2) can be solved using the solutions of Pell's equation, and the
solutions are based on Brahmagupta's identity.
\section{Brahmagupta's Identity}
Brahmagupta's identity is:
\begin{align}
  (x^2-ny^2)(a^2-nb^2) &= a^2x^2-na^2y^2-nb^2x^2+n^2b^2y^2\nonumber\\
                       &= (ax)^2+(nby)^2-n(ay)^2-n(bx)^2\nonumber\\
                       &= (ax)^2+2abnxy+(nby)^2-n(ay)^2-2abnx-n(bx)^2\nonumber\\
                       &= (ax+bny)^2-n(ay+bx)^2
\end{align}
To put it in words, the result is a square minus $n$ times a square.
\section{Pell's equation}
Pell's equation is a diophantine equation, were $x^2-ny^2=1$, thus\\
$\forall k\in\mathbb{Z},\quad {(x^2-ny^2)}^k=1$
and
\begin{equation}x^2-ny^2=(x-\sqrt{n}y)(x+\sqrt{n}y)\end{equation}
and from (3), if a solution is represented as $x+\sqrt{n}y$, then for any 
natural number $k$, $(x+\sqrt{n}y)^k$ is a solution too.
\subsection{The Solution Set}
Now, be $(x_1,y_1)$ a pair of the minimal $x$ and $y$, such that $x^2-ny^2=1$.
And $(x_k,y_k)$ is the pair satisfying
\begin{equation}x_k+\sqrt{n}y_k=(x_1+\sqrt{n}y_1)^k\quad k\in\mathbb{N}\end{equation}
Then, you can prove by mathematical induction, for example, that 
\[(x_k,y_k)\quad k\in\mathbb{N}\] is the complete solution set.\\
\underline{Proof:}\\
Let us sort all the solutions with positive components so
\[ k<m\Rightarrow x_k+\sqrt{n}y_k<x_m+\sqrt{n}y_m\]
Be $K$ a natural number, such that
\[ \forall k\in\mathbb{N},\quad k\leq K\Rightarrow x_k+\sqrt{n}y_k=(x_1+\sqrt{n}y_1)^k\]
Let us divide $x_{K+1}+\sqrt{n}u_{K+1}$ by $x_k+\sqrt{n}y_k$:
\begin{align}
  X+\sqrt{n}Y&=(x_{K+1}+\sqrt{n}y_{K+1})(x_k-\sqrt{n}y_k)\nonumber\\
  &= x_{K+1}\cdot x_K-ny_{K+1}\cdot y_K+\sqrt{n}y_{K+1}\cdot x_K-\sqrt{n}y_K\cdot x_{K+1}\nonumber\\
  &= (x_{K+1}\cdot x_K-ny_{K+1}\cdot y_K)+\sqrt{n}(y_{K+1}\cdot x_K-y_K\cdot x_{K+1})
\end{align}
From the result (6) and $X,Y$ being integers, we get that:
\[ X=x_{K+1}\cdot x_K-ny_{K+1}\cdot y_K \]
and
\[ Y=y_{K+1}\cdot x_K-y_K\cdot x_{K+1} \]
Now, let us show that $X$ and $Y$ are positive integers.\\
To do so, let us express $x$'s in terms of $y$'s:
\[ x^2-ny^2=1\Rightarrow x=\sqrt{ny^2+1} \]
Thus,
\begin{align*}
X&=\sqrt{ny_{K+1}^2+1}\sqrt{ny_K^2+1}-ny_{K+1}y_K\\
&>ny_{k+1}y_k-ny_{k+1}y_k=0
\end{align*}
and
\begin{equation*}
Y=y_{K+1}\cdot\sqrt{ny_k^2+1}-y_k\sqrt{ny_{K+1}^2+1}
\end{equation*}
Now,
\begin{align*}
&Y<0\Rightarrow\\
\Rightarrow& y_{K+1}\cdot\sqrt{ny_k^2+1}<y_K\sqrt{ny_{K+1}^2+1}\Rightarrow\\
\Rightarrow& y_{K+1}^2(ny_K^2+1)<y_K^2(ny_{K+1}^2+1)\Rightarrow\\
\Rightarrow& ny_{K+1}^2y_K^2+y_{K+1}^2<ny_{K+1}^2y_K^2+y_K^2\Rightarrow\\
\Rightarrow& y_{K+1}^2<y_K^2\Rightarrow\\
\Rightarrow& y_{K+1}<y_K
\end{align*}
That's a contradiction! Thus, $X>0\text{ and }Y>0$
And from the definition of $X$ and $Y$:
\[ X+\sqrt{n}Y < x_{K+1}+y_{K+1} \]
Because $(x_{X+1},y_{K+1})$ is the next solution after $(x_{K},y_{K})$:
\[ X+\sqrt{n}Y\leq x_K+\sqrt{n}y_K \]
and
\begin{equation} X+\sqrt{n}Y\leq x_1+\sqrt{n}y_1\end{equation}
According to the order we have defined:
\[ \exists k\in\{1,2,\ldots,K\},\ s.t.\ (X,Y)=(x_k,y_k) \]
and, per the induction hypothesis:
\[ x+\sqrt{n}Y=(x_1+\sqrt{n}y_1)^k \]
combined with (7), $(X,Y)$ has no choice but to be $(x_1,y_1)$.
\\
\\QED.
\section{Solving $x^2-2y^2=-1$}
The first solution of that equation is $(x,y)=(1,1)$
or \[ x+\sqrt2y=1+\sqrt2 \]
and
\[ (1+\sqrt2)^2 = 3+2\sqrt2 \]
The first solution of Pell's equation with $n=2$.
Thus, we can write the solutions as:
\[ x_k+\sqrt2y_k = (1+\sqrt2)^{2k} \]
Thus, we can write the solutions of $x^2-2y^2=-1$ as
\[ x_k+\sqrt2k = (1+\sqrt2)^{2k-1} \]
\underline{Closed Form}\\
Feel free to use binomial expansion to get the solutions in closed form.
Following are the solutions:
\[ x_k=\frac{(1+\sqrt2)^{2k-1}+(1-\sqrt2)^{2k-1}}2 \]
and
\[ y_k=\frac{\sqrt2[(1+\sqrt2)^{2k-1}-(1-\sqrt2)^{2k-1}]}4 \]
\section{Getting the Triangle Sides}
Let us refer back to section 1:
\begin{align*}
 x&=2a+1\Rightarrow a=\frac{x-1}2\\
 b&=a+1\Rightarrow a=\frac{x+1}2\\
 c&=y
\end{align*}
But the first solution is 
\[ (x,y)=(1,1)\Rightarrow a=0 \]
So, we'll write our solutions as:
\begin{align*}
 a_k&=\frac{(1+\sqrt2)^{2k+1}+(1-\sqrt2)^{2k+1}i-2}4 \\
 b_k&=\frac{(1+\sqrt2)^{2k+1}+(1-\sqrt2)^{2k+1}i+2}4 \\
 c_k&=\frac{\sqrt2[(1+\sqrt2)^{2k-1}-(1-\sqrt2)^{2k-1}]}4
\end{align*}
The first 10 solutions are:
\begin{lstlisting}
(a,b,c)=(3,4,5)
(a,b,c)=(20,21,29)
(a,b,c)=(119,120,169)
(a,b,c)=(696,697,985)
(a,b,c)=(4059,4060,5741)
(a,b,c)=(23660,23661,33461)
(a,b,c)=(137903,137904,195025)
(a,b,c)=(803760,803761,1136689)
(a,b,c)=(4684659,4684660,6625109)
(a,b,c)=(27304196,27304197,38613965)
\end{lstlisting}
\end{document}

