continued fractions and number systems applications to
play

Continued fractions and number systems: applications to - PowerPoint PPT Presentation

Continued fractions and number systems: applications to correctly-rounded implementations of elementary functions and modular arithmetic. Mourad Gouicem PEQUAN Team, LIP6/UPMC Nancy, France May 28 th 2013 Table of Contents Continued fraction


  1. Continued fractions and number systems: applications to correctly-rounded implementations of elementary functions and modular arithmetic. Mourad Gouicem PEQUAN Team, LIP6/UPMC Nancy, France May 28 th 2013

  2. Table of Contents Continued fraction expansion reminders 1 Application to correctly-rounded implementations of elementary 2 functions Application to modular arithmetic 3 M. Gouicem Continued fractions and Number systems applications 1 / 37

  3. Table of Contents Continued fraction expansion reminders 1 Application to correctly-rounded implementations of elementary 2 functions Application to modular arithmetic 3 M. Gouicem Continued fractions and Number systems applications 2 / 37

  4. Notations Let a real 0 < α < 1. There exists a unique integer sequence ( k i ) i ∈ N with k i ∈ N ∗ such that 1 α = := [0; k 1 , k 2 , . . . ] . 1 k 1 + k 2 + 1 ... This sequence is finite if α is rational, or infinite otherwise. M. Gouicem Continued fractions and Number systems applications 3 / 37

  5. Notations We denote by : ( r i ) i ∈ N the real sequence of the tails of α such that α = [0; k 1 , k 2 , . . . , k i + r i ] ; ( p i / q i ) i ∈ N the rational sequence of the convergents such that p i / q i = [0; k 1 , k 2 , . . . , k i ] ; ( θ i ) i ∈ N the real sequence of the such that θ i = | q i α − p i | ; M. Gouicem Continued fractions and Number systems applications 4 / 37

  6. Notations We denote by : ( r i ) i ∈ N the real sequence of the tails of α such that α = [0; k 1 , k 2 , . . . , k i + r i ] ; ( p i / q i ) i ∈ N the rational sequence of the convergents such that p i / q i = [0; k 1 , k 2 , . . . , k i ] ; ( θ i ) i ∈ N the real sequence of the such that θ i = | q i α − p i | ; Leitmotif of the talk Use the fact that r i = θ i /θ i − 1 to do modular arithmetic ! M. Gouicem Continued fractions and Number systems applications 4 / 37

  7. Recurrence relations All sequences can be computed recursively : p − 1 = 1 p 0 = 0 p i = p i − 2 + k i p i − 1 , q − 1 = 0 q 0 = 1 q i = q i − 2 + k i q i − 1 , θ − 1 = 1 θ 0 = α θ i = θ i − 2 − k i θ i − 1 . with k i = ⌊ θ i − 2 /θ i − 1 ⌋ . k i can be computed by subtraction (subtraction-based Euclidean algorithm) or by division (division-based Euclidean algorithm). M. Gouicem Continued fractions and Number systems applications 5 / 37

  8. Table of Contents Continued fraction expansion reminders 1 Application to correctly-rounded implementations of elementary 2 functions Application to modular arithmetic 3 M. Gouicem Continued fractions and Number systems applications 6 / 37

  9. The IEEE 754-2008 standard Aim Ensure predictable and portable numerical software. Basic Formats single-precision (binary32) double-precision (binary64) quadruple-precision (binary128) Rounding Modes Rounding to nearest Directed rounding (towards 0, −∞ and + ∞ ) Correctly rounded operations + , − , × , /, √ M. Gouicem Continued fractions and Number systems applications 7 / 37

  10. The IEEE 754-2008 standard And for elementary mathematical functions ? exp, log, sin, cos, tan, · · · ⇒ IEEE-754-2008 only recommends correct rounding because of the Table Maker’s Dilemma M. Gouicem Continued fractions and Number systems applications 8 / 37

  11. The Table Maker’s Dilemma Correct rounding ◦ p ( f ( x ) ± ε ) = ◦ p ( f ( x )) Hard-to-round case Midpoints Floating-points [ f ( x ) − ε, f ( x ) + ε ] M. Gouicem Continued fractions and Number systems applications 9 / 37

  12. HR-case search by isolation Function Isolate(Exists ?, P , D , depth, k ) Input : Exists? ( P , D ) test the existence of ( p , ǫ ′ ) HR-cases of P in D , P an approximation of f in D , depth and k two integers if Exists? (P, D) then if depth = 0 then retourner ExhaustiveSearch ( P , D ); else ( D 1 , . . . , D k ) := Subdivide ( D , k ); ( P 1 , . . . , P k ) := Refine ( P , D , k ); return � i Isolate ( Exists? , P i , D i , depth - 1, k ); else return ∅ ; M. Gouicem Continued fractions and Number systems applications 10 / 37

  13. HR-case search by isolation Function Isolate(Exists ?, P , D , depth, k ) Input : Exists? ( P , D ) test the existence of ( p , ǫ ′ ) HR-cases of P in D , P an approximation of f in D , depth and k two integers if Exists? (P, D) then if depth = 0 then retourner ExhaustiveSearch ( P , D ); else ( D 1 , . . . , D k ) := Subdivide ( D , k ); ( P 1 , . . . , P k ) := Refine ( P , D , k ); return � i Isolate ( Exists? , P i , D i , depth - 1, k ); else return ∅ ; M. Gouicem Continued fractions and Number systems applications 10 / 37

  14. HR-case existence test Problem Given P ∈ R [ x ], is there any x ∈ � 0 , # p D � such that P ( x ) mod 1 < ǫ. Solutions (with p the floating-point precision) Exhaustive search : O (2 p ) ; evre when deg P = 1 : O (2 2 p / 3 ) intervals in O ( p 2 ) ; Lef` SLZ when deg P > 1 : O (2 p / 2 ) intervals in O (poly( p , deg P , α )). Example of computation times e x in full domain and p = 53 with Lef` evre : 5 years of CPU time ; 2 x in [1 / 2 , 1[ and p = 64 with SLZ : 8 years of CPU time. M. Gouicem Continued fractions and Number systems applications 11 / 37

  15. Challenges Binary128 is actually out of reach ; compute the hardest-to-round case for each of the 32 functions recommended by the IEEE std 754-2008 in binary64 ; tackle any function in reasonable time in binary64 ; and certify the results. Lef` evre HR-case search Efficient for binary64 in practice : all known hardest-to-round in binary64 have been generated by Lef` evre ; Massively parallel ; � Perfect for GPU ! Fine-grain parallelism. M. Gouicem Continued fractions and Number systems applications 12 / 37

  16. Lef` evre HR-case existence test Problem Given b − ax ∈ R [ x ], is there any x ∈ � 0 , # p D � such that b − ax mod 1 < ǫ. Geometrically Is there any multiple of a in { ax mod 1 | x ≤ # p D } at a distance less than ǫ to the left of b ? b 0 1 a · 0 a · 7 a · 1 a · 2 a · 3 a · 4 a · 5 a · 6 M. Gouicem Continued fractions and Number systems applications 13 / 37

  17. The three distance theorem Three distance theorem (Slater) The points { a · x mod 1 | x < N } split the segment [0 , 1[ into N segments. Their lengths take at most three different values, one being the sum of the two others. Link with continued fraction expansion q i the i th convergent. Given a = [0; k 1 , k 2 , k 3 , . . . ] and p i The lengths are the θ i − 1 , t = θ i − 1 − t · θ i , with 0 ≤ t < k i +1 . Their number are the q i − 1 , t = q i − 1 + t · q i , with 0 ≤ t < k i +1 . There are O (log N ) two-length configurations and they verify q i θ i − 1 , t + q i − 1 , t θ i = 1 . Interpretation : if we place N = q i + q i − 1 , t multiples of a , there are q i intervals of length θ i − 1 , t ; there are q i − 1 , t intervals of length θ i . M. Gouicem Continued fractions and Number systems applications 14 / 37

  18. Example : a = 14 / 45 45 ( 0 , 0 ) 0 14 31 ( 0 , 1 ) 0 1 14 14 17 ( 0 , 2 ) 0 1 2 14 14 14 3 ( 1 , 0 ) 0 1 2 3 11 3 11 3 11 3 3 ( 1 , 1 ) 0 4 1 5 2 6 3 8 3 3 8 3 3 8 3 3 3 ( 1 , 2 ) 0 7 4 1 8 5 2 9 6 3 5 3 3 3 5 3 3 3 5 3 3 3 3 ( 1 , 3 ) 0 10 7 4 1 11 8 5 2 12 9 6 3 2 3 3 3 3 2 3 3 3 3 2 3 3 3 3 3 ( 2 , 0 ) 0 13 10 7 4 1 14 11 8 5 2 15 12 9 6 3 M. Gouicem Continued fractions and Number systems applications 15 / 37

  19. Lef` evre HR-case existence test Idea Write b in the basis ( θ i , t ) i ∈ N to get best approximations. If i is even θ i +1 θ i θ i θ i θ i θ i θ i θ i b ( i , 1) ( i , 2) ( i , 3) ( i , 4) ( i , 5) ( i , 6) ( i + 1 , 0) ( b − ˜ b i , t +1 ) = ( b − ˜ ( b − ˜ b i +1 , 0 ) = ( b − ˜ b i , t ) − θ i or b i , t ) If i is odd θ i +1 θ i θ i θ i θ i θ i θ i θ i b ( i + 1 , 0) ( i , 6) ( i , 5) ( i , 4) ( i , 3) ( i , 2) ( i , 1) ( b − ˜ b i +1 , 0 ) = ( b − ˜ ( b − ˜ b i , t +1 ) = ( b − ˜ b i , t ) − θ i − 1 , t +1 or b i , t ) M. Gouicem Continued fractions and Number systems applications 16 / 37

  20. An irregular control flow : bad for SIMD Algorithm 1: Lef` evre HR-case existence test. input : b − a · x , ǫ ′′ , N p ← { a } ; q ← 1 − { a } ; d ← { b } ; initialisation : u ← 1 ; v ← 1 ; if d < ǫ ′′ then return Failure; while True do if d < p then k = ⌊ q / p ⌋ ; q ← q − k ∗ p ; u ← u + k ∗ v ; if u + v ≥ N then return Success; p ← p − q ; v ← v + u ; else d ← d − p ; if d < ǫ ′′ then return Failure; k = ⌊ p / q ⌋ ; p ← p − k ∗ q ; v ← v + k ∗ u ; if u + v ≥ N then return Success; q ← q − p ; u ← u + v ; M. Gouicem Continued fractions and Number systems applications 17 / 37

  21. An irregular control flow : the SPMD on SIMD model SPMD on SIMD Develop a scalar program : a kernel Launch multiple threads running the same kernel Group their execution on SIMD units by warps of 32 threads Control flow regularity i=1 switch (i) { i=1 i=1 i=1 i=0 i=3 i=2 i=1 i = 0 : . . . i = 1 : . . . i = 2 : . . . i = 3 : . . . } M. Gouicem Continued fractions and Number systems applications 18 / 37

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend