Elliptic-curve addition formula (source code)

= Elliptic-curve addition formula

On $y^2=x^3+a_2x^2+a_4x+a_6$, let $\lambda$ be the secant slope through distinct points $P,Q$, or the tangent slope when $P=Q$. Then
$$
x(P+Q)=\lambda^2-a_2-x(P)-x(Q),
\qquad
y(P+Q)=-y(P)+\lambda\bigl(x(P)-x(P+Q)\bigr).
$$