HOPS - Animations

The two animations below both show evaluation sequences calculating the factorial of 20. The factorial has the usual recursive definition:

factorial definition term graph rule

factorial n = if iszero n then 1 else n * factorial (pred n)
where pred is the predecessor function.

In the first animation, the calculation is done as directly resulting from this definition:

factorial 20 in linear space

Now an additional rule employing the associativity of multiplication has been activated, allowing the calculation to run in constant space:

factorial 20 in constant space


Wolfram Kahl