next up previous contents
Next: Finding m and n Up: Pythagorean Triples, etc. Previous: Pythagorean Triples, etc.   Contents

Generating all Pythagorean Triples

\includegraphics[width=1.5in]{../../../texdocs/ip1}


This section in pdf form. triples2.pdf


If $ (a,b,c)$ is a positive integer solution to the equation

$\displaystyle a^2+b^2=c^2$ (1)

then $ (a,b,c)$ is a Pythagorean triple. If $ a,b$ , and $ c$ have no common divisors greater than $ 1$ , then $ (a,b,c)$ is a primitive Pythagorean triple (PPT). Similarly, if $ a^2+b^2=c^2$ where $ (a,b,c)$ is a PPT then $ a^2+b^2=c^2$ is primitive. In the following list only the second triangle is not primitive.
  1. $ 3^2+4^2=5^2$
  2. $ 6^2+8^2=10^2$
  3. $ 5^2+12^2=13^2$
  4. $ 7^2+24^2=\left(5^2\right)^2$
  5. $ \left(15^2\right)^2+272^2=353^2$

Clearly, if $ k$ divides any two of $ a, b$ , and $ c$ it divides all three. And if $ a^2+b^2=c^2$ then $ k^2a^2+k^2b^2=k^2c^2$ . That is, for a positive integer $ k$ , if $ (a,b,c)$ is a Pythagorean triple then so is $ (ka,kb,kc)$ . Hence, to find all Pythagorean triples, it's sufficient to find all primitive Pythagorean triples.

Let $ a,b$ , and $ c$ be relatively prime positive integers such that $ a^2+b^2=c^2$ . Set

$\displaystyle \frac{m}{n}=\frac{c+a}{b}$

reduced to lowest terms, That is, $ \gcd(m,n)=1$ . From the triangle inequality $ m > n$ . Then

$\displaystyle \frac{m}{n} b-a=c.$ (2)

Squaring both sides of (2) and multiplying through by $ n^2$ we get

$\displaystyle m^2b^2-2mnab+n^2a^2=n^2a^2+n^2b^2;
$

which, after canceling and rearranging terms, becomes

$\displaystyle b\left(m^2-n^2\right)=a(2mn).$ (3)

There are two cases, either $ m$ and $ n$ are of opposite parity, or they or both odd. Since $ \gcd(m,n)=1$ , they can not both be even.

Case 1. $ m$ and $ n$ of opposite parity, i.e., $ m
\not\equiv \pm n (  mod   2  )$ . So 2 divides b since $ m^2-n^2$ is odd. From equation (2), $ n$ divides $ b$ . Since $ \gcd(m,n)=1$ then $ \gcd(m,m^2-n^2)=1$ , therefore $ m$ also divides $ b$ . And since $ \gcd(a,b)=1$ , $ b$ divides $ 2mn$ . Therefore $ b=2mn$ . Then

$\displaystyle a=m^2-n^2, \quad b=2mn,$   and from (2)$\displaystyle ,   c=\frac{m}{n} 2mn-(m^2-n^2)=m^2+n^2.$ (4)

Case 2. $ m$ and $ n$ both odd, i.e., $ m \equiv \pm n ( 
mod   2  )$ . So 2 divides $ m^2-n^2$ . Then by the same process as in the first case we have

$\displaystyle a=\frac{m^2-n^2}{2}, \quad b=mn,\quad and \quad c=\frac{m^2+n^2}{2}.$ (5)

The parametric equations in (4) and (5) appear to be different but they generate the same solutions. To show this, let

$\displaystyle u=\frac{m+n}{2}  $    and $\displaystyle   v=\frac{m-n}{2} .
$

Then $ m=u+v$ , and $ n=u-v$ . Substituting those values for $ m$ and $ n$ into (5) we get

$\displaystyle a=2uv,     b=u^2-v^2,$   and$\displaystyle \quad c=u^2+v^2$ (6)

where $ u > v$ , $ gcd(u,v)=1$ , and $ u$ and $ v$ are of opposite parity. Therefore (6), with the labels for a and b interchanged, is identical to (4). Thus since $ \left\{m^2-n^2,2mn,m^2+n^2\right\}$ , as in (4), is a primitive Pythagorean triple, we can say that $ (a,b,c)$ is a primitive pythagorean triple if and only if there exists relatively prime, positive integers $ m$ and $ n$ , $ m > n$ , such that $ a=m^2-n^2,   b=2mn,  $ and $     c=m^2+n^2$ . And $ (a,b,c)$ is a Pythagorean triple if and only if

$\displaystyle a=k\left(m^2-n^2\right),\quad b=k(2mn),$   and$\displaystyle \quad
c=k\left(m^2+n^2\right)
$

where $ k$ is a positive integer.


Alternatively, $ (a,b,c)$ is a Pythagorean triple if and only if there exists relatively prime, positive integers $ u$ and $ v$ , $ u > v$ , $ u \equiv v \pmod{2}$ such that

$\displaystyle a=k\left(\frac{u^2-v^2}{2}\right),\quad b=k(uv),$   and$\displaystyle \quad
c=k\left(\frac{u^2+v^2}{2}\right).
$


Another Method (using Gaussian Integers).


Let

$\displaystyle a^2+b^2=c^2$ (7)

where $ a, b$ , and $ c$ are pairwise, relatively prime, positive integers. Let $ z=a+bi$ and $ \bar{z}=a-bi$ , where $ i=\sqrt{-1}$ . Then $ z$ and $ \bar{z}$ are Gaussian Integers, and $ \bar{z}$ is the conjugate of $ z$ . Note that

$\displaystyle a=\frac{z+\bar{z}}{2},\quad b=\frac{z-\bar{z}}{2i} ,$   and$\displaystyle \quad c=\sqrt{z\bar{z}}.$ (8)

Since $ \gcd(a,b)=1$ then $ \gcd(z,\bar{z})=1$ . Hence each of $ z$ and $ \bar{z}$ is a square. That is, there exists integers $ m$ and $ n$ such that $ (m+ni)^2=z$ and $ (m-ni)^2=\bar{z}$ . So, from equation (8),

$\displaystyle a$ $\displaystyle =\frac{(m+ni)^2+(m-ni)^2}{2}=m^2-n^2,$    
$\displaystyle b$ $\displaystyle =\frac{(m+ni)^2-(m-ni)^2}{2i}=2mn,$    
and$\displaystyle \quad c$ $\displaystyle =\sqrt{(m+ni)^2(m-ni)^2}=m^2+n^2.$    

Since $ a$ is a positive integer, $ m$ and $ n$ must be positive integers, $ m > n$ . And since $ \gcd(a,b)=1$ , $ m$ and $ n$ must be relatively prime and of opposite parity.

Equation (8) illustrates a method for finding primitive Pythagorean triangles where the hypotenuse is to a power. We have the identity,

$\displaystyle \left\vert \frac{z^{2k}+\bar{z}^{2k}}{2}\right\vert^2+\left\vert ...
...c{z^{2k}-\bar{z}^{2k}}{2i}\right\vert^2 =\Bigl(\left(z\bar{z}\right)^k\Bigr)^2.$ (9)

The absolute values are necessary since the terms on the left, depending on $ k$ , may, or may not, be positive.


Example


Let $ a=3, b=4$ , and $ k=3$ . Then, from equation (9), we have,

  $\displaystyle \left\vert\frac{(3+4i)^6+(3-4i)^6}{2}\right\vert^2+ \left\vert\frac{(3+4i)^6-(3-4i)^6}{2i}\right\vert^2 =\Bigl(\bigl((3+4i)(3-4i)\bigr)^3\Bigr)^2$    
$\displaystyle =$ $\displaystyle 11753^2+\bigl\vert-10296\bigr\vert^2=\left(25^3\right)^2.$    


Still another method -- the difference method.


Let $ (a,b,c)$ be a primitive Pythagorean triple. Without loss of generality, let $ a$ be odd. Equation (7) can be written as,

$\displaystyle a^2=c^2-b^2.
$

Set $ w=c+b$ and $ \bar{w}=c-b$ . Thus,

$\displaystyle a=\sqrt{w\bar{w}} ,\quad c=\frac{w+\bar{w}}{2},$   and$\displaystyle \quad b=\frac{w-\bar{w}}{2}.$ (10)

Since $ (a,b,c)$ is primitive, $ \gcd(c,b)=\gcd(w,\bar{w})=1$ . This implies that each of $ w$ and $ \bar{w}$ is a square. So, since any odd positive integer greater than 1 can be written as the difference of two positive integer squares, there exists positive integers $ m$ and $ n$ , $ m > n$ , such that $ (m+n)^2=w$ and $ (m-n)^2=\bar{w}$ . Hence, from equation (10),

$\displaystyle a$ $\displaystyle = \sqrt{(m+n)^2(m-n)^2}=m^2-n^2,$    
$\displaystyle c$ $\displaystyle = \frac{(m+n)^2+(m-n)^2}{2}=m^2+n^2,$    
and$\displaystyle \quad b$ $\displaystyle =\frac{(m+n)^2-(m-n)^2}{2}=2mn.$    

And, since $ \gcd(a,b)=1$ , $ m$ and $ n$ must be relatively prime and of opposite parity.

Equation (10) illustrates an efficient method for finding primitive Pythagorean triples where the odd leg is to a power. We have the identity,

$\displaystyle \Bigl(\left(w\bar{w}\right)^k\Bigr)^2=\left(\frac{w^{2k}+\bar{w}^{2k}}{2}\right)^2 -\left(\frac{w^{2k}-\bar{w}^{2k}}{2}\right)^2 .$ (11)


Example


Let $ c=5,  b=4$ , and $ k=3$ . Then, from equation (11), we have,

$\displaystyle \Bigl(\bigl((5+4)(5-4)\bigr)^3\Bigr)^2$ $\displaystyle =\left(\frac{(5+4)^6+(5-4)^6}{2}\right)^2 -\left(\frac{(5+4)^6-(5-4)^6}{2}\right)^2.$    
That is,$\displaystyle \quad \left(9^3\right)^2$ $\displaystyle =265721^2-265720^2.$    


next up previous contents
Next: Finding m and n Up: Pythagorean Triples, etc. Previous: Pythagorean Triples, etc.   Contents
f. barnes 2008-04-29
Hosted by www.Geocities.ws

1