Documentation

AIT.PrefixMachine

A universal prefix machine: KB, the prefix complexity KE is about #

Extends CodeLayer/AdditiveComplexity.lean (E, elen, KE) and CodeLayer/BinaryKraft.lean.

What this establishes #

A description is a machine c : Code, serialized by E, followed by a binary argument p; the machine is made prefix-free the standard way (prefix-free-ification by stages) rather than assumed so.

What this does NOT establish (flagged) #

pfy_partrec (Partrec₂ pfy, uniformity in c) — the boundary this module once flagged — is established in CodeLayer/BitStringPrimrec.lean, over the bit-string computability layer it adds.

Hypotheses: standard vs added #

A bit-string / natural bijection #

decide (x = 1) recovers a bit from its Bool.toNat.

Prefix-free sets of bit-strings #

PrefixFree is Mathlib's InformationTheory.IsPrefixFree at the binary alphabet (prefixFree_iff_isPrefixFree). Mathlib proves that a prefix-free set without the empty word is uniquely decodable and Kraft's inequality for an arbitrary prefix-free set over a finite alphabet; the two theorems below are those, specialized to bit-strings and to the base 1 / 2 of KB's series.

No member is a proper prefix of another. (A prefix-free set containing [] is forced, by this very property, down to {[]}, Mathlib's IsPrefixFree.eq_singleton_empty_of_empty_mem; unique decodability needs the extra hypothesis [] ∉ S ruling that degenerate case out.)

Equations
Instances For

    The local predicate is Mathlib's IsPrefixFree at the binary alphabet.

    A prefix-free set not containing the empty word is uniquely decodable.

    theorem PrefixMachine.kraft_of_prefixFree {S : Set (List Bool)} (h : PrefixFree S) :
    ∑' (p : ↑S), (1 / 2) ^ (↑p).length ≤ 1

    Kraft's inequality for a prefix-free set of bit-strings — including the degenerate case S = {[]}, where the single term 2⁻⁰ = 1 meets the bound with equality.

    Prefix-free-ification of a code, by stages #

    accepted c s greedily accepts, at each stage, the inputs newly halting there whose bit-strings are comparable to nothing accepted so far — the standard effective enumeration of prefix machines, with E c (via pfy's caller) in place of the usual index prefix. Input 0 (the empty bit-string []) is a candidate like any other: if it halts, prefix-freeness ([] a prefix of everything) forces it to be the ONLY thing ever accepted, which is exactly the guard-code construction KB_le_KE needs.

    Reject n if some element of acc is comparable (prefix or extension) to n; otherwise append it.

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

      The inputs newly halting at stage s + 1.

      Equations
      Instances For

        The accepted inputs at stage s: greedily, by foldStep, over what newly halts at each earlier stage.

        Equations
        Instances For
          theorem PrefixMachine.acceptedList_mono {c : Nat.Partrec.Code} {s s' : ℕ} :
          s ≤ s' → ∀ {n : ℕ}, n ∈ acceptedList c s → n ∈ acceptedList c s'

          Once accepted, an input stays accepted at every later stage.

          Anything accepted at stage s + 1 has halted by then.

          noncomputable def PrefixMachine.pfy (c : Nat.Partrec.Code) :

          The prefix-free-ification of c. n's output is evaln s c n at the first stage s where n is accepted, if any.

          Equations
          Instances For
            theorem PrefixMachine.pfy_sub (c : Nat.Partrec.Code) (n v : ℕ) (h : v ∈ pfy c n) :
            v ∈ c.eval n

            pfy is a restriction of eval: every output pfy gives is an output eval gives.

            pfy c's domain, read as bit-strings, is prefix-free.

            pfy reproduces eval exactly, once eval's halting domain is already prefix-free.

            KB: prefix complexity over the universal prefix machine pfy #

            A description is a serialized machine E c, followed by a binary argument p; KB x is the least total length elen c + p.length over descriptions decoding, via pfy, to x.

            noncomputable def PrefixMachine.KB (x : ℕ) :

            Prefix complexity: least elen c + p.length over a serialized machine and a binary argument decoding to x via pfy.

            Equations
            Instances For
              theorem PrefixMachine.KB_le_KE :
              ∃ (c₀ : ℕ), ∀ (x : ℕ), KB x ≤ AdditiveComplexity.KE x + c₀

              KB x is achieved by some serialized-machine-plus-argument description.

              A shortest description for x (exists_min_KB makes the choice possible).

              Equations
              Instances For
                noncomputable def PrefixMachine.minDescArg (x : ℕ) :

                Its binary argument.

                Equations
                Instances For

                  The counting bound on KB: at most finitely many naturals are describable within a fixed budget — KB's twin of AdditiveComplexity.finite_KE_le, over E c ++ q (injective by E_append_inj) in place of E c alone, since a KB-description carries an argument too.

                  The Kraft weight of a description, zeroed out unless its argument is genuinely in pfy c's domain (read as a bit-string). A nonnegative function on Code × List Bool whose row sums (fixed c) are Kraft-bounded by kraft_of_prefixFree, and whose column sum over c (kraft_KP_E) bounds the whole.

                  Equations
                  Instances For
                    theorem PrefixMachine.summable_two_pow_neg_KB :
                    Summable fun (x : ℕ) => (1 / 2) ^ KB x

                    KB's Kraft series is summable. Each x contributes the weight of its own shortest description (min_desc_spec), and the descriptions are pairwise distinct (min_desc_injective), so the series is dominated, along that injection, by summable_kbWeight. Hoisted out of kraft_KB so the counting bound (AIT/PrefixCounting.lean) can cite it without re-deriving kraft_KB itself.

                    theorem PrefixMachine.kraft_KB :
                    ∑' (x : ℕ), (1 / 2) ^ KB x ≤ 1

                    Kraft's inequality for KB: ∑ₓ 2⁻ᴷᴮ⁽ˣ⁾ ≤ 1 — KB is a semimeasure. Each x contributes the weight of its own shortest description; the descriptions are pairwise distinct (min_desc_injective), and for a fixed machine c the arguments range over pfy c's domain, prefix-free by pfy_prefixFree, hence Kraft-summable by kraft_of_prefixFree.