HP Forums

Full Version: integer right triangles
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am just playing around with find all of the integer right triangles with my DM 42s.
I have A program that will do it but it gives me twice the count ( 3,4,5 and 4,3,5).
Does any one know of any to compare them and remove the duplicates using the DM 42? I am drawing A blank.
Start with the smaller number, a. You're now looking for pairs of numbers b, c, such that c^2 - b^2 = a^2. For the difference between two squares, there are two useful constraints.

First, you don't want to find the same triplet twice. That leads to the first constraint: b > a. (You don't need to consider b = a, since a^2 + a^2 = c^2 has no solutions in the positive integers, because sqrt(2) is irrational.)

Second, you don't want to search any further than you have to. The difference between two consecutive squares grows monotonically: (b+1)^2 - b^2 = 2*b - 1, so for a given a, you can stop searching when 2*b - 1 > a^2.

Further optimizations are possible, but with these two constraints, you can write a simple program that will enumerate all the Pythagorean triplets, and do it reasonably efficiently. I actually wrote this on my HP-41C back in the day, but that program was lost ages ago. Please share what you come up with!
Look at Wikipedia for Pythagorean Triples:

Euclid's formula is a fundamental formula for generating Pythagorean triples given an arbitrary pair of integers m and n with m > n > 0. The formula states that the integers
$$a=m^{2}-n^{2}, b=2mn, c=m^{2}+n^{2}$$
form a Pythagorean triple. The triple generated by Euclid's formula is primitive if and only if m and n are coprime and not both odd.
Perhaps the thread (41C) Pythagorean Triples posted in HP-41C Software Library may be of minor interest?

BEST!
SlideRule
ok thank you! All I had to do was modify the inner loop counter on my original program. The program is still A bit of A mess but I dough it will run much faster (my Poor printer can't go that fast)! Sad
(10-15-2019 02:34 AM)vanLudwig Wrote: [ -> ]Euclid's formula is a fundamental formula for generating Pythagorean triples given an arbitrary pair of integers m and n with m > n > 0. The formula states that the integers
$$a=m^{2}-n^{2}, b=2mn, c=m^{2}+n^{2}$$
form a Pythagorean triple. The triple generated by Euclid's formula is primitive if and only if m and n are coprime and not both odd.

A bit of related fun: The sequence of Pell Numbers (1, 2, 5, 12, 29, 70, 169, ...) is defined recursively as P(1)=1, P(2)=2, and P(n)=2*P(n-1)+P(n-2). Try consecutive pairs of Pell Numbers (e.g. 1 and 2, or 2 and 5) for m and n in the above formulas, and as they get bigger, you'll see why the Pythagorean Triples they yield are called "almost-isosceles primitive Pythagorean triangles".

Spoiler Alert: the above is an immediate consequence of the matrix definition of Pell Numbers:

[Image: Pell.png]

Just take the determinant of both sides. VoilĂ !
Reference URL's