That's correct, but any integer multiple of a primitive Pythagorean triple is also a Pythagorean triple. (The proof is left as an exercise for the reader) This sequence generates the set of primitive Pythagorean triples (assuming that $m & $n are coprime)
thor
The only easy day was yesterday
| [reply] |
Well, it's true that the primitive triples are of that form,
but not conversely; 6,8,10 occurs for n=3,m=1 (which are coprime), and that triple isn't primitive. So the code generates primitive (i.e. having no common factor) triples, but some others as well. The real point is that it isn't so easy to print a list of all Pythagorean triples without duplication, and I guess that thought was what motivated my reply.
| [reply] |
True, but it's fairly easy to filter out the non-primitives.
If m and n are both even, skip (a, b, and c will all be divisible by two).
If m and n are both odd, skip (a, b, and c will all be divisible by two).
If m and n have a divisor in common (e.g., GCD{12,3} != 1) skip (a, b, and c will have that factor in common).
The first case can be wrapped up in third case (actually, it can be wrapped up in the second case too), but I find that it makes things clearer to separate them out.
| [reply] |
The third case should of course have been written as:
If m and n have a divisor in common (e.g., GCD{m,n} != 1) skip (a, b, and c will have that divisor in common).
Sorry about that
| [reply] |