Documentation

LeanPool.DomainTheory.Neighborhood.Exercise512

Exercise 5.12 (Scott 1981, PRG-19, §5) — the while combinator #

Given a domain D, a predicate p : DT (into the truth domain of Example 1.2) and an update f : DD, Scott's while-loop

while p do f

is the function DD that keeps applying f while p holds. It is characterised as the least solution w : DD 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 : DD the approximable function it denotes.

We prove:

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) × DD, 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

      The while-loop element of the function space DD: the least fixed point of Wop.

      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.