We recall Euclid’s algorithm below:
We consider the case where both arguments are multiplied by l:
gcd (l * m, l * n) =
let r = rem (l * m, l * n) in
if r = 0 then l * n else gcd (l * n, r)
Note that rem (l * m, l * n) = l * (rem (m, n)).
gcd (l * m, l * n) =
let r = l * (rem (m, n)) in
if r = 0 then l * n else gcd (l * n, r)
Furthemore, because l is assumed positive, l * (rem (m, n)) is equal to zero if and only if rem (m, n) is. So we may rewrite as follows:
gcd (l * m, l * n) =
let r = rem (m, n) in
if r = 0 then l * n else gcd (l * n, l * r)
We now consider the entire trace of recursive calls. If gcd (l * m, l * n) returns straightaway, we must have had rem (m, n) = 0 and it returns l * n which is indeed l * (gcd (m, n)). If there is a recursive call to gcd (l * n, l * r) we may assume by induction that gcd (l * n, l * r) = l * (gcd (n, r)), which is exactly what we needed.