Documentation

ReflectiveSubsystems.MDLCoding

Lookup-table coding bound — [Discovery], Theorem 2.1 eq. (2) #

Provenance: [Discovery] §2.2 eq. (2), the lookup-table (direct-storage) lower bound MDL₂(lookup) ≥ L = n·log₂|O|. ReflectiveSubsystems/MDLDominance.lean proves the dominance arithmetic taking Ltable = n·log|O| as a definition; this file derives that table cost from an explicit binary coding model so the bound is content-checked, not just named. Mathlib has no coding theory; the argument here is elementary counting (Nat.clog, pigeonhole/cardinality).

Model (stated explicitly) #

What is proved (this file — the off-by-one-free "fixed-width memorization" form) #

A concrete lossless code tableEnc storing each symbol in a fixed ⌈log₂ O⌉-bit block:

Nat.clog 2 O is ⌈log₂ O⌉; the bound uses Nat.le_pow_clog (O ≤ 2^⌈log₂ O⌉). No sorry.

Block width: ⌈log₂ |A|⌉ bits per symbol.

Equations
Instances For
    noncomputable def ReflectiveSubsystems.blockEmb (A : Type u_1) [Fintype A] :

    A lossless assignment of each symbol to a distinct tableWidth-bit block (exists because |A| ≤ 2^tableWidth).

    Equations
    Instances For
      noncomputable def ReflectiveSubsystems.tableEnc (A : Type u_1) [Fintype A] (n : ℕ) (s : Fin n → A) :

      The fixed-width lookup-table encoder: concatenate the tableWidth-bit block of each of the n symbols, as one bitstring of length n · tableWidth.

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        theorem ReflectiveSubsystems.tableEnc_length (A : Type u_1) [Fintype A] (n : ℕ) (s : Fin n → A) :

        The code length is exactly n · ⌈log₂ |A|⌉ bits.

        The lookup-table code is lossless (injective).

        theorem ReflectiveSubsystems.tableEnc_length_ge (A : Type u_1) [Fintype A] (n : ℕ) (s : Fin n → A) :
        ↑n * Real.logb 2 ↑(Fintype.card A) ≤ ↑(tableEnc A n s).length

        Lookup-table lower bound, off-by-one-free. The modeled table code stores n symbols in n · ⌈log₂ |A|⌉ bits, which is ≥ n · log₂ |A| = L.

        theorem ReflectiveSubsystems.ltable_lower_bound (A : Type u_1) [Fintype A] (n : ℕ) (s : Fin n → A) :
        Ltable ↑(Fintype.card A) ↑n ≤ ↑(tableEnc A n s).length

        Connection to ReflectiveSubsystems.Ltable. The §2.2 eq. (2) quantity Ltable |A| n = n·log|A| (natural-log units) is a genuine lower bound on the modeled table code's length.

        The genuine bound: pigeonhole lower bound on ANY lossless code #

        The fixed-width code above is one specific code; the real eq. (2) content is that every lossless code costs ≥ L. Counting: there are |A|^n sequences but only 2^L − 1 bitstrings of length < L, so an injective code must use a codeword of length ≥ ⌊log₂(|A|^n)⌋, i.e. length + 1 ≥ n·log₂|A|. The +1 is the genuine integer-counting gap (a length-<L set has 2^L − 1 < 2^L elements), not removable by pure counting.

        theorem ReflectiveSubsystems.exists_long_codeword (A : Type u_1) [Fintype A] (n : ℕ) [Nonempty A] (enc : (Fin n → A) → List Bool) (henc : Function.Injective enc) :
        ∃ (o : Fin n → A), ↑n * Real.logb 2 ↑(Fintype.card A) ≤ ↑(enc o).length + 1

        Pigeonhole lower bound (the genuine eq. (2) bound). For ANY lossless (injective) binary code enc of the n-symbol sequences over A, some sequence has a codeword with n·log₂|A| ≤ length + 1. Proof: |A|^n sequences inject into the 2^(M+1)−1 bitstrings of length ≤ M (M = the longest codeword), forcing |A|^n < 2^(M+1), i.e. n·log₂|A| < M + 1. The +1 is the intrinsic integer gap (flagged); it is absorbed into the O(1) overheads of §2.1.

        Rule-based two-part code — [Discovery], Theorem 2.1 eq. (1) (upper bound) #

        Provenance: [Discovery] §2.2 eq. (1), MDL₂(rule) ≤ Lrule = r + 2·log₂ r + c₃ + log₂|O| + log₂ n + O(1). ReflectiveSubsystems.Lrule takes this as a definition; here we build an explicit two-part code and bound its length, so Lrule is a proved upper bound on a real code.

        The substance is the self-delimiting length prefix: a program of r bits whose length is a priori unknown must be framed so the decoder finds its end, and the cheapest framing (Elias-γ) costs r + 2·log₂ r + O(1) — the 2 log r term of Kmin.

        Units (flagged) #

        This is a genuine binary (MDL₂) code, so its length is in bits (Real.logb 2). ReflectiveSubsystems.Lrule/Kmin are written in Real.log (nats). Bits = nats / ln 2 and ln 2 < 1, so the bit cost is the larger of the two: the bound here is ≤ r + 2·log₂ r + log₂|O| + log₂ n + O(1), the faithful MDL₂ cost. (We do NOT claim ≤ the natural-log Lrule, which is smaller; the per-term base-change factor is the O(1)-per-log the paper's O(·) absorbs, and dominance is unaffected since every term is O(log) against Ltable = Θ(n log O).)

        What is proved vs. assumed #

        Elias-γ code of m: ⌊log₂ m⌋ zeros followed by the binary digits of m (length 2·⌊log₂ m⌋ + 1 for m ≥ 1). Self-delimiting: the zero-run marks where the digits start.

        Equations
        Instances For

          Self-delimiting wrapper: prepend the Elias-γ encoding of the payload's length.

          Equations
          Instances For

            Self-delimiting length bound (selfDelim p).length ≤ |p| + 2·log₂|p| + 1. The 2·log₂|p| is the cost of framing an a-priori-unknown-length program — the Kmin 2 log r term, content-checked.

            Cor 2.2 content-check. The model part of the rule-based two-part code for a program p of bit-length r = |p| is the self-delimiting code selfDelim p, whose length meets the bits-form capacity threshold KminBits r 1. So Cor 2.2's 2 log r overhead is a real code length, not an assertion — exactly as eq.(1)/eq.(2) ground MDLDominance.

            Plain binary encoding of m (no framing), length ≤ log₂ m + 1.

            Equations
            Instances For

              Data-given-model field: the alphabet size |O| and step count n, in plain binary.

              Equations
              Instances For

                The rule-based two-part code: self-delimited program, then the data-given-model field.

                Equations
                Instances For
                  theorem ReflectiveSubsystems.lrule_upper_bound (p : List Bool) (O n : ℕ) :
                  ↑(ruleCode p O n).length ≤ ↑p.length + 2 * Real.logb 2 ↑p.length + Real.logb 2 ↑O + Real.logb 2 ↑n + 3

                  Theorem 2.1 eq. (1) (upper bound), in bits. The two-part code for an r-bit rule program p generating an n-symbol sequence over an |O|-symbol alphabet has length ≤ r + 2·log₂ r + log₂|O| + log₂ n + 3, i.e. Lrule (in bits) is a proved upper bound on an actual lossless code. The +3 is the O(1); the 2·log₂ r self-delimiting cost is the content-checked Kmin term.

                  Losslessness of the self-delimited program code #

                  selfDelim is injective: the program is recovered from its self-delimited encoding. We prove this via the length channel — a ↦ (eliasγ a).length + a is strictly monotone, so equal codes force equal payload lengths, after which the (now identical) γ-prefix cancels. (This is the lossless encoding of the program. The full two-part decoder that also separates the program from the trailing data field by parsing the γ zero-run — (p, data) ↦ selfDelim p ++ data injective for nonempty p — is the standard Elias-γ prefix property; its formalization is the residual and is not needed for the length bound lrule_upper_bound.)

                  selfDelim is lossless (injective): the program is uniquely recovered from its self-delimited encoding.

                  The two-part code is genuinely lossless (Elias-γ prefix property) #

                  selfDelim_injective recovers the program from its standalone self-delimited encoding. Here we close the residual: the program is recovered even with a trailing data field — the map (p, data) ↦ selfDelim p ++ data is injective (for nonempty programs). The proof builds the actual Elias-γ decoder: read the leading zero-run to get ⌊log₂|p|⌋, hence the γ-prefix length; split off the prefix and recover |p| from its binary digits (recoverNat); then split p from data. This makes ruleCode a genuinely lossless two-part code, not merely a length bound. (Nonemptiness is required and flagged: selfDelim [] = [], so an empty program cannot be delimited from the data.)

                  theorem ReflectiveSubsystems.twoPart_injective {p₁ p₂ d₁ d₂ : List Bool} (h₁ : p₁ ≠ []) (h₂ : p₂ ≠ []) (h : selfDelim p₁ ++ d₁ = selfDelim p₂ ++ d₂) :
                  p₁ = p₂ ∧ d₁ = d₂

                  Two-part losslessness (Elias-γ prefix property). For nonempty programs, the self-delimited program followed by an arbitrary data field uniquely determines both: selfDelim p₁ ++ d₁ = selfDelim p₂ ++ d₂ → p₁ = p₂ ∧ d₁ = d₂. This closes the eq.(1) residual — ruleCode is a genuinely lossless two-part code.

                  Capstone: dominance between actual code lengths (Theorem 2.1) #

                  Combining the two derived coding bounds — eq. (1) lrule_upper_bound and eq. (2) tableEnc_length_ge — with a regime margin gives the headline of Theorem 2.1 at the level of actual binary codes: the rule-based two-part code is strictly shorter than the lookup table.

                  Units (route A) #

                  Both coding bounds are in bits (Real.logb 2), so we prove the dominance arithmetic directly in bits (a logb-2 analogue of ReflectiveSubsystems.mdl_dominance's natural-log proof). The only estimate is Real.logb 2 n ≤ n − 1 for integer n ≥ 1 (logb_two_nat_le_sub_one, via n ≤ 2^(n−1)), the bit analogue of Real.log n ≤ n − 1. We do NOT route through mdl_dominance itself: its r (a raw bit count) and its Ltable = n log O (a log term) scale differently under base change, so a clean divide-through is not available; the direct bit proof is shorter.

                  Scope (what the comparison asserts) #

                  This compares the lengths of two codes that each losslessly represent the sequence: the table fully (tableEnc_injective), the rule program via selfDelim_injective. The decode-correctness residual (that running the program n steps regenerates the sequence — Code/Computes) is, as previously noted, NOT formalized; it is not needed for the MDL₂ length comparison, which is exactly what Theorem 2.1 asserts.

                  theorem ReflectiveSubsystems.mdl_dominance_codes (A : Type u_1) [Fintype A] (n : ℕ) (p : List Bool) (s : Fin n → A) (_hO : 3 ≤ Fintype.card A) (hn : 2 ≤ n) (hReg : ↑p.length + 2 * Real.logb 2 ↑p.length + 4 ≤ (↑n - 1) * (Real.logb 2 ↑(Fintype.card A) - 1)) :

                  Theorem 2.1 (codes). Under the bit-unit regime margin hReg, the rule-based two-part code for an r-bit program p generating the length-n sequence s over the |A|-symbol alphabet is strictly shorter than the lookup-table code. _hO (|A| ≥ 3, strengthened from the paper's ≥ 2) documents the regime constant subsumed by hReg (it forces log₂|A| > 1).

                  Decode-correctness: linking the program to the generated sequence (eq.(1) residual 2) #

                  The program field of ruleCode is the binary index of a Code (Mathlib's universal machine Nat.Partrec.Code, via AIT/KolmogorovComplexity.lean). "The rule c generates the output x" is KolmogorovComplexity.Computes c x (c.eval 0 = Part.some x) — the paper's modelling premise (imported, taken as a hypothesis, not re-derived: Mathlib has the universal machine but we do not re-execute it). With the two-part losslessness (twoPart_injective) and injectivity of the binary index, the rule code uniquely determines the generated output (ruleEncode_lossless) — closing the decode-correctness residual at the coding level.

                  The rule code of a generating Code c: the program is c's binary index (shifted by 1 so it is nonzero, hence a nonempty program), framed self-delimitingly, followed by the data field.

                  Equations
                  Instances For
                    theorem ReflectiveSubsystems.ruleEncode_lossless {c₁ c₂ : Nat.Partrec.Code} {x₁ x₂ O n : ℕ} (h₁ : KolmogorovComplexity.Computes c₁ x₁) (h₂ : KolmogorovComplexity.Computes c₂ x₂) (h : ruleEncode c₁ O n = ruleEncode c₂ O n) :
                    x₁ = x₂

                    Decode-correctness (losslessness of the generated output). If c₁ generates x₁ and c₂ generates x₂, then equal rule codes force equal generated outputs. The two-part decoder recovers the program (twoPart_injective), binCode/Encodable.encode injectivity recover the Code, and the generation hypotheses then equate the outputs x₁ = x₂. So ruleEncode is a lossless encoding of the rule-generated output.

                    theorem ReflectiveSubsystems.mdl_dominance_codes_generated (A : Type u_1) [Fintype A] (n : ℕ) [Encodable A] (c : Nat.Partrec.Code) (s : Fin n → A) (_hgen : KolmogorovComplexity.Computes c (Encodable.encode s)) (_hO : 3 ≤ Fintype.card A) (hn : 2 ≤ n) (hReg : ↑(binCode (Encodable.encode c + 1)).length + 2 * Real.logb 2 ↑(binCode (Encodable.encode c + 1)).length + 4 ≤ (↑n - 1) * (Real.logb 2 ↑(Fintype.card A) - 1)) :

                    Theorem 2.1 (codes), linked to the generated sequence. When the program c generates the sequence s (hgen : Computes c (encode s) — the paper's premise, so both sides describe the same s: the table encodes s directly and losslessly via tableEnc_injective, the rule encodes s via c losslessly via ruleEncode_lossless), the rule-based code of s is strictly shorter than the lookup-table code of s, under the same regime margin. The length comparison reuses mdl_dominance_codes; hgen is the modelling premise that fixes the common sequence (it is not needed for the length inequality itself, only to make "same s on both sides" honest).