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
- Euclid’s algorithm, on input EuclidAlg(a, b) fora,b∈N+,a,b not both 0, always terminates in time proportional to log2a.theorem