finding a Pythagorean triple of a given size

Pythagorean triples are any whole numbers that meet the famous formula A²+B²=C². I’d like to be able to find an example where C is close to but not over a certain value; let’s say 1000 for example. Ideally it should also be “primitive”- that is, it doesn’t factor into a smaller example like 600²+800²=1000² does, and for larger values confirming that there aren’t any common denominators is a problem. I’m aware of how Pythagorean triples can be generated by a set of formulas but I don’t know how to work the process backward from a given end.

Do you care at all about the shape of the triangle? The simplest family of primitive Pythagorean triples gives you really long, skinny triangles. For every odd integer n, there’s a triple with n as the short side, and with the other two sides being separated by 1: For instance, 3, 4, 5; 5, 12, 13; 7, 24, 25; 9, 40, 41; and so forth. In each of these cases, if the short side is n, the other two sides are (n^2-1)/2 and (n^2+1)/2. If we want to find such a triple with the long side close to but not over 1000, then we take the equation 1000 = (n^2+1)/2 , or rearranging to solve for n, n = sqrt(2*1000 - 1) = sqrt(1999). The square root of 1999 is 44.71… . Rounding down to the next odd number, that gives us 43, so our triple is 43, 924, 925 .

All that said, though, there are plenty of primitive Pythagorean triples that don’t fall into that family, too, and one of those might be closer to 1000 (in fact, I’d be surprised if there weren’t).

The hypotenuse will be a[sup]2[/sup]+b[sup]2[/sup] in the usual parametric form. You can try all cases to find the closest to 1000; it is 31[sup]2[/sup] + 6[sup]2[/sup] = 997

The other sides of the right triangle are a[sup]2[/sup]-b[sup]2[/sup] and 2ab, and a=31, b=6, so
(997, 925, 372)

A few years ago I was thinking about this kind of thing: I was particularly interested in a couple of things: how to generate Pythagorean triples with some rule, and whether I could find a triple where all the integers were relatively prime (having no common factor) and which the difference between b and c was an integer other than 1 (the most commonly mentioned Pythagorean triples are 3-4-5 and 5-12-13, both of which have a difference of 1 between b and c - it’s easy enough to make an arbitrary integer difference between b and c by multiplying creating a’=ka, b’=kb, and c’=k*c, but then the triple is not a “primitive triple” since the integers share a common factor (note that I’m only interested in positive integers in this case).

        Here's how I reasoned.  Let d be the difference between b and c - c=b+d.  Then, a*a=(b+d)*(b+d)-b*b, or a*a=d*(2b+d).  If d=1, then b=(a*a-1)/2; for any odd a, you can create a Pythagorean triple; for a=1 we get the degenerate case of 1-0-0, but a=3 gives 3-4-5, a=5 gives 5-12-13, a=7 gives 7-24-25, and so on.

        For d=2, a*a=2*(2*b+2), or b=(a*a-4)/4.  For any even a, you can create a Pythagorean triple; for a=2, again we get a degenerate case (2-0-2), but for a=4, we get 4-3-5 (again!), for a=6, we get 6-8-10 (not a primitive triple - all the integers are divisible by 2), for a=8, we get 8-15-17, for a=10, we get 10-24-26 (another non-primitive), and so on (for a divisible by 2 but not by 4, you get a non-primitive triple, for a divisible by 4 you get a primitive triple).

        What happens when d is greater than 2?  a*a still needs to equal d*(2b+d), so a*a must be divisible by d.  Since a*a is a perfect square, (2b+d) must also be divisible by d, which means that b must be divisible by d.  Since c*c=a*a+b*b, c must also be divisible by d.  Therefore, every Pythagorean triple with d>2 is not primitive.  QED.

You could consult a list of Pythagorean triples that’s sorted by c.

Here’s where I’m coming from: at one point I thought that all Pythagorean triples were of the skinnier and skinnier triangles type, where B and C differ by either one or two. Then I learned about Euclid’s Formula, which allows you to generate triples by taking two numbers M and N, where A=M²-N², B=2MN, and C=M²+N². I then learned of counter-examples to the skinny triangles types, especially 20²+21²=29², the next triple after 3-4-5 where A and B differ by one.

The triples where A and B differ by one are based on the values of M and N for a series sometimes called the “Silver Ratio” by analogy with the Golden Ratio, where each term after 2 is double the previous term plus the term before that: 1,2,5,12,29, etc. I decided for a lark to see what was the largest such triple that I could verify the full integer value of C² using Windows Calculator, which can handle 31 digits before going into floating-point values. I came up with a ridiculously huge value of C², roughly 3 x 10[sup]30[/sup].

For the next largest Silver Ratio triple C² would be over 31 digits and thus calculated only approximately in floating point mode. However there could still be a verifiable triple where C² is close to 9 x 10[sup]30[/sup] that would trump the example I came up with. But finding it by trial and error would be impossible; one would have to find a proof or formula that generated it.

For the obsessive-compulsive, the values I came up with:[spoiler]
M= 38,613,965
N= 15,994,428
A=M²-N²= 1,235,216,565,974,041
B=2MN= 1,235,216,565,974,040
C=M²+N²= 1,746,860,020,068,409

A²= 1,525,759,964,856,702,382,327,085,869,681
B²= 1,525,759,964,856,699,911,893,953,921,600
(A²+B²)=C²= (calculated separately and compared):
3,051,519,929,713,402,294,221,039,791,281
[/spoiler]

This book has a whole chapter (complete on Google Books) on Pythagorean triples which may be helpful. Recreations in the Theory of Numbers (chapter 14, The Eternal Triangle)

Your proof looked pretty good until this line. The problem is that d could contain a perfect square, and then (2b+d) must only divide the remaining factors. Take Lumpy’s example of 20²+21²=29²: d is 8, or 222. (2b+d) is 50, and does not divide 8, but does divide 2 (which is what remains after removing 2*2 from d).

Yeah, I realized my mistake when I saw Lumpy’s example. So close…

If you’re looking for Pythagorean Triples where one leg and the hyponteneuise differ by one, then you should know that every odd number is the short leg in such a puthagorean triple. If that short leg is 2 n + 1, then the other side is **2 n [sup]2[/sup] + 2 n ** and the hypoteneuse is, predictably, 2 n [sup]2[/sup] + 2 n + 1. (And the radius of the inscribed circle is simply n).

It’s true that you can thus generate more and more unique, non-divisible Pythagorean Triples in this fashion, but that doesn’t mean that all further non-divisible Pythagorean triples are of this form, as you can verify by playing with Euclid’s formula. In addition, that very useful formula will not generate all possible Pythagoream triples. You can easily verify, by plugging in numbers, that it skips some of the multiples of lower-order triples. I don’t know if it generates all lowest order triples, but I suspect it doesn’t.

Euclid’s formula tells you that for a primitive Pythagorean triple, the hypotenuse c is a sum of two squares, c=m[sup]2[/sup]+n[sup]2[/sup]. Your question (I think) is, What constraints does this place on c; and how can I find m and n given c?

The answer to the first question (which integer values can be hypotenuses of primitive Pythagorean triangles) is given by Fermat’s theorem on the sum of two squares:

The “only if” part is obvious: squares are either 0 or 1 (mod 4), so the sum of two squares cannot be 3 (mod 4)–the important part is the “if” statement. There’s also an algorithm (Cornacchia’s algorithm) for finding m and n more efficiently than the O(sqrt(c)) exhaustive search.

With Fermat’s theorem together with an equation which goes by the impressive name of the “Brahmagupta-Fibonacci identity”

(this identity, btw, looks amazing when first encountered; but when looked at in the right way, as a statement about complex numbers, it is trivial) you can prove that you can write a number c as the sum of two squares (and so use it as the hypotenuse of a primitive Pythagorean triple) if and only if, in the prime factorization of c, each odd prime factor congruent to 3 (mod 4) occurs to an even power. The idea is to write each 1-mod-4 prime in the squarefree part of c as a sum of squares (by Fermat) and then combine these factors using Brahmagupta-Fibonacci.

For example, take c=33513=585. We have 5=2[sup]2[/sup]+1[sup]2[/sup] and 13=3[sup]2[/sup]+2[sup]2[/sup] for the two 1-mod-4 factors of c. Using BF gives us
5
13=(2[sup]2[/sup]+1[sup]2[/sup])(3[sup]2[/sup]+2[sup]2[/sup])=8[sup]2[/sup]+1[sup]2[/sup]=7[sup]2[/sup]+4[sup]2[/sup],
and then multiplying by the square root of the square factor of c gives
c=(3
8)[sup]2[/sup]+(31)[sup]2[/sup]=24[sup]2[/sup]+3[sup]2[/sup]
and
c=(3
7)[sup]2[/sup]+(34)[sup]2[/sup]=21[sup]2[/sup]+12[sup]2[/sup].
For your example of c~1000, you can just look in the neighborhood of 1000 for appropriate values. 999, 995, 991, … are all 3 (mod 4) so they’re out; but 997 is prime and 1 (mod 4) so it would work (997=31[sup]2[/sup]+6[sup]2[/sup]). 993 has a single factor of 3 so it’s out; likewise 989 is out; but 985=5
197 and 981=33109, so they would also work (though 981 wouldn’t give a primitive triple, since m and n would share a factor of 3).

So as long as you can factor c, it’s easy to determine whether it can be the hypotenuse of a primitive Pythagorean triangle:

And of course if you don’t demand primitivity, you can factor out all of the offending 3-mod-4 factors to give a smaller triangle, as long as there’s at least one 1-mod-4 factor left to use to make a triangle with.

Factoring c, if you are not constructing c explicitly by multiplying primes, will eventually get difficult; but at the sizes c~10[sup]15[/sup] you’re interested in, factoring is still easy to do by exhaustive search.

Euclid’s formula (m[sup]2[/sup]-n[sup]2[/sup],2mn,m[sup]2[/sup]+n[sup]2[/sup]) actually does generate all and precisely the primitive Pythagorean triples, when m and n are chosen with m>n, m+n odd, and m and n relatively prime. To get the nonprimitive triangles you just consider all multiples of the primitive triangles, (k(m[sup]2[/sup]-n[sup]2[/sup]),2kmn,k(m[sup]2[/sup]+n[sup]2[/sup])).

But , as I said, it doesn’t generate all the non-priomitive ones. It does generate most of the non-primitive ones, but there are curious gaps.

I was responding to your suspicion that Euclid’s formula doesn’t generate all of the primitive triples.

If you remove the restrictions on relative primality (i.e., require only m>n) then Euclid’s formula does generate some nonprimitive triples, but not really most of them except for small common factors: in fact it generates only the triples which are either a square multiple or twice a square multiple of the primitive triples (i.e., k=1, 2, 4, 8, 9, 16, 18, 25, 32, …). So it generates (3,4,5) and (6,8,10) but not (9,12,15); then it gets (12,16,20) but misses (15,20,25), (18,24,30), and (21,28,35); and so on.

For what it’s worth, recent versions of the Windows Calculator actually use more precision than this internally; it’s just the display that is limited to 31-or-whatever digits. (Wiki says it’s using arbitrary-precision arithmetic; I don’t know what limits it has, but it seems to be substantially more than 31 digits.)

I can’t speak for Windows Calculator specifically, but generally “arbitrary-precision” is limited only by available memory in the machine and the user’s patience while waiting for the answer.

You declare that, but is it true? I’ve never seen a proof of it. certainly it’s worked as far as I’ve taken it, but that’ not a proof.

I wrote a little program to generate this table of numbers with (b-a)=1:
a=3, b=4, c=5
a=20, b=21, c=29
a=119, b=120, c=169
a=696, b=697, c=985
a=4059, b=4060, c=5741
a=23660, b=23661, c=33461
a=137903, b=137904, c=195025
a=803760, b=803761, c=1136689
a=4684659, b=4684660, c=6625109
a=27304196, b=27304197, c=38613965

Obviously, the ratios here are all close to sqrt(2), and coincidentally one of them has the hypotenuse 985 that you mentioned.

If Euclid’s formula generates all primitive triplets, I can show that there is a restriction on the differences (c-a) and (c-b): for all primitive triplets, the difference is either a perfect square or 2 times a perfect square. That makes me feel a little better (I had thought there (c-a) and (c-b) couldn’t equal 3 in a primitive triplet, though my proof to show that went astray)

Sorry to stray a bit off-topic, but I just noticed that the ratio between successive a’s seems to converge on a constant:
6.6666666666666670
5.9500000000000002
5.8487394957983190
5.8318965517241379
5.8290219265829020
5.8285291631445482
5.8284446313713261
5.8284301283965361
5.8284276400907729

Anyone know if this constant has a name?

Looks like the sequence is known, and the ratio is 3+sqrt(8). It does make it fairly easy to generate new triples with nearly-equal a and b.

Or more preciesely, it’s converging on (√2+1)², which is a natural consequence of how the sequence is defined. If we’re looking for triples where A and B are as close to equal as possible (differing only by one), and A=M²-N² and B=2MN, then taking A and B as exactly equal as a limit you start with M²-N²=2MN. If you take N as 1 then the equation successively becomes:
M²-1=2M,
M²-2M-1=0
M²-2m+1=2
(M-1)²=2
M-1=√2
M=√2+1

So for M and N you have the sequence of 1,2,5,12,29,… where each new term is about (√2+1**) **x the previous term. This is equivalent to the rule where each term is equal to double the previous term plus the one before that because each term is then about (√2+1)² x the term two places back, which is 2+2√2+1, then 2(√2+1)+1, when the term two places back is taken as 1.

So using that sequence to define each new A means the ratio of the A’s converges on (√2+1)²