Documentation

AIT.KraftChaitin

The online Kraft–Chaitin assignment #

Over the fixed-width code PrefixMachine.bitsFixed of AIT/CodingTheoremWeak.lean and the bit-string computability layer of CodeLayer/BitStringPrimrec.lean.

What this establishes #

The online Kraft–Chaitin codeword assignment, effective and invariant-preserving:

What this does NOT establish (flagged) #

The coding theorem this assignment serves — the O(1) form over a lower-semicomputable semimeasure's own request stream — is not attempted here.

@[reducible, inline]

Free dyadic intervals [a / 2 ^ l, (a + 1) / 2 ^ l), as (length, numerator) pairs.

Equations
Instances For

    bitsFixed is primitive recursive #

    The word–interval dictionary #

    def PrefixMachine.Nested (l a l' a' : ℕ) :

    (l, a)'s dyadic interval contains (l', a')'s: l ≤ l' and a is a''s ancestor at level l. Exactly the prefix relation of the two bitsFixed codewords, given both numerators are within their own width (bitsFixed_prefix_iff).

    Equations
    Instances For
      def PrefixMachine.Comparable (l a l' a' : ℕ) :

      Either code prefixes the other.

      Equations
      Instances For
        theorem PrefixMachine.bitsFixed_prefix_iff {l a l' a' : ℕ} (ha : a < 2 ^ l) (ha' : a' < 2 ^ l') :
        bitsFixed l a <+: bitsFixed l' a' ↔ Nested l a l' a'

        The word–interval dictionary.

        splitBuild: the pieces produced by one online split #

        Splits the piece (j, a) down to width k = j + m, freeing the intermediate right-hand pieces: splitBuild j a m = (2 ^ m * a, [(j + m, 2 ^ m * a + 1), …, (j + 1, 2 * a + 1)]).

        Equations
        Instances For

          bestFreePair: the largest free length at most k #

          The free pair of the largest length at most k, found by a descending search: the length-k entry if there is one, else the best among lengths below k.

          Equations
          Instances For

            kcServe: one online Kraft–Chaitin step #

            The structural invariant on a free space: pairwise distinct lengths, each numerator within its own width, and no two entries comparable.

            Equations
            Instances For

              Serve one request of length k against the free space, in (length, numerator) pair form.

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

                Serve one request of length k: the assigned word and the updated free space.

                Equations
                Instances For

                  kcRun: the run over a request stream #

                  One step of the run, in (length, numerator) pair form.

                  Equations
                  Instances For

                    The run over a request stream, by steps, in (length, numerator) pair form.

                    Equations
                    Instances For

                      One step of the run: the free space and the words assigned so far.

                      Equations
                      Instances For

                        The run over a request stream, by steps: the free space and the words assigned so far.

                        Equations
                        Instances For
                          def PrefixMachine.kcWord (req : ℕ → ℕ) (m : ℕ) :

                          The word assigned at step m.

                          Equations
                          Instances For
                            theorem PrefixMachine.kcServe'_inv {free : FreeSpace} (hinv : FreeInv free) {k a : ℕ} {free' : FreeSpace} (h : kcServe' free k = some ((k, a), free')) :
                            FreeInv free' ∧ a < 2 ^ k ∧ (∀ q ∈ free', ¬Comparable k a q.1 q.2) ∧ ∃ jp ∈ free, Nested jp.1 jp.2 k a ∧ ∀ q ∈ free', q ∈ free ∨ Nested jp.1 jp.2 q.1 q.2

                            The single-step invariant.

                            kcMass: the free measure #

                            noncomputable def PrefixMachine.kcMass (free : FreeSpace) :

                            The free measure: the total mass of the free dyadic intervals.

                            Equations
                            Instances For
                              theorem PrefixMachine.kcServe'_mass {free : FreeSpace} (hnodup : (List.map Prod.fst free).Nodup) {k a : ℕ} {free' : FreeSpace} (h : kcServe' free k = some ((k, a), free')) :
                              kcMass free = (1 / 2) ^ k + kcMass free'

                              The single-step mass identity: serving a request spends exactly 2 ^ (-k) of the free measure.

                              Distinct lengths above k carry mass below 2 ^ (-k) #

                              theorem PrefixMachine.two_pow_neg_succ_double (n : ℕ) :
                              (1 / 2) ^ n = 2 * (1 / 2) ^ (n + 1)
                              theorem PrefixMachine.two_pow_neg_antitone {m n : ℕ} (h : m ≤ n) :
                              (1 / 2) ^ n ≤ (1 / 2) ^ m
                              theorem PrefixMachine.kcMass_lt_of_bestFreePair_none {free : FreeSpace} (hnd : (List.map Prod.fst free).Nodup) {k : ℕ} (hnone : bestFreePair free k = none) :
                              kcMass free < (1 / 2) ^ k

                              Under FreeInv, a request that fails leaves the whole free measure below 2 ^ (-k).

                              RunInv: the run-level invariant, over the whole request history #

                              def PrefixMachine.RunInv (free : FreeSpace) (assigned : List (ℕ × ℕ)) :

                              Every past assignment stays incomparable with the current free space and with every other past assignment.

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

                                The run-level induction #

                                def PrefixMachine.kcWordPair (req : ℕ → ℕ) (i : ℕ) :

                                The pair assigned at step i, in (length, numerator) form.

                                Equations
                                Instances For
                                  theorem PrefixMachine.kcWord_eq_kcWordPair (req : ℕ → ℕ) (i : ℕ) :
                                  kcWord req i = Option.map (fun (p : ℕ × ℕ) => bitsFixed p.1 p.2) (kcWordPair req i)
                                  theorem PrefixMachine.kcServe'_fst_eq (free : FreeSpace) (k : ℕ) {p : ℕ × ℕ} {free' : FreeSpace} (h : kcServe' free k = some (p, free')) :
                                  p.1 = k
                                  theorem PrefixMachine.kcRunPairs_inv {req : ℕ → ℕ} (hmass : ∀ (N : ℕ), ∑ i ∈ Finset.range N, (1 / 2) ^ req i ≤ 1) (m : ℕ) :
                                  RunInv (kcRunPairs req m).1 (kcRunPairs req m).2 ∧ kcMass (kcRunPairs req m).1 + ∑ i ∈ Finset.range m, (1 / 2) ^ req i = 1 ∧ ∀ i < m, ∃ (p : ℕ × ℕ), kcWordPair req i = some p ∧ p.1 = req i
                                  theorem PrefixMachine.kcWordPair_mem_kcRunPairs {req : ℕ → ℕ} {i : ℕ} {p : ℕ × ℕ} (hp : kcWordPair req i = some p) (n : ℕ) :
                                  i < n → p ∈ (kcRunPairs req n).2

                                  Once assigned, a pair stays in the run's assigned list forever after.

                                  theorem PrefixMachine.kcRun_invariant {req : ℕ → ℕ} (hmass : ∀ (N : ℕ), ∑ m ∈ Finset.range N, (1 / 2) ^ req m ≤ 1) (m : ℕ) :
                                  (List.map Prod.fst (kcRun req m).1).Nodup ∧ (∀ i < m, ∃ (w : List Bool), kcWord req i = some w ∧ w.length = req i) ∧ PrefixFree {w : List Bool | ∃ i < m, kcWord req i = some w} ∧ kcMass (kcRun req m).1 + ∑ i ∈ Finset.range m, (1 / 2) ^ req i = 1

                                  kcRun's invariant: at every step of a request stream whose partial sums stay at most one, the free lengths stay pairwise distinct, every request so far was served at its own requested length, the assigned words are pairwise prefix-free, and the assigned mass plus the free measure is one.

                                  theorem PrefixMachine.kcWord_prefixFree {req : ℕ → ℕ} (hmass : ∀ (N : ℕ), ∑ m ∈ Finset.range N, (1 / 2) ^ req m ≤ 1) :
                                  PrefixFree {w : List Bool | ∃ (i : ℕ), kcWord req i = some w}

                                  The assigned words, over the whole stream, are pairwise prefix-free.