 
 with
 with 
 .  Then
by Proposition 2.1.12
the equation
.  Then
by Proposition 2.1.12
the equation 
 has a unique solution.
How can we find it?
 has a unique solution.
How can we find it?
 is a multiple of
 is a multiple of  , then
, then 
 so
 so 
 can
also be written in terms of
 can
also be written in terms of  and
 and  .
.
 .  Then
.  Then
  
 , so by Proposition 2.1.14 the equation
, so by Proposition 2.1.14 the equation
 .  Multiplying (2.3.1) through by
.  Multiplying (2.3.1) through by  yields
 
yields 
 , so there exists
, so there exists  such that
 such that
  
 .   Then
.   Then  , as required.
, as required.
  
Given  and
 and 
 , our proof of
Proposition 2.3.1 gives a way to explicitly find
, our proof of
Proposition 2.3.1 gives a way to explicitly find  such
that
 such
that  , assuming one knows an algorithm to solve linear
equations modulo
, assuming one knows an algorithm to solve linear
equations modulo  . Since we do not know such an algorithm, we now
discuss a way to explicitly find
. Since we do not know such an algorithm, we now
discuss a way to explicitly find  and
 and  .  This algorithm
will in fact enable us to solve linear equations modulo
.  This algorithm
will in fact enable us to solve linear equations modulo  --to solve
--to solve
 when
 when 
 , use the algorithm below to
find
, use the algorithm below to
find  and
 and  such that
 such that  .  Then
.  Then 
 
 and
 and  .  The steps of Algorithm 1.1.13 to
  compute
.  The steps of Algorithm 1.1.13 to
  compute  are, as follows.  Here we underline certain
  numbers, because it clarifies the subsequent back substitution we
  will use to find
 are, as follows.  Here we underline certain
  numbers, because it clarifies the subsequent back substitution we
  will use to find  and
 and  .
.
|  |  | so  |  | |
|  |  | so  |  | 
 and
 and  .  In the last step,
we obtain
.  In the last step,
we obtain  as a linear combination of
 as a linear combination of  and
 and  , as
desired.
, as
desired.
 and
 and  .  We have
.  We have
|  |  |  |  | |
|  |  |  |  | |
|  |  |  |  | |
|  |  |  |  | |
|  |  |  |  | 
 and
 and  is a solution to
 is a solution to 
 .
.
|  |  |  |  | |
|  |  |  |  | |
|  |  |  |  | |
|  |  |  |  | |
|  |  |  |  | 
 of
 of  and
 and  along with
 along with  such that
 such that 
 .
.
sage: xgcd(5,7) (1, 3, -2) sage: xgcd(130,61) (1, 23, -49)
 and
 and  are integers and let
 are integers and let 
 .
This algorithm finds
.
This algorithm finds  ,
,  and
 and  such that
 such that  .
We describe only the steps when
.
We describe only the steps when  , since one
can easily reduce to this case.
, since one
can easily reduce to this case.
 , so it terminates and when
it terminates
, so it terminates and when
it terminates 
 .
We omit the rest of the inductive proof that the algorithm
is correct, and instead refer the  reader to 
[#!knuth1!#, §1.2.1] which contains a detailed proof
in the context of a discussion of how one
writes mathematical proofs.
.
We omit the rest of the inductive proof that the algorithm
is correct, and instead refer the  reader to 
[#!knuth1!#, §1.2.1] which contains a detailed proof
in the context of a discussion of how one
writes mathematical proofs.
  
 )    
Suppose
)    
Suppose  and
 and  are integers and
 are integers and 
 .
This algorithm finds an
.
This algorithm finds an  such that
 such that 
 .
.
 such that
 such that 
 .
.
 .
.
 modulo
 modulo  to see that
 to see that  satisfies
satisfies 
 .
.
  
 . For example,
. For example,
sage: a = Mod(17, 61) sage: a^(-1) 18
William 2007-06-01