div(n,k) = if smaller(n,k) then 0 else div(n-k,k) + 1The definitions of the relation "smaller" and of the function "minus" can also be given by recursion:
smaller(n,k) = if n = 0 then (if k = 0 then false else true)
else smaller(n-1,k-1)
minus(n,k) = if k = 0 then n else minus(n-1,k-1)
The rest follows the standard construction using the fixpoint operator.
Thus we have:
[div] = Y (\f n k. [if_then_else] ([smaller] n k) [0] (f ([minus] n k) k))
[smaller] = Y (\f n k. [if_then_else] ([is_zero] n)
([if_then_else] ([is_zero] k) [false] [true])
(f ([predecessor] n) ([predecessor] k)) )
[minus] = Y (\f n k. [if_then_else] ([is_zero] k) [n] (f ([predecessor] n) ([predecessor] k)) )
P -> o -> o -> M | . V . o . | . V . N .............? Yes: P -> o -> o -> M | | | | V V V V o -> o -> o -> o | | | | V V V V N -> o -> o -> Q
P -----> R ----> M | . | . | . V . N ...............? No: P -----> R ----> M | | . | V . | | . V V . N -->--> T ......?A simpler proof is the following: Consider the following diagram
Namely, P -> R and R -> P, P -> S and S -> P, R -> M and S -> N. Then -> is weakly confluent but ->> is not confluent, in fact P ->> M and P ->> N but there is no common term to which M and N both reduce.
[if_then_else]([is_zero] [0]) [1] Omega -> [if_then_else] [true] [1] Omega -> [1] (normal form)but also, by reducing Omega, we get
[if_then_else]([is_zero] [0]) [1] Omega -> [if_then_else] ([is_zero] [0]) [1] Omega -> ...
[if_then_else]([is_zero] Omega) [0] [1] -> ([is_zero] Omega) [0] [1]
-> Omega ([true][false]) [true] [0] [1]
-> Omega (\y.[false]) [true] [0] [1]
but then we have that Omega (\y.[false]) [true] [0] [1] can only reduce to itself:
Omega (\y.[false]) [true] [0] [1] -> Omega (\y.[false]) [true] [0] [1] -> ...
Y F [3] ->> [if_then_else] ([is_zero] [3]) [1] ([times] [3] (G ([predecessor] [3])))
->> [times] [3] (G [2])
->> [times] [3] (F G [2])
->> [times] [3] ([if_then_else] ([is_zero] [2]) [1] ([times] [2] (G ([predecessor] [2]))))
->> ...
->> [times] [3] ([times] [2] ([times] [1] ([if_then_else] ([is_zero] [0]) [1] ([times] [0] (G ([predecessor] [0]))))))
->> [times] [3] ([times] [2] ([times] [1] [1]))
->> [6] (normal form)
but also
Y F [3] -> F G [3] -> F(F G) [3] -> ...Note that we cannot replace G by Y F in the above formulas. In fact, although we have Y F = F(Y F) = F(F(Y F)) = ..., it is not true that Y F ->> F(Y F).
This last exercise illustrates the fact that, even in eager langauges like ML, the if_then_else operator must have a lazy semantics, otherwise recursive definition cannot be given.
[true] Omega [0] -> Omega -> Omega ...In this derivation, the first step is not monotonic. A more interesting example is the following, were every other step is not monotonic. The symbol I represents the lambda term \y.y (identity).
(\x. I x x)(\x. I x x) -> I (\x. I x x)(\x. I x x)
-> (\x. I x x)(\x. I x x)
-> I (\x. I x x)(\x. I x x)
-> (\x. I x x)(\x. I x x)
-> ...