The Euclidean Algorithm is an algorithm that computes for integers and in time and space.
Algorithm
Lemma
Applying the lemma yields an algorithm that solves the problem in time and space.
return y_combinator([&](auto &&self, int a, int b) -> int {
return b ? self(b, a % b) : a;
})(a, b);Proof
It is easy to prove that, since the third recursion, and .
If and ,