Analysis of Fast Versions of the Euclid Algorithm Eda Cesaratto, Julien Clément, Benoît Daireaux, Loïck Lhote, Véronique Maume-Deschamps, Brigitte Vallée
Total Page:16
File Type:pdf, Size:1020Kb
Analysis of fast versions of the euclid algorithm Eda Cesaratto, Julien Clément, Benoît Daireaux, Loïck Lhote, Véronique Maume-Deschamps, Brigitte Vallée To cite this version: Eda Cesaratto, Julien Clément, Benoît Daireaux, Loïck Lhote, Véronique Maume-Deschamps, et al.. Analysis of fast versions of the euclid algorithm. 2008. hal-00211424 HAL Id: hal-00211424 https://hal.archives-ouvertes.fr/hal-00211424 Preprint submitted on 21 Jan 2008 HAL is a multi-disciplinary open access L’archive ouverte pluridisciplinaire HAL, est archive for the deposit and dissemination of sci- destinée au dépôt et à la diffusion de documents entific research documents, whether they are pub- scientifiques de niveau recherche, publiés ou non, lished or not. The documents may come from émanant des établissements d’enseignement et de teaching and research institutions in France or recherche français ou étrangers, des laboratoires abroad, or from public or private research centers. publics ou privés. Analysis of fast versions of the Euclid Algorithm Eda Cesaratto ∗ Julien Cl´ement † Benoˆıt Daireaux‡ Lo¨ıck Lhote § V´eronique Maume-Deschamps ¶ Brigitte Vall´ee k To appear in the ANALCO’07 Proceedings Abstract gebra. Many gcd algorithms have been designed since There exist fast variants of the gcd algorithm which are Euclid. Most of them compute a sequence of remainders all based on principles due to Knuth and Sch¨onhage. On by successive divisions, which leads to algorithms with inputs of size n, these algorithms use a Divide and Con- a quadratic bit–complexity (in the worst-case and in the quer approach, perform FFT multiplications and stop average-case). Using Lehmer’s ideas [20] (which replace the recursion at a depth slightly smaller than lg n. A large divisions by large multiplications and small divi- rough estimate of the worst–case complexity of these sions), computations can be sped-up by a constant fac- fast versions provides the bound O(n(log n)2 log log n). tor, but the asymptotic complexity remains quadratic. However, this estimate is based on some heuristics and Major improvements in this area are due to Knuth [19], is not actually proven. Here, we provide a precise prob- who designed the first subquadratic algorithm in 1970, abilistic analysis of some of these fast variants, and we and to Sch¨onhage [24] who subsequently improved it the prove that their average bit–complexity on random in- same year. They use both Lehmer’s ideas and Divide puts of size n is Θ(n(log n)2 log log n), with a precise and Conquer techniques to compute in a recursive way remainder term. We view such a fast algorithm as a se- the quotient sequence (whose total size is O(n)). More- quence of what we call interrupted algorithms, and we over, if a fast multiplication with subquadratic complex- obtain three results about the (plain) Euclid Algorithm ity (FFT, Karatsuba...) is performed, then one obtains which may be of independent interest. We precisely a subquadratic gcd algorithm (in the worst-case). Such describe the evolution of the distribution during the ex- a methodology has been recently used by Stehl´eand ecution of the (plain) Euclid Algorithm; we obtain a Zimmermann [25] to design a Least-Significant-Bit ver- sharp estimate for the probability that all the quotients sion of the Knuth-Sch¨onhage algorithm. According to produced by the (plain) Euclid Algorithm are small experiments due to [5] or [22], these algorithms (with a enough; we also exhibit a strong regularity phenomenon, FFT multiplication) become efficient only for integers of which proves that these interrupted algorithms are lo- size larger than 10000 words, whereas, with the Karat- cally “similar” to the total algorithm. This finally leads suba multiplication, they are efficient for smaller inte- to the precise evaluation of the average bit–complexity gers (around 100 words). A precise description of the of these fast algorithms. This work uses various tools, Knuth-Sch¨onhage algorithm can be found in [29, 22] for and is based on a precise study of generalised transfer instance. operators related to the dynamical system underlying the Euclid Algorithm. 1.1 Previous results. The average-case behaviour of the quadratic gcd algorithms is now well understood. 1 Introduction First results are due to Heilbronn and Dixon in the sev- enties, who studied for the first time the mean number Gcd computation is a widely used routine in compu- of iterations of the Euclid Algorithm, then Brent anal- tations on long integers. It is omnipresent in rational ysed the Binary algorithm [4], and Hensley [15] provided computations, public key cryptography or computer al- the first distributional analysis for the number of steps of the Euclid Algorithm. Since 90, the Caen Group ∗Facultad de Ingeniera, Universidad de Buenos Aires, Ar- [26, 28, 27] has performed an average-case analysis of gentina and GREYC, Universit´ede Caen, France various parameters of a large class of Euclidean algo- † GREYC, Universit´ede Caen, F-14032 Caen, France rithms. More recently, distributional results have also ‡IrisResearch Center, Stavanger, Norway §GREYC, Universit´ede Caen, F-14032 Caen, France been obtained for the Euclid algorithm and some of its ¶IMB, Universit´ede Bourgogne, F-21078 Dijon Cedex, France variants: first Baladi and Vall´ee prove that a whole class kGREYC, Universit´ede Caen, F-14032 Caen, France of so–called additive costs of moderate growth follows bution relative to the Gauss density ϕ, defined as an asymptotic gaussian law [2] (for instance, the num- 1 1 ber of iterations, the number of occurrences of a given (1.1) ϕ(x)= . log2 1+ x digit, etc). This year, Lhote and Vall´ee [21] show that a more general class of parameters also follows an asymp- For rational inputs, one begins with some distribution totic gaussian law. This class contains the length of a on the set of the inputs x := A1/A0 of size n, and remainder at a fraction of the execution, and the bit- we consider the rationals xk := Ak+1/Ak. We focus complexity. To the best of our knowledge, there are on the first index k where the binary size of xk is less yet few results on “efficient” gcd algorithms. In [9], the than (1 δ)n and we denote the corresponding rational − authors perform an average-case analysis of Lehmer’s xk by x δ . What is the distribution of the rational h i algorithm, and exhibit the average speed-up obtained x δ ? The evolution of this distribution is clearly more using these techniques. But, as far as we know, there intricateh i than in the real case, since at the end of the does not exist any probabilistic analysis of subquadratic Algorithm (when δ = 1), the distribution is the Dirac gcd algorithms. This is the goal of this paper to perform measure at x = 0. We obtain here a precise description such a study. of this distribution (see Theorem 2 and Figure 1) which involves another density 1.2 Our results. There are two algorithms to be 12 log(m + x) analyzed, the algorithm and the algorithm. The (1.2) ψ(x) := . HG G π2 (m + x)(m + x + 1) algorithm computes the gcd, and the algorithm m 1 X≥ (forG Half-gcd Algorithm) only simulates theHG “first half” of the algorithm. We first show that these algorithms G Theoretical can be viewed as a sequence of the so–called Interrupted 1.4 Experimental Euclidean algorithms. An Interrupted Euclidean algo- rithm is a subsequence formed by successive iterations of 1.2 the algorithm. On an input (A, B), the plain Euclid al- 1 gorithm builds a sequence of remainders Ai, a sequence of quotients Qi, and a sequence of matrix i [see Sec- 0.8 tion 2.1]. On an input (A, B) of binary sizeMn, the Inter- 0.6 rupted Euclidean algorithm starts at the index Density probability E[δ,δ+γ] k of the execution of the Euclid Algorithm, as soon as 0.4 the remainder Ak has already lost δn bits (with respect to the initial A which has n bits) and stops at index 0.2 k + i as soon as the remainder Ak+i has lost γn supple- 0 mentary bits (with respect to the remainder Ak). The 0 0.2 0.4 0.6 0.8 1 x algorithm is just an algorithm which simulates the interruptedHG algorithm . A quite natural question E[0,1/2] Figure 1: Density distribution of xhδi in the case δ = 1/2. is: How many iterations are necessary to lose these γn This corresponds to the density distribution of the rational bits? Of course, it is natural to expect that this sub- xk := Ak+1/Ak obtained as soon as ℓ(Ak) is smaller than sequence of the Euclidean algorithm is just “regular” (1/2)ℓ(A0). The density distribution is plotted against its and locally similar to the “total” Euclidean Algorithm; theoretical counterparts ψ(x). Here we consider Ωn for in this case, the number of iterations would be close to n = 48 (48 bits), the interval [0, 1] is subdivided into equal γ P (where P is the number of iterations of the “total” subintervals of length 1/50 to estimate the density, and Euclid algorithm). We prove in Theorem 1 that this is 3 537 944 rational are drawn from Ωn according to the initial the case. density distribution ϕ by Monte Carlo simulation. We also need precise results on the distribution of some truncatures of these remainders. This is done For a probabilistic study of these fast variants, a precise in Theorem 3. Then, the choice of parameters in the description of the evolution of the distribution during fast algorithms must take into account this evolution the execution of the plain Euclid Algorithm is of crucial of distribution.