David EppsteinDavid Eppstein - 2016-07-03 16:15:41-0700 - Updated: 2016-07-03 16:15:41-0700

Streaming integer points sorted by distance

Shared with: Public, David Eppstein, Sariel Har-Peled
+1'd by: Thanh Oai Dao, scabello, Leonid Boytsov, Math Solver, Daniel Lemire, Adam Smith
Reshared by: Charalampos Tsourakakis, William Rutiser
Sariel Har-Peled - 2016-07-04 04:50:46-0700
n^1/3 poly log space is possible using discrete hull stuff I think. The details are not immediate...
Sariel Har-Peled - 2016-07-04 04:55:58-0700
... Which is a good excuse to mention pick's theorem... https://en.m.wikipedia.org/wiki/Pick%27s_theorem
David Eppstein - 2016-07-04 18:12:35-0700
+Sariel Har-Peled nice. Pick's theorem does indeed come up in the details of that idea, but I think there is no polylog. See http://11011110.livejournal.com/332116.html for my attempt at filling in the details.
Sariel Har-Peled - 2016-07-05 11:42:59-0700
Nice! I think generating the candidate point is not easy. You can do it with gcd algorithm (essentially) - see http://sarielhp.org/p/97/dhull/dch.pdf. There might be an easier way to do it but I don't see it.

Also ch edges might have vertices in the middle of them - this needs handling but it is not hard...
David Eppstein - 2016-07-05 12:06:08-0700
I think generating the next candidate from the previous one and the edge is much easier than generating it from scratch given only the edge.
Sariel Har-Peled - 2016-07-06 06:31:49-0700
+David Eppstein it's essentially rational approximation to the slope of the edge.
David Eppstein - 2016-07-06 08:54:40-0700
+Sariel Har-Peled sure, if you start with the edge and no additional information. But you do have additional information, from the previous edge it came from, that allows you to jump-start the rational approximation algorithm.
Sariel Har-Peled - 2016-07-06 09:51:47-0700
Maybe...
Sariel Har-Peled - 2016-07-08 08:17:01-0700
Related... http://mathworld.wolfram.com/SumofSquaresFunction.html
David Eppstein - 2016-07-08 16:36:12-0700
+Sariel Har-Peled Ok, I implemented it and tested it up to r=100: see http://www.ics.uci.edu/~eppstein/PADS/IntegerPoints.py
Part of the trick to getting constant time per point is to maintain a candidate for each hull edge that is in a rectangle with that edge as a side and with the closest parallel grid line as the opposite side, even when there are other points beyond the hull edge but outside the rectangle that are closer (as sometimes happens). This is safe, because each successively generated point will necessarily be in one of these rectangles. And (as the box subroutine of the code shows) when the hull grows, it allows the new candidate point for each of the new edges to be calculated in constant time, essentially by doing only a single step of the (multiplicative) Euclidean gcd algorithm.
Sariel Har-Peled - 2016-07-09 00:12:25-0700
Seems believable. I am still wondering if one can do better using the number theory stuff I linked to above...
David Eppstein - 2016-07-09 00:20:40-0700
I wouldn't be surprised. You can get constant space and O(n^epsilon) time per point by factoring the integers from 1 to n^2, using the factorization to test whether they can be a squared distance (a numbers for which all prime factors that are 3 mod 4 divide an even number of times) and then also using the factorization to generate the points with that distance. Or you can use Eratosthenes to generate the sequence of factored integers without individually factoring them, but that seems to need lots of space again...
Sariel Har-Peled - 2016-07-09 05:21:32-0700
Yep. Something along these lines...
http://mathoverflow.net/questions/29644/enumerating-ways-to-decompose-an-integer-into-the-sum-of-two-squares