# Pythagorean and Almost Pythagorean Triples

Pythagoras’ theorem leads into algebra and geometry, the theory of diophantine equations and applications outside mathematics: notably in cryptography and explaining why the SolarSystem is stable.

Pythagoras’ Theorem has fascinated mathematicians for a long time. If the solutions of this equation are restricted to whole numbers the resulting tripleshave interesting properties which require a knowledge of number theory, in particular the theory of prime numbers to determine which perfect squares can be decomposed into the sum of two perfect squares.

## Circles and triangles

Draw a square grid and, usinga pair of compasses, draw circles about the origin at distances 1,2,3….….. along the x- axis

Lets call a circle pythagorean if its centre is at the origin and the circle hits a grid point that is not on an axis.

A circle of radius R is pythagorean if R2 is the sum of two perfect squares.

Not all circles are pythagorean – some circles miss all off axis grid points.

A pythagorean triangle is a triangle inside a pythagorean circle with one end of the hypotenuse at the centre and the other where the circle hits a grid point. A circle may support many pythagorean triangles.

A pythagorean circle has at least eight off axis grid points on its circumference.This is because the equation a2 + b2 = c2 is true for positive and negative values and exchanging a with b.

## Pythagorean triples

It is simpler to consider only one quadrant of the circle and minimise the number of triangles involved. This can turn the discussion away from geometry towards algebra

A pythagorean triple is three whole numbers (a,b,c) with 0 < a <b <c and a2 + b2 = c2

Example: (3,4,5) is a pythagorean triple while (4,3,5) is not pythagorean but does represent a pythagorean triangle.

A triple is primitive if a, b are coprime.

Scroll to Continue

Euclid’s formula lets you generate primitive triples

Given two coprime integers m and n exactly one of which is odd, with m > n > 0 the integers

a = m2 -n2 b = 2mn c = a2 +b2

form a primitive pythagorean triple.

Multiplying a, b and c by any integer greater than zero results in a non primitive triple.

There is a countable infinity of primitive pythagorean triples – this means we can associate the primitive triples in a one to one fashion with the natural numbers {1,2,3,…..}

There may be more than one pythagorean triangle for a given value of R or equivalently there may be multiple pythagorean triples with the same value of c.

One of many fascinating results about Pythagorean triples is

For each natural number n, there are at least n different Pythagorean triples with the same hypotenuse (radius of circle or value of c)

Alternatively For each natural number n there is a pythagorean circle that contains at least n distinct pythagorean triangles in the first quadrant.

Or yet another way, for each natural number n there is a perfect square that can be decomposed into a sum of two squares in at least n ways.

Given the radius of a pythagorean circle we can use a result from number theory to find how many pythagorean triangles the circle holds by reducing R2 to the product of primes and examining the powers of each prime. It is then relatively simple to construct a number larger than n.

## Near Pythagorean triples

In 1987 Orrin Frink started investigating two more difficult problems: Almost Pythagorean Triples (x2 + y2 =c2 -1), or APT and Near Pythagorean Triples (x2 + y2 =c2 +1) (NPT) and showed they are related to the figure obtained by rotating a hyperbola about the vertical axis (a hyperboloid). He did not however derive a way to generate all such triples. This problem seems to be open still, partly because the diophantine equations involved are harder to solve than the pythagorean equation.

It is possible to generate APT and NPT from Pythagorean triples but not clear whether this generates all APT and NPT.

## Computational aspects

A python function, primefac, is available for download that is reasonably efficient at factorising an integer into the product of powers of prime numbers, though there is no quick way to factorise really large numbers. The most efficient such algorithm, the Generalised Number Field Sieve requires a good knowledge of advanced algebra to implement.

Determining all pythagorean triples, APT or NPT with hypotenuse less than a given number n has a time proportional to the square root of n but the need to factorise each integer less than n to find how many ways it can be split into the sum of squares (some integers can’t be split into the sum of two squares) dominates the calculation for large values of n. In addition for really large numbers it may be necessary to use infinite precision arithmetic, which will again tend to slow down the computation.

## Summary and conclusion

Pythagorean Triples and Frink’s extensions link Geometry, Algebra and Number Theory and provide a fascinating introduction to these fields. Computational investigation of these objects is difficult because there is no efficient prime number factorisation algorithm for arbitrarily large numbers and an analytic solution for NPT and APT has not been discovered.