Program derivation methodology is applied to reconstruct Euler's proof that every prime congruent to 1 modulo 4 is the sum of two squares.