https://en.wikipedia.org/w/index.php?action=history&feed=atom&title=Binary_GCD_algorithm Binary GCD algorithm - Revision history 2025-05-25T17:18:19Z Revision history for this page on the wiki MediaWiki 1.45.0-wmf.2 https://en.wikipedia.org/w/index.php?title=Binary_GCD_algorithm&diff=1272402879&oldid=prev Frap: Add category 2025-01-28T13:05:04Z <p>Add category</p> <table style="background-color: #fff; color: #202122;" data-mw="interface"> <col class="diff-marker" /> <col class="diff-content" /> <col class="diff-marker" /> <col class="diff-content" /> <tr class="diff-title" lang="en"> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 13:05, 28 January 2025</td> </tr><tr> <td colspan="2" class="diff-lineno">Line 207:</td> <td colspan="2" class="diff-lineno">Line 207:</td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>{{DEFAULTSORT:Binary Gcd Algorithm}}</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>{{DEFAULTSORT:Binary Gcd Algorithm}}</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>[[Category:Number theoretic algorithms]]</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>[[Category:Number theoretic algorithms]]</div></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>[[Category:Articles with example <del style="font-weight: bold; text-decoration: none;">C</del> code]]</div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>[[Category:Articles with example <ins style="font-weight: bold; text-decoration: none;">Rust</ins> code]]</div></td> </tr> </table> Frap https://en.wikipedia.org/w/index.php?title=Binary_GCD_algorithm&diff=1256794162&oldid=prev Dyspophyr: /* Further reading */ link -> simple continued fraction 2024-11-11T16:14:32Z <p><span class="autocomment">Further reading: </span> link -&gt; <a href="/wiki/Simple_continued_fraction" title="Simple continued fraction">simple continued fraction</a></p> <table style="background-color: #fff; color: #202122;" data-mw="interface"> <col class="diff-marker" /> <col class="diff-content" /> <col class="diff-marker" /> <col class="diff-content" /> <tr class="diff-title" lang="en"> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 16:14, 11 November 2024</td> </tr><tr> <td colspan="2" class="diff-lineno">Line 187:</td> <td colspan="2" class="diff-lineno">Line 187:</td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>|isbn= 0-387-55640-0|publisher=[[Springer-Verlag]]|series=[[Graduate Texts in Mathematics]]|volume=138</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>|isbn= 0-387-55640-0|publisher=[[Springer-Verlag]]|series=[[Graduate Texts in Mathematics]]|volume=138</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>|url= https://books.google.com/books?id=hXGr-9l1DXcC}}</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>|url= https://books.google.com/books?id=hXGr-9l1DXcC}}</div></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>Covers a variety of topics, including the extended binary GCD algorithm which outputs [[Bézout coefficients]], efficient handling of multi-precision integers using a variant of [[Lehmer's GCD algorithm]], and the relationship between GCD and [[continued fraction]]<del style="font-weight: bold; text-decoration: none;"> expansions</del> of real numbers.</div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>Covers a variety of topics, including the extended binary GCD algorithm which outputs [[Bézout coefficients]], efficient handling of multi-precision integers using a variant of [[Lehmer's GCD algorithm]], and the relationship between GCD and [[<ins style="font-weight: bold; text-decoration: none;">simple </ins>continued fraction<ins style="font-weight: bold; text-decoration: none;">|continued fraction expansion</ins>]]<ins style="font-weight: bold; text-decoration: none;">s</ins> of real numbers.</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>* {{cite journal|last=Vallée |first=Brigitte | author-link=Brigitte Vallée</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>* {{cite journal|last=Vallée |first=Brigitte | author-link=Brigitte Vallée</div></td> </tr> </table> Dyspophyr https://en.wikipedia.org/w/index.php?title=Binary_GCD_algorithm&diff=1251644223&oldid=prev Bubba73: /* Extensions */ 2024-10-17T06:56:36Z <p><span class="autocomment">Extensions</span></p> <table style="background-color: #fff; color: #202122;" data-mw="interface"> <col class="diff-marker" /> <col class="diff-content" /> <col class="diff-marker" /> <col class="diff-content" /> <tr class="diff-title" lang="en"> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 06:56, 17 October 2024</td> </tr><tr> <td colspan="2" class="diff-lineno">Line 96:</td> <td colspan="2" class="diff-lineno">Line 96:</td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>==Extensions==</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>==Extensions==</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>The binary GCD algorithm can be extended in several ways, either to output additional information, deal with [[Arbitrary-precision arithmetic|arbitrarily<del style="font-weight: bold; text-decoration: none;">-</del>large integers]] more efficiently, or to compute GCDs in domains other than the integers.</div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>The binary GCD algorithm can be extended in several ways, either to output additional information, deal with [[Arbitrary-precision arithmetic|arbitrarily<ins style="font-weight: bold; text-decoration: none;"> </ins>large integers]] more efficiently, or to compute GCDs in domains other than the integers.</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>The ''extended binary GCD'' algorithm, analogous to the [[extended Euclidean algorithm]], fits in the first kind of extension, as it provides the [[Bézout coefficients]] in addition to the GCD: integers &lt;math&gt;a&lt;/math&gt; and &lt;math&gt;b&lt;/math&gt; such that &lt;math&gt;a\cdot{}u + b\cdot{}v = \gcd(u, v)&lt;/math&gt;.&lt;ref name="egcd-knuth"/&gt;&lt;ref name="egcd-applied-crypto"/&gt;&lt;ref name="egcd-cohen"/&gt;</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>The ''extended binary GCD'' algorithm, analogous to the [[extended Euclidean algorithm]], fits in the first kind of extension, as it provides the [[Bézout coefficients]] in addition to the GCD: integers &lt;math&gt;a&lt;/math&gt; and &lt;math&gt;b&lt;/math&gt; such that &lt;math&gt;a\cdot{}u + b\cdot{}v = \gcd(u, v)&lt;/math&gt;.&lt;ref name="egcd-knuth"/&gt;&lt;ref name="egcd-applied-crypto"/&gt;&lt;ref name="egcd-cohen"/&gt;</div></td> </tr> </table> Bubba73 https://en.wikipedia.org/w/index.php?title=Binary_GCD_algorithm&diff=1251644163&oldid=prev Bubba73: /* Complexity */ no hyphen after -ly adverbs 2024-10-17T06:55:37Z <p><span class="autocomment">Complexity: </span> no hyphen after -ly adverbs</p> <table style="background-color: #fff; color: #202122;" data-mw="interface"> <col class="diff-marker" /> <col class="diff-content" /> <col class="diff-marker" /> <col class="diff-content" /> <tr class="diff-title" lang="en"> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 06:55, 17 October 2024</td> </tr><tr> <td colspan="2" class="diff-lineno">Line 86:</td> <td colspan="2" class="diff-lineno">Line 86:</td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>[[Big O notation|Asymptotically]], the algorithm requires &lt;math&gt;O(n)&lt;/math&gt; steps, where &lt;math&gt;n&lt;/math&gt; is the number of bits in the larger of the two numbers, as every two steps reduce at least one of the operands by at least a factor of &lt;math&gt;2&lt;/math&gt;. Each step involves only a few arithmetic operations (&lt;math&gt;O(1)&lt;/math&gt; with a small constant); when working with [[Word (computer architecture)|word-sized]] numbers, each arithmetic operation translates to a single machine operation, so the number of machine operations is on the order of &lt;math&gt;n&lt;/math&gt;, i.e. &lt;math&gt;\log_{2}(\max(u, v))&lt;/math&gt;.</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>[[Big O notation|Asymptotically]], the algorithm requires &lt;math&gt;O(n)&lt;/math&gt; steps, where &lt;math&gt;n&lt;/math&gt; is the number of bits in the larger of the two numbers, as every two steps reduce at least one of the operands by at least a factor of &lt;math&gt;2&lt;/math&gt;. Each step involves only a few arithmetic operations (&lt;math&gt;O(1)&lt;/math&gt; with a small constant); when working with [[Word (computer architecture)|word-sized]] numbers, each arithmetic operation translates to a single machine operation, so the number of machine operations is on the order of &lt;math&gt;n&lt;/math&gt;, i.e. &lt;math&gt;\log_{2}(\max(u, v))&lt;/math&gt;.</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>For arbitrarily<del style="font-weight: bold; text-decoration: none;">-</del>large numbers, the [[asymptotic notation|asymptotic complexity]] of this algorithm is &lt;math&gt;O(n^2)&lt;/math&gt;,&lt;ref name="gmplib"/&gt; as each arithmetic operation (subtract and shift) involves a linear number of machine operations (one per word in the numbers' binary representation).</div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>For arbitrarily<ins style="font-weight: bold; text-decoration: none;"> </ins>large numbers, the [[asymptotic notation|asymptotic complexity]] of this algorithm is &lt;math&gt;O(n^2)&lt;/math&gt;,&lt;ref name="gmplib"/&gt; as each arithmetic operation (subtract and shift) involves a linear number of machine operations (one per word in the numbers' binary representation).</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>If the numbers can be represented in the machine's memory, ''i.e.'' each number's ''size'' can be represented by a single machine word, this bound is reduced to:</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>If the numbers can be represented in the machine's memory, ''i.e.'' each number's ''size'' can be represented by a single machine word, this bound is reduced to:</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>&lt;math display="block"&gt;</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>&lt;math display="block"&gt;</div></td> </tr> </table> Bubba73 https://en.wikipedia.org/w/index.php?title=Binary_GCD_algorithm&diff=1251643998&oldid=prev Bubba73: Changing short description from "Algorithm in mathematics" to "Algorithm for computing the greatest common divisor" 2024-10-17T06:53:19Z <p>Changing <a href="/wiki/Wikipedia:Short_description" title="Wikipedia:Short description">short description</a> from &quot;Algorithm in mathematics&quot; to &quot;Algorithm for computing the greatest common divisor&quot;</p> <table style="background-color: #fff; color: #202122;" data-mw="interface"> <col class="diff-marker" /> <col class="diff-content" /> <col class="diff-marker" /> <col class="diff-content" /> <tr class="diff-title" lang="en"> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 06:53, 17 October 2024</td> </tr><tr> <td colspan="2" class="diff-lineno">Line 1:</td> <td colspan="2" class="diff-lineno">Line 1:</td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>{{Short description|Algorithm <del style="font-weight: bold; text-decoration: none;">in</del> <del style="font-weight: bold; text-decoration: none;">mathematics</del>}}</div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>{{Short description|Algorithm <ins style="font-weight: bold; text-decoration: none;">for</ins> <ins style="font-weight: bold; text-decoration: none;">computing the greatest common divisor</ins>}}</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>{{Use dmy dates|date=April 2022}}</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>{{Use dmy dates|date=April 2022}}</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>[[File:binary_GCD_algorithm_visualisation.svg|thumb|upright=1.8|Visualisation of using the binary GCD algorithm to find the greatest common divisor (GCD) of 36 and 24. Thus, the GCD is 2&lt;sup&gt;2&lt;/sup&gt; × 3 = 12.]]</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>[[File:binary_GCD_algorithm_visualisation.svg|thumb|upright=1.8|Visualisation of using the binary GCD algorithm to find the greatest common divisor (GCD) of 36 and 24. Thus, the GCD is 2&lt;sup&gt;2&lt;/sup&gt; × 3 = 12.]]</div></td> </tr> </table> Bubba73 https://en.wikipedia.org/w/index.php?title=Binary_GCD_algorithm&diff=1248891311&oldid=prev LR.127: Adding local short description: "Algorithm in mathematics", overriding Wikidata description "algorithm that computes the greatest common divisor of two integers using only arithmetic shifts, comparisons, and subtraction" 2024-10-02T00:55:14Z <p>Adding local <a href="/wiki/Wikipedia:Short_description" title="Wikipedia:Short description">short description</a>: &quot;Algorithm in mathematics&quot;, overriding Wikidata description &quot;algorithm that computes the greatest common divisor of two integers using only arithmetic shifts, comparisons, and subtraction&quot;</p> <table style="background-color: #fff; color: #202122;" data-mw="interface"> <col class="diff-marker" /> <col class="diff-content" /> <col class="diff-marker" /> <col class="diff-content" /> <tr class="diff-title" lang="en"> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 00:55, 2 October 2024</td> </tr><tr> <td colspan="2" class="diff-lineno">Line 1:</td> <td colspan="2" class="diff-lineno">Line 1:</td> </tr> <tr> <td colspan="2" class="diff-empty diff-side-deleted"></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>{{Short description|Algorithm in mathematics}}</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>{{Use dmy dates|date=April 2022}}</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>{{Use dmy dates|date=April 2022}}</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>[[File:binary_GCD_algorithm_visualisation.svg|thumb|upright=1.8|Visualisation of using the binary GCD algorithm to find the greatest common divisor (GCD) of 36 and 24. Thus, the GCD is 2&lt;sup&gt;2&lt;/sup&gt; × 3 = 12.]]</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>[[File:binary_GCD_algorithm_visualisation.svg|thumb|upright=1.8|Visualisation of using the binary GCD algorithm to find the greatest common divisor (GCD) of 36 and 24. Thus, the GCD is 2&lt;sup&gt;2&lt;/sup&gt; × 3 = 12.]]</div></td> </tr> </table> LR.127 https://en.wikipedia.org/w/index.php?title=Binary_GCD_algorithm&diff=1244674464&oldid=prev AstonishingTunesAdmirer: /* Implementation */ this template is for use in discussions 2024-09-08T14:01:22Z <p><span class="autocomment">Implementation: </span> this template is for use in discussions</p> <table style="background-color: #fff; color: #202122;" data-mw="interface"> <col class="diff-marker" /> <col class="diff-content" /> <col class="diff-marker" /> <col class="diff-content" /> <tr class="diff-title" lang="en"> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 14:01, 8 September 2024</td> </tr><tr> <td colspan="2" class="diff-lineno">Line 73:</td> <td colspan="2" class="diff-lineno">Line 73:</td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>&lt;/syntaxhighlight&gt;</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>&lt;/syntaxhighlight&gt;</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">{{A note}}</del> The implementation above accepts ''unsigned'' (non-negative) integers; given that &lt;math&gt;\gcd(u, v) = \gcd(\pm{}u, \pm{}v)&lt;/math&gt;, the signed case can be handled as follows:</div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">'''Note''':</ins> The implementation above accepts ''unsigned'' (non-negative) integers; given that &lt;math&gt;\gcd(u, v) = \gcd(\pm{}u, \pm{}v)&lt;/math&gt;, the signed case can be handled as follows:</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>&lt;syntaxhighlight lang="rust"&gt;</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>&lt;syntaxhighlight lang="rust"&gt;</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>/// Computes the GCD of two signed 64-bit integers</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>/// Computes the GCD of two signed 64-bit integers</div></td> </tr> </table> AstonishingTunesAdmirer https://en.wikipedia.org/w/index.php?title=Binary_GCD_algorithm&diff=1236689228&oldid=prev 174.89.113.20 at 02:27, 26 July 2024 2024-07-26T02:27:38Z <p></p> <table style="background-color: #fff; color: #202122;" data-mw="interface"> <col class="diff-marker" /> <col class="diff-content" /> <col class="diff-marker" /> <col class="diff-content" /> <tr class="diff-title" lang="en"> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 02:27, 26 July 2024</td> </tr><tr> <td colspan="2" class="diff-lineno">Line 4:</td> <td colspan="2" class="diff-lineno">Line 4:</td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>The '''binary GCD algorithm''', also known as '''Stein's algorithm''' or the '''binary Euclidean algorithm''',{{r|brenta|brentb}} is an algorithm that computes the [[greatest common divisor]] (GCD) of two nonnegative integers. Stein's algorithm uses simpler arithmetic operations than the conventional [[Euclidean algorithm]]; it replaces division with [[arithmetic shift]]s, comparisons, and subtraction.</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>The '''binary GCD algorithm''', also known as '''Stein's algorithm''' or the '''binary Euclidean algorithm''',{{r|brenta|brentb}} is an algorithm that computes the [[greatest common divisor]] (GCD) of two nonnegative integers. Stein's algorithm uses simpler arithmetic operations than the conventional [[Euclidean algorithm]]; it replaces division with [[arithmetic shift]]s, comparisons, and subtraction.</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>Although the algorithm in its contemporary form was first published by the<del style="font-weight: bold; text-decoration: none;"> Israeli</del> physicist and programmer Josef Stein in 1967,&lt;ref name="Stein"/&gt; it <del style="font-weight: bold; text-decoration: none;">may have been</del> known by the 2nd century BCE, in ancient China.{{r|Knuth98}}</div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>Although the algorithm in its contemporary form was first published by the physicist and programmer Josef Stein in 1967,&lt;ref name="Stein"/&gt; it <ins style="font-weight: bold; text-decoration: none;">was</ins> known by the 2nd century BCE, in ancient China.{{r|Knuth98}}</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>==Algorithm==</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>==Algorithm==</div></td> </tr> </table> 174.89.113.20 https://en.wikipedia.org/w/index.php?title=Binary_GCD_algorithm&diff=1231635222&oldid=prev HTinC23: changed gcd and max to upright (MOS:MATH#Multi-letter names) 2024-06-29T11:20:36Z <p>changed gcd and max to upright (<a href="/wiki/MOS:MATH#Multi-letter_names" class="mw-redirect" title="MOS:MATH">MOS:MATH#Multi-letter names</a>)</p> <table style="background-color: #fff; color: #202122;" data-mw="interface"> <col class="diff-marker" /> <col class="diff-content" /> <col class="diff-marker" /> <col class="diff-content" /> <tr class="diff-title" lang="en"> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 11:20, 29 June 2024</td> </tr><tr> <td colspan="2" class="diff-lineno">Line 10:</td> <td colspan="2" class="diff-lineno">Line 10:</td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>The algorithm finds the GCD of two nonnegative numbers &lt;math&gt;u&lt;/math&gt; and &lt;math&gt;v&lt;/math&gt; by repeatedly applying these identities:</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>The algorithm finds the GCD of two nonnegative numbers &lt;math&gt;u&lt;/math&gt; and &lt;math&gt;v&lt;/math&gt; by repeatedly applying these identities:</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div># &lt;math&gt;gcd(u, 0) = u&lt;/math&gt;: everything divides zero, and &lt;math&gt;u&lt;/math&gt; is the largest number that divides &lt;math&gt;u&lt;/math&gt;.</div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div># &lt;math&gt;<ins style="font-weight: bold; text-decoration: none;">\</ins>gcd(u, 0) = u&lt;/math&gt;: everything divides zero, and &lt;math&gt;u&lt;/math&gt; is the largest number that divides &lt;math&gt;u&lt;/math&gt;.</div></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div># &lt;math&gt;gcd(2u, 2v) = 2 \cdot gcd(u, v)&lt;/math&gt;: &lt;math&gt;2&lt;/math&gt; is a common divisor.</div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div># &lt;math&gt;<ins style="font-weight: bold; text-decoration: none;">\</ins>gcd(2u, 2v) = 2 \cdot <ins style="font-weight: bold; text-decoration: none;">\</ins>gcd(u, v)&lt;/math&gt;: &lt;math&gt;2&lt;/math&gt; is a common divisor.</div></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div># &lt;math&gt;gcd(u, 2v) = gcd(u, v)&lt;/math&gt; if &lt;math&gt;u&lt;/math&gt; is odd: &lt;math&gt;2&lt;/math&gt; is then not a common divisor.</div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div># &lt;math&gt;<ins style="font-weight: bold; text-decoration: none;">\</ins>gcd(u, 2v) = <ins style="font-weight: bold; text-decoration: none;">\</ins>gcd(u, v)&lt;/math&gt; if &lt;math&gt;u&lt;/math&gt; is odd: &lt;math&gt;2&lt;/math&gt; is then not a common divisor.</div></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div># &lt;math&gt;gcd(u, v) = gcd(u, v - u)&lt;/math&gt; if &lt;math&gt;u, v&lt;/math&gt; odd and &lt;math&gt;u \leq v&lt;/math&gt;.</div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div># &lt;math&gt;<ins style="font-weight: bold; text-decoration: none;">\</ins>gcd(u, v) = <ins style="font-weight: bold; text-decoration: none;">\</ins>gcd(u, v - u)&lt;/math&gt; if &lt;math&gt;u, v&lt;/math&gt; odd and &lt;math&gt;u \leq v&lt;/math&gt;.</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>As GCD is commutative (&lt;math&gt;gcd(u, v) = gcd(v, u)&lt;/math&gt;), those identities still apply if the operands are swapped: &lt;math&gt;gcd(0, v) = v&lt;/math&gt;, &lt;math&gt;gcd(2u, v) = gcd(u, v)&lt;/math&gt; if &lt;math&gt;v&lt;/math&gt; is odd, etc.</div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>As GCD is commutative (&lt;math&gt;<ins style="font-weight: bold; text-decoration: none;">\</ins>gcd(u, v) = <ins style="font-weight: bold; text-decoration: none;">\</ins>gcd(v, u)&lt;/math&gt;), those identities still apply if the operands are swapped: &lt;math&gt;<ins style="font-weight: bold; text-decoration: none;">\</ins>gcd(0, v) = v&lt;/math&gt;, &lt;math&gt;<ins style="font-weight: bold; text-decoration: none;">\</ins>gcd(2u, v) = <ins style="font-weight: bold; text-decoration: none;">\</ins>gcd(u, v)&lt;/math&gt; if &lt;math&gt;v&lt;/math&gt; is odd, etc.</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>==Implementation==</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>==Implementation==</div></td> </tr> <tr> <td colspan="2" class="diff-lineno">Line 73:</td> <td colspan="2" class="diff-lineno">Line 73:</td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>&lt;/syntaxhighlight&gt;</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>&lt;/syntaxhighlight&gt;</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>{{A note}} The implementation above accepts ''unsigned'' (non-negative) integers; given that &lt;math&gt;gcd(u, v) = gcd(\pm{}u, \pm{}v)&lt;/math&gt;, the signed case can be handled as follows:</div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>{{A note}} The implementation above accepts ''unsigned'' (non-negative) integers; given that &lt;math&gt;<ins style="font-weight: bold; text-decoration: none;">\</ins>gcd(u, v) = <ins style="font-weight: bold; text-decoration: none;">\</ins>gcd(\pm{}u, \pm{}v)&lt;/math&gt;, the signed case can be handled as follows:</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>&lt;syntaxhighlight lang="rust"&gt;</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>&lt;syntaxhighlight lang="rust"&gt;</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>/// Computes the GCD of two signed 64-bit integers</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>/// Computes the GCD of two signed 64-bit integers</div></td> </tr> <tr> <td colspan="2" class="diff-lineno">Line 83:</td> <td colspan="2" class="diff-lineno">Line 83:</td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>==Complexity==</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>==Complexity==</div></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>[[Big O notation|Asymptotically]], the algorithm requires &lt;math&gt;O(n)&lt;/math&gt; steps, where &lt;math&gt;n&lt;/math&gt; is the number of bits in the larger of the two numbers, as every two steps reduce at least one of the operands by at least a factor of &lt;math&gt;2&lt;/math&gt;. Each step involves only a few arithmetic operations (&lt;math&gt;O(1)&lt;/math&gt; with a small constant); when working with [[Word (computer architecture)|word-sized]] numbers, each arithmetic operation translates to a single machine operation, so the number of machine operations is on the order of &lt;math&gt;n&lt;/math&gt;, i.e. &lt;math&gt;\log_{2}(max(u, v))&lt;/math&gt;.</div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>[[Big O notation|Asymptotically]], the algorithm requires &lt;math&gt;O(n)&lt;/math&gt; steps, where &lt;math&gt;n&lt;/math&gt; is the number of bits in the larger of the two numbers, as every two steps reduce at least one of the operands by at least a factor of &lt;math&gt;2&lt;/math&gt;. Each step involves only a few arithmetic operations (&lt;math&gt;O(1)&lt;/math&gt; with a small constant); when working with [[Word (computer architecture)|word-sized]] numbers, each arithmetic operation translates to a single machine operation, so the number of machine operations is on the order of &lt;math&gt;n&lt;/math&gt;, i.e. &lt;math&gt;\log_{2}(<ins style="font-weight: bold; text-decoration: none;">\</ins>max(u, v))&lt;/math&gt;.</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>For arbitrarily-large numbers, the [[asymptotic notation|asymptotic complexity]] of this algorithm is &lt;math&gt;O(n^2)&lt;/math&gt;,&lt;ref name="gmplib"/&gt; as each arithmetic operation (subtract and shift) involves a linear number of machine operations (one per word in the numbers' binary representation).</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>For arbitrarily-large numbers, the [[asymptotic notation|asymptotic complexity]] of this algorithm is &lt;math&gt;O(n^2)&lt;/math&gt;,&lt;ref name="gmplib"/&gt; as each arithmetic operation (subtract and shift) involves a linear number of machine operations (one per word in the numbers' binary representation).</div></td> </tr> <tr> <td colspan="2" class="diff-lineno">Line 97:</td> <td colspan="2" class="diff-lineno">Line 97:</td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>The binary GCD algorithm can be extended in several ways, either to output additional information, deal with [[Arbitrary-precision arithmetic|arbitrarily-large integers]] more efficiently, or to compute GCDs in domains other than the integers.</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>The binary GCD algorithm can be extended in several ways, either to output additional information, deal with [[Arbitrary-precision arithmetic|arbitrarily-large integers]] more efficiently, or to compute GCDs in domains other than the integers.</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>The ''extended binary GCD'' algorithm, analogous to the [[extended Euclidean algorithm]], fits in the first kind of extension, as it provides the [[Bézout coefficients]] in addition to the GCD: integers &lt;math&gt;a&lt;/math&gt; and &lt;math&gt;b&lt;/math&gt; such that &lt;math&gt;a\cdot{}u + b\cdot{}v = gcd(u, v)&lt;/math&gt;.&lt;ref name="egcd-knuth"/&gt;&lt;ref name="egcd-applied-crypto"/&gt;&lt;ref name="egcd-cohen"/&gt;</div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>The ''extended binary GCD'' algorithm, analogous to the [[extended Euclidean algorithm]], fits in the first kind of extension, as it provides the [[Bézout coefficients]] in addition to the GCD: integers &lt;math&gt;a&lt;/math&gt; and &lt;math&gt;b&lt;/math&gt; such that &lt;math&gt;a\cdot{}u + b\cdot{}v = <ins style="font-weight: bold; text-decoration: none;">\</ins>gcd(u, v)&lt;/math&gt;.&lt;ref name="egcd-knuth"/&gt;&lt;ref name="egcd-applied-crypto"/&gt;&lt;ref name="egcd-cohen"/&gt;</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>In the case of large integers, the best asymptotic complexity is &lt;math&gt;O(M(n) \log n)&lt;/math&gt;, with &lt;math&gt;M(n)&lt;/math&gt; the cost of &lt;math&gt;n&lt;/math&gt;-bit multiplication; this is near-linear and vastly smaller than the binary GCD algorithm's &lt;math&gt;O(n^2)&lt;/math&gt;, though concrete implementations only outperform older algorithms for numbers larger than about 64 kilobits (''i.e.'' greater than 8×10&lt;sup&gt;19265&lt;/sup&gt;). This is achieved by extending the binary GCD algorithm using ideas from the [[Schönhage–Strassen algorithm]] for fast integer multiplication.&lt;ref name="stehlé-zimmermann"/&gt; </div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>In the case of large integers, the best asymptotic complexity is &lt;math&gt;O(M(n) \log n)&lt;/math&gt;, with &lt;math&gt;M(n)&lt;/math&gt; the cost of &lt;math&gt;n&lt;/math&gt;-bit multiplication; this is near-linear and vastly smaller than the binary GCD algorithm's &lt;math&gt;O(n^2)&lt;/math&gt;, though concrete implementations only outperform older algorithms for numbers larger than about 64 kilobits (''i.e.'' greater than 8×10&lt;sup&gt;19265&lt;/sup&gt;). This is achieved by extending the binary GCD algorithm using ideas from the [[Schönhage–Strassen algorithm]] for fast integer multiplication.&lt;ref name="stehlé-zimmermann"/&gt; </div></td> </tr> </table> HTinC23 https://en.wikipedia.org/w/index.php?title=Binary_GCD_algorithm&diff=1217222861&oldid=prev 147.83.76.249 at 15:13, 4 April 2024 2024-04-04T15:13:06Z <p></p> <table style="background-color: #fff; color: #202122;" data-mw="interface"> <col class="diff-marker" /> <col class="diff-content" /> <col class="diff-marker" /> <col class="diff-content" /> <tr class="diff-title" lang="en"> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 15:13, 4 April 2024</td> </tr><tr> <td colspan="2" class="diff-lineno">Line 10:</td> <td colspan="2" class="diff-lineno">Line 10:</td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>The algorithm finds the GCD of two nonnegative numbers &lt;math&gt;u&lt;/math&gt; and &lt;math&gt;v&lt;/math&gt; by repeatedly applying these identities:</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>The algorithm finds the GCD of two nonnegative numbers &lt;math&gt;u&lt;/math&gt; and &lt;math&gt;v&lt;/math&gt; by repeatedly applying these identities:</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div># &lt;math&gt;gcd(u, 0) = u&lt;/math&gt;: everything divides zero, and &lt;math&gt;<del style="font-weight: bold; text-decoration: none;">v</del>&lt;/math&gt; is the largest number that divides &lt;math&gt;<del style="font-weight: bold; text-decoration: none;">v</del>&lt;/math&gt;.</div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div># &lt;math&gt;gcd(u, 0) = u&lt;/math&gt;: everything divides zero, and &lt;math&gt;<ins style="font-weight: bold; text-decoration: none;">u</ins>&lt;/math&gt; is the largest number that divides &lt;math&gt;<ins style="font-weight: bold; text-decoration: none;">u</ins>&lt;/math&gt;.</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div># &lt;math&gt;gcd(2u, 2v) = 2 \cdot gcd(u, v)&lt;/math&gt;: &lt;math&gt;2&lt;/math&gt; is a common divisor.</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div># &lt;math&gt;gcd(2u, 2v) = 2 \cdot gcd(u, v)&lt;/math&gt;: &lt;math&gt;2&lt;/math&gt; is a common divisor.</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div># &lt;math&gt;gcd(u, 2v) = gcd(u, v)&lt;/math&gt; if &lt;math&gt;u&lt;/math&gt; is odd: &lt;math&gt;2&lt;/math&gt; is then not a common divisor.</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div># &lt;math&gt;gcd(u, 2v) = gcd(u, v)&lt;/math&gt; if &lt;math&gt;u&lt;/math&gt; is odd: &lt;math&gt;2&lt;/math&gt; is then not a common divisor.</div></td> </tr> </table> 147.83.76.249