The two animations below both show evaluation sequences calculating the factorial of 20. The factorial has the usual recursive definition:
factorial n = if iszero n then 1 else n * factorial (pred n)where
predis the predecessor function.
In the first animation, the calculation is done as directly resulting from this definition:
Now an additional rule employing the associativity of multiplication has been activated, allowing the calculation to run in constant space: