Pythagorean triples have a long and storied tradition. But what about the near misses?
You’d be surprised how much math[s] you can learn by exploring some of the implications and ramifications of what may seem at first no more than a trivial brainteaser
Martin Gardner
Every so often, I get nerdsniped good and proper. In some cases, multiple times in a week. Here is Chris Smith doing just that:
Here’s Chris’s question in text form:
Can we find three different triangular numbers
, and so that every combination of the three gives a triangular number? So
, , and should all be triangular numbers.
In this case, it wasn’t the puzzle itself that did for me; I solved that fairly quickly. But in so doing, I dug up something deeper and more interesting, and – to the best of my knowledge – unsolved.
Welcome to the fascinating world of almost Pythagorean triples.
What is an almost Pythagorean triple?
You, being an avid Aperiodical reader, might have come across Pythagorean triples before: three integers,
In the 1980s, Orrin Frink wondered: what about triples that are off by one? That is, what if
These are not to be confused with nearly Pythagorean triples, in which
Some examples of APTs include
Antalan and Tomenes also looked at APTs, and asked the key question I will answer in this article: “Is there an explicit formula to generate APTs?” The answer to this is “yes”, but we’ll need to do some work to get there.
First, some definitions: it’s useful to distinguish between isosceles APTs, such as
The two shorter elements of an APT cannot both be even – if they were:
would be a multiple of 4 would be odd, so would be two more than a multiple of 4
These two things can’t both be true! So at least one of
Without loss of generality, I can assume that
So:
What can I easily say about APTs?
Let’s apply some algebra to the key equation
That can be rearranged to
I’ve asserted that
The algorithm I’m about to present treats each of these four factors as a product of two integers, so that the product on the left-hand side and the product on the right-hand side match. In particular, I’m going to generate four integers,
Note that
For example, if
The goal is to begin with values of
- How can
and be found? - Does every pair of coprime
and give an APT? - Is every APT is generated by some
pair? - Is every APT is generated by exactly one
pair?
If the answers to this are (respectively) “like so”, “yes”, “yes” and “yes”, then I’ll have an answer to Antalan and Tomenes’s challenge.
Generating APTs
I’m going to give a proposition:
Given a pair of coprime integers,
and , there are infinitely many integer values of and such that . However, there is only one of each such that and , which is a lemma you may wish to prove. Using the multiplicative inverse, let
and . Then
is an almost Pythagorean triple.
In the restriction
A proof will follow later. You may provide your own if you can’t wait that long.
Hold on hold on hold on, what’s this multiwhotsit hoojimaflip?
I thought you’d never ask. We need to take a quick detour into modular arithmetic — or rather, the world of remainders; modular arithmetic is fascinating and wonderful, but we’re only after one small aspect of it here.
A tl;dr, in case you just don’t recognise the term: if you’ve got two coprime integers,
Again, with the
For example, suppose
If you want to have a look at this in action, find (or write out) a times tables grid and find the entries that end in one. You will notice (I hope) that there is exactly one of these in each times table that doesn’t share a factor with 10.
Modulo 10, 7 is the multiplicative inverse of 3, and we write that as
There’s no such restriction on
So how do we find a multiplicative inverse if the numbers are too big to bother listing all the possibilities? We know an identity about that!
Bézout’s identity: Suppose
In particular, if
- Take away as many
s from as possible: - Take away as many
s from as possible: , which makes sense, if you think about it.
I can add any multiple of
To double-check:
TL;DR, repeated for emphasis: Given that
With regard to the algorithm, Euclid offers two-for-the-price-of-one here: if I work out
A fuller example
Let’s pick two coprime integers at random to try this with:
Step 1: apply the Euclidean algorithm to find
- Take away as many
s as possible: - Take away as many
s as possible: - Take away as many
s as possible: - Take away as many
s as possible: , as one would hope.
In this case, the
Solving the simultaneous equations:
gives
Proofs
These proofs have not been properly refereed, and I am not a proper number theorist. I would very much welcome constructive criticism about tightening them up.
A quick note on an edge case: as I mentioned previously if
In the proofs that follow, I adopt the convention that
1 The algorithm always gives an APT
Proposition:
- If
and are positive integers with - Let
and - If:
- Then
.
Proof:
Note that for given coprime
for some integer for some integer .
By inspection,
Now, let’s show that this gives an APT.
Consider
Similarly,
However,
So,
2 Every APT is generated by the algorithm
Proposition: For every triple of positive integers
Proof:
Note that
Let:
Note that
Let:
By similar reasoning,
- Since
, . - Since
, I can say - So
and .
This means
Therefore, for any
3 No APT is generated more than once
Suppose an APT
This implies:
Note that
Let
Since
Since
Since
Therefore, if
A small wrinkle
We’ve shown that the triple
I won’t work through the details here, but if an odd APT
If we care about this, we can place restrictions on our inputs to insist that
For
I’m not aware of a simple restriction on
Finding a nicer restriction here is left as an exercise for the interested reader.
Instead, we can simply reject any APTs where
Consequence
Since (1) every pair of positive coprime integers
As a result, by looping over the coprime positive integers and applying the given restriction, each possible APT is generated exactly once.
Conclusion
In this article, I’ve answered Antalan and Tomenes’s question: yes, there is a simple method to generate almost Pythagorean triples. It’s not clear to me that this is a new result (I haven’t been able to find any more on the topic, but I don’t know if that’s because (a) it’s not been done, (b) it’s been done and I’m looking in the wrong places, or (c) it’s been done and considered too trivial to be worth writing down.)
I haven’t answered Chris’s original question here, which is whether you can find a set of three triangular numbers
Neither have I explained the link between the puzzle and APTs. I’ll happily send a postcard to the first reader who figures it out!
Nerdsniping: the gift that keeps on giving.
More information
This article refers to:
- Antalan, J.R.M. and Tomenes, M.D.: A Note on Generating Almost Pythagorean Triples, International Journal Of Mathematics And Scientific Computing, Vol. 5, No. 2, 2015, pp. 100-102
- Frink, O.: Almost Pythagorean Triples, Mathematics Magazine, Vol. 60, No. 4, October 1987, pp. 234-236
I’m grateful to Chris Smith, Dominika Vasilkova and Elizabeth A. Williams for their help with this article.
Post edited 2021-11-22 to fix a typo in the ‘small wrinkle’ section (I had
Dear Colin, Many thanks for this, My interest is in what I call Near Fermat Triples. For each power n, what is the smallest non trivial constant Cn such that x^n + y^n = z^n +/- Cn has a solution in integer values of x,y,z,n and Cn. C2 is zero of course, but what about the higher values? Is anything known and in particular, is it ever as low as one? Best wishes Robert
I’m interested in this APT generating algorithm. But I think I’m missing something: For example if I plug in s=4, t=3 (so satisfying gcd(s,t)=1) and turn the handle on that, I get s’=1, t’=3 and so a=9, b=13, c=15… which doesn’t satisfy a^2+b^2=c^2+1. I’m puzzled.
Just to follow up previous comment (“queued for moderation” but I can’t see it after a page refresh).
Working through the other stuff… based on the thing I see that the should be negated (ie ) such that instead. And indeed when I update my implementation to do that, a stream of delicious APT triples flood out.