Sorry, I know nothing about the algorithm. I can only suggest ways to try to debug the code.help with is to try and minimise this timing lag.
You need to find a forum that deals with math algorithms. This one is for java programming.
For example when I added some print statements I saw that res1 - res4 were never different. They were either always all false or all true.
Is that expected?
When I printed the value of x1 it was the same for hundreds of lines. When should it change?