This enumeration of all Pythagorean triples (PTs) generates exactly one PT from every natural number, thus creating a comprehensive ordered list of PTs, indexed by the natural numbers. This is done by first creating a twodimensional table of ordered pairs of the form
, to be traversed in diagonal stripes (inspired by Cantor's demonstration of the countability of the rational numbers). The integers
and
are then used as the multiplier and the index of the primitive PT (PPT), for which the precise algorithm is explained more fully in a previous Demonstration. Thus, the function
produces only those CW pairs of the form
that comply with the conditions that
and
be relatively prime, have opposite parity and
. These pairs are then used to generate PPTs of the form
. Multiplying these PPTs by
thus gives a onetoone mapping between the set of all natural numbers and the set of all PTs.
The "
" slider controls how many PTs are calculated, and in graph mode the "zoom" slider determines how much to zoom in on those points close to the origin. Use the "mode" toggle bar to change the display: graphing PTs, generating a simple list of PTs, displaying the Cantor diagonal ordering of
and the
PPT, or generating a commented table showing the derivation of the PTs.
Snapshot 1: the scatter plot graph of the enumerated PTs as given in the

plane, where
is the odd leg and
the even leg of the triangle represented by the PT, zoomed in to show only
of the largest value, with all side lengths and a proportional triangle shown on mouseover
Snapshot 2: a simple list of the first 50 PTs generated by the enumeration
Snapshot 3: a Cantor diagonal ordering of the first 50 PTs, showing multiplier
and the PPT indexed by
, with values and resultant PTs shown on mouseover
Overlaying diagonal stripes on a doubly infinite table was a clever idea proposed by Georg Cantor to demonstrate the countability of the set of all rationals, which inspired a whole class of countability proofs. The image shown on tab 3 is a modification of one in [1], in which various enumerations are considered. One significant difference between Cantor's scheme, where the enumeration includes an infinite number of duplicate entries, and the present enumeration of all PTs is that here all
pairs generate distinct PTs, so the algorithm defines a 11 and onto function.
Snapshot 4: a table showing all steps of the process: natural numbers,
pairs, compliant natural numbers, compliant CW pairs, PPTs with multipliers and finally PTs generated by the enumeration algorithm