I was adding a test-case to my code to check that the above relationship is always true and instead found that it was only true about 50% of the time. That is, if I generated pairs of private keys at random only about half of them would pass this test.
It is always true. Only half keys passed, because you probably skipped modulo "n". All operations are always modulo "n".
That's a good guess, but in this case the problem was caused by applying the modulo operation too many times, not too few.
In summary, don't do math on private keys in the wrong field
It is better than that: you can join sub-fields if you know how it works. For example, you have two public keys with the same x-value, and you have three public keys with the same y-value. That means, for a given public key, you always have six "trivial" points, forming some area. And you can do crazy stuff if you start dealing with such rectangles.
I've made a topic about this
here, when you find the time I'd appreciate your input!