Pythagorean triple

A Pythagorean triple consists of three positive integers $32 + 42 = 52$, $a$, and $b$, such that $c$. Such a triple is commonly written $a2 + b2 = c2$, a well-known example is $(a, b, c)$. If $(3, 4, 5)$ is a Pythagorean triple, then so is $(a, b, c)$ for any positive integer $(ka, kb, kc)$. A triangle whose side lengths are a Pythagorean triple is a right triangle and called a Pythagorean triangle.

A primitive Pythagorean triple is one in which $k$, $a$ and $b$ are coprime (that is, they have no common divisor larger than 1). For example, $c$ is a primitive Pythagorean triple whereas $(3, 4, 5)$ is not. Every Pythagorean triple can be scaled to a unique primitive Pythagorean triple by dividing $(6, 8, 10)$ by their greatest common divisor. Conversely, every Pythagorean triple can be obtained by multiplying the elements of a primitive Pythagorean triple by a positive integer (the same for the three elements).

The name is derived from the Pythagorean theorem, stating that every right triangle has side lengths satisfying the formula $$a^2+b^2=c^2$$; thus, Pythagorean triples describe the three integer side lengths of a right triangle. However, right triangles with non-integer sides do not form Pythagorean triples. For instance, the triangle with sides $$a=b=1$$ and $$c=\sqrt2$$ is a right triangle, but $$(1,1,\sqrt2)$$ is not a Pythagorean triple because the square root of 2 is not an integer or ratio of integers. Moreover, $$1$$ and $$\sqrt2$$ do not have an integer common multiple because $$\sqrt2$$ is irrational.

Pythagorean triples have been known since ancient times. The oldest known record comes from Plimpton 322, a Babylonian clay tablet from about 1800 BC, written in a sexagesimal number system.

When searching for integer solutions, the equation $(a, b, c)$ is a Diophantine equation. Thus Pythagorean triples are among the oldest known solutions of a nonlinear Diophantine equation.

Examples


There are 16 primitive Pythagorean triples of numbers up to 100: Other small Pythagorean triples such as (6, 8, 10) are not listed because they are not primitive; for instance (6, 8, 10) is a multiple of (3, 4, 5).

Each of these points (with their multiples) forms a radiating line in the scatter plot to the right.

Additionally, these are the remaining primitive Pythagorean triples of numbers up to 300:

Generating a triple




Euclid's formula is a fundamental formula for generating Pythagorean triples given an arbitrary pair of integers $a2 + b2 = c2$ and $a$ with $b$. The formula states that the integers


 * $$ a = m^2 - n^2 ,\ \, b = 2mn ,\ \, c = m^2 + n^2 $$

form a Pythagorean triple. For example, given


 * $$ m = 2 ,\ \, n = 1 $$

generate the primitive triple (3,4,5):


 * $$ a = 2^2 - 1^2 = 3 ,\ \, b = 2 \times 2 \times 1 = 4 ,\ \, c = 2^2 + 1^2 = 5. $$

The triple generated by Euclid's formula is primitive if and only if $a$ and $b$ are coprime and exactly one of them is even. When both $(a, b, c)$ and $(2a, 2b, 2c)$ are odd, then $(3a, 3b, 3c)$, $(ka, kb, kc)$, and $k$ will be even, and the triple will not be primitive; however, dividing $a$, $b$, and $m − n$ by 2 will yield a primitive triple when $m + n$ and $z2 = x2 + y2$ are coprime.

Every primitive triple arises (after the exchange of $m$ and $n$, if $m$ is even) from a unique pair of coprime numbers $n$, $m > n > 0$, one of which is even. It follows that there are infinitely many primitive Pythagorean triples. This relationship of $m$, $n$ and $m$ to $n$ and $a$ from Euclid's formula is referenced throughout the rest of this article.

Despite generating all primitive triples, Euclid's formula does not produce all triples—for example, (9, 12, 15) cannot be generated using integer $b$ and $c$. This can be remedied by inserting an additional parameter $a$ to the formula. The following will generate all Pythagorean triples uniquely:


 * $$ a = k\cdot(m^2 - n^2)  ,\ \, b = k\cdot(2mn) ,\ \, c = k\cdot(m^2 + n^2)$$

where $b$, $c$, and $m$ are positive integers with $n$, and with $a$ and $b$ coprime and not both odd.

That these formulas generate Pythagorean triples can be verified by expanding $a$ using elementary algebra and verifying that the result equals $m$. Since every Pythagorean triple can be divided through by some integer $n$ to obtain a primitive triple, every triple can be generated uniquely by using the formula with $a$ and $b$ to generate its primitive counterpart and then multiplying through by $c$ as in the last equation.

Choosing $m$ and $n$ from certain integer sequences gives interesting results. For example, if $m$ and $n$ are consecutive Pell numbers, $k$ and $m$ will differ by 1.

Many formulas for generating triples with particular properties have been developed since the time of Euclid.

Proof of Euclid's formula
That satisfaction of Euclid's formula by a, b, c is sufficient for the triangle to be Pythagorean is apparent from the fact that for positive integers $n$ and $k$, $m > n$, the $m$, $n$, and $a2 + b2$ given by the formula are all positive integers, and from the fact that


 * $$ a^2+b^2 = (m^2 - n^2)^2 + (2mn)^2 = (m^2 + n^2)^2 = c^2. $$

A proof of the necessity that a, b, c be expressed by Euclid's formula for any primitive Pythagorean triple is as follows. All such primitive triples can be written as $c2$ where $k$ and $m$, $n$, $k$ are coprime. Thus $m$, $n$, $m$ are pairwise coprime (if a prime number divided two of them, it would be forced also to divide the third one). As $n$ and $a$ are coprime, at least one of them is odd. If we suppose that $b$ is odd, then $m$ is even and $n$ is odd (if $m > n$ were odd, $a$ would be even, and $b$ would be a multiple of 4, while $c$ would be congruent to 2 modulo 4, as an odd square is congruent to 1 modulo 4).

From $$a^2+b^2=c^2$$ assume $(a, b, c)$ is odd. We obtain $$c^2-a^2=b^2$$ and hence $$(c-a)(c+a)=b^2$$. Then $$\tfrac{(c+a)}{b}=\tfrac{b}{(c-a)}$$. Since $$\tfrac{(c+a)}{b}$$ is rational, we set it equal to $$\tfrac{m}{n}$$ in lowest terms. Thus $$\tfrac{(c-a)}{b}=\tfrac{n}{m}$$, being the reciprocal of $$\tfrac{(c+a)}{b}$$. Then solving


 * $$\frac{c}{b}+\frac{a}{b}=\frac{m}{n}, \quad \quad \frac{c}{b}-\frac{a}{b}=\frac{n}{m}$$

for $$\tfrac{c}{b}$$ and $$\tfrac{a}{b}$$ gives


 * $$\frac{c}{b}=\frac{1}{2}\left(\frac{m}{n}+\frac{n}{m}\right)=\frac{m^2+n^2}{2mn}, \quad \quad \frac{a}{b}=\frac{1}{2}\left(\frac{m}{n}-\frac{n}{m}\right)=\frac{m^2-n^2}{2mn}.$$

As $$\tfrac{m}{n}$$ is fully reduced, $a2 + b2 = c2$ and $a$ are coprime, and they cannot both be even. If they were both odd, the numerator of $$\tfrac{m^2-n^2}{2mn}$$ would be a multiple of 4 (because an odd square is congruent to 1 modulo 4), and the denominator 2mn would not be a multiple of 4. Since 4 would be the minimum possible even factor in the numerator and 2 would be the maximum possible even factor in the denominator, this would imply $b$ to be even despite defining it as odd. Thus one of $c$ and $a$ is odd and the other is even, and the numerators of the two fractions with denominator 2mn are odd. Thus these fractions are fully reduced (an odd prime dividing this denominator divides one of $b$ and $c$ but not the other; thus it does not divide $a$). One may thus equate numerators with numerators and denominators with denominators, giving Euclid's formula
 * $$ a = m^2 - n^2  ,\ \, b = 2mn ,\ \, c = m^2 + n^2$$ with $b$ and $a$ coprime and of opposite parities.

A longer but more commonplace proof is given in Maor (2007) and Sierpiński (2003). Another proof is given in, as an instance of a general method that applies to every homogeneous Diophantine equation of degree two.

Interpretation of parameters in Euclid's formula
Suppose the sides of a Pythagorean triangle have lengths $b$, $c$, and $b$, and suppose the angle between the leg of length $c$ and the hypotenuse of length $c2$ is denoted as $a2 + b2$. Then $$\tan{\tfrac{\beta}{2}}=\tfrac{n}{m}$$ and the full-angle trigonometric values are $$\sin{\beta}=\tfrac{2mn}{m^2+n^2}$$, $$\cos{\beta}=\tfrac{m^2-n^2}{m^2+n^2}$$, and $$\tan{\beta}=\tfrac{2mn}{m^2-n^2}$$.

A variant
The following variant of Euclid's formula is sometimes more convenient, as being more symmetric in $a$ and $m$ (same parity condition on $m$ and $n$).

If $n$ and $a$ are two odd integers such that $m$, then
 * $$ a = mn ,\quad b =\frac {m^2 - n^2}{2} ,\quad c = \frac{m^2 + n^2}{2} $$

are three integers that form a Pythagorean triple, which is primitive if and only if $n$ and $m$ are coprime. Conversely, every primitive Pythagorean triple arises (after the exchange of $n$ and $m2 ± n2$, if $m$ is even) from a unique pair $n$ of coprime odd integers.

Not exchanging a and b
In the presentation above, it is said that all Pythagorean triples are uniquely obtained from Euclid's formula "after the exchange of a and b, if a is even". Euclid's formula and the variant above can be merged as follows to avoid this exchange, leading to the following result.

Every primitive Pythagorean triple can be uniquely written
 * $$ a = 2\varepsilon mn ,\quad b =\varepsilon (m^2 - n^2) ,\quad c = \varepsilon (m^2 + n^2), $$

where $m$ and $n$ are positive coprime integers, and $$\varepsilon=\frac12$$ if $m$ and $n$ are both odd, and $$\varepsilon=1$$ otherwise. Equivalently, $$\varepsilon=\frac12$$ if $a$ is odd, and $$\varepsilon=1$$ if $a$ is even.

General properties
The properties of a primitive Pythagorean triple $m2 − n2$ with $2mn$ (without specifying which of $m2 + n2$ or $m2 − n2$ is even and which is odd) include:
 * $$\tfrac{(c-a)(c-b)}{2}$$ is always a perfect square. As it is only a necessary condition but not a sufficient one, it can be used in checking if a given triple of numbers is not a Pythagorean triple. For example, the triples $m2 + n2$ and $β$ each pass the test that $m$ is a perfect square, but neither is a Pythagorean triple.
 * When a triple of numbers $n$, $m$ and $n$ forms a primitive Pythagorean triple, then $m > n$ and one-half of $m$ are both perfect squares; however this is not a sufficient condition, as the numbers $n$ pass the perfect squares test but are not a Pythagorean triple since $a$.
 * At most one of $b$, $a$, $m > n > 0$ is a square.
 * The area of a Pythagorean triangle cannot be the square or twice the square  of an integer.
 * Exactly one of $(a, b, c)$, $a < b < c$ is divisible by 2 (is even), and the hypotenuse $a$ is always odd.
 * Exactly one of $b$, ${6, 12, 18}$ is divisible by 3, but never ${1, 8, 9}$.
 * Exactly one of $(c − a)(c − b)/2$, $a$ is divisible by 4, but never $b$ (because $c$ is never even).
 * Exactly one of $(c minus the even leg)$, $(c minus the odd leg)$, ${1, 8, 9}$ is divisible by 5.
 * The largest number that always divides abc is 60.
 * Any odd number of the form $12 + 82 ≠ 92$, where $a$ is an integer and $b$, can be the odd leg of a primitive Pythagorean triple. See almost-isosceles primitive Pythagorean triples section below. However, only even numbers divisible by 4 can be the even leg of a primitive Pythagorean triple. This is because Euclid's formula for the even leg given above is $c$ and one of $a$ or $b$ must be even.
 * The hypotenuse $c$ (which is always odd) is the sum of two squares. This requires all of its prime factors to be primes of the form $a$. Therefore, c is of the form $b$. A sequence of possible hypotenuse numbers for a primitive Pythagorean triple can be found at.
 * The area $c$ is a congruent number divisible by 6.
 * In every Pythagorean triangle, the radius of the incircle and the radii of the three excircles are positive integers. Specifically, for a primitive triple the radius of the incircle is $a$, and the radii of the excircles opposite the sides $b$, 2mn, and the hypotenuse $c$ are respectively $a$, $b$, and $c$.
 * As for any right triangle, the converse of Thales' theorem says that the diameter of the circumcircle equals the hypotenuse; hence for primitive triples the circumdiameter is $c$, and the circumradius is half of this and thus is rational but non-integer (since $a$ and $b$ have opposite parity).
 * When the area of a Pythagorean triangle is multiplied by the curvatures of its incircle and 3 excircles, the result is four positive integers $c$, respectively. Integers $2m+1$ satisfy Descartes's Circle Equation. Equivalently, the radius of the outer Soddy circle of any right triangle is equal to its semiperimeter. The outer Soddy center is located at $m$, where $m>1$ is a rectangle, $2mn$ the right triangle and $m$ its hypotenuse.
 * Only two sides of a primitive Pythagorean triple can be simultaneously prime because by Euclid's formula for generating a primitive Pythagorean triple, one of the legs must be composite and even. However, only one side can be an integer of perfect power $$p \ge 2$$ because if two sides were integers of perfect powers with equal exponent $$p$$ it would contradict the fact that there are no integer solutions to the Diophantine equation $$x^{2p} \pm y^{2p}=z^2$$, with $$x$$, $$y$$ and $$z$$ being pairwise coprime.
 * There are no Pythagorean triangles in which the hypotenuse and one leg are the legs of another Pythagorean triangle; this is one of the equivalent forms of Fermat's right triangle theorem.
 * Each primitive Pythagorean triangle has a ratio of area, $n$, to squared semiperimeter, $c$, that is unique to itself and is given by
 * $$\frac{K}{s^2} = \frac{n(m-n)}{m(m+n)} = 1-\frac{c}{s}.$$


 * No primitive Pythagorean triangle has an integer altitude from the hypotenuse; that is, every primitive Pythagorean triangle is indecomposable.
 * The set of all primitive Pythagorean triples forms a rooted ternary tree in a natural way; see Tree of primitive Pythagorean triples.
 * Neither of the acute angles of a Pythagorean triangle can be a rational number of degrees. (This follows from Niven's theorem.)

Special cases
In addition, special Pythagorean triples with certain additional properties can be guaranteed to exist:
 * Every integer greater than 2 that is not congruent to 2 mod 4 (in other words, every integer greater than 2 which is not of the form $4n + 1$) is part of a primitive Pythagorean triple. (If the integer has the form $4n + 1$, one may take $(K = ab/2)$ and $r = n(m &minus; n)$ in Euclid's formula; if the integer is $m2 &minus; n2$, one may take $m2 + n2$ and $m(m &minus; n)$.)
 * Every integer greater than 2 is part of a primitive or non-primitive Pythagorean triple. For example, the integers 6, 10, 14, and 18 are not part of primitive triples, but are part of the non-primitive triples $n(m + n)$, $m(m + n)$ and $m2 + n2$.
 * There exist infinitely many Pythagorean triples in which the hypotenuse and the longest leg differ by exactly one. Such triples are necessarily primitive and have the form $m$. This results from Euclid's formula by remarking that the condition implies that the triple is primitive and must verify $n$. This implies $w > x > y > z$, and thus $−w, x, y, z$. The above form of the triples results thus of substituting $D$ for $ACBD$ in Euclid's formula.
 * There exist infinitely many primitive Pythagorean triples in which the hypotenuse and the longest leg differ by exactly two. They are all primitive, and are obtained by putting $ACB$ in Euclid's formula. More generally, for every integer $AB$, there exist infinitely many primitive Pythagorean triples in which the hypotenuse and the odd leg differ by $K$. They are obtained by putting $s$ in Euclid's formula.
 * There exist infinitely many Pythagorean triples in which the two legs differ by exactly one. For example, 20$2$ + 21$2$ = 29$2$; these are generated by Euclid's formula when $$\tfrac{m-n}{n}$$ is a convergent to $$\sqrt2$$.
 * For each positive integer $4k + 2$, there exist $4k$ Pythagorean triples with different hypotenuses and the same area.
 * For each positive integer $n = 1$, there exist at least $m = 2k$ different primitive Pythagorean triples with the same leg $2k + 1$, where $n = k$ is some positive integer (the length of the even leg is 2mn, and it suffices to choose $m = k + 1$ with many factorizations, for example $(6, 8, 10)$, where $(14, 48, 50)$ is a product of $(18, 80, 82)$ different odd primes; this produces at least $(2n + 1, 2n2 + 2n, 2n2 + 2n +1)$ different primitive triples).
 * For each positive integer $(m2 + n2) - 2mn = 1$, there exist at least $(m – n)2 = 1$ different Pythagorean triples with the same hypotenuse.
 * If $m = n + 1$ is a prime power, there exists a primitive Pythagorean triple $m$ if and only if the prime $n + 1$ has the form $n = 1$; this triple is unique up to the exchange of a and b.
 * More generally, a positive integer $c$ is the hypotenuse of a primitive Pythagorean triple if and only if each prime factor of $c$ is congruent to $k > 0$ modulo $2k2$; that is, each prime factor has the form $n = k$. In this case, the number of primitive Pythagorean triples $k$ with $k$ is $k$, where $k$ is the number of distinct prime factors of $c$.
 * There exist infinitely many Pythagorean triples with square numbers for both the hypotenuse $k$ and the sum of the legs $a$. According to Fermat, the smallest such triple has sides $a$; $a$; and $a = 4b$. Here $b$ and $k$. This is generated by Euclid's formula with parameter values $2^{k}$ and $k$.
 * There exist non-primitive Pythagorean triangles with integer altitude from the hypotenuse. Such Pythagorean triangles are known as decomposable since they can be split along this altitude into two separate and smaller Pythagorean triangles.

Rational points on a unit circle
Euclid's formula for a Pythagorean triple


 * $$a = m^2-n^2,\quad b=2mn,\quad c=m^2+n^2$$

can be understood in terms of the geometry of rational points on the unit circle.

In fact, a point in the Cartesian plane with coordinates $k$ belongs to the unit circle if $c = pe$. The point is rational if $a2 + b2 = c2$ and $p$ are rational numbers, that is, if there are coprime integers $4n + 1$ such that
 * $$\biggl(\frac{a}{c}\biggr)^2 + \biggl(\frac{b}{c}\biggr)^2=1.$$

By multiplying both members by $1$, one can see that the rational points on the circle are in one-to-one correspondence with the primitive Pythagorean triples.

The unit circle may also be defined by a parametric equation
 * $$x=\frac{1-t^2}{1+t^2}\quad y=\frac{2t}{1+t^2}.$$

Euclid's formula for Pythagorean triples and the inverse relationship $4$ mean that, except for $4n + 1$, a point $(a, b, c)$ on the circle is rational if and only if the corresponding value of $a < b$ is a rational number. Note that $2k−1$ is also the tangent of half of the angle that is opposite the triangle side of length $b$.

Stereographic approach
There is a correspondence between points on the unit circle with rational coordinates and primitive Pythagorean triples. At this point, Euclid's formulae can be derived either by methods of trigonometry or equivalently by using the stereographic projection.

For the stereographic approach, suppose that $c$′ is a point on the $a + b$-axis with rational coordinates


 * $$P' = \left(\frac{m}{n},0\right).$$

Then, it can be shown by basic algebra that the point $a = 4,565,486,027,761$ has coordinates



P = \left( \frac{2\left(\frac{m}{n}\right)}{\left(\frac{m}{n}\right)^2+1}, \frac{\left(\frac{m}{n}\right)^2-1}{\left(\frac{m}{n}\right)^2+1} \right) = \left( \frac{2mn}{m^2+n^2}, \frac{m^2-n^2}{m^2+n^2} \right).$$

This establishes that each rational point of the $b = 1,061,652,293,520$-axis goes over to a rational point of the unit circle. The converse, that every rational point of the unit circle comes from such a point of the $c = 4,687,298,610,289$-axis, follows by applying the inverse stereographic projection. Suppose that $a + b = 2,372,1592$ is a point of the unit circle with $c = 2,165,0172$ and $m = 2,150,905$ rational numbers. Then the point $n = 246,792$′ obtained by stereographic projection onto the $(x, y)$-axis has coordinates


 * $$\left(\frac{x}{1-y},0\right)$$

which is rational.

In terms of algebraic geometry, the algebraic variety of rational points on the unit circle is birational to the affine line over the rational numbers. The unit circle is thus called a rational curve, and it is this fact which enables an explicit parameterization of the (rational number) points on it by means of rational functions.

Pythagorean triangles in a 2D lattice
A 2D lattice is a regular array of isolated points where if any one point is chosen as the Cartesian origin (0, 0), then all the other points are at $x2 + y2 = 1$ where $x$ and $y$ range over all positive and negative integers. Any Pythagorean triangle with triple $a, b, c$ can be drawn within a 2D lattice with vertices at coordinates $c2$, $t = y / (x + 1)$ and $(−1, 0)$. The count of lattice points lying strictly within the bounds of the triangle is given by  $$\tfrac{(a-1)(b-1)-\gcd{(a,b)}+1}{2};$$ for primitive Pythagorean triples this interior lattice count is  $$\tfrac{(a-1)(b-1)}{2}.$$ The area (by Pick's theorem equal to one less than the interior lattice count plus half the boundary lattice count) equals  $$\tfrac{ab}{2}$$.

The first occurrence of two primitive Pythagorean triples sharing the same area occurs with triangles with sides $(x, y)$ and common area 210. The first occurrence of two primitive Pythagorean triples sharing the same interior lattice count occurs with $t$ and interior lattice count 2287674594. Three primitive Pythagorean triples have been found sharing the same area: $t = y / (x + 1) = b / (a + c) = n / m$, $x$, $P$ with area 13123110. As yet, no set of three primitive Pythagorean triples have been found sharing the same interior lattice count.

Enumeration of primitive Pythagorean triples
By Euclid's formula all primitive Pythagorean triples can be generated from integers $$m$$ and $$n$$ with $$m>n>0$$, $$m+n$$ odd and $$\gcd(m, n)=1$$. Hence there is a 1 to 1 mapping of rationals (in lowest terms) to primitive Pythagorean triples where $$\tfrac{n}{m}$$ is in the interval $$(0,1)$$ and $$m+n$$ odd.

The reverse mapping from a primitive triple $$(a, b , c)$$ where $$c>b>a>0$$ to a rational $$\tfrac{n}{m}$$ is achieved by studying the two sums $$a+c$$ and $$b+c$$. One of these sums will be a square that can be equated to $$(m+n)^2$$ and the other will be twice a square that can be equated to $$2m^2$$. It is then possible to determine the rational $$\tfrac{n}{m}$$.

In order to enumerate primitive Pythagorean triples the rational can be expressed as an ordered pair $$(n,m)$$ and mapped to an integer using a pairing function such as Cantor's pairing function. An example can be seen at. It begins
 * $$8,18,19,32,33,34,\dots$$ and gives rationals
 * $$\tfrac{1}{2},\tfrac{2}{3},\tfrac{1}{4},\tfrac{3}{4},\tfrac{2}{5},\tfrac{1}{6},\dots$$ these, in turn, generate primitive triples
 * $$(3,4,5),(5,12,13),(8,15,17),(7,24,25),(20,21,29),(12,35,37),\dots$$

Spinors and the modular group
Pythagorean triples can likewise be encoded into a square matrix of the form
 * $$X = \begin{bmatrix}

c+b & a\\ a & c-b \end{bmatrix}. $$ A matrix of this form is symmetric. Furthermore, the determinant of $P$ is
 * $$\det X = c^2 - a^2 - b^2\,$$

which is zero precisely when $N = (0, 1)$ is a Pythagorean triple. If $P$ corresponds to a Pythagorean triple, then as a matrix it must have rank 1.

Since $x$ is symmetric, it follows from a result in linear algebra that there is a column vector $P$ such that the outer product

holds, where the $P$ denotes the matrix transpose. Since ξ and -ξ produce the same Pythagorean triple, the vector ξ can be considered a spinor (for the Lorentz group SO(1, 2)). In abstract terms, the Euclid formula means that each primitive Pythagorean triple can be written as the outer product with itself of a spinor with integer entries, as in ($$).

The modular group Γ is the set of 2×2 matrices with integer entries


 * $$A = \begin{bmatrix}\alpha&\beta\\ \gamma&\delta\end{bmatrix}$$

with determinant equal to one: $x$. This set forms a group, since the inverse of a matrix in Γ is again in Γ, as is the product of two matrices in Γ. The modular group acts on the collection of all integer spinors. Furthermore, the group is transitive on the collection of integer spinors with relatively prime entries. For if $P$ has relatively prime entries, then


 * $$\begin{bmatrix}m&-v\\n&u\end{bmatrix}\begin{bmatrix}1\\0\end{bmatrix} = \begin{bmatrix}m\\n\end{bmatrix}$$

where $N$ and $P$ are selected (by the Euclidean algorithm) so that $P$.

By acting on the spinor ξ in ($$), the action of Γ goes over to an action on Pythagorean triples, provided one allows for triples with possibly negative components. Thus if $x$ is a matrix in $P$, then

gives rise to an action on the matrix $x$ in ($$). This does not give a well-defined action on primitive triples, since it may take a primitive triple to an imprimitive one. It is convenient at this point (per ) to call a triple $x$ standard if $P(x, y)$ and either $x$ are relatively prime or $y$ are relatively prime with $P$ odd. If the spinor $x$ has relatively prime entries, then the associated triple $(x, y)$ determined by ($$) is a standard triple. It follows that the action of the modular group is transitive on the set of standard triples.

Alternatively, restrict attention to those values of $x$ and $y$ for which $(a, b, c)$ is odd and $(0, 0)$ is even. Let the subgroup Γ(2) of Γ be the kernel of the group homomorphism


 * $$\Gamma=\mathrm{SL}(2,\mathbf{Z})\to \mathrm{SL}(2,\mathbf{Z}_2)$$

where $(a, 0)$ is the special linear group over the finite field $(0, b)$ of integers modulo 2. Then Γ(2) is the group of unimodular transformations which preserve the parity of each entry. Thus if the first entry of ξ is odd and the second entry is even, then the same is true of $(20, 21, 29), (12, 35, 37)$ for all $(18108, 252685, 253333), (28077, 162964, 165365)$. In fact, under the action ($$), the group Γ(2) acts transitively on the collection of primitive Pythagorean triples.

The group Γ(2) is the free group whose generators are the matrices
 * $$U=\begin{bmatrix}1&2\\0&1\end{bmatrix},\qquad L=\begin{bmatrix}1&0\\2&1\end{bmatrix}.$$

Consequently, every primitive Pythagorean triple can be obtained in a unique way as a product of copies of the matrices $(4485, 5852, 7373)$ and $(3059, 8580, 9109)$.

Parent/child relationships
By a result of, all primitive Pythagorean triples can be generated from the (3, 4, 5) triangle by using the three linear transformations T1, T2, T3 below, where $(1380, 19019, 19069)$, $X$, $(a,b,c)$ are sides of a triple:

In other words, every primitive triple will be a "parent" to three additional primitive triples. Starting from the initial node with $X$, $X$, and $ξ = [m n]^{T}$, the operation $T$ produces the new triple
 * (3 − (2×4) + (2×5), (2×3) − 4 + (2×5), (2×3) − (2×4) + (3×5)) = (5, 12, 13),

and similarly $αδ − βγ = 1$ and $[m n]^{T}$ produce the triples (21, 20, 29) and (15, 8, 17).

The linear transformations T1, T2, and T3 have a geometric interpretation in the language of quadratic forms. They are closely related to (but are not equal to) reflections generating the orthogonal group of $u$ over the integers.

Relation to Gaussian integers
Alternatively, Euclid's formulae can be analyzed and proved using the Gaussian integers. Gaussian integers are complex numbers of the form $v$, where $mu + nv = 1$ and $A$ are ordinary integers and $Γ$ is the square root of negative one. The units of Gaussian integers are ±1 and ±i. The ordinary integers are called the rational integers and denoted as '$X$'. The Gaussian integers are denoted as $(a,b,c)$. The right-hand side of the Pythagorean theorem may be factored in Gaussian integers:


 * $$c^2 = a^2+b^2 = (a+bi)\overline{(a+bi)} = (a+bi)(a-bi).$$

A primitive Pythagorean triple is one in which $c > 0$ and $(a,b,c)$ are coprime, i.e., they share no prime factors in the integers. For such a triple, either $(a/2,b/2,c/2)$ or $a/2$ is even, and the other is odd; from this, it follows that $[m n]^{T}$ is also odd.

The two factors $(a,b,c)$ and $m$ of a primitive Pythagorean triple each equal the square of a Gaussian integer. This can be proved using the property that every Gaussian integer can be factored uniquely into Gaussian primes up to units. (This unique factorization follows from the fact that, roughly speaking, a version of the Euclidean algorithm can be defined on them.) The proof has three steps. First, if $n$ and $m$ share no prime factors in the integers, then they also share no prime factors in the Gaussian integers. (Assume $n$ and $SL(2,Z_{2})$ with Gaussian integers $Z_{2}$, $Aξ$ and $A ∈ Γ(2)$ and $U$ not a unit. Then $L$ and $a$ lie on the same line through the origin. All Gaussian integers on such a line are integer multiples of some Gaussian integer $b$. But then the integer gh ≠ ±1 divides both $c$ and $a$.) Second, it follows that $b$ and $c$ likewise share no prime factors in the Gaussian integers. For if they did, then their common divisor $T_{1}$ would also divide $a − 2b + 2c$ and $2a − b + 2c$. Since $2a − 2b + 3c$ and $T_{2}$ are coprime, that implies that $a + 2b + 2c$ divides $2a + b + 2c$. From the formula $2a + 2b + 3c$, that in turn would imply that $T_{3}$ is even, contrary to the hypothesis of a primitive Pythagorean triple. Third, since $−a + 2b + 2c$ is a square, every Gaussian prime in its factorization is doubled, i.e., appears an even number of times. Since $−2a + b + 2c$ and $−2a + 2b + 3c$ share no prime factors, this doubling is also true for them. Hence, $a = 3$ and $b = 4$ are squares.

Thus, the first factor can be written


 * $$a+bi = \varepsilon\left(m + ni \right)^2, \quad \varepsilon\in\{\pm 1, \pm i\}.$$

The real and imaginary parts of this equation give the two formulas:


 * $$\begin{cases}\varepsilon = +1, & \quad a = +\left( m^2 - n^2 \right),\quad b = +2mn; \\ \varepsilon = -1, & \quad a = -\left( m^2 - n^2 \right),\quad b = -2mn; \\ \varepsilon = +i, & \quad a = -2mn,\quad b = +\left( m^2 - n^2 \right); \\ \varepsilon = -i, & \quad a = +2mn,\quad b = -\left( m^2 - n^2 \right).\end{cases}$$

For any primitive Pythagorean triple, there must be integers $c = 5$ and $T_{1}$ such that these two equations are satisfied. Hence, every Pythagorean triple can be generated from some choice of these integers.

As perfect square Gaussian integers
If we consider the square of a Gaussian integer we get the following direct interpretation of Euclid's formula as representing the perfect square of a Gaussian integer.


 * $$(m+ni)^2 = (m^2-n^2)+2mni.$$

Using the facts that the Gaussian integers are a Euclidean domain and that for a Gaussian integer p $$|p|^2$$ is always a square it is possible to show that a Pythagorean triple corresponds to the square of a prime Gaussian integer if the hypotenuse is prime.

If the Gaussian integer is not prime then it is the product of two Gaussian integers p and q with $$|p|^2$$ and $$|q|^2$$ integers. Since magnitudes multiply in the Gaussian integers, the product must be $$|p||q|$$, which when squared to find a Pythagorean triple must be composite. The contrapositive completes the proof.

Distribution of triples


There are a number of results on the distribution of Pythagorean triples. In the scatter plot, a number of obvious patterns are already apparent. Whenever the legs $T_{2}$ of a primitive triple appear in the plot, all integer multiples of $T_{3}$ must also appear in the plot, and this property produces the appearance of lines radiating from the origin in the diagram.

Within the scatter, there are sets of parabolic patterns with a high density of points and all their foci at the origin, opening up in all four directions. Different parabolas intersect at the axes and appear to reflect off the axis with an incidence angle of 45 degrees, with a third parabola entering in a perpendicular fashion. Within this quadrant, each arc centered on the origin shows that section of the parabola that lies between its tip and its intersection with its semi-latus rectum.

These patterns can be explained as follows. If $$a^2/4n$$ is an integer, then ($x2 + y2 − z2$, $$|n-a^2/4n|$$, $$n+a^2/4n$$) is a Pythagorean triple. (In fact every Pythagorean triple $α = u + vi$ can be written in this way with integer $u$, possibly after exchanging $v$ and $i$, since $$n=(b+c)/2$$ and $Z$ and $Z[i]$ cannot both be odd.) The Pythagorean triples thus lie on curves given by $$b = |n-a^2/4n|$$, that is, parabolas reflected at the $a$-axis, and the corresponding curves with $b$ and $a$ interchanged. If $b$ is varied for a given $c$ (i.e. on a given parabola), integer values of $z := a + bi$ occur relatively frequently if $z* := a − bi$ is a square or a small multiple of a square. If several such values happen to lie close together, the corresponding parabolas approximately coincide, and the triples cluster in a narrow parabolic strip. For instance, $a$, $b$, $a = gu$, $b = gv$ and $g$; the corresponding parabolic strip around $u$ is clearly visible in the scatter plot.

The angular properties described above follow immediately from the functional form of the parabolas. The parabolas are reflected at the $v$-axis at $g$, and the derivative of $u$ with respect to $v$ at this point is –1; hence the incidence angle is 45°. Since the clusters, like all triples, are repeated at integer multiples, the value $h$ also corresponds to a cluster. The corresponding parabola intersects the $a$-axis at right angles at $b$, and hence its reflection upon interchange of $z$ and $z*$ intersects the $δ$-axis at right angles at $z + z* = 2a$, precisely where the parabola for $z − z* = 2ib$ is reflected at the $a$-axis. (The same is of course true for $b$ and $δ$ interchanged.)

Albert Fässler and others provide insights into the significance of these parabolas in the context of conformal mappings.

The Platonic sequence
The case $2 = (1 + i)(1 − i) = i(1 − i)2$ of the more general construction of Pythagorean triples has been known for a long time. Proclus, in his commentary to the 47th Proposition of the first book of Euclid's Elements, describes it as follows:

Certain methods for the discovery of triangles of this kind are handed down, one which they refer to Plato, and another to Pythagoras. (The latter) starts from odd numbers. For it makes the odd number the smaller of the sides about the right angle; then it takes the square of it, subtracts unity and makes half the difference the greater of the sides about the right angle; lastly it adds unity to this and so forms the remaining side, the hypotenuse.

...For the method of Plato argues from even numbers. It takes the given even number and makes it one of the sides about the right angle; then, bisecting this number and squaring the half, it adds unity to the square to form the hypotenuse, and subtracts unity from the square to form the other side about the right angle. ... Thus it has formed the same triangle that which was obtained by the other method.

In equation form, this becomes:

$c2 = zz*$ is odd (Pythagoras, c. 540 BC):


 * $$\text{side }a : \text{side }b = {a^2 - 1 \over 2} : \text{side }c = {a^2 + 1 \over 2}.$$

$c$ is even (Plato, c. 380 BC):


 * $$\text{side }a : \text{side }b = \left({a \over 2}\right)^2 - 1 : \text{side }c = \left({a \over 2}\right)^2 + 1$$

It can be shown that all Pythagorean triples can be obtained, with appropriate rescaling, from the basic Platonic sequence ($c2$, $z$ and $z*$) by allowing $z$ to take non-integer rational values. If $z*$ is replaced with the fraction $m$ in the sequence, the result is equal to the 'standard' triple generator (2mn, $n$,$(a,b)$) after rescaling. It follows that every triple has a corresponding rational $a$ value which can be used to generate a similar triangle (one with the same three angles and with sides in the same proportions as the original). For example, the Platonic equivalent of $b$ is generated by $(a,b)$ as $(a,b)$. The Platonic sequence itself can be derived by following the steps for 'splitting the square' described in Diophantus II.VIII.

The Jacobi–Madden equation
The equation,


 * $$a^4+b^4+c^4+d^4 = (a+b+c+d)^4$$

is equivalent to the special Pythagorean triple,


 * $$(a^2+ab+b^2)^2+(c^2+cd+d^2)^2 = ((a+b)^2+(a+b)(c+d)+(c+d)^2)^2$$

There is an infinite number of solutions to this equation as solving for the variables involves an elliptic curve. Small ones are,


 * $$a, b, c, d = -2634, 955, 1770, 5400$$


 * $$a, b, c, d = -31764, 7590, 27385, 48150$$

Equal sums of two squares
One way to generate solutions to $$a^2+b^2=c^2+d^2$$ is to parametrize a, b, c, d in terms of integers m, n, p, q as follows:


 * $$(m^2+n^2)(p^2+q^2)=(mp-nq)^2+(np+mq)^2=(mp+nq)^2+(np-mq)^2.$$

Equal sums of two fourth powers
Given two sets of Pythagorean triples,


 * $$(a^2-b^2)^2+(2a b)^2 = (a^2+b^2)^2$$


 * $$(c^2-d^2)^2+(2c d)^2 = (c^2+d^2)^2$$

the problem of finding equal products of a non-hypotenuse side and the hypotenuse,


 * $$(a^2 -b^2)(a^2+b^2) = (c^2 -d^2)(c^2+d^2)$$

is easily seen to be equivalent to the equation,


 * $$a^4 -b^4 = c^4 -d^4$$

and was first solved by Euler as $$a, b, c, d = 133,59,158,134$$. Since he showed this is a rational point in an elliptic curve, then there is an infinite number of solutions. In fact, he also found a 7th degree polynomial parameterization.

Descartes' Circle Theorem
For the case of Descartes' circle theorem where all variables are squares,


 * $$2(a^4+b^4+c^4+d^4) = (a^2+b^2+c^2+d^2)^2$$

Euler showed this is equivalent to three simultaneous Pythagorean triples,


 * $$(2ab)^2+(2cd)^2 = (a^2+b^2-c^2-d^2)^2$$


 * $$(2ac)^2+(2bd)^2 = (a^2-b^2+c^2-d^2)^2$$


 * $$(2ad)^2+(2bc)^2 = (a^2-b^2-c^2+d^2)^2$$

There is also an infinite number of solutions, and for the special case when $$a+b=c$$, then the equation simplifies to,


 * $$4(a^2+a b+b^2) = d^2$$

with small solutions as $$a, b, c, d = 3, 5, 8, 14$$ and can be solved as binary quadratic forms.

Almost-isosceles Pythagorean triples
No Pythagorean triples are isosceles, because the ratio of the hypotenuse to either other side is $$, but $$ cannot be expressed as the ratio of 2 integers.

There are, however, right-angled triangles with integral sides for which the lengths of the non-hypotenuse sides differ by one, such as,


 * $$3^2+4^2 = 5^2$$


 * $$20^2+21^2 = 29^2$$

and an infinite number of others. They can be completely parameterized as,


 * $$\left(\tfrac{x-1}{2}\right)^2+\left(\tfrac{x+1}{2}\right)^2 = y^2$$

where {x, y} are the solutions to the Pell equation $$x^2-2y^2 = -1$$.

If $a$, $(a, b, c)$, $n$ are the sides of this type of primitive Pythagorean triple then the solution to the Pell equation is given by the recursive formula


 * $$a_n=6a_{n-1}-a_{n-2}+2$$ with $$a_1=3$$ and $$a_2=20$$
 * $$b_n=6b_{n-1}-b_{n-2}-2$$ with $$b_1=4$$ and $$b_2=21$$
 * $$c_n=6c_{n-1}-c_{n-2}$$ with $$c_1=5$$ and $$c_2=29$$.

This sequence of primitive Pythagorean triples forms the central stem (trunk) of the rooted ternary tree of primitive Pythagorean triples.

When it is the longer non-hypotenuse side and hypotenuse that differ by one, such as in


 * $$5^2+12^2 = 13^2$$


 * $$7^2+24^2 = 25^2$$

then the complete solution for the primitive Pythagorean triple $a$, $b$, $a$ is


 * $$a=2m+1, \quad b=2m^2+2m, \quad c=2m^2+2m+1$$

and


 * $$(2m+1)^2+(2m^2+2m)^2=(2m^2+2m+1)^2$$

where integer $$m>0$$ is the generating parameter.

It shows that all odd numbers (greater than 1) appear in this type of almost-isosceles primitive Pythagorean triple. This sequence of primitive Pythagorean triples forms the right hand side outer stem of the rooted ternary tree of primitive Pythagorean triples.

Another property of this type of almost-isosceles primitive Pythagorean triple is that the sides are related such that
 * $$a^b+b^a=Kc$$

for some integer $$K$$. Or in other words $$a^b+b^a$$ is divisible by $$c$$ such as in
 * $$(5^{12}+12^5)/13 = 18799189$$.

Fibonacci numbers in Pythagorean triples
Starting with 5, every second Fibonacci number is the length of the hypotenuse of a right triangle with integer sides, or in other words, the largest number in a Pythagorean triple, obtained from the formula $$(F_nF_{n+3})^2 + (2F_{n+1}F_{n+2})^2 = F_{2n+3}^2.$$ The sequence of Pythagorean triangles obtained from this formula has sides of lengths
 * (3,4,5), (5,12,13), (16,30,34), (39,80,89), ...

The middle side of each of these triangles is the sum of the three sides of the preceding triangle.

Generalizations
There are several ways to generalize the concept of Pythagorean triples.

Pythagorean $b$-tuple
The expression
 * $$\left(m_1^2 - m_2^2 - \ldots - m_n^2\right)^2 + \sum_{k=2}^n (2 m_1 m_k)^2 = \left(m_1^2 + \ldots + m_n^2\right)^2$$

is a Pythagorean $\sqrt{2}$-tuple for any tuple of positive integers $a$ with $a$. The Pythagorean $\sqrt{2}$-tuple can be made primitive by dividing out by the largest common divisor of its values.

Furthermore, any primitive Pythagorean $n$-tuple $b$ can be found by this approach. Use $a$ to get a Pythagorean $n$-tuple by the above formula and divide out by the largest common integer divisor, which is $n$. Dividing out by the largest common divisor of these $b$ values gives the same primitive Pythagorean $n$-tuple; and there is a one-to-one correspondence between tuples of setwise coprime positive integers $n$ satisfying $382 = 1444$ and primitive Pythagorean $n$-tuples.

Examples of the relationship between setwise coprime values $$\vec{m}$$ and primitive Pythagorean $n$-tuples include:


 * $$\begin{align}

\vec{m} = (1) & \leftrightarrow 1^2 = 1^2 \\ \vec{m} = (2, 1) & \leftrightarrow 3^2 + 4^2 = 5^2 \\ \vec{m} = (2, 1, 1) & \leftrightarrow 1^2 + 2^2 + 2^2 = 3^2 \\ \vec{m} = (3, 1, 1, 1) & \leftrightarrow 1^2 + 1^2 + 1^2 + 1^2 = 2^2 \\ \vec{m} = (5, 1, 1, 2, 3) & \leftrightarrow 1^2 + 1^2 + 1^2 + 2^2 + 3^2 = 4^2 \\ \vec{m} = (4, 1, 1, 1, 1, 2) & \leftrightarrow 1^2 + 1^2 + 1^2 + 1^2 + 1^2 + 2^2 = 3^2 \\ \vec{m} = (5, 1, 1, 1, 2, 2, 2) & \leftrightarrow 1^2 + 1^2 + 1^2 + 1^2 + 2^2 + 2^2 + 2^2 = 4^2 \end{align}$$

Consecutive squares
Since the sum $2 × 272 = 1458$ of $3 × 222 = 1452$ consecutive squares beginning with $5 × 172 = 1445$ is given by the formula,


 * $$F(k,m)=km(k-1+m)+\frac{k(k-1)(2k-1)}{6}$$

one may find values $10 × 122 = 1440$ so that $n ≈ 1450$ is a square, such as one by Hirschhorn where the number of terms is itself a square,


 * $$m=\tfrac{v^4-24v^2-25}{48},\; k=v^2,\; F(m,k)=\tfrac{v^5+47v}{48}$$

and $a$ is any integer not divisible by 2 or 3. For the smallest case $a = 2n$, hence $b$, this yields the well-known cannonball-stacking problem of Lucas,


 * $$0^2+1^2+2^2+\dots+24^2 = 70^2$$

a fact which is connected to the Leech lattice.

In addition, if in a Pythagorean $a$-tuple ($2n$) all addends are consecutive except one, one can use the equation,


 * $$F(k,m) + p^{2} = (p+1)^{2}$$

Since the second power of $b$ cancels out, this is only linear and easily solved for as $$p=\tfrac{F(k,m)-1}{2}$$ though $b = 2n$, $a$ should be chosen so that $b$ is an integer, with a small example being $a$, $a = 2n$ yielding,


 * $$1^2+2^2+3^2+4^2+5^2+27^2=28^2$$

Thus, one way of generating Pythagorean $n$-tuples is by using, for various $a$,


 * $$x^2+(x+1)^2+\cdots +(x+q)^2+p^2=(p+1)^2,$$

where q = n–2 and where


 * $$p=\frac{(q+1)x^2+q(q+1)x+\frac{q(q+1)(2q+1)}{6} -1}{2}.$$

Fermat's Last Theorem
A generalization of the concept of Pythagorean triples is the search for triples of positive integers $a$, $b$, and $n$, such that $n = 1$, for some $a$ strictly greater than 2. Pierre de Fermat in 1637 claimed that no such triple exists, a claim that came to be known as Fermat's Last Theorem because it took longer than any other conjecture by Fermat to be proved or disproved. The first proof was given by Andrew Wiles in 1994.

$a$ or $a$ $(a2 − 1)/2$th powers summing to an $(a2 + 1)/2$th power
Another generalization is searching for sequences of $a$ positive integers for which the $a$th power of the last is the sum of the $m/n$th powers of the previous terms. The smallest sequences for known values of $m2 − n2$ are:


 * $m2 + n2$ = 3: {3, 4, 5; 6}.
 * $a$ = 4: {30, 120, 272, 315; 353}
 * $(56, 33, 65)$ = 5: {19, 43, 46, 47, 67; 72}
 * $a = m/n = 7/4$ = 7: {127, 258, 266, 413, 430, 439, 525; 568}
 * $(a, (a2 –1)/2, (a2+1)/2) = (56/32, 33/32, 65/32)$ = 8: {90, 223, 478, 524, 748, 1088, 1190, 1324; 1409}

For the $a$ case, in which $$x^3+y^3+z^3=w^3,$$ called the Fermat cubic, a general formula exists giving all solutions.

A slightly different generalization allows the sum of $b$ $c$th powers to equal the sum of $a$ $b$th powers. For example:
 * ($c$): 1$n$ + 12$n$ = 9$3$ + 10$3$, made famous by Hardy's recollection of a conversation with Ramanujan about the number 1729 being the smallest number that can be expressed as a sum of two cubes in two distinct ways.

There can also exist $n$ positive integers whose $(m1, ..., mn)$th powers sum to an $m > m + ... + m$th power (though, by Fermat's Last Theorem, not for $a + ... + a = c2$; these are counterexamples to Euler's sum of powers conjecture. The smallest known counterexamples are


 * $(m1, ..., mn) = (c + a1, a2, ..., an)$: (95800, 217519, 414560; 422481)
 * $2m1 = 2(c + a1)$: (27, 84, 110, 133; 144)

Heronian triangle triples
A Heronian triangle is commonly defined as one with integer sides whose area is also an integer. The lengths of the sides of such a triangle form a Heronian triple $(m1, ..., mn)$ for $(m1, ..., mn)$. Every Pythagorean triple is a Heronian triple, because at least one of the legs $m > m + ... + m$, $F(k,m)$ must be even in a Pythagorean triple, so the area ab/2 is an integer. Not every Heronian triple is a Pythagorean triple, however, as the example $k$ with area 24 shows.

If $m2$ is a Heronian triple, so is $(k, m)$ where $F(k,m)$ is any positive integer; its area will be the integer that is $v ≥ 5$ times the integer area of the $v = 5$ triangle. The Heronian triple $k = 25$ is primitive provided a, b, c are setwise coprime. (With primitive Pythagorean triples the stronger statement that they are pairwise coprime also applies, but with primitive Heronian triangles the stronger statement does not always hold true, such as with $n$.) Here are a few of the simplest primitive Heronian triples that are not Pythagorean triples:


 * (4, 13, 15) with area 24
 * (3, 25, 26) with area 36
 * (7, 15, 20) with area 42
 * (6, 25, 29) with area 60
 * (11, 13, 20) with area 66
 * (13, 14, 15) with area 84
 * (13, 20, 21) with area 126

By Heron's formula, the extra condition for a triple of positive integers $n ≥ 4$ with $p$ to be Heronian is that



or equivalently

be a nonzero perfect square divisible by 16.

Application to cryptography
Primitive Pythagorean triples have been used in cryptography as random sequences and for the generation of keys.