Documentation

CodeLayer.AdditiveComplexity

Additive AST program-length complexity KE #

Extends CodeLayer/Code/EvalLaws.lean (Computes, const_computes) with an additive program-length measure that the index/bit-length measures (codelen, codelen') cannot provide. The public surface is the encoding E with its length elen and the induced complexity KE, the exact length laws (E_len_comp, E_len_pair, E_len_prec and the one-node cases), the upper bounds (KE_le, KE_le_const, KE_comp_le, KE_pair_le, KE_subadditive), parse uniqueness and Kraft's inequality (E_injective, kraft_KE), and the counting bounds (card_KE_le, card_KE_le_two_pow, KE_unbounded).

Why additive E (not the existing encode-based measures) #

AIT/KolmogorovComplexity.lean and AIT/KolmogorovBitlen.lean measure a program by its Gödel index encode c (resp. Nat.size (encode c)). Mathlib's encodeCode pairs children with the quadratic Nat.pair at every binary node, so encode (comp cf cg) is super-linear in encode cf + encode cg; there is no additive law |comp cf cg| = |cf| + |cg| + O(1). This blowup is the obstruction to the two-machine additive-invariance bound K_U ≤ K_V + c_{U,V} and to a clean KE(x) ≤ K_d(x) + c_d.

E fixes this by serializing the AST in prefix (Polish) form with a fixed 3-bit opcode per node, so program length is additive by construction: |E (comp cf cg)| = 3 + |E cf| + |E cg| (E_len_comp). This is the first half of the invariance target: the compositional length algebra.

What this establishes #

What this does NOT establish (flagged) #

Hypotheses: standard vs added #

Program length under the additive encoding: the bit-length of E c.

Equations
Instances For
    noncomputable def AdditiveComplexity.KE (x : ℕ) :

    Additive Kolmogorov complexity: least elen-length over codes computing x from input 0. Well-defined — Code.const x computes x (see Computes), so the minimand is nonempty.

    Equations
    Instances For
      theorem AdditiveComplexity.E_len_comp (cf cg : Nat.Partrec.Code) :
      elen (cf.comp cg) = 3 + elen cf + elen cg

      The additive length law for comp (the payoff the encode index measure cannot give): the 3-bit opcode plus the two children's lengths. E (comp …) unfolds by rfl, and simp only computes the list lengths and normalizes the sum.

      theorem AdditiveComplexity.E_len_pair (cf cg : Nat.Partrec.Code) :
      elen (cf.pair cg) = 3 + elen cf + elen cg

      The additive length law for pair (identical shape to E_len_comp).

      theorem AdditiveComplexity.E_len_prec (cf cg : Nat.Partrec.Code) :
      elen (cf.prec cg) = 3 + elen cf + elen cg

      The additive length law for prec (identical shape to E_len_comp).

      The additive length law for rfind': the 3-bit opcode plus the child's length.

      The base code zero is one 3-bit opcode.

      The base code succ is one 3-bit opcode.

      The base code left is one 3-bit opcode.

      The base code right is one 3-bit opcode.

      Any program computing x bounds KE x by its own additive length. (Mirrors KolmogorovComplexity.K_le: elen c is a member of the minimand.)

      KE is at most the additive length of the unary constant code: Code.const x computes x (const_computes).

      KE x is achieved by some code. (Mirrors KolmogorovComplexity.exists_min_code: the minimand is nonempty via const_computes, so Nat.sInf_mem applies.)

      Composition upper bound: a comp c d computing x bounds KE x additively — KE_le on the witness, then the additive E_len_comp.

      Pairing upper bound: a pair c d computing x bounds KE x additively — KE_le on the witness, then the additive E_len_pair.

      theorem AdditiveComplexity.KE_subadditive (x y : ℕ) :
      KE (Nat.pair x y) ≤ KE x + KE y + 3

      Subadditivity (the headline additive bound): KE (Nat.pair x y) ≤ KE x + KE y + 3. Take the KE-optimal codes cx, cy for x, y; pair cx cy computes Nat.pair x y (the pair eval law is definitional), and its length is 3 + elen cx + elen cy by E_len_pair.

      Parse uniqueness: E is injective #

      The serialization is a prefix code by construction: the 3-bit opcode at the head of a node says how many children follow, so a serialized program can be read off the front of any bit-stream that begins with it, and nothing else can. The statement that carries the induction is the stronger parse-uniqueness form (E_append_inj) — if two serializations agree after arbitrary trailing bits, the programs and the trailing bits agree — from which injectivity is the empty-tail case.

      theorem AdditiveComplexity.E_append_inj (c d : Nat.Partrec.Code) (L₁ L₂ : List Bool) :
      E c ++ L₁ = E d ++ L₂ → c = d ∧ L₁ = L₂

      Parse uniqueness. A serialized program determines itself and its trailing bits: no E c is a proper prefix of another E d. The induction is on c, with d and both tails universally quantified — the binary nodes consume their two children by two applications of the induction hypothesis.

      The serialization is injective: distinct programs have distinct bit-strings (the empty-tail case of E_append_inj). Distinct outputs therefore need distinct shortest programs — the prerequisite of every counting bound on KE (card_KE_le).

      Kraft's inequality: the code lengths are affordable #

      Parse uniqueness says E is a prefix code, and a prefix code is uniquely decodable: a concatenation of serialized programs parses back to exactly one list of programs. Kraft's inequality (McMillan's counting argument, InformationTheory.IsUniquelyDecodable.finsetSum_one_div_card_pow_length_le_one) then prices the lengths — ∑ 2 ^ (-elen c) ≤ 1 over ALL programs at once. The counting bounds below are the finite shadow of this: a budget of L bits cannot be spent twice.

      E never emits the empty string: every node opens with its 3-bit opcode.

      The serialization is uniquely decodable: two lists of programs whose concatenations agree are the same list. Parse uniqueness (E_append_inj) peels one program off each side at a time — the head programs coincide and the tails still agree, so the induction closes.

      theorem AdditiveComplexity.kraft_sum_le_one (F : Finset Nat.Partrec.Code) :
      ∑ c ∈ F, (1 / 2) ^ elen c ≤ 1

      Kraft's inequality over any finite set of programs. McMillan's argument applies to the serialized codewords; injectivity of E (E_injective) transports the sum back to the programs themselves. Both steps are generic in the code, so this is BinaryKraft.indexed_finset_sum_le_one at E.

      Kraft's inequality for the additive encoding: ∑ 2 ^ (-elen c) ≤ 1, over all programs. Every finite subtotal is at most one (kraft_sum_le_one), and the summands are nonnegative, so the sum over the whole (countably infinite) space of programs is too. Short programs are therefore scarce by arithmetic, not by convention: halving the length doubles the price.

      Counting programs: how many naturals are L-compressible #

      Fewer than 2 ^ (L + 1) bit-strings have length at most L; parse uniqueness turns that into a bound on how many naturals admit a program of length at most L. This is the supply side of the incompressibility method: a budget of L bits describes at most 2 ^ (L + 1) objects, so any set of more than that many objects contains an incompressible one.

      The bit-strings of length at most L, as a finite set: the empty string, and everything obtained by prefixing a bit to a bit-string of length at most L - 1.

      Equations
      Instances For

        bitLists L contains every bit-string of length at most L.

        theorem AdditiveComplexity.card_bitLists (L : ℕ) :
        (bitLists L).card ≤ 2 ^ (L + 1) - 1

        There are at most 2 ^ (L + 1) - 1 bit-strings of length at most L (in fact exactly that many; the inequality is all the counting needs). One empty string, plus two copies of the previous level.

        A shortest program for x (exists_min_E makes the choice possible).

        Equations
        Instances For

          Distinct values have distinct shortest programs. A program computes ONE value, and E is injective, so x ↦ E (minCode x) is injective — the pigeonhole map behind card_KE_le.

          The Kraft series over KE is summable: the object-indexed series ∑ 2 ^ (-KE x) is the program-indexed series (summable by BinaryKraft.indexed_summable at the injective, uniquely decodable E) reindexed along minCode, an injection (minCode_E_injective), so its summability is that of a subseries. The summability Summable.sum_le_tsum needs in the sharp count finset_card_KE_le_two_pow, and the first step of kraft_KE.

          theorem AdditiveComplexity.kraft_KE :
          ∑' (x : ℕ), (1 / 2) ^ KE x ≤ 1

          Kraft's inequality for KE itself: ∑ 2 ^ (-KE x) ≤ 1, over all naturals — the object-indexed semimeasure kraft_KP_E gives only for programs. Each x contributes the weight of its own shortest program (elen_minCode), and x ↦ minCode x is injective (E ∘ minCode is injective by minCode_E_injective, hence so is minCode), so the object-indexed sum is the program-indexed sum reindexed along an injection and is bounded by it.

          Only finitely many naturals are describable within a fixed budget.

          theorem AdditiveComplexity.KE_unbounded (n : ℕ) :
          ∃ (x : ℕ), n < KE x

          KE is unbounded: incompressible numbers of every additive complexity exist, because only finitely many naturals have KE x ≤ n (finite_KE_le) and there are infinitely many naturals.

          theorem AdditiveComplexity.card_KE_le (L : ℕ) :
          {x : ℕ | KE x ≤ L}.ncard ≤ 2 ^ (L + 1)

          The counting bound: at most 2 ^ (L + 1) naturals have complexity at most L. Each such value carries its own shortest program (minCode_E_injective), and those programs are bit-strings of length at most L, of which there are fewer than 2 ^ (L + 1) (card_bitLists).

          A description budget of L bits buys at most 2 ^ (L + 1) objects: this is the supply side of the incompressibility method.

          theorem AdditiveComplexity.finset_card_KE_le_two_pow (L : ℕ) (F : Finset ℕ) (hF : ∀ x ∈ F, KE x ≤ L) :
          F.card ≤ 2 ^ L

          The sharp counting bound on KE, Finset form: at most 2 ^ L naturals are describable within a budget of L bits, against the 2 ^ (L + 1) of card_KE_le. Each member of F weighs at least 2 ^ (-L) in the Kraft series (pow_le_pow_of_le_one), so F.card copies of that weight sit below the series' partial sum over F (Finset.sum_le_sum), below the full series (Summable.sum_le_tsum, at summable_two_pow_neg_KE), below one (kraft_KE). The count is PrefixMachine.finset_card_KB_le's argument at KE, and needs no finiteness hypothesis.

          The sharp counting bound on KE, ncard form: finset_card_KE_le_two_pow's corollary at the finiteness finite_KE_le supplies, over its own Finite.toFinset. Stated separately from the Finset form because Set.ncard of an infinite set is 0, so this sentence alone could not fail; the Finset form is what shows the bound bites. Sharpens card_KE_le's constant, which is kept as stated.

          Time-bounded refinement #

          A one-symbol swap of the KolmogorovTimeBounded.K_t construction: elen in place of the index codelen, over the same evaln step-budget set.

          Additive lengths of programs outputting x from input 0 within t evaln-steps.

          Equations
          Instances For
            noncomputable def AdditiveComplexity.KE_t (t x : ℕ) :

            Time-bounded additive complexity: least elen-length over codes outputting x from input 0 within t evaln-steps; ⊤ if none halts in budget t. Mirrors KolmogorovTimeBounded.K_t with the additive length elen in place of the index codelen.

            Equations
            Instances For
              theorem AdditiveComplexity.KE_le_KE_t (t x : ℕ) :
              ↑(KE x) ≤ KE_t t x

              More compute never hurts: KE x ≤ KE_t t x — the t-bounded programs are a sub-collection of all programs (evaln_sound). Mirrors KolmogorovTimeBounded.K_le_K_t.

              theorem AdditiveComplexity.KE_t_antitone {t₁ t₂ : ℕ} (h : t₁ ≤ t₂) (x : ℕ) :
              KE_t t₂ x ≤ KE_t t₁ x

              Antitone in the budget: more steps ⇒ no larger KE_t (evaln_mono). Mirrors KolmogorovTimeBounded.K_t_antitone.

              theorem AdditiveComplexity.KE_t_le {t x : ℕ} {c : Nat.Partrec.Code} (h : x ∈ Nat.Partrec.Code.evaln t c 0) :
              KE_t t x ≤ ↑(elen c)

              Time-bounded analogue of KE_le: any code halting on x within budget t bounds KE_t t x by its own additive length (elen c ∈ tElens t x, then sInf_le).