Trace of the square of an elliptic-curve endomorphism (source code)

= Trace of the square of an elliptic-curve endomorphism

The characteristic equation $\phi^2-[\operatorname{tr}\phi]\phi+[\deg\phi]=0$ gives
$$
\operatorname{tr}(\phi^2)=\operatorname{tr}(\phi)^2-2\deg\phi.
$$