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:
kcServe,kcRun,kcWord: serve a stream of length requests against a free space of dyadic intervals, greedily, one request per step.primrec₂_kcServe,computable_kcRun,computable_kcWord: the assignment is effective.kcRun_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.kcWord_prefixFree: the assigned words, over the whole stream, are pairwise prefix-free.
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.
Free dyadic intervals [a / 2 ^ l, (a + 1) / 2 ^ l), as (length, numerator) pairs.
Instances For
bitsFixed is primitive recursive #
The word–interval dictionary #
(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).
Instances For
Either code prefixes the other.
Equations
- PrefixMachine.Comparable l a l' a' = (PrefixMachine.Nested l a l' a' ∨ PrefixMachine.Nested l' a' l a)
Instances For
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
- PrefixMachine.splitBuild j a 0 = (a, [])
- PrefixMachine.splitBuild j a i.succ = (2 * (PrefixMachine.splitBuild j a i).1, (j + i + 1, 2 * (PrefixMachine.splitBuild j a i).1 + 1) :: (PrefixMachine.splitBuild j a i).2)
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
- PrefixMachine.bestFreePair free 0 = (List.filter (fun (p : ℕ × ℕ) => decide (p.1 = 0)) free).head?
- PrefixMachine.bestFreePair free i.succ = match (List.filter (fun (p : ℕ × ℕ) => decide (p.1 = i + 1)) free).head? with | some p => some p | none => PrefixMachine.bestFreePair free i
Instances For
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: the assigned word and the updated free space.
Equations
- PrefixMachine.kcServe free k = Option.map (fun (q : (ℕ × ℕ) × PrefixMachine.FreeSpace) => (PrefixMachine.bitsFixed q.1.1 q.1.2, q.2)) (PrefixMachine.kcServe' free k)
Instances For
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
- PrefixMachine.kcRunPairs req 0 = ([(0, 0)], [])
- PrefixMachine.kcRunPairs req i.succ = PrefixMachine.kcStep' (PrefixMachine.kcRunPairs req i) (req i)
Instances For
The run over a request stream, by steps: the free space and the words assigned so far.
Equations
- PrefixMachine.kcRun req 0 = ([(0, 0)], [])
- PrefixMachine.kcRun req i.succ = PrefixMachine.kcStep (PrefixMachine.kcRun req i) (req i)
Instances For
The word assigned at step m.
Equations
- PrefixMachine.kcWord req m = Option.map Prod.fst (PrefixMachine.kcServe (PrefixMachine.kcRun req m).1 (req m))
Instances For
Distinct lengths above k carry mass below 2 ^ (-k) #
The run-level induction #
The pair assigned at step i, in (length, numerator) form.
Equations
- PrefixMachine.kcWordPair req i = Option.map Prod.fst (PrefixMachine.kcServe' (PrefixMachine.kcRunPairs req i).1 (req i))
Instances For
Once assigned, a pair stays in the run's assigned list forever after.
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.