euclidean algorithm
Let such that
m
>
;
n
, if
m
%
n
>
;
0
, then
gcd
(
m
,
n
)
=
gcd
(
n
,
m
%
n
)
. Otherwise if
m
%
n
=
0
, then
n
|
m
and
gcd
(
m
,
n
)
=
n
If
m
%
n
=
0
, then
m
=
(
m
/
/
n
)
⋅
n
, therefore
gcd
(
m
,
n
)
=
gcd
(
(
m
/
/
n
)
⋅
n
,
n
)
=
n
, so now assume that
m
%
n
>
;
0
Recall that
m
=
(
m
/
/
n
)
⋅
n
+
m
%
n
, therefore
m
−
(
m
/
/
n
)
⋅
n
=
m
%
n
, so that if
d
divides both
m
,
n
, then it must divide
m
%
n
(and clearly
n
), and by the original equation if
d
is a divisor of both
n
,
m
%
n
then
d
divides
m
(and clearly
n
).
The above paragraph shows that a number is a divisor of
m
,
n
if and only if it is a divisor
of
n
,
m
%
n
, which shows that their set of divisors are equal and thus
gcd
(
m
,
n
)
=
gcd
(
n
,
m
%
n
)
bounded sum implies one less then half
Suppose that
x
,
y
,
b
∈
N
1
and
x
<
;
y
with
x
+
y
≤
b
, then
x
<
;
b
2
Suppose for the sake of contradiction that
x
≥
b
2
, then we know that
y
>
;
x
≥
b
2
so therefore
x
+
y
>
b
2
+
b
2
=
b
, so we have
x
+
y
>
;
b
which is a contradiction so that
x
<
;
b
2
.
euclidean algorithm has exponentially decreasing remainders
Let
a
,
b
∈
N
1
with
a
≥
b
be two integers, and suppose we will preform the
euclidean algorithm on them to compute
gcd
(
m
,
n
)
, supposing that
r
k
represents the remainder after
k
(where
k
∈
N
1
) steps into the euclidean
algorithm, then
r
2
n
<
b
2
n
For the base case, suppose that
n
=
1
, so we'd like to prove that
r
2
<
b
2
. Firstly we know that
a
=
b
q
0
+
r
0
with
0
≤
r
0
<
b
, then applying the next
iteration we have
b
=
r
0
q
1
+
r
1
with
0
≤
r
1
<
r
0
and one more time, we
get
r
0
=
r
1
q
2
+
r
2
with
0
≤
r
2
<
r
1
, this shows us that
b
=
(
r
1
q
2
+
r
2
)
q
1
+
r
1
.
Since
a
≥
b
,
b
>
r
0
and
r
0
>
r
1
, then
q
0
≥
1
,
q
1
≥
1
and
q
2
≥
1
, therefore
b
=
(
r
1
q
2
+
r
2
)
q
1
+
r
1
≥
(
r
1
⋅
1
+
r
2
)
⋅
1
+
r
1
≥
r
1
+
r
2
therefore
r
2
<
;
b
2
which concludes the base case
Now let
k
∈
N
1
assuming that
r
2
k
≤
b
2
k
, we want to prove
that
r
2
(
k
+
1
)
=
b
2
k
+
1
, noting that
2
(
k
+
1
)
=
2
k
+
2
.
To start let's say we have an intance of the euclidean algorithm that lasts for at least
2
k
+
2
iterations, therefore we know that
r
2
k
≤
b
2
k
by our induction
hypothesis, additionally at the
2
k
-th iteration we would have an equation of the form
r
2
k
=
r
2
k
+
1
(
q
2
k
+
2
)
+
r
2
k
+
2
, since we know that
r
2
k
+
1
>
;
r
2
k
+
2
, then
q
2
k
+
2
≥
1
, which then shows that
r
2
k
=
r
2
k
+
1
(
q
2
k
+
2
)
+
r
2
k
+
2
≥
r
2
k
+
1
+
r
2
k
+
1
, and since
b
2
k
>
r
2
k
,
then we know that
r
2
k
+
2
<
1
2
⋅
b
2
k
=
b
2
k
+
1
which is what we needed to
show
upper bound on euclidean algorithm iterations
The euclidean algorithm terminates in at most
2
log
2
(
b
)
iterations
The euclidean algorithm terminates in
k
iterations if and only if
r
k
=
0
, we know that
for all
n
∈
N
1
that
r
2
n
<
b
2
n
, therefore when
n
=
log
2
(
b
)
, then we have
r
2
log
2
(
b
)
<
b
2
log
2
(
b
)
=
b
b
=
1
, but if
r
2
log
2
(
b
)
<
1
, then since the remainders are always elements of
N
0
, then we
know that
r
2
log
2
(
b
)
=
0
, thus we've shown after
2
log
2
(
b
)
iterations the algorithm must terminate