Euclid & GCD algorithm
Description:
-
def EuclidAgl(a,b):
if b = 0:
return a
else:
return EuclidAlg(b, a mod b)
- If a,b∈N,b=0 then gcd(a,b)=gcd(b,amodb)lemma
- Euclid’s algorithm, on input EuclidAlg(a, b) for a,b∈N+,a,b not both 0, always terminates and produces the correct output.theorem
- For every two recursive calls made by EuclidAlg, the first argument a is at least reduced by halved.claim
- theorem Euclid’s algorithm, on input EuclidAlg(a, b) for a,b∈N+, a, b not both 0, always terminates in time proportional to log2a
- if a larger, algorithm increase logarithmically, not linearly
Theorem 11 (Bézout Theorem)
- Let a, b ∈ N+, a, b not both 0. Then, there exist s, t (Bézout coefficients) ∈ Z such that sa+tb=gcd(a,b) (Bézout identity)
- How to compute s,t from gcd(a,b)=z
- write out a = b.q + r for each recursive call (from r1 → rn , for eg) of solving EuclidAlg(a, b), until there is no remainder left
- writing in backward order, from z = elements of r1 → rn
- compute so that you get the form sa+tb=z