1. 16
atilanevesoncode.wordpress.com
1. 9

By the way, is it a secret to programmers that Pythagorean triples can be parametrised?

I understand that the point of the code is to enumerate them without knowing that they can be parametrised, but the parametrisation in this case is not so scary, so it’s a fun bit of trivia for programmers (for mathematicians, it’s more fundamental, as the Pythagorean parametrisation is an important prototype for counting rational points on elliptic curves, a fundamental problem in number theory).

https://en.wikipedia.org/wiki/Pythagorean_triple#Generating_a_triple

Slightly less easy nor well-known amongst mathemticians (or at least, this is new to me), you can enumerate all primitive Pythagorean triples in a tree!

https://en.wikipedia.org/wiki/Tree_of_primitive_Pythagorean_triples

This tree is really interesting! I wonder where those matrices come from. The proof that it works is a boring mechanical check, but I’m now interested in how they were derived in the first place. This is a 20th century discovery, unlike the parametrisation which comes from antiquity. I think I’ll be reading some papers about this.

1. 2

I’d never heard of Pythagorean triples until Eric Niebler’s post, I definitely wouldn’t have picked it as an example of ranges!

I just went from the rebuttal post and its code to what I wrote today.

2. 4

I know this wasn’t the point of this post but I love stuff like this because it makes learning concepts in other languages easier.

I was just looking into ranges in D the other day and now not only do I have a good example of how to write a fairly simple one I also have a generator example to boot. I didn’t even know D had generators!

3. 2

Here’s a Common Lisp version of the “lambda” code, based on this C++ code. Compile time was instantaneous at the REPL and the runtime for the first 1000 triples was 0.227 seconds.

For comparison, the C++ code compiled with clang++ -O3 (XCode on OSX Mojave) on the same machine took 0.1 second to compile and ran in 0.15 seconds.