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?

  • $\begingroup$ If you've copied it correctly, then Wikipedia is wrong. Shocking, I know. $\endgroup$ – Gerry Myerson Oct 29 '11 at 9:20
  • 1
    $\begingroup$ A proof of a very similar expression of Pythagorean quadruples is given in Andreescu et al.: An Introduction to Diophantine Equations, Theorem 2.2.3, p.79. (They use the parametrization based on the two numbers from the quadruple which are even.) $\endgroup$ – Martin Sleziak Oct 29 '11 at 10:51

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} $$

  • 1
    $\begingroup$ I think that makes more sense. And it appears to work. Now to see if I can put that to use. Thanks. $\endgroup$ – Mike Oct 29 '11 at 14:11

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





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

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



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.


  • 2
    $\begingroup$ Do you know that you can use TeX here? I added dollar signs and underscores so I could read what you wrote - I hope I put them all in the right places. $\endgroup$ – Gerry Myerson Aug 13 '12 at 3:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.