3

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?

Jeel Shah
  • 9,306
  • What is wrong with this one? It gets all the primitive ones if $m,n$ have no common factor and one is even. – Ross Millikan May 18 '13 at 14:26
  • 1
    Why don't you like these formulas? – Boris Novikov May 18 '13 at 14:26
  • @RossMillikan I was looking for one that could be easier to implement into a program. I am making a program that generates pythagorean triples. I have implemented this formula but I would like to know if there are more or if there are better more advance ones. EDIT: Also, this formula is a little cumbersome to implement, anyway. – Jeel Shah May 18 '13 at 14:28
  • @gekkostate: That's the most efficient formula for generating primitive triples.Are you looking for all the triples in order? – Inceptio May 18 '13 at 14:33
  • http://en.wikipedia.org/wiki/Formulas_for_generating_Pythagorean_triples – lab bhattacharjee May 18 '13 at 14:33
  • @Inceptio I'm looking for triples in order – Jeel Shah May 18 '13 at 14:33
  • @gekkostate: Well, in what order? How do you define the order of triples in increasing order? – Inceptio May 18 '13 at 15:14
  • @Inceptio Like starting from the smallest pair to the largest pair? – Jeel Shah May 18 '13 at 15:21
  • Smallest pair? How would you like to define it? The sum of triples makes more sense to me. – Inceptio May 18 '13 at 15:22
  • @Inceptio like {3,4,5} is the smallest pair and then {7,24,25} would be higher than that. But your interpretation makes sense also. – Jeel Shah May 18 '13 at 16:15
  • How about ${6,8,10 }$ in between? – Inceptio May 18 '13 at 16:17
  • 1
    @JeelShah: why did you accept a solution that doesn't achieve a particular order ? –  May 30 '16 at 06:42
  • @Jeel Shah For ordered triples in distinct sets, try these functions: $$A=(2n-1)^2+2(2n-1)k$$ $$B=2(2n-1)k+2k^2$$ $$C=(2n-1)^2+2(2n-1)k+2k^2$$ They produce triples where the GCD(A,B,C) is an odd square and the difference between B and C in each set is the] $n^{th}$ odd square. The functions are not popular here but I found them in a pattern among 8 million spreadsheet formulas I used in my search for just such a thing. – poetasis Apr 20 '19 at 14:03

9 Answers9

3

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$

Ross Millikan
  • 374,822
3

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.

Kaish
  • 6,126
2

Euclid's method is only one of many for producing Pythagorean triples. See the following article for some other methods.

See: http://en.m.wikipedia.org/wiki/Formulas_for_generating_Pythagorean_triples

KYZYL
  • 21
1

Let $x$ be side of the Pythagorean triangle then all integral triples are function of $x$: $x\geq3$. This generates all possible integral triples. Trick:Take divisors of same parity (as of $x$) of squared $x$ and less than $x$; the number of triples is equal to no of such divisors. If these are $j$ values; corresponding $k$ values are obtained as quotient (same parity as of $x$) by dividing $x^2$ by each $j$. Then $x=\sqrt{j\cdot k};y=\frac{k-j}{2}; z=\frac{k+j}{2};\,(x,y,z)$ constitute Pythagorean triple. No of such triples=No of $j$ or $k$ divisors of $x^2$= Half the No of pairable divisors of Squared $x$ having parity those of $x$. This is Mir's Generalized Theorem Defining All Pythagorean Integral Triples As Function of side of Pythagorean triangle (say $x$). Ref:Academia.edu

  • 2
    There might be something to this, but it's pretty close to illegible at the moment. Perhaps you could demonstrate it using $x = 15$ as one of the side lengths? – pjs36 Mar 23 '16 at 15:34
  • Demonstration: If x=15, x^2=225; divisors less than x dividing 225 include 1,3,5,9 these are j values; obtain k values by dividing 225 with each j, we get corresponding k values as 225,75,45,9; apply formula: y=(k-j)/2 and z=(k+j)/2; we get 4 triples: (15,112,113),(15,36,39),(15,20,25) and (15,8,17);first and 4th are primitive; other two are non-primitive. the formula generates triples for every x (x>=3). I have generated 260235 triples covering 11124 pages for x = 3 through 20000; uploaded Acad.edu https://www.academia.edu/38563078/Abundant_List_Triples_March_2019.pdf – Dr. Shabir Ahmad Mir Mar 23 '19 at 18:18
  • Some error in typing: j set= (1,3,5,9) and correspong k set=(225, 75, 45, 25); therefore read 25 instead of 9 in k set; rest is OK; 225 = 9*25; – Dr. Shabir Ahmad Mir Mar 23 '19 at 18:43
1

Here is the method I use:

  1. Take a number $c >= 1$
  2. Find all pairs $a, b$ such that $ab = 2c^2$
  3. For every pair of $a, b$ you get an unique solution $x = a + 2c, y = b + 2c, z = a + b + 2c$. It can be easily proven that $x^2 + y^2 = z^2$ is reduced to $4c^2 = 2ab$ which is satisfied at point 2.

The advantage of this method is that you can get all possible triplets. For example with $c = 3, a = 3, b = 6$ a triplet $9, 12, 15$ is found, which cannot be found with euclid's formula.

It can be proven that this method give all possible triplets. If there is a pythagorean triplet $x, y, z$ than it can be represented in a form $x = a + 2c, y = b + 2c, z = a + b + 2c$ such that $ab = 2c^2$:

  1. We have $x^2 + y^2 = z^2$
  2. $a = z - y, b = z - x, c = (x + y - z) / 2$
  3. Now we have to prove that $ab = 2c^2$
  4. $ab = (z - y)(z - x) ? 2c^2 = (x + y - z)^2 / 2$
  5. $z^2 - yz - xz + xy ? (x^2 + y^2 + z^2 + 2xy - 2xz - 2yz) / 2$
  6. $2z^2 - 2yz - 2xz + 2xy ? x^2 + y^2 + z^2 + 2xy - 2xz - 2yz$
  7. After removing all repeating parts we get $z^2 ? x^2 + y^2$ which are equal. Done.
sanyassh
  • 111
0

One method I used was considering the differences of a compared to b and c. I let a=a, b = a + m, c = a + n. (a < b < c and m < n. All are positive integers). By using high school algebra (and using the quadratic equation), I was able to derive a formula using only the differences m and n: a = (n-m) + SqRoot(2 * n *(n - m)). If the square root is perfect, one has an integer solution.

Example: \m,n\ = \1,2\ = {a, a+m, a+n}

a = (2 - 1) + SqRt(2 * 2( 2 -1))

a = 1 + SqRt(2 * 2(1)) = 1 + SqRt(4) = 1 + 2 = 3

a = 3

b = a + m = 3 + 1 = 4

c = a + n = 3 + 2 = 5

\1, 2\ = {3, 4, 5}

0

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.

  • For some basic information about writing math at this site see e.g. here, here, here and here. – Martin Sleziak May 17 '17 at 04:13
  • @ Martin Sleziak Your equations are new and interesting but they only generate $Set_1$ or the first members of all sets show in the sample in my answer below. The same can be achieved making one or the other variable equal $1$ in my equations: $$A=2n^2+1\quad B=2n^2+2n\quad C=2n^2+2n+1$$ $$A=4n^2-1\quad B=4n\quad C=4n^2+1$$ – poetasis Jun 29 '19 at 11:15
0

There is one variation of and one alternative to Euclid's formula and they both generate only and all Pythagorean triples where $GCD(A,B,C)=(2x-1)^2,x\in\mathbb{N}$, which includes all primitives. Another post showed me that the one I developed from an observation that the subset above can be further divided into distinct sets... is nothing more than a variation of Euclid.

Euclid's variation simply substitutes $2m-1+n$ for $m$: $$A=(2m-1+n)^2-n^2\qquad B=2(2m-1+n)n\qquad C=(2m-1+n)^2+n^2$$

Mine is useful for proving when primes are generated (without requiring $m,n$ to be of opposite parity) and we can see (by subtraction) that $C-B=(2n-1)^2$. If we let $n=1$ for mine, we get only primitives where $C-B=1$. If we let $k=1$ and reverse $A$ and $B$, we get $C-B=2$. Both have their uses. The one I derived is not popular but does have the advantage of making it clear which set and which set member is described by f(n,k): $$A=(2n-1)^2+2(2n-1)k\quad B=2(2n-1)k+2k^2\quad C=(2n-1)^2+2(2n-1)k+2k^2$$ Both generate the same triples for all natural numbers, i.e. f(m,n)=g(n,k), e.g. $f(1,1)=g(1,1)=(3,4,5)$ and $f(2,3)=g(2,3)=(27,36,45).$ See samples: $$\begin{array}{c|c|c|c|c|} \text{$Set_n$}& \text{$Triple_1$} & \text{$Triple_2$} & \text{$Triple_3$} & \text{$Triple_4$}\\ \hline \text{$Set_1$} & 3,4,5 & 5,12,13& 7,24,25& 9,40,41\\ \hline \text{$Set_2$} & 15,8,17 & 21,20,29 &27,36,45 &33,56,65\\ \hline \text{$Set_3$} & 35,12,37 & 45,28,53 &55,48,73 &65,72,97 \\ \hline \text{$Set_{25}$} &2499,100,2501 &2597,204,2605 &2695,312,2713 &2793,424,2825\\ \hline \end{array}$$ The caveat is that neither will generate all triples such as $(6,8,10)$ or $(9,12, 15)$ so they will not be useful in finding $all$ matching sides, etc.; the advantage is that they eliminate these non-odd-square multiples.

poetasis
  • 6,338
-3

I can tell formula for any odd number but this formula always works.

take any odd number=(x) . Solve for $(a+a+1 = x^2)$.

$(a)$ and $(a+1)$ will be the two numbers that will satisfy pythagoran triplet with $x$.

$(x)$ should be a natural number.

$(a+1)$ will be hypotenuse, $(a)$ will be the longer side ( if you consider perpendicular is greater, then $(a)$ is the perpendicular) and $(x)$ will be the shortest side.

This is the new trick which is invented by me shreyas.

yash
  • 1