Recursive Extended Euclidean Algorithm

The greatest common divisor of positive integers , , …, is the largest integer such that divides each of the integers. There always exist integers , , …, such that .
Mathematica's built-in function ExtendedGCD returns , given the arguments . This Demonstration implements ExtendedGCD with a recursive extended Euclidean algorithm that computes a list of the results of the recursive steps.
The basic case is . The algorithm, given and , returns the list (as a column):
,
,
…,
.
Here, , where , using the division algorithm, and .
The correct result is returned in the deepest step of the recursion, and .
We define , , and , .
Suppose , and .
Then .
And, .
Thus, if the correct result is returned at depth , the correct result is returned at depth . By induction, the result at depth 0 is correct: and .
The idea behind the the algorithm () can be gleaned by studying numerical examples provided by the Demonstration. In each case, observe that the result is correct at the deepest level of the recursion (last line of the list), and the correctness at depth (a given line) implies the correctness at depth (the previous line). The result at depth 0 (the first line) is therefore correct.

(24 lines omitted)

The correctness of the definitions in the program can be argued by observing 1) they terminate, 2) they return the correct result when they terminate, and 3) they return the correct result whenever a recursive call returns the correct result.
A classic exposition of these ideas is found in "1.7 The Euclidean Algorithm", in Birkhoff and MacLane, which can be read online.
The recursive algorithm we have used (for ) is described in Euclidean algorithm, under "Extended Euclidean Algorithm".
G. Birkhoff and S. MacLane, A Survey of Modern Algebra, 4th ed., New York: MacMillan Publishing Co., 1977.
K. H. Rosen, Elementary Number Theory and its Applications, 4th ed., Reading, MA: Addison–Wesley, 2000.
comments
 
Powered by Wolfram Mathematica
Give us your feedback
Give us your feedback

Source page:




 often  occasionally  never

Note: Please do not include anything you consider confidential or proprietary. Your message and contact information may be shared with the author of any specific Demonstration for which you give feedback, but will not otherwise be published or distributed.
Privacy Policy »

Note: To run this Demonstration you need the free
Mathematica Player
or Mathematica 7+
Download or upgrade to Mathematica Player 7
I already have Mathematica Player or Mathematica 7+