Extended Euclid’s Algorithm; integer linear combinations II [01EO]
There is more to Euclid’s algorithm than meets the eye. Let us first return to an illustrative trace of the algorithm:
Let’s annotate each step of Example [01E2] with the quotient and remainder that was computed:
| \gcd {\mathopen {}\left (m,n\right )\mathclose {}} | m = q\cdot n + r |
|---|---|
| \gcd {\mathopen {}\left (34,13\right )\mathclose {}}{} | 34 = 2\cdot 13 + 8{} |
| \gcd {\mathopen {}\left (13,8\right )\mathclose {}}{} | 13 = 1\cdot 8 + 5{} |
| \gcd {\mathopen {}\left (8,5\right )\mathclose {}}{} | 8 = 1\cdot 5 + 3{} |
| \gcd {\mathopen {}\left (5,3\right )\mathclose {}}{} | 5 = 1\cdot 3 + 2{} |
| \gcd {\mathopen {}\left (3,2\right )\mathclose {}}{} | 3 = 1\cdot 2 + 1{} |
| \gcd {\mathopen {}\left (2,1\right )\mathclose {}}{} | 2 = 2\cdot 1 + 0{} |
| 1{} | {} |
What is interesting is that in each step, we can express the quotient and the remainder as an integer linear combination of the two arguments to \gcd :
| \gcd {\mathopen {}\left (m,n\right )\mathclose {}} | m = q\cdot n + r | r = m + j \cdot n |
|---|---|---|
| \gcd {\mathopen {}\left (34,13\right )\mathclose {}}{} | 34 = 2\cdot 13 + 8{} | 8 = 34 - 2\cdot 13{} |
| \gcd {\mathopen {}\left (13,8\right )\mathclose {}}{} | 13 = 1\cdot 8 + 5{} | 5 = 13 - 1\cdot 8{} |
| \gcd {\mathopen {}\left (8,5\right )\mathclose {}}{} | 8 = 1\cdot 5 + 3{} | 3 = 8 - 1\cdot 5{} |
| \gcd {\mathopen {}\left (5,3\right )\mathclose {}}{} | 5 = 1\cdot 3 + 2{} | 2 = 5 - 1\cdot 3{} |
| \gcd {\mathopen {}\left (3,2\right )\mathclose {}}{} | 3 = 1\cdot 2 + 1{} | 1 = 3 - 1\cdot 2{} |
| \gcd {\mathopen {}\left (2,1\right )\mathclose {}}{} | 2 = 2\cdot 1 + 0{} | {} |
| 1{} | {} | {} |
The proof of the following theorem is left as an exercise to the reader: it can be done using the extended Euclid’s algorithm, which we will define soon.
The proof of the above relies on the following elementary properties of linear combinations: