Sunday, 27 September 2015

Euclid's Formula for generating Pythagorean Triples

Pythagorean triple

$$a^2 + b^2 = c^2$$

Euclid's formula:

$$ m,n \in N, m > n $$ $$ a = m^2 - n^2, b = 2mn, c = m^2 + n^2$$ $$ => a^2 + b^2 = c^2$$
Trivial proof.

Primitive pythagorean triples are ones that cannot be reduced (think $ k.a^2 + k.b^2 = k.c^2 $). The triple  is primitive if $a$, $b$ and $c$ are coprime (ie they share no common divisors except 1). An example of a primitive pythagorean triple is (3,4,5).

The pythagorean triples generated using Euclid's formula are primitive iff $m$ and $n$ are coprime and $m-n$ is odd.

Clearly this second point is true because if both $m$ and $n$ were even, then all three terms will be even when squared, so $k$ could equal two so the triple would not be primitive.

Similar if they are not coprime, you could obvs divide every term.




Scala with Cats: Answers to revision questions

I'm studying the 'Scala with Cats' book. I want the information to stick so I am applying a technique from 'Ultralearning...