Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
go ahead... be a heretic
 
PerlMonks  

Re: pythagorean triples

by chas (Priest)
on Apr 24, 2006 at 03:16 UTC ( #545188=note: print w/ replies, xml ) Need Help??


in reply to pythagorean triples

But that doesn't really give "all" of them - e.g. 9,12,15 isn't of that form, is it? (Of course it is a multiple of 3,4,5 which is of that form...)


Comment on Re: pythagorean triples
Re^2: pythagorean triples
by thor (Priest) on Apr 24, 2006 at 03:50 UTC
    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

      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.
Re^2: pythagorean triples
by jgamble (Pilgrim) on Apr 24, 2006 at 21:21 UTC

    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.

      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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://545188]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (16)
As of 2014-04-23 11:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (541 votes), past polls