While testing gcd
function I ended up needing to know a termination bound
for gcd m n
, so had to investigate how many steps the recursion took.
The case I tested was for gcd 7 5
- it had enough steps. The defintion
for gcd
follows the euclidean algorithm, which reduces gcd a b
to gcd b c
for a smaller c
. At each stage, this reduction is simply c = a rem b
Algorithm terminates in 4 steps:
(7, 5) -> (5, 2) -> (2, 1) -> (1, 0). As hcf a 0 = a , hcf 7 5 = 1
Taking the ID from the metadata after evaluating:
gcd a b
- metadata ID
gcd 7 5
- 2078
gcd 5 2
- 1189
gcd 2 1
- 564
gcd 1 0
- 276