Solution (source code)

= Solution

The nonzero <elliptic-curve discriminant> forces $b\ne0$. At $P$, the derivative with respect to $y$ is $b$ and that with respect to $x$ is zero, so the tangent is $y=0$. Substitution gives $x^2(x+b)=0$: its third point is $(-b,0)$. Applying the negation formula gives
$$
\boxed{-2P=(-b,0),\qquad2P=(-b,b(a-1)).}
$$
The line through $P$ and $2P$ has slope $1-a$, because their x-coordinates are distinct. Substitution of $y=(1-a)x$ gives
$$
x\bigl(x+b\bigr)\bigl(x+a-1\bigr)=0.
$$
Its third point is $(1-a,(1-a)^2)$, interpreted with multiplicity if it coincides with a previously used point. Negating it yields
$$
\boxed{-3P=(1-a,(1-a)^2),\qquad3P=(1-a,a-b-1).}
$$
By associativity, $5P=O$ exactly when $3P=-2P$. Equality of their x-coordinates forces $1-a=-b$, and when $a=b+1$ their y-coordinates also agree and are zero. Therefore
$$
\boxed{5P=O\iff a=b+1.}
$$
Since $P\ne O$, its order in this case is exactly five. These are the <torsion multiples in a two-parameter Weierstrass family> formulas.