Formulas for calculating pythagorean triples

7.1k Views Asked by At

I'm looking for formulas or methods to find pythagorean triples. I only know one formula for calculating a pythagorean triple and that is euclid's which is:

$$\begin{align} &a = m^2-n^2 \\ &b = 2mn\\ &c = m^2+n^2 \end{align}$$

With numerous parameters.

So are there other formulas/methods?

3

There are 3 best solutions below

0
On BEST ANSWER

It doesn't seem cumbersome to me. Just loop on $m$ starting at $2$. Loop on $n$ starting at $1$ or $2$ depending on the parity of $m$ and going up to $m-1$. Check the GCD using Euclid's algorithm. If it is $1$ you have a primitive set, so calculate $a,b,c$. If you want all sets up to some $N$, multiply $a,b,c$ by all values up to $\lfloor \frac Nc \rfloor$. Stop the $m$ loop at $\sqrt N$

0
On

The one I was taught in my lectures was:

Assume that $(x, y, z)$ is a Pythagorean triple in which $x$ is odd, so that $y$ is even and $z$ is odd. For similar reasons, we assume that $p$ and $q$ are coprime $(x,y,z,p,q \in \mathbb{Z})$. The theory of Pythagorean triples then tells us that there are nonzero integers $p$ and $q$ (with $p > q$)such that

$$x + iy = (p + iq)^2 \hspace{1.5cm} z = |p + iq|^2 = p^2 + q^2.$$

If $x$ is odd then one of $p$ and $q$ must be even and the other is odd.

In case it isn't obvious, the way it works is this: let's first check with the smallest three triples. Let's pick two small numbers satisfying the criteria for $p$ and $q$, i.e take $p = 2$ and $q = 1$ (one of them is odd, both are co-prime and $p > q$). First, to find our $z$ value, we simply do $p^2 + q^2 = 1^2 + 2^2 = 5$. Now, let's calculate our $x$ and $y$ values:

$$x + iy = (p + iq)^2 = (2 + i)(2 + i) = 4 + 4i - 1 = 3 + 4i.$$

From here, we see that $x = 3$ and $y = 4$, which we know to be true as $3^2 + 4^2 = 5^2$/

This might not give you ALL the Pythagorean triples but its another way of doing it, seeing as you only need to pick $p,q$ and the rest are worked out for you.

The coding I've ever done is Matlab so I can only really think how to put this in terms of Matlab (and even then it might be wrong), so I'm not sure if it will work for your program or whatever you're making, but here is another way anyway.

2
On

I have found that for all odd $A$ numbers the following is true $\frac{A^2-1}2=b$ and $b+1=c$

For all even numbers $$\frac{A^2}4-1=b \qquad\text{ and }\qquad b+2=c$$

These get many of the triples and it works because the difference of squares of 2 consecutive numbers is always an odd square And that difference of the squares of 2 consecutive odd numbers is always an even square. I hope I worded that correctly.