§ Extended euclidian algorithm
§ Original definition
I feel like I only understand the extended euclidian algorithm algebraically,
so I've been trying to understand it from other perspectives. Note that
we want to find gcd(p,p′). WLOG, we assume that p>p′.
We now find a coefficient d such that p=dp′+r where 0≤r<p′.
At this stage, we need to repeat the algorithm to find gcd(p′,r). We
stop with the base case gcd(p′,0)=p′.
§ My choice of notation
I dislike the differentiation that occurs between p, p′, and r
in the notation. I will notate this as gcd(p0,p1). WLOG, assume
that p0>p1. We now find a coefficient d0 such that p0=p1d1+p2
such that 0≤p2<p1. At this stage, we recurse to find
gcd(p1,p2). We stop with the base case gcd(pn−1,pn)=pn iff
pn−1=dnpn+0. That is, when we have pn+1=0, we stop
with the process, taking the gcd to be pn.
§ Matrices
We can write the equation p0=p1d1+p2 as the equation
p0=[d1;1][p1;p2]T. But now, we have lost some state. We used
to have both p1 and p2, but we are left with p0. We should always
strive to have "matching" inputs and output so we can iterate maps. This
leads us to the natural generalization:
[p0p1]=[d1110][p1p2]
So at the first step, we are trying to find a (d1,p2) such that the
matrix equation holds, and 0≤p2<d1.
§ Extended euclidian division
When we finish, we have that gcd(pn−1,pn)=pn. I'll call the GCD
as g for clarity. We can now write the GCD as a linear combination
of the inputs g=pn=0⋅pn−1+1⋅pn. We now
want to backtrack to find out how to write g=ωn−2pn−2+ωn−1pn−1.
And so on, all the way to g=ω0p0+ω1p1.
- We can begin with the general case:
g=[ω′ω′′][p′p′′]
- We have the relationship:
[pp′]=[d′110][p′p′′]
- We can invert the matrix to get:
[p′p′′]=[011−d′][pp′]
- now combine with the previous equation to get:
g=[ω′ω′′][p′p′′]g=[ω′ω′′][011−d′][pp′]g=[ω′′ω−d′ω′][pp′]
§ Fractions
- GCD factorization equation: p/p′=(αp′+p′′)/p′=α+p′′/p′.
- Bezout equation: ω′p′+ω′′p′′=g.
- Bezout equation as fractions ω′+ω′′p′′/p′=g/p′.