Documentation

LeanPool.DomainTheory.Neighborhood.Theorem56Full

Theorem 5.6 (Scott 1981, PRG-19, ยง5) โ€” the FULL closure: partial recursive โŸน #

ฮป-definable

Theorem56.lean builds the constructive heart (strict starting functions, the primitive-recursion and ฮผ combinators with their scheme equations). This file wires those pieces together against Mathlib's arity-aware inductive predicates Nat.Primrec'/Nat.Partrec' (over List.Vector โ„• n), whose constructors are exactly Scott's generation grammar:

We prove: every Nat.Primrec'/Nat.Partrec' function is denoted by an approximable map ฯ† : ๐’ฉ โ†’ N, where ๐’ฉ := N^โˆž (Exercise 3.16) is the universal argument domain โ€” a k-ary function is realised by a single map that depends only on coordinates 0..k-1. The realisation is very strict (Scott): โŠฅ in any relevant coordinate forces โŠฅ, which is what makes composition and minimisation compose. The capstone is partrec_lamDef and the 1-ary corollary partrec_one.

@[reducible, inline]

The universal argument domain ๐’ฉ = N^โˆž (Exercise 3.16). All k-ary number functions are realised as approximable maps ๐’ฉ โ†’ N depending only on coordinates 0..k-1.

Equations
Instances For

    T.bot = Example23.botElt (both least); bridges zeroMap_bot (lands in T.bot) with cond_bot (phrased with Example23.botElt).

    Element builders. #

    The argument element of ๐’ฉ whose first n coordinates are optElem (a i) and the rest โŠฅ.

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For

      The argument element of ๐’ฉ carrying a List.Vector โ„• n in its first n coordinates.

      Equations
      Instances For

        Two ๐’ฉ-elements are equal iff all components agree.

        A ๐’ฉ-element is arg-like if every coordinate is total or โŠฅ (true of all argElem).

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For

          Components through push. #

          The strictifier guard1/strictGuardN (Scott's cond(zero(x),ยท,ยท) #

          device).

          guard1 j ฯ† z = cond(zero(zโฑผ), ฯ† z, ฯ† z): equals ฯ† z when zโฑผ is total, โŠฅ when zโฑผ = โŠฅ. Composing the guards for j = 0..n-1 makes a map very strict in its first n coordinates.

          Test coordinate j: cond(zero(zโฑผ), ฯ† z, ฯ† z).

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For

            If ฯ† z = โŠฅ and zโฑผ is total-or-โŠฅ, the guard stays โŠฅ.

            On arguments whose first n coordinates are all total, the guard is transparent.

            If some coordinate i < n is โŠฅ (and z is arg-like), the guard forces โŠฅ.

            tupleMap: assemble n scalar maps into the first n coordinates of #

            ๐’ฉ.

            โŸจgโ‚€, โ€ฆ, g_{n-1}โŸฉ : ๐’ฉ โ†’ ๐’ฉ placing gแตข at coordinate i (< n) and โŠฅ beyond.

            Equations
            Instances For

              Coordinate i < n of the tuple is exactly gแตข.

              The ฮป-definability specification. #

              ฯ† : ๐’ฉ โ†’ N realises the n-ary partial function f (a very strict ฮป-definition): ฯ† returns f's value on total arguments, โŠฅ where f is undefined, and โŠฅ on any arg-like input with a โŠฅ among its first n coordinates.

              Instances For

                Every coordinate j < n of vecElem v is the total v.get j.

                vecElem v has total coordinates throughout its arity.

                A coordinate that an argElem sets to none is โŠฅ.

                theorem Domain.Neighborhood.Theorem56Full.lamDef_of_inner {n : โ„•} (inner : ApproximableMap ๐’ฉ Example43.N) (f : List.Vector โ„• n โ†’. โ„•) (hdef : โˆ€ (v : List.Vector โ„• n), โˆ€ c โˆˆ f v, inner.toElementMap (vecElem v) = Example43.natElem c) (hundef : โˆ€ (v : List.Vector โ„• n), ยฌ(f v).Dom โ†’ inner.toElementMap (vecElem v) = Example43.N.bot) :
                LamDef (strictGuardN n inner) f

                Master constructor. Wrapping an inner map (correct on total arguments) in strictGuardN n yields a full, very strict ฮป-definition. The strict clause is then automatic.

                The total-function specialisation of lamDef_of_inner.

                Primitive recursive base cases: zero, succ, get. #

                zero : Vector โ„• 0 โ†’ โ„•, the constant 0 (nullary).

                succ : Vector โ„• 1 โ†’ โ„•, v โ†ฆ v.head + 1.

                theorem Domain.Neighborhood.Theorem56Full.lamDef_get {n : โ„•} (i : Fin n) :
                LamDef (strictGuardN n (projN Example43.N โ†‘i)) โ†‘fun (v : List.Vector โ„• n) => v.get i

                get i : Vector โ„• n โ†’ โ„•, the i-th projection.

                theorem Domain.Neighborhood.Theorem56Full.lamDef_congr {n : โ„•} {ฯ† : ApproximableMap ๐’ฉ Example43.N} {f f' : List.Vector โ„• n โ†’. โ„•} (h : โˆ€ (v : List.Vector โ„• n), f v = f' v) (hf : LamDef ฯ† f) :
                LamDef ฯ† f'

                Transport a ฮป-definition along pointwise equality of the realised function.

                The value a realiser takes on a total argument is total-or-โŠฅ (arg-like).

                Composition. #

                Coordinates of the bottom stack are โŠฅ.

                Coordinates โ‰ฅ n of the tuple are โŠฅ.

                theorem Domain.Neighborhood.Theorem56Full.tupleMap_vecElem_eq {m nn : โ„•} (ฯ†g : Fin nn โ†’ ApproximableMap ๐’ฉ Example43.N) (g : Fin nn โ†’ List.Vector โ„• m โ†’. โ„•) (hg : โˆ€ (i : Fin nn), LamDef (ฯ†g i) (g i)) (v : List.Vector โ„• m) (w : List.Vector โ„• nn) (hw : โˆ€ (i : Fin nn), w.get i โˆˆ g i v) :

                The tuple of realisers, applied to a total argument, equals vecElem w where wแตข = gแตข(v).

                theorem Domain.Neighborhood.Theorem56Full.tupleMap_argLike {m nn : โ„•} (ฯ†g : Fin nn โ†’ ApproximableMap ๐’ฉ Example43.N) (g : Fin nn โ†’ List.Vector โ„• m โ†’. โ„•) (hg : โˆ€ (i : Fin nn), LamDef (ฯ†g i) (g i)) (v : List.Vector โ„• m) :

                The tuple of realisers, applied to a total argument, is arg-like.

                Membership in mOfFn (Part monad): a vector is produced iff each coordinate is a value.

                theorem Domain.Neighborhood.Theorem56Full.lamDef_comp {m nn : โ„•} (f : List.Vector โ„• nn โ†’. โ„•) (g : Fin nn โ†’ List.Vector โ„• m โ†’. โ„•) (ฯ†f : ApproximableMap ๐’ฉ Example43.N) (hf : LamDef ฯ†f f) (ฯ†g : Fin nn โ†’ ApproximableMap ๐’ฉ Example43.N) (hg : โˆ€ (i : Fin nn), LamDef (ฯ†g i) (g i)) :
                LamDef (strictGuardN m (ฯ†f.comp (tupleMap nn ฯ†g))) fun (v : List.Vector โ„• m) => (List.Vector.mOfFn fun (i : Fin nn) => g i v) >>= f

                Composition (Scott's multivariate composition). If f and each gแตข are ฮป-defined, so is v โ†ฆ (โŸจgโ‚€ v, โ€ฆ, g_{nn-1} vโŸฉ) >>= f.

                A realiser of a total function evaluates to its value.

                theorem Domain.Neighborhood.Theorem56Full.lamDef_primComp {m nn : โ„•} (fโ‚€ : List.Vector โ„• nn โ†’ โ„•) (gโ‚€ : Fin nn โ†’ List.Vector โ„• m โ†’ โ„•) (ฯ†f : ApproximableMap ๐’ฉ Example43.N) (hf : LamDef ฯ†f โ†‘fโ‚€) (ฯ†g : Fin nn โ†’ ApproximableMap ๐’ฉ Example43.N) (hg : โˆ€ (i : Fin nn), LamDef (ฯ†g i) โ†‘(gโ‚€ i)) :
                LamDef (strictGuardN m (ฯ†f.comp (tupleMap nn ฯ†g))) โ†‘fun (a : List.Vector โ„• m) => fโ‚€ (List.Vector.ofFn fun (i : Fin nn) => gโ‚€ i a)

                Composition of total functions (the Nat.Primrec'.comp shape).

                vecElem of a cons is a push. #

                Primitive recursion. #

                The recursion lives over prod (funSpace ๐’ฉ N) ๐’ฉ: k is the unknown, z the argument stack whose head is the recursion variable and whose tail carries the parameters. The body is M(k, z) = cond(zero(head z), f(tail z), g(โŸจpred(head z), โŸจk(โŸจpred(head z), tail zโŸฉ), tail zโŸฉโŸฉ)).

                The primitive-recursion body.

                Equations
                • One or more equations did not get rendered due to their size.
                Instances For
                  theorem Domain.Neighborhood.Theorem56Full.recMap_eval (ฯ†f ฯ†g : ApproximableMap ๐’ฉ Example43.N) {n : โ„•} (fโ‚€ : List.Vector โ„• n โ†’ โ„•) (gโ‚€ : List.Vector โ„• (n + 2) โ†’ โ„•) (hf : LamDef ฯ†f โ†‘fโ‚€) (hg : LamDef ฯ†g โ†‘gโ‚€) (u : List.Vector โ„• n) (d : โ„•) :
                  (recMap ฯ†f ฯ†g).toElementMap (vecElem (d ::แตฅ u)) = Example43.natElem (Nat.rec (fโ‚€ u) (fun (y IH : โ„•) => gโ‚€ (y ::แตฅ IH ::แตฅ u)) d)

                  Primitive recursion computes. recMap(โŸจd, uโŸฉ) = (Nat.rec (f u) (g โ€ฆ) d).

                  theorem Domain.Neighborhood.Theorem56Full.lamDef_prec (ฯ†f ฯ†g : ApproximableMap ๐’ฉ Example43.N) {n : โ„•} (fโ‚€ : List.Vector โ„• n โ†’ โ„•) (gโ‚€ : List.Vector โ„• (n + 2) โ†’ โ„•) (hf : LamDef ฯ†f โ†‘fโ‚€) (hg : LamDef ฯ†g โ†‘gโ‚€) :
                  LamDef (strictGuardN (n + 1) (recMap ฯ†f ฯ†g)) โ†‘fun (v : List.Vector โ„• (n + 1)) => Nat.rec (fโ‚€ v.tail) (fun (y IH : โ„•) => gโ‚€ (y ::แตฅ IH ::แตฅ v.tail)) v.head

                  Primitive recursion (Nat.Primrec'.prec shape).

                  Closure of the primitive recursive functions. #

                  Every Nat.Primrec' function is ฮป-definable by a (very strict) approximable map.

                  Minimisation (rfind). #

                  The ฮผ-operator searches upward for the least k with f(k ::แตฅ v) = 0. We carry the counter in the head coordinate of the stack. The search body over prod (funSpace ๐’ฉ N) ๐’ฉ is

                  S(k, z) = cond(zero(f z), head z, k(push(succ(head z), tail z))) :

                  if the current value f z is 0, return the counter head z; otherwise recurse with the counter bumped by one. searchMap is the least fixed point, and findMap kicks the search off at counter 0. The hard direction is divergence: when no k zeroes f, every finite approximant Sโฟ(โŠฅ) returns โŠฅ along the search trace, so the directed sup (Theorem 4.2(iii)) is โŠฅ too.

                  The search body S(k, z) = cond(zero(f z), head z, k(push(succ(head z), tail z))).

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For

                    findMap : ๐’ฉ โ†’ N starts the search with counter 0.

                    Equations
                    • One or more equations did not get rendered due to their size.
                    Instances For

                      Search step (found). If f(k ::แตฅ v) = 0, the search returns the counter k.

                      Search step (continue). If f(k ::แตฅ v) โ‰  0, the search advances to counter k + 1.

                      theorem Domain.Neighborhood.Theorem56Full.searchMap_climb (ฯ†f : ApproximableMap ๐’ฉ Example43.N) {n : โ„•} {f : List.Vector โ„• (n + 1) โ†’ โ„•} (hf : LamDef ฯ†f โ†‘f) (v : List.Vector โ„• n) (m : โ„•) (hm0 : f (m ::แตฅ v) = 0) (hmin : โˆ€ i < m, f (i ::แตฅ v) โ‰  0) (d j : โ„•) :
                      j + d = m โ†’ (searchMap ฯ†f).toElementMap (vecElem (j ::แตฅ v)) = Example43.natElem m

                      Capstone (least zero โŸน value). If m is a zero of f(ยท ::แตฅ v) and nothing below it is, then starting from any counter j โ‰ค m the search returns m. (Downward induction on m - j.)

                      Divergence via the directed sup of approximants. #

                      The least map of the function space evaluates to โŠฅ everywhere.

                      evalAt z evaluates a function-space element at the fixed argument z.

                      Equations
                      • One or more equations did not get rendered due to their size.
                      Instances For

                        The 0-th approximant Sโฐ(โŠฅ) is the bottom map.

                        theorem Domain.Neighborhood.Theorem56Full.iterVal_bot (ฯ†f : ApproximableMap ๐’ฉ Example43.N) {n : โ„•} {f : List.Vector โ„• (n + 1) โ†’ โ„•} (hf : LamDef ฯ†f โ†‘f) (v : List.Vector โ„• n) (hdiv : โˆ€ (k : โ„•), f (k ::แตฅ v) โ‰  0) (m k : โ„•) :

                        Along a no-zero trace, every finite approximant returns โŠฅ (induction on the approximant index, with the counter universally quantified since the search advances it).

                        theorem Domain.Neighborhood.Theorem56Full.searchMap_diverge (ฯ†f : ApproximableMap ๐’ฉ Example43.N) {n : โ„•} {f : List.Vector โ„• (n + 1) โ†’ โ„•} (hf : LamDef ฯ†f โ†‘f) (v : List.Vector โ„• n) (hdiv : โˆ€ (k : โ„•), f (k ::แตฅ v) โ‰  0) (k : โ„•) :

                        Divergence. If f(ยท ::แตฅ v) has no zero, the search is โŠฅ from every counter. The fixed point is the directed union of the approximants Sแต(โŠฅ) (Theorem 4.2(iii)); pushing the evaluation at vecElem (k ::แตฅ v) through this sup (continuity, toElementMap_iSupDirected) reduces the claim to iterVal_bot.

                        theorem Domain.Neighborhood.Theorem56Full.lamDef_rfind (ฯ†f : ApproximableMap ๐’ฉ Example43.N) {n : โ„•} {f : List.Vector โ„• (n + 1) โ†’ โ„•} (hf : LamDef ฯ†f โ†‘f) :
                        LamDef (strictGuardN n (findMap ฯ†f)) fun (v : List.Vector โ„• n) => Nat.rfind fun (k : โ„•) => Part.some (decide (f (k ::แตฅ v) = 0))

                        Minimisation (Nat.Partrec'.rfind shape). Given a (very strict) realiser of a total f : Vector โ„• (n+1) โ†’ โ„•, strictGuardN n (findMap ฯ†f) ฮป-defines v โ†ฆ ฮผk. f(k ::แตฅ v) = 0.

                        Closure of the partial recursive functions โ€” the full meta-theorem. #

                        Theorem 5.6 (Scott 1981, PRG-19) โ€” every partial recursive function is ฮป-definable. For each Nat.Partrec' function f : Vector โ„• n โ†’. โ„• there is an approximable map ฯ† : ๐’ฉ โ†’ N that is a very strict ฮป-definition of f: it returns f's value on total arguments, โŠฅ where f is undefined, and โŠฅ on any arg-like input with a โŠฅ among its first n coordinates.

                        Scott's 1-ary statement. #

                        Every partial recursive h : โ„• โ†’. โ„• is realised by an approximable map ฯ„ : N โ†’ N over the flat naturals: ฯ„(nฬ‚) = mฬ‚ when h n = m, ฯ„(nฬ‚) = โŠฅ when h n diverges, and ฯ„(โŠฅ) = โŠฅ (strictness).

                        Inject N โ†’ ๐’ฉ as the stack whose only nonzero coordinate is the head.

                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For

                          Scott's 1-ary meta-theorem. A partial recursive h : โ„• โ†’. โ„• (presented as a unary Nat.Partrec') is denoted by a single approximable map ฯ„ : N โ†’ N that is correct on values, divergent where h diverges, and strict.