Fermat's Two Squares Theorem/Uniqueness Lemma/Proof 2

Proof
Suppose:
 * $p = a^2 + b^2 = c^2 + d^2$

where $a > b > 0$ and $c > d > 0$.

We are going to show that $a = c$ and $b = d$.

From the two expressions for $p$, we have:

So we have:
 * $\paren {a d - b c} \paren {a d + b c} \equiv 0 \pmod p$

From Euclid's Lemma, that means:
 * $p \divides \paren {a d - b c}$

or:
 * $p \divides \paren {a d + b c}$

$p \divides \paren {a d + b c}$.

Now, we have that each of $a^2, b^2, c^2, d^2$ must be less than $p$.

Hence $0 < a, b, c, d < \sqrt p$.

This implies $0 < a d + b c < 2 p$.

That must mean that $a d + b c = p$.

But then:

That means:
 * $a c - b d = 0$

But since $a > b$ and $c > d$ we have:
 * $a c > b d$

This contradiction shows that $a d + b c$ can not be divisible by $p$.

So this means:
 * $p \divides \paren {a d - b c}$

Similarly, because $0 < a, b, c, d < \sqrt p$ we have:
 * $-p < a d - b c < p$

This means:
 * $a d = b c$

So:
 * $a \divides b c$

But $a \perp b$ otherwise $a^2 + b^2$ has a common divisor greater than $1$ and less than $p$.

This cannot happen because $p$ is prime.

So by Euclid's Lemma:
 * $a \divides c$

So we can put $c = k a$ and so $a d = b c$ becomes $d = k b$.

Hence:
 * $p = c^2 + d^2 = k^2 \paren {a^2 + b^2} = k^2 p$

This means $k = 1$ which means $a = c$ and $b = d$ as we wanted to show.