To install click the Add extension button. That's it.

The source code for the WIKI 2 extension is being checked by specialists of the Mozilla Foundation, Google, and Apple. You could also do it yourself at any point in time.

4,5
Kelly Slayton
Congratulations on this excellent venture… what a great idea!
Alexander Grigorievskiy
I use WIKI 2 every day and almost forgot how the original Wikipedia looks like.
Live Statistics
English Articles
Improved in 24 Hours
Added in 24 Hours
Languages
Recent
Show all languages
What we do. Every page goes through several hundred of perfecting techniques; in live mode. Quite the same Wikipedia. Just better.
.
Leo
Newton
Brights
Milds

Lehmer's GCD algorithm

From Wikipedia, the free encyclopedia

Lehmer's GCD algorithm, named after Derrick Henry Lehmer, is a fast GCD algorithm, an improvement on the simpler but slower Euclidean algorithm. It is mainly used for big integers that have a representation as a string of digits relative to some chosen numeral system base, say β = 1000 or β = 232.

YouTube Encyclopedic

  • 1/2
    Views:
    1 130
    68 918
  • Eriko Hironaka - Lehmer's Problem and Dilatations of Mapping Classes
  • The Euclidean Algorithm (GCD or GCF)

Transcription

Algorithm

Lehmer noted that most of the quotients from each step of the division part of the standard algorithm are small. (For example, Knuth observed that the quotients 1, 2, and 3 comprise 67.7% of all quotients.[1]) Those small quotients can be identified from only a few leading digits. Thus the algorithm starts by splitting off those leading digits and computing the sequence of quotients as long as it is correct.

Say we want to obtain the GCD of the two integers a and b. Let ab.

  • If b contains only one digit (in the chosen base, say β = 1000 or β = 232), use some other method, such as the Euclidean algorithm, to obtain the result.
  • If a and b differ in the length of digits, perform a division so that a and b are equal in length, with length equal to m.
  • Outer loop: Iterate until one of a or b is zero:
    • Decrease m by one. Let x be the leading (most significant) digit in a, x = a div β m and y the leading digit in b, y = b div β m.
    • Initialize a 2 by 3 matrix
    to an extended identity matrix
    and perform the euclidean algorithm simultaneously on the pairs (x + A, y + C) and (x + B, y + D), until the quotients differ. That is, iterate as an inner loop:
    • Compute the quotients w1 of the long divisions of (x + A) by (y + C) and w2 of (x + B) by (y + D) respectively. Also let w be the (not computed) quotient from the current long division in the chain of long divisions of the euclidean algorithm.
      • If w1w2, then break out of the inner iteration. Else set w to w1 (or w2).
      • Replace the current matrix
      with the matrix product
      according to the matrix formulation of the extended euclidean algorithm.
      • If B ≠ 0, go to the start of the inner loop.
    • If B = 0, we have reached a deadlock; perform a normal step of the euclidean algorithm with a and b, and restart the outer loop.
    • Set a to aA + bB and b to Ca + Db (again simultaneously). This applies the steps of the euclidean algorithm that were performed on the leading digits in compressed form to the long integers a and b. If b ≠ 0 go to the start of the outer loop.

References

  1. ^ Knuth, The Art of Computer Programming vol 2 "Seminumerical algorithms", chapter 4.5.3 Theorem E.
This page was last edited on 11 January 2020, at 18:19
Basis of this page is in Wikipedia. Text is available under the CC BY-SA 3.0 Unported License. Non-text media are available under their specified licenses. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc. WIKI 2 is an independent company and has no affiliation with Wikimedia Foundation.