What is the value of twice twice twice inc 0?
Here we use the following definitions:
> inc x = x+1 > twice f = f . f > (f . g) x = f (g x)
The expression twice twice twice inc 0 is equivalent to
(((twice twice) twice) inc) 0 since the function application is
right associative.
-- Version with explicit braces (((twice twice) twice) inc) 0 = (((twice . twice) twice) inc) 0 = ((twice (twice twice)) inc) 0 = ((twice (twice . twice)) inc) 0 = ((twice . twice . twice . twice) inc) 0 = (twice (twice (twice (twice inc)))) 0 = (twice (twice (twice (inc . inc)))) 0 = (twice (twice (inc . inc .inc . inc))) 0 = (twice (inc.inc.inc.inc.inc.inc.inc.inc)) 0 = (inc.inc.inc.inc.inc.inc.inc.inc.inc.inc.inc.inc.inc.inc.inc.inc) 0 = (inc(inc(inc(inc(inc(inc(inc(inc(inc(inc(inc(inc(inc(inc(inc(inc 0)))))))))))))))) = (inc(inc(inc(inc(inc(inc(inc(inc(inc(inc(inc(inc(inc(inc(inc 1))))))))))))))) = (inc(inc(inc(inc(inc(inc(inc(inc(inc(inc(inc(inc(inc(inc 2)))))))))))))) = ... (inc 15) = 16
-- Version without braces (only needed ones) twice twice twice inc 0 = (twice . twice) twice inc 0 = twice (twice twice) inc 0 = twice (twice . twice) inc 0 = (twice . twice . twice . twice) inc 0 = twice (twice (twice (twice inc))) 0 = twice (twice (twice (inc . inc))) 0 = twice (twice (inc . inc .inc . inc)) 0 = twice (inc.inc.inc.inc.inc.inc.inc.inc) 0 = (inc.inc.inc.inc.inc.inc.inc.inc.inc.inc.inc.inc.inc.inc.inc.inc) 0 = inc(inc(inc(inc(inc(inc(inc(inc(inc(inc(inc(inc(inc(inc(inc(inc 0))))))))))))))) = inc(inc(inc(inc(inc(inc(inc(inc(inc(inc(inc(inc(inc(inc(inc 1)))))))))))))) = inc(inc(inc(inc(inc(inc(inc(inc(inc(inc(inc(inc(inc(inc 2))))))))))))) = ... inc 15 = 16
In fact these are not all reductions that are made but the most important.