Exercise 5.12 (Scott 1981, PRG-19, §5) — the while combinator #
Given a domain D, a predicate p : D → T (into the truth domain of Example
1.2) and an
update f : D → D, Scott's while-loop
while p do f
is the function D → D that keeps applying f while p holds. It is
characterised as the least
solution w : D → D of the recursion
w(x) = cond(p(x), w(f(x)), x).
We realise this semantically inside the approximable-map framework: the
right-hand side, read as
a function of the unknown w, is an approximable operator
Wop : (D → D) → (D → D), Wop(w) = λx. cond(p(x), w(f(x)), x),
built from the conditional cond of Exercise 3.26, evaluation eval, the
projections, pairing and
composition. The loop is then whileFix = fixElement Wop, the least fixed point
of Wop
(Theorem 4.1), and whileMap = toApproxMap whileFix : D → D the approximable
function it denotes.
We prove:
whileMap_rec— the defining recursionw(x) = cond(p(x), w(f(x)), x);whileMap_true— ifp(x) = truethenw(x) = w(f(x))(loop body runs);whileMap_false— ifp(x) = falsethenw(x) = x(loop exits);whileMap_bot— ifp(x) = ⊥thenw(x) = ⊥(divergent test diverges);whileMap_least— leastness: anyw'satisfying the recursion dominateswhileMap.
Everything is choice-free in spirit; the only classical input is inherited from
cond/T
(Example 1.2) and the project's Element.ext / ext_of_toElementMap machinery.
The body of the loop as a two-argument map M : (D → D) × D → D,
M(w, x) = cond(p(x), w(f(x)), x). It is assembled from cond, eval, the
projections,
pairing and composition, hence approximable.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Value of the loop body: M(w, x) = cond(p(x), w(f(x)), x).
The loop operator Wop : (D → D) → (D → D), Wop(w) = λx. cond(p(x), w(f(x)), x).
Equations
Instances For
Wop(w)(x) = cond(p(x), w(f(x)), x).
The while-loop element of the function space D → D: the least fixed point
of Wop.
Equations
Instances For
The approximable function while p do f : D → D denoted by whileFix.
Equations
Instances For
Exercise 5.12 (Scott 1981, PRG-19). The defining recursion of the
while-loop:
w(x) = cond(p(x), w(f(x)), x).
If the test holds (p(x) = true), the loop runs the body: w(x) = w(f(x)).
If the test fails (p(x) = false), the loop exits: w(x) = x.
If the test diverges (p(x) = ⊥), the loop diverges: w(x) = ⊥.
Leastness. Any w' satisfying the while-recursion w'(x) = cond(p(x), w'(f(x)), x)
dominates the least solution whileMap.