Rational Points on the Unit : Approximation Complexity and Practical Constructions Improved Analysis[1] Daniel Bahrdt ∗ Martin P. Seybold∗ July 27, 2017

Abstract 1. Introduction Each non-zero point in Rd identifies a closest point x on d−1 the unit sphere S . We are interested in computing an Many mathematical sciences use trigonometric functions d d−1 ε-approximation y ∈ Q for x, that is exactly on S in symbolic coordinate transformations to simplify fun- and has low bit size. We revise lower bounds on rational damental equations of physics or mathematical systems. approximations and provide explicit, spherical instances. However, rational numbers are dominating in computer We prove that floating-point numbers can only pro- processing as they allow for simple storage as well as 2 vide trivial solutions to the sphere equation in R and fast exact and inexact arithmetics (e.g. GMP[12], IEEE 3 R . Moreover, we show how to construct a rational point Float, MPFR[11]). Therefore problems on spherical sur- 2 with denominators of at most 10(d − 1)/ε for any given faces often require to scale a point vector, as in choosing 1  ε ∈ 0, 8 , improving on a previous result. The method a point uniform at random[20], or to evaluate a trigono- further benefits from algorithms for simultaneous Dio- metric function for a rational angle argument, as in deal- phantine approximation. ing with Geo-referenced data. Our open-source implementation and experiments A classical theoretical barrier is Niven’s theorem[21], demonstrate the practicality of our approach in the con- which states that the sole rational values of sine for ratio- text of massive data sets Geo-referenced by latitude and nal multiplies of π are 0, ±1/2 and ±1. The well known longitude values. Chebyshev polynomials have roots at these values, hence Keywords Diophantine approximation, Rational give rise to representations for these algebraic numbers. points, Unit sphere, Perturbation, Stable geometric However, arithmetics in a full algebraic number field constructions might well be too demanding for many applications. For products of sine and cosine, working with Euler’s formula on the complex unit and Chebyshev polynomials would suffice though. This manifests in problems of exact geometrical com- putations, since standard methodology relies on Carte- sian input[18]. and ellipsoids are common ge- ometric objects and rational solutions to their defining arXiv:1707.08549v1 [cs.CG] 26 Jul 2017 quadratic polynomials are closely related to Diophantine equations of degree 2. The famous Pythagorean Triples are known to identify the rational points on the circle S1. Moreover, the unit sphere has a dense set of ratio- nal points and so do ellipsoids with rational half-axes through scaling. Spherical coordinates are convenient to reference such Cartesians with angle coordinates and geo-referenced data denotes points with rational angles. Figure 1: Spherical Delaunay triangulation (gray) con- Standard approximations of Cartesians do not necessar- strained to contain all line segments (black) of ily fulfill these equations, therefore subsequent algorith- streets in Ecuador and the intersection points mic results can suffer greatly. of constraints (red). This paper focuses on finding rational points exactly d−1  d P 2 on the unit sphere S = x ∈ R : i xi = 1 with ∗Formale Methoden der Informatik, University of Stuttgart, Ger- bounded to the point x/kxk2 – its closest point many, {bahrdt, seybold}@fmi.uni-stuttgart.de on Sd−1. In this work, x ∈ Rd can be given by any finite

1 means that allow to compute a rational approximation to 1.2. Contribution it with arbitrary target precision. Using rational Carte- The strong lower bound on rational approximations to sian approximations for spherical coordinates, as derived other rational values does not hold for Geo-referenced from MPFR, is just one example of such a black-box data considering Niven’s theorem. We derive explicit model. Moreover, we are interested in calculating ratio- constants to Liouville’s lower bound, for a concrete nal points on d with small denominators. S Geo-referenced point, that is within a factor 2 of the strong lower bound. Moreover, we prove that floating- point numbers cannot represent Cartesian coordinates of 1.1. Related Work points that are exactly on S1 or S2. We describe how the use of rotation symmetry and Studies on spherical Delaunay triangulations (SDT), us- approximations with fixed-point numbers suffice to im- ing great-circle segments on the sphere S2, provide com- prove on the main theorem of [28]. We derive rational mon ways to avoid and deal with the point-on-sphere points exactly on Sd−1 with denominators of at most problem in computational geometry. 2 1  10(d−1)/ε for any ε ∈ 0, 8 . Moreover, our method al- The fragile approaches [23, 14, 25] ignore that the in- lows for even smaller denominators based on algorithms put may not be on S2 and succeed if the results of all for simultaneous Diophantine approximations, though a predicate evaluations happen to be correct. Input point potentially weaker form of approximation would suffice. arrangements with close proximity or unfortunate loca- The controlled perturbations provided by our method tions bring these algorithms to crash, loop or produce allow exact geometric algorithms on Sd to rely on ra- erroneous output. The quasi-robust approaches [5,4] tional rather than algebraic numbers – E.g. enabling weaken the objective and calculate a Delaunay tessel- convex hull algorithms to efficiently obtain spherical De- lation in d-Simplexes. Lifting to a d + 1 convex hull launay triangulations on Sd and not just Delaunay tes- problem is achieved by augmenting a rational coordinate sellations. Moreover, the approach allows for inexact but from a – The augmented point exactly ε-stable geometric constructions – E.g. intersections of meets the (elliptic) paraboloid equation. However, the Great Circle segments. output only identifies a SDT if all input points are al- We demonstrate the quality and effectiveness of the ready on the sphere, otherwise the objectives are distinct. method on several, including one whole-world sized, Equally unclear is how to address spherical predicates point sets. We provide open-source implementations for and spherical constructions. The robust approaches [27] the method and its application in the case of spherical use the circle preserving from Delaunay triangulations with intersections of constraints. S2 to the plane. The perturbation to input, for which the output is correct, can be very large as the projec- tion does not preserve . Furthermore, achieving 2. Definitions and Tools additional predicates and constructions remains unclear. The 2nd Chebyshev polynomials U of degree n are in The stable approaches provide geometric predicates and n Z[X], given their recursive definition: constructions for points on S2 by explicitly storing an al- gebraic number, originating from scaling an ordinary ra- U0(x) = 1 U1(x) = 2x tional approximation to unit length[10]. Algebraic num- Un+1(x) = 2xUn(x) − Un−1(x) . ber arithmetics can be avoided for S2, but exact evalua- tion relies on specifically tailored predicates [8], leaving It is well known [26], that the n roots of Un are exactly the implementation of new constructions and predicates the values { cos (πk/ (n + 1)) : k = 1, . . . , n }. Hence open. the polynomials Un give rise to algebraic representations Kleinbock and Merrill provide methods to quantify the for cosine values of rational multiplies of π. This is par- density of rational points on Sd [16], that extend to other ticularly useful in conjunction with classic results on Dio- as well. Recently, Schmutz[28] provided an phantine approximations, that are known since 1844[19]: divide-&-conquer approach on the sphere equation, us- ing Diophantine approximation by continued fractions, Theorem 1 (Liouville’s Lower Bound). For any alge- to derive points in Qd ∩ Sd−1 for a point on the unit braic α ∈ R of degree n ≥ 2, there is a positive constant sphere Sd−1. The main theorem bounds the denomina- c(α) > 0 such that tors in ε-approximations, under the k k , with √ ∞ p c(α) ( 32dlog de/ε)2dlog2 de. Based on this, rational approxi- α − ≥ 2 q qn mations in the orthogonal group O(n, R) and in the uni- tary matrix group U(n, ) are found. This is of particu- C for any p ∈ Z and q ∈ N. lar interest for sweep-line algorithms: [7] studies finding a rotation matrix with small rationals for a given rational Apart from this lower bound on rational approxima- rotation angle of an 2D arrangement. tions, there is another important folklore result on the

2 a p existence of simultaneous Diophantine approximations. Observation 1. For rational numbers b 6= q , we have Such approximations have surprisingly small errors, de- spite their rather small common denominator. a p aq − bp 1 − = ≥ b q bq bq Theorem 2 (Dirichlet’s Upper Bound). Let N ∈ N and α ∈ d with 0 ≤ α ≤ 1. There are integers p ∈ d, q ∈ R i Z 2 with 1 ≤ q ≤ N and If q < b, we have a lower bound of 1/q for ratio- Z a nal approximations to b with denominators up to q. 1 3 α − pi ≤ √ . Pythagorean triples (x, y, z) ∈ N provide such ratio- i q d 1 2 2 q N nal points on S , since (x/z) + (y/z) = 1. We have a lower bound of 1/z2 for approximations with denomina- (See AppendixB for a proof.) For d = 1, the continued tors q < z. See Section 3.4 for rational points on Sd with fraction (equivalently the Euclidean) algorithm is famous the same denominator property. [13] for finding approximations with |α − p/q| ≤ 1/2q2. The situation might look different when dealing with This spurred the field of number theory to study gener- Geo-referenced data (rational angle arguments) only. alizations of the continued fraction algorithm that come However, using Chebyshev’s polynomials in conjunction close to Dirichlet’s upper bound, but avoid brute-force with Liouville’s lower bound (c.f. Theorem1) allows to calculations. Some more recent methods are discussed in derive explicit constants for Diophantine approximations Section 3.4. of cos (108◦). Our approach uses the Stereographic Projection in Rd. d Given spherical coordinates, the first coordinate of a Let p = (0,..., 0, 1) ∈ R be the fixed point for the d point on S might well have algebraic values of ri = projection τ, mapping all points of a ray from p to the i cos( 5 π) for i ∈ {1, 2, 3, 4}. intersection with the hyperplane xd = 0.

d d−1 d−1 √ √ √ √ ! τ : R \ (R × {1}) → R 1 + 5 −1 + 5 1 − 5 −1 − 5 (r1, r2, r3, r4) = , , ,  x1 xd−1  4 4 4 4 x 7→ ,..., 1 − x 1 − x d d ≈ (+0.8090, +0.3090, −0.3090, −0.8090) The surjective mapping τ is injective as well, when re- d−1 4 2 stricted to the domain S \{p}. We further define the Over Z[X], the polynomial U4(x) = 16x − 12x + 1 has mapping σ, which is the irreducible factors

σ : d−1 → d \{p} 2 2 R R U4(x) = (4x − 2x + 1)(4x + 2x − 1)  2x 2x −1 + S2  | {z } x 7→ 1 ,..., d−1 , =:f(x) 1 + S2 1 + S2 1 + S2 Since r and r are the roots of the polynomial f, they 2 Pd−1 2 d−1 1 3 where S = j=1 xj . We have img σ ⊆ S , since have algebraic degree n = 2.

2 2 d−1 2 Using Liouville’s lower bound for r3, we have for all (−1 + S ) + P (2x ) p 2 i=1 i ∈ kσ(x)k2 = 2 2 = 1 . q Q (1 + S ) 1 min{c2, } p c1 d−1 r − ≥ , Furthermore, x = τ ◦ σ(x) for all x ∈ R , since 3 q qn

2xi 1+S2 2xi with constants c1 and c2 according to the proof of Liou- (τ ◦ σ) (x) = = = xi i −1+S2 1 + S2 + 1 − S2 ville’s Theorem[19]. The constants c1, c2 > 0 exist, since 1 − 1+S2 the polynomial division of f with the linear factor (x−r3) holds for all 1 ≤ i < d. Hence, σ and τ are inverse results in the√ continuous function g(x) = (x − r1). For mappings. Note that images of rational points remain c2 = 1/2 < 5/2, the interval I := [r3 − c2, r3 + c2] ⊆ R rational in both mappings, establishing a bijection be- is sufficiently small to exclude different roots of f and tween rational points in Rd−1 and Sd−1. the inequality

max g(x) = max x − r1 < c1 2.1. Lower Bounds and Instances for x∈I x∈I Geo-referenced Data on Sd is met with a generous choice of c1 = 2. This leads to It is well known in Diophantine approximation that ratio- an explicit lower bound on the approximation error to r3 nal numbers have algebraic degree 1 and are hard (in the with denominators q of following qualitative sense) to approximate with other rational numbers. The following folklore observation is ◦ p 1 cos (108 ) − ≥ . an analog to Liouville’s lower bound. q 2 · q2

3 3. Results Where the characteristic function χe1 (ej) is 1 for e1 = ej and 0 otherwise. For d ∈ {2, 3} the right hand side can Apart from integers, contemporary computing hardware only have values of 0, −1 or −2, a contradiction. heavily relies on floating point numbers. These are triplets (s, m, e) with s ∈ {0, 1}, m ∈ {0,..., 2l − 1} Note that theorem3 translates to spheres with other k−1 k−1 and e ∈ {−2 + 1,..., 2 − 1}. The IEEE standard radii through scaling. Suppose a sphere in R3 of radius for Float is (l, k) = (23, 8) and (52, 11) for Double. The 2j has a non-trivial solution y ∈ P 3, then y/2j ∈ P 3 and rational number described by such a triplet is would be on S2, too.  l 2 + m e  2 e > 0  2l 3.2. Snapping to Rational Points   l s 2 + m 1 We now describe how to compute a good rational ap- val(s, m, e) = (−1) · e < 0 l |e| proximation exactly on the unit sphere d−1. The in-  2 2 S  put point x ∈ d can be given by any finite means 0 + m 1 R  e = 0 that allows to compute rational approximations of ar-  l 2k−1−2 2 2 bitrary target precision – E.g. rational approximations where the latter case describes ‘denormalized’ numbers. of Cartesians for spherical coordinates. For the input d−1 In each case, the uncanceled rational value has some x, we denote its closest point on S with x/kxk2. power of 2 as the denominator. Since powers of two are The stereographic projection τ and its inverse map- i the sole divisors of a 2 , the denominator of the canceled ping σ provide σ (τ (x/kxk2)) = x/kxk2, since the ar- rational has to be a power of two, too. Hence, rational gument is on Sd−1. Instead of determining the value values representable by floating point numbers are a sub- of τ exactly, we calculate an approximation y ∈ Qd set of the following set P and fixed-point binary numbers and finally evaluate σ(y) under exact, rational arith- d−1 are a subset of Pi: metics. Hence, the result σ(y) is exactly on S . The stereographic projection does n z o not preserve distances, leaving it img val ⊆ i : i ∈ N, z ∈ Z, z odd =P (0, 1) 2 open to bound the approximation n z o : z ∈ = P ⊆P. error and the size of the resulting 2i Z i denominators. We use the rotation τ (x/kxk2) y 3.1. Floating Point Numbers are Insufficient symmetry of the sphere to limit the stretching of σ (c.f. Lemma 2): For a non-zero point x ∈ d σ(y) Fix-point and floating-point arithmetics of modern CPUs R x/kxk2 work within a subset of rational numbers, in which the we can assume that i = d maxi- x denominator is some power of two and the result of each mizes |xi| and xd < 0, otherwise arithmetic operation is ‘rounded’. we change the standard orthonor- mal basis by swapping dimension i and d and using a Theorem 3. There are only 4 floating point numbers on negative sign for dimension d. Note that such rotations 1 2 S and 6 on S . do not change the actual coordinate values. To keep the Proof. We show d−1 ∩ P d {−1, 0, 1}d implies d ≥ 4. size of denominators in σ(y) small, we use fixed-point S * arithmetics to determine y ∈ d−1 (c.f. Lemma3). Suppose there is a non-trivial p ∈ Sd−1 ∩ P d with d min- Q ei imal. Let xi/2 denote the canceled fraction of its i-th Algorithm 1 PointToSphere coordinate. We have that all xi 6= 0, xi are odd numbers and all e > 0 (since p is not one of the 2d poles and d is d 1  i In: x ∈ R , ε ∈ 0, minimal). 8 W.l.o.g. e1 ≤ e2 ≤ ... ≤ ed. We rewrite the sphere 1. Assert xd = mini −|xi| Pd ei 2 equation 1 = j=1(xi/2 ) to 2. Choose y ∈ d−1 with |y − τ (x/kxk ) | ≤ √ε Q i i 2 2 d−1 d d 2 e1 X e1−ej 2 3. Return σ(y) ∈ . x1 = 4 − 4 xj . Q j=2

2 2 2 For an odd integer y, we have y = (2k + 1) = 4(k + See Algorithm1 for a precise description. Note that k) + 1, leading to the congruence the rational point y in statement2 solely needs to meet

d the target approximation in the individual coordinates X 1 ≡ 0 − χ (e ) mod 4 . for e1 j xi j=2 τi(x/kxk2) = . kxk2 − xd

4 Generally, this can be determined with methods In this section we denote with B = bx the perpendic- 0 0 0 of ‘approximate expression evaluation’ to our tar- ular from x on py ,E = xx , L = yy and Lx = xa its get precision[18]. If x is an approximation to a triangle scaled version meeting x. Note that B and Lx geo-referenced point, this denominator is well condi- are above H0, hence above E. tioned for calculations with multi-precision floating-point Lemma 1. For x, x0 ∈ Bd−1 with kxk ≤ kx0k , we have arithmetics[6, 11]. Using exact rational arithmetics for 1 2 2 statement3, we obtain a rational Cartesian coordinates kxk2 0 0 kσ(x) − σ(x )k2 ≤ kx − x k2 . on the unit sphere. kp − σ(x)k2 d−1 Observation 2. For d > 1 and x ∈ S with xd = Proof. We show Lx ≤ E by proofing α ≤ β for the two mini −|xi|, we have angles s√ 0 d − 1 β := ]bxx kτ(x)k2 ≤ √ < 1 . d + 1 α := ]axb . Proof. Using x = min −|x | and P x2 = 1, we have The inner angle sum of 4xab with a supplementary d i i i i 0 the bounds 1/d ≤ x2 ≤ 1 and angle argument and triangle scaling provide ]py y = d ◦ √ 90 + α. Let m denote the center of C. Since pm Pd−1 x2 1 − x2 1 + x 1 − 1/ d is orthogonal on H and bx0x = 90◦ − β, we have 2 i=1 i d d √ 0 ] kτ(x)k2 = 2 = 2 = ≤ . 0 0 (1 − xd) (1 − xd) 1 − xd 1 + 1/ d ]mpx = β. In the isosceles triangle 4py m, the cen- tral angle γ = 180◦ − 2β. Fixing arc py0 on C for the Where the latter term is in (0, 1) for any d. 0 inscribed angle theorem provides ]y yp = γ/2. 0 d−1 d Now, suppose α > β. The inner angle sum of 4pyy Hence the (d − 1)- B1 = {x ∈ R : kxk2 ≤ 1} contains τ(x). states 0 ◦ 0 0 0 ≤ ]y py = 180 − ]y yp − ]py y ◦ 0 ◦ 3.3. Approximation Quality = 180 − ]y yp − (90 + α) See [1] for an earlier version of this paper with a weaker, = 180◦ − γ/2 − (90◦ + α) but elementary, analysis. = −α + β We consider the problem in the 2D hyperplane Hpyy0 , 0 0 d−1 a contradiction. defined by two points y = σ(x), y = σ(x ) on S and d the projection pole p ∈ R . Given the rotation step in Al- Lemma 2. For x, x0 ∈ Bd−1 , we have d 1 gorithm1, the projection plane H0 = {x ∈ R : xd = 0} 0 d 0 0 separates p and y, y in R and√ in Hpyy0 . Since each σ(x) − σ(x ) ≤ 2 kx − x k2. d−1 2 q ∈ H0 ∩ S has kq − pk2 = 2 (consider pq in H0pq), 0 the circumcircle C of p, y and y contains exactly two of Proof. Using Lemma1, we have Lx ≤ E and the state- these points. Hence, the line of Hpyy0 ∩ H0 is orthogonal ment follows via triangle scaling: to the circumcircle’s diameter√ through p. Moreover, the L = L py / px ≤ 2L ≤ 2E, diameter is in [ 2, 2]. We denote with x the point x x 0 that is closer to p in Hpyy0 , meaning kxk2 ≤ kx k2. Note since px ≥ 1 and py ≤ 2. that x0 and x can be on the same or opposite circumcircle This statement is tight, considering the two points x = halves. √ √ 0 and x0 = ε/ d − 1, . . . , ε/ d − 1. We have kx − p x0k = ε and kσ(x) − σ(x0)k = 2 √ 1 ε. 2 2 1+ε2 Theorem 4. Algorithm1 calculates an ε-approximation exactly on the unit sphere. ∗ √ √ Proof. Let x = x/kxk2 and σ(y) denote the result. = 2 = 2 Given the rotation, x∗ holds for Observation2. Hence, we can use Lemma2 to derive a γ ∗ ∗ b m kσ(y) − x k∞ = kσ(y) − σ(τ(x ))k∞ ≤ kσ(y) − σ(τ(x∗))k 0 x 2 x H0 ∗ ≤ 2ky − τ(x )k2 s y0 ε2 ≤ 2 (d − 1) = ε 4(d − 1) y as upper bound on the approximation error.

5 This analysis is rather tight, as demonstrated by the Proof. Using standard multi-precision floating point red curve and points in Figure2. arithmetics allows to derive√ rational values y, with de- 2 d−1 nominators that are Q = d ε e. Using ε ≤ 1/8 and 3.4. Denominator Sizes Lemma3 bounds the size of the denominators in images σ with We now describe a relation between rational images of σ √ 2 and the lowest common multiple of denominators of its  2 d − 1 2Q2 ≤ 2 1 + rational pre-images. This leads to several strategies for ε achieving small denominators in the results of Algorithm   1. 2 √ = ε2 + ε4 d − 1 +4(d − 1) . 2   Lemma 3 (Size of images under σ). Let x ∈ ε | {z } ≤(d−1) d−1 d−1 Q ∩ B1 with xi = pi/qi and Q = lcm(q1, . . . , qd−1) be the lowest common multiple, then

nk σk (x) = For certain dimensions and in practice(c.f. Section m 5.1), we can improve on the simple usage of fixed-point 2 2 1 with integers ni, m ∈ {−2Q ,..., 2Q } for all 1 ≤ k ≤ d. binary numbers. For S we can rely on the continued fraction algorithm to derive rational approximations of 0 0 2 Proof. Let qi ∈ {1,...,Q} such that qi · qi = Q for all α = τ(x/kxk2) with |α − p/q| ≤ 1/2q . Using this in i. Since the formula of σ is similar in all but the last Algorithm1 leads to approximations with ε = 1/q2 on dimension, we describe the following two cases. For k = the circle S1 with denominators of at most 2q2. d, we have Note that for Sd with d ≥ 2 one can rely on algorithms for simultaneous Diophantine approximations (c.f. The- Pd−1 2 2 2 Pd−1 02 2 −1 + i=1 pi /qi −Q + i=1 qi pi nk orem2) to keep the lowest common multiple Q in Lemma σk (x) = = =: Pd−1 2 2 2 Pd−1 02 2 m 1 + i=1 pi /qi Q + i=1 qi pi 3 small. Note that it might well be simpler to find Dio- phantine approximations with small Q. d−1 Pd−1 02 2 Using the bound x ∈ B1 , we have 0 ≤ i=1 qi pi ≤ There have been many approaches to find general- 2 Q and we derive for nk and m izations of the continued fraction algorithm for d > 1. One of the first approaches is the Jacobi-Perron al- d−1 X 2 gorithm, which is rather simple to implement[29](c.f. |n | = − Q2 + q0 p2 ≤ Q2 k i i Section 5.1). More advanced approaches [22] rely on i=1 the LLL-algorithm for lattice basis reduction[17]. For d−1 X 2 m = Q2 + q0 p2 ≤ 2Q2 d = 2 there is an algorithm to compute all Dirichlet i i Approximations[15], which we find hard to oversee given i=1 its extensive presentation. Moreover, their experimen- For k < d, we have tal comparison shows that the Jacobi-Perron algorithm is practically well suited for d = 2. 2pk/qk σk (x) = We close this section with a transfer result of Theorem Pd−1 2 2 1 + i=1 pi /qi 2 with our Theorem4 and Lemma3. 2 Q · 2pk/qk d−1 = d−1 2 Corollary 1. Let x ∈ S and N ∈ N. There is p ∈ Q2 + P q0 p2 d−1 i=1 i i Z and q ∈ {1,...,N} with 0 Qq · 2pk nk = k =:   √ 2 Pd−1 02 2 m 1 2 d − 1 Q + i=1 qi pi √ x − σ p ≤ d−1 q ∞ q N Using the bound x ∈ Bd−1, we have that each |p | ≤ q 1 i i   and this bounds |n | = Qq0 · 2|p | ≤ 2Q2. We already 1 2 k k k and all denominators of σ q p are at most 2q . discussed the bound on m in the first case. This existence statement allows for brute-force com- Note that we apply this lemma in practice with fixed- putations. However, we just use it for comparisons in s point binary numbers pi/qi ∈ Ps. Meaning all qi = 2 = Section 5.1. Q for some significant size s. Theorem 5. Denominators in ε-approximations of Al- gorithm1 are at most 4. Implementation 2 10(d − 1) Apart from [8] for S , most implementations of spheri- . ε2 cal Delaunay triangulations are not ‘stable’. Approaches

6 based on d-dimensional convex hull algorithms produce only a tessellation for input not exactly on Sd−1. (c.f. Section 1.1) Few available implementations allow dynamic point or constraint insertion and deletion – not even in the planar case of R2. The ‘Computational Geometry Algorithms Library’ (CGAL [24]) is, to our knowledge, the sole im- plementation providing dynamic insertions/deletions of points and constraint line segments in R2. With [3], we provide open-source implementations of Algorithm1 for Sd. In [2], we provide an implemen- tation for spherical Delaunay triangulations on S2 with ε-stable constructions of intersection points of constraint line-segments (c.f. Section 4.2.1).

4.1. RATional Sphere Snapping for Sd Libratss is a C++ library which implements Algorithm 1, based on the open-source GMP library for exact ra- tional arithmetics [12] and the GNU ‘Multiple Preci- Figure 2: Approximation quality and denominator size of sion Floating-Point Reliably’(MPFR) library[11]. The 100 random points on S2 for various levels of implementation allows both, input of Cartesian coordi- target precision e and approximation strategies nates of arbitrary dimension and spherical coordinates (red, blue) of Algorithm1. Theoretic bounds of S2. Note that this implementation allows geometric are indicated with lines. algorithms, as for d-dimensional convex hull, to rely on rational input points that are exactly on Sd−1. In light Consider two intersecting segments of rational points on of the discussion on the denominator sizes in Section 2 3.4, we provide two additional strategies to fixed-point S . The two planes, containing the segments and the snapping, as analyzed in Theorem4. We implemented origin as a third point, intersect in a straight line. Each the Continued Fraction Algorithm to derive rational ε- (rational) point on this line can be used as input for our approximations with small denominators and the Jacobi- method, as they identify the two intersection points on the sphere. Using such input for Algorithm1 allows sim- Perron algorithm for S2. The library interface also allows ple schemes to derive stable geometric constructions of to automatically chose the approximation method which d results in smaller denominators, approximation errors or rational points on S within a distance of ε to the target other objectives, like byte-size. point.

4.2. Incremental Constrained Delaunay 5. Experiments Triangulation on S2 We used real world and synthetic data for our experi- Libdts2 implements an adapter for the dynamic con- ments. Geo-referenced data was sampled from regional straint Delaunay triangulation in the Euclidean plane extracts from the OpenStreetMap project[30], as of Jan- R2 of CGAL. Since this implementation requires an ini- uary 26th, 2017. Random Cartesian coordinates of tial outer face, we introduce an small triangle, that only points on Sd were created with the uniform generator contains the north-pole, to allow subsequent insertions 2 of [20]. All benchmarks were conducted on a single of points and constraints. For points exactly on the unit core of an Intel Xeon E5-2650v4. Peak memory usage sphere, the predicate ‘is A in the circumcircle of B,C and time were measured using the time utility. and D’ reduces to the well studied predicate ‘is A above the plane through B,C and D’. The implementation overloads all predicate functions accordingly and uses Al- 5.1. Approximation Quality and Size gorithm1 for the construction of rational points on the We experimentally analyze the actual approximation er- sphere for intersections of Great Circle segments. ror in results of Algorithm1 for several levels of ε using the MPFR library. In this section e denotes the signif- 4.2.1. ε-stable geometric constructions icands required in statement2 of Algorithm1 for the required result precision ε. This is Any means of geometric construction that allows to ap- proximate a certain point, can be used as input for Algo-   ε  e = − log √ . rithm1 – E.g. the intersection of Great Circle segments. 2 2 d − 1

7 We simply setup the MPFR data types with significand sizes up to 1024 Bits, and conducted our experiments 2 9 99 Germany Planet u.a.r S u.a.r S u.a.r S on much lower levels of e. This allows us to derive dimension 3 3 3 10 100 some ‘measure’ of the actual approximation errors of our size [103] 2,579.6 3,702.4 1,000.0 1,000.0 100.0 method. e=23 We analyzed the approximation errors δ and denomi- δ[m] 0.7 0.7 0.7 1.0 3.2 nator bit-sizes q for 100 random points on S2. Figure2 fx q [1] 46.0 46.0 46.0 46.0 46.0 compares the results of our algorithm under several lev- t [µs] 17 16 16 117 546 els of target precision e and strategies for statement2 in δ[m] 0.4 0.4 0.5 - - our method. The magenta line indicates the quality and jp q [1] 33.6 34.2 34.1 - - size of the approach in [28]. The red line indicates the t [µs] 63 57 58 - - bounds of our Theorems4 and5 on the fixed-point strat- e=31 δ[m] 2.7e-3 2.6e-3 2.8e-3 4.0e-3 12.6e-3 egy, while the yellow line indicates the bound of Corol- fx q [1] 62.0 62.0 62.0 62.0 62.0 lary1. Note that results using the Jacobi-Perron strategy t [µs] 17 16 17 118 554 (blue dots) allows our method to further improve on the δ[m] 1.7e-3 1.7e-3 1.8e-3 - - fixed-point strategy (red dots). Note that we use Liou- jp q [1] 45.2 45.8 45.8 - - ville’s lower bound as statement on the approximability t [µs] 77 72 73 - - of a worst-case point. There might well be points of e=53 higher algebraic degree that allow better approximations δ[m] 6.3e-10 6.2e-10 6.6e-10 9.6e-10 30.1e-10 (c.f. Section 2.1). fx q [1] 106.0 106.0 106.0 106.0 106.0 Table1 exhibits average approximation errors δ, de- t [µs] 16 16 17 118 548 nominator bit-sizes q and the computation time t of our δ[m] 3.9e-10 3.9e-10 4.3e-10 - - method for millions of points. Synthetic data sets have jp q [1] 77.2 77.8 77.7 - - t [µs] 118 111 112 - - several dimensions, while the real world data sets have 2 e=113 dimension 3. For S , we provide comparison of the fixed- δ[m] 5.5e-28 5.4e-28 5.7e-28 8.3e-28 26.1e-28 point strategy (fx) with the Jacobi-Perron strategy (jp) fx q [1] 226.0 226.0 226.0 226.0 226.0 of our method. Using e = 31 is sufficient to obtain re- t [µs] 19 19 19 126 617 2 sults exactly on S with a δ of less than 1cm, relative to a δ[m] 3.4e-28 3.4e-28 3.7e-28 - - sphere with radius of the earth. This is enough for most jp q [1] 164.5 165.1 165.1 - - applications dealing with spatial data and allows storage t [µs] 219 218 220 - - within the word size of contemporary computing hard- ware. This allows practical applications on S2 to store 4 Table 1: Mean-values of approximation error δ [m], de- integer long values for the 3 numerators and the common nominator bit-size q [1] and computation time denominator (c.f. Lemma3) occupying 32 Bytes. Note t [µs] for synthetic and real-world point sets for that storing 3 double values occupies 24 Bytes but cannot various dimensions and levels of target precision represent Cartesian coordinates exactly on the sphere. e. The Jacobi-Perron strategy is denoted by ‘jp’ and the fixed-point strategy by ‘fx’.

5.2. Constrained Delaunay Triangulation with Intersection Constructions

A Constrained Delaunay Triangulation of a point set con- Saarland Germany Europe Planet tains required line-segments as edges, but is as close to Input the Delaunay triangulation as possible [9]. We used very Segments 106 0.32 25.75 222.92 668.61 large street networks of several regions from the Open- Output StreetMap project for points and constraint edges – E.g. Vertices 106 0.29 24.45 213.01 634.42 each line-segment of a street is an edge in the result trian- Edges 106 0.87 73.37 639.04 1, 903.27 gulation. Since ∼ 0.5% of the line-segments in these data Faces 106 0.58 48.91 426.03 1, 268.84 sets intersect, we approximated the intersection points Resource usage using e = 31 for Algorithm1. Table2 exhibits total run- Time [h:m] < 0:01 19:27 3:21 12:04 ning time, peak memory usage and the result sizes of our Memory [GiB] 0.3 20.4 182 545 libdts2 implementation. Small data sets like Saarland and Germany allow quick calculation on a recent work- Table 2: Time and memory usage to compute spheri- station computer. See Figure1 for the Ecuador dataset. cal Delaunay triangulations for OpenStreetMap Note that the current implementation has a storage over- data sets. head for each point, as we keep the results of the GMP library rather than truncating to integers of architectures

8 word size. Computing the triangulation for the planet data set was only possible on rather powerful hardware with at least 550 Gigabytes of memory taking half a day.

6. Open Problems

From a practical point of view, it is of great interest to bound the storage size of denominators to a maximum of 64Bits – the word size of current computing archi- tectures. We seek to improve our (already satisfactory) results by using advanced algorithms for simultaneous approximation, like the LLL-algorithm or the Dirichlet approximation algorithm for S2. For the theoretical part, we are interested if finding simultaneous rational approximations with small lowest common multiple of the denominators is simpler than finding Dirichlet approximations. We are also interested in generalizing the method to provide rational approxi- mations with small absolute errors on ellipsoids with ra- tional semi-principal axes – E.g. the geographic WGS84 ellipsoid.

9 References [15] W. Jurkat, W. Kratz, and A. Peyerimhoff. On best two-dimensional Dirichlet-approximations and their [1] D. Bahrdt and M. P. Seybold. Rational Points on algorithmic calculation. Mathematische Annalen, the Unit Sphere: Approximation Complexity and 244(1), 1979. Practical Constructions. In Proc. of International Symposium on Symbolic and Algebraic Computa- [16] D. Kleinbock and K. Merrill. Rational approxi- tion, ISSAC ’17. mation on spheres. Israel Journal of Mathematics, 209(1):293–322, 2015. [2] D. Bahrdt and M. P. Seybold. Libdts2 library on GitHub. www.github.com/fmi-alg/libdts2, 2017. [17] A. K. Lenstra, H. W. Lenstra, and L. Lovasz. Factoring polynomials with rational coefficients. [3] D. Bahrdt and M. P. Seybold. Libratss library MATH. ANN, 261:515–534, 1982. on GitHub. www.github.com/fmi-alg/libratss, 2017. [18] C. Li, S. Pion, and C. Yap. Recent progress in exact geometric computation. J. Log. Algebr. Program., [4] C. B. Barber, D. P. Dobkin, and H. Huhdanpaa. 64(1):85–111, 2005. The Quickhull Algorithm for Convex Hulls. ACM Trans. Math. Softw., 22(4):469–483, 1996. [19] J. Liouville. Sur des classes tr`es-´etendues de quan- tit´esdont la valeur n’est ni alg´ebrique, ni mˆeme [5] K. Q. Brown. Voronoi Diagrams from Convex Hulls. r´eductible`ades irrationalles alg´ebriques. J. Math. Inf. Process. Lett., 9(5):223–228, 1979. pures et app., 16:133–142, 1851. [6] C. Burnikel, S. Funke, and M. Seel. Exact Geometric [20] G. Marsaglia. Choosing a point from the Predicates Using Cascaded Computation. In Proc. of a sphere. The Annals of Mathematical Statistics, of Sympos. on Comput. Geom., 1998. 43(2), 1972. [7] J. Canny, B. Donald, and E. Ressler. A rational [21] I. Niven. Irrational Numbers, volume 11. Math. rotation method for robust geometric algorithms. In Assoc. of America, 1 edition, 1985. Proc. of Sympos. on Comput. Geom., 1992. [22] A. Peth˝o,M. E. Pohst, and C. Bert´ok. On multidi- [8] M. Caroli, P. M. M. de Castro, S. Loriot, O. Rouiller, mensional Diophantine approximation of algebraic M. Teillaud, and C. Wormser. Robust and Efficient numbers. J. Number Theory, 171, 2017. Delaunay Triangulations of Points on Or Close to a Sphere. In Proc. of Sympos. on Exp. Alg., pages [23] F. Prill and G. Z¨angl. A Compact Parallel Algo- 462–473, 2010. rithm for Spherical Delaunay Triangulations. In [9] L. P. Chew. Constrained Delaunay Triangulations. Proc. Conf. on Parallel Processing and Appl. Math., In Proc. of Sympos. on Comput. Geom., pages 215– 2015. 222, 1987. [24] T. C. Project. CGAL User and Reference Manual. [10] P. M. M. de Castro, F. Cazals, S. Loriot, and CGAL Editorial Board, 4.7 edition, 2015. M. Teillaud. Design of the CGAL 3D Spherical Ker- [25] R. J. Renka. Algorithm772 STRIPACK Delaunay nel and application to arrangements of circles on a Triangulation and Voronoi Diagram on the Surface sphere. Comput. Geom., 42(6-7):536–550, 2009. of a Sphere. Trans. Math. Softw., 23(3), 1997. [11] L. Fousse, G. Hanrot, V. Lef`evre,P. P´elissier,and [26] T. J. Rivlin. The Chebyshev Polynomials: From Ap- P. Zimmermann. MPFR: A Multiple-precision Bi- proximation Theory to Algebra and Number Theory. nary Floating-point Library with Correct Rounding. Tracts in Pure & Applied Mathematics. Wiley, 1974. ACM Trans. Math. Softw., 33(2), June 2007. [27] A. Saalfeld. Delaunay Triangulations and Stereo- [12] T. Granlund and the GMP development team. GNU graphic Projections. Cartography and Geographic MP: The GNU Multiple Precision Arithmetic Li- Information Science, 26(4):289–296, 1999. brary, 5.0.5 edition, 2012. http://gmplib.org/. [28] E. Schmutz. Rational points on the unit sphere. [13] G. H. Hardy and E. M. Wright. An introduction Central European Journal of Mathematics, 6(3), to the theory of numbers. Oxford University Press., 2008. 1954. [29] H. Tachii. On Jacobi-Perron algorithm. volume 70, [14] D. W. Jacobsen, M. Gunzburger, T. Ringler, pages 317–322. The Japan Academy, 1994. J. Burkardt, and J. Peterson. Parallel algorithms for planar and spherical Delaunay construction with [30] The OpenStreetMap Project. www.openstreetmap. an application to centroidal Voronoi tessellations. org, 2017. Geosci. Model Dev., 6(4), 2013.

10 A. Proof of Liouville’s B. Proof of Dirichlet’s Approximation Theorem Approximation Theorem

This nice proof was translated from the German wiki- The folklore proof bases on Dirichlet’s famous Pigeonhole books Project – thanks to the anonymous authors. See Principle. See proofwiki.org or Chapter 11.12 in [13]. [19] for the original proof in French language. d d of Theorem2. We consider the partition√ of [0, 1] in N of Theorem1. Let α ∈ be algebraic of degree n and d R regular d-cubes of length L = N. We further de- root of the corresponding polynomial f(X) ∈ [X] of (j) d Z fine a sequence of points (a ) d ∈ [0, 1] with degree n, meaning j=1,...,N +1 a(j) := j · α − bj · αc (component wise operations). There n (k) (l) f(α) = a0 + a1α + ··· + anα = 0 are indices k > l such that the points a and a are contained in the same d-cube. We have the (component with a0, . . . , an ∈ Z and an 6= 0. wise) inequalities Polynomial division with the linear factor X −α in the ring [X] provides 1 1 C − < a(k) − a(l) < L L f(X) = (X − α) · g(X). (A.1) 1 1 − < kα − bkαc − lα + blαc < L L Note that the polynomial g(X) has algebraic coeffi- 1 1 cients and is not necessarily in [X]. However, the map- − < (k − l)α − (bkαc − blαc) < Z L L ping R → C, t 7→ g(t) is continuous, by means of real numbers c1 > 0, c2 > 0 with

|g(x)| ≤ c1 (A.2) Setting q = k −l and pi = bkαic−blαic provides integers as required. for |α − x| < c2. Since n < ∞, we can assume w.l.o.g. that no additional roots are in this neighborhood of α, meaning C. Reductions of Spherical f(x) 6= 0 (A.3) Predicates to Cartesian Orientation Predicates for |α − x| < c2 and x 6= α. Claim: The statement of the Theorem holds for We first describe a reduction from the spherical predi-  1  cates to well studied Cartesian predicates. c := min c2, . c1 Lemma 4 (Great Circle Orientation Predicate). Let 2 Suppose there are p, q ∈ Z, q > 0 with p1, p2 ∈ S with p1 6= p2 and P the plane containing p1, p2 and the origin (0, 0, 0) and C be the Great Circle p c 2 α − < . (A.4) through p1 and p2. For q ∈ S we have q qn p q left-of P ⇐⇒ q left-of C We show that his implies α = q . From (A.4), we immediately derive q ∈ P ⇐⇒ q ∈ C q right-of P ⇐⇒ q right-of C p α − < c ≤ c2 , (A.5) q Proof. 2 ∩ P = C and 2 = L ∪ C ∪ R. leading (A.2) to imply g( p ) ≤ c . We derive, from S S q 1 (A.1) and again (A.4), that Lemma 5 (Circumsphere Predicate). Let P denote the 2 plane through non-identical points p1, p2, p3 ∈ and the p p p c 1 S f = − α · g < n · c1 ≤ n , half space containing the origin (0, 0, 0) is called ‘below q q q q q 3 P ’. We further call S123 ⊆ R the closed volume of the   sphere with p , p , p and the origin on its surface. For meaning qn · f p < 1. 1 2 3 q a point q ∈ S2 we have n  p  n n−1 n However q · f q = a0q + a1pq + ··· + anp ∈ Z and its absolute value is smaller than 1, hence has to q above P ⇐⇒ q ∈ S123 \ ∂S123 p q ∈ P ⇐⇒ q ∈ ∂S123 be 0. Moreover, f( q ) = 0 and (A.5) with (A.3) imply p α = q , which closes the argument. q below P ⇐⇒ q∈ / S123

11 Proof. P is uniquely determined because three different points on the unit sphere are not co-linear. Since S123 and S2 are spheres, their cuts with P are circles in P and the two circles are identical as they contain p1, p2 and p3 on their boundary. This circle C has a radius of at most 1 and partitions the points of the unit sphere into three sets 2 S = A ∪ C ∪ B where A ⊆ S123 ) B. If C is a Great Circle we resolve ambiguity for ‘above’ and the center of S123 by choos- ing the open half spaces that first contain (0, 0, 1), then 2 (0, 1, 0) and eventually (1, 0, 0). We have S 6= ∂S123, since the origin is a fourth point on S123 and q ∈ P iff. q ∈ C iff. q ∈ ∂S123. Therefore it is sufficient to show q ∈ A ⇐⇒ q above P . To this end we consider the con- 3 vex volume of the unit sphere S ⊆ R and D = S ∩ S123. Note that ∂D contains C and A. Since the cut with the closed half-space of the plane P cuts a convex body into at most three parts and C ⊆ P , we have that all of A is ‘above’ P .

12 Figure 3: Spherical constraint Delaunay triangulation(green) of all streets(black) in the Germany data set (c.f. Section 5.2).

13