How get invert(2*P.y) =
the full name is Modular Multiplicative Inverse and to compute ModInverse(2*P.y) you have to find a value that when multiplied by your value and divided by the prime gives 1.
you can read more about it on wikipedia:
https://en.wikipedia.org/wiki/Modular_multiplicative_inverselook at the examples below that.
the computation uses the extended Euclidean algorithm.