Another Project Euler problem has me checking the internet again. Among other conditions, four of my variables satisfy:

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

According to Wikipedia, this is known as a Pythagorean Quadruple. It goes on to say all quadruples can be generated from an odd value of $a$ and an even value of $b$ as:

$$c=\frac{a^2+b^2-p^2}{2}, \quad d=\frac{a^2+b^2+p^2}{2} ,$$

where $p$ is any factor of $a^2+b^2$ that satisfies $p^2<a^2+b^2$.

However, I can’t see how or why this works. I also can’t seem to see how this works for $\lbrace 4,4,7,9 \rbrace$. Am I missing something here?

#### Solutions Collecting From Web of "Pythagorean quadruples"

I think $c$ and $d$ should have been
$$\begin{split} c &= \frac{a^2+b^2-p^2}{2 p}\qquad\qquad d &= \frac{a^2+b^2+p^2}{2 p} \end{split}$$

According to this document a set of Pythagorean Quadruples is given by:

$a=2mp$

$b=2np$

$c=p^2-(n^2+m^2)$

$d=p^2+(n^2+m^2)$

where $m,n,p$ are integers such that:

$m+n+p \equiv 1 (\mod 2) \land gcd(m,n,p)=1$

Sum3Squares

I thought of extremely simple derivation of the parametrization of three squares which sum to square.

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

then $a^2 + b^2 = d^2 – c^2$

As is well known, any number which is the sum of two squares is the product of only primes which are the sum of two squares.

We can thus easily derive from complex number arithmetic the parametrization of composite numbers which are the sum of two squares.

$$(a_1 + i b_1)(a_1-i b_1)(a_2 + i b_2)(a_2 – i b_2) = (a_1 + i b_1)(a_2 + i b_2) (a_1 – i b_1) (a_2 – i b_2)$$

$$(a_1^2 + b_1^2) (a_2^2 + b_2^2) = ( (a_1 a_2 – b_1 b_2) + i (a_1 b_2 + b_1 a_2) )( (a_1 a_2 – b_1 b_2) – i (a_1 b_2 + b_1 a_2) )$$

$$(a_1^2 + b_1^2) (a_2^2 + b_2^2) = (a_1 a_2 – b_1 b_2)^2 + (a_1 b_2 + b_1 a_2)^2$$

Also, since the product of two numbers is the difference of the squares of half their sum and half their difference,

$$(a_1^2 + b_1^2)(a_2^2 + b_2^2) = ((a_1^2 + b_1^2 + a_2^2 + b_2^2)/2)^2 – ((a_1^2 + b_1^2 – a_2^2 -b_2^2)/2)^2$$

Thus
$$(a_1 a_2 – b_1 b_2)^2 + (a_1 b_2 + b_1 a_2)^2 = ((a_1^2 + b_1^2 + a_2^2 + b_2^2)/2)^2 – ((a_1^2 + b_1^2 – a_2^2 -b_2^2)/2)^2$$

$$(a_1 a_2 – b_1 b_2)^2 + (a_1 b_2 + b_1 a_2)^2 + ((a_1^2 + b_1^2 – a_2^2 -b_2^2)/2)^2 = ((a_1^2 + b_1^2 + a_2^2 + b_2^2)/2)^2$$

$(a_1 a_2 – b_1 b_2)^2 + (a_1 b_2 + b_1 a_2)^2$ not have remainder 2 when divided by 4.

That is why it is required that not both $(a_1 a_2 – b_1 b_2)$ and $(a_1 b_2 + b_1 a_2)$
be odd.

Kermit