I'm trying to double the Point $P(1,17)$ on the Elliptic Curve $y^2 = x^3 + 3x + 6 \pmod {31}$.
I'm using the formulae: $$\begin{split} λ&=(3xp^2+a)(2yp)^{-1}\\ xr &= λ^2 - 2xp\\ yr &= λ(xp-xr)-yp \end{split}$$
I get $λ = 29$, $xr = 2$, $yr = 16 \implies 2P = (2,16)$. However, according to an online calculator, the solution should be $2P = (2,12)$. If I use $-λ$ instead of $λ$ while calculating $yr$, I get the right result, but if I then try to double again to $4P$ it only works with $λ$.
What am I not getting here?
The formula is correct, compare with point doubling formula. I will use $m$ instead of $\lambda$ for the slope, simpler to type. Let us do the computations explicitly:
The values for $a,b$ are $3,6$, we are working over the field $\Bbb F_p$ with $p=31$ elements, and consider the given curve $y^2 =x^3 +ax+b$. Then for $P=(x_P,y_P)=(1,17)\in E(F)$ we have the computation of $R=2P$ in $F$... $$ \begin{aligned} m &=\frac{3x_P^2+a}{2y_p}=\frac{3\cdot 1^2+3}{2\cdot 17} =6\cdot 2^{-1}\cdot17^{-1}=6\cdot16\cdot 11=96\cdot 11=3\cdot 11=33 \\ &=\bbox[yellow]{\boxed{2}}\ , \\ x_R &=m^2-2x_P=2^2-2\cdot 1=\bbox[yellow]{\boxed{2}}\ ,\\ y_R &=m(x_P-x_R)-y_P=2(1-2)-17=-2-17=-19=\bbox[yellow]{\boxed{12}}\ . \end{aligned} $$ Please compare with your own computation.
Computer check, here using sage: