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 #
E,elen,KE: self-delimiting AST encoding, its bit-length, and the induced complexity.E_len_comp,E_len_pair,E_len_prec,E_len_rfind',elen_zero,elen_succ,elen_left,elen_right: exact additive length laws, one per constructor (the payoffencodecannot give).KE_le,KE_le_const,exists_min_E: the minimization API (mirrorsK_le/K_le_const/exists_min_codeofAIT/KolmogorovComplexity.lean).KE_comp_le,KE_pair_le,KE_subadditive: compositional upper bounds —KE (Nat.pair x y) ≤ KE x + KE y + 3(the additive subadditivity the index measure cannot prove).E_append_inj,E_injective: parse uniqueness — the prefix encoding decodes: a serialized program is a prefix of no other program's serialization, soEis injective. This is what makes program length a code length rather than an arbitrary weight.card_KE_le,finite_KE_le,KE_unbounded: the counting bound — at most2 ^ (L + 1)naturals haveKE ≤ L, because distinct values need distinct shortest programs,Eis injective, and there are fewer than2 ^ (L + 1)bit-strings of length at mostL. This is the incompressibility method's supply side.summable_two_pow_neg_KE,finset_card_KE_le_two_pow,card_KE_le_two_pow: the sharp count — at most2 ^ Lnaturals haveKE ≤ L, by Kraft's inequality forKE(kraft_KE) rather than by counting bit-strings, the same three-line argumentPrefixMachine.finset_card_KB_leruns forKB.card_KE_lekeeps its constant2 ^ (L + 1).KE_t,KE_le_KE_t,KE_t_antitone: time-bounded refinement, a one-symbol swap of theK_tconstruction (elenfor the indexcodelen).
What this does NOT establish (flagged) #
- Two-machine additive invariance itself: it needs a length-efficient binary constant
bconst : ℕ → Codewith|E (bconst n)| = O(Nat.size n), since Mathlib'sCode.constis a unary tower (const (n+1) = comp succ (const n)) with|E (Code.const n)| = Θ(n), exponential in bit-length.CodeLayer/BinaryConstant.leanbuildsbconstand proves that bound, and the invariance statements (invariance_general) are proved there. - Does NOT relate
KEto an abstract real-valued description length.
Hypotheses: standard vs added #
- Standard: additive program length; subadditivity
KE(⟨x,y⟩) ≤ KE x + KE y + O(1). - Added / modeling: one fixed machine (
Code.eval); 3-bit Polish opcode; input-0convention (Computes) inherited fromCodeLayer/Code/EvalLaws.lean.
Self-delimiting AST encoding of a Code in prefix (Polish) form: a fixed 3-bit opcode per node,
followed by the children's encodings. Additive by construction (E_len_comp/E_len_pair).
Equations
- AdditiveComplexity.E Nat.Partrec.Code.zero = [false, false, false]
- AdditiveComplexity.E Nat.Partrec.Code.succ = [false, false, true]
- AdditiveComplexity.E Nat.Partrec.Code.left = [false, true, false]
- AdditiveComplexity.E Nat.Partrec.Code.right = [false, true, true]
- AdditiveComplexity.E (cf.pair cg) = [true, false, false] ++ AdditiveComplexity.E cf ++ AdditiveComplexity.E cg
- AdditiveComplexity.E (cf.comp cg) = [true, false, true] ++ AdditiveComplexity.E cf ++ AdditiveComplexity.E cg
- AdditiveComplexity.E (cf.prec cg) = [true, true, false] ++ AdditiveComplexity.E cf ++ AdditiveComplexity.E cg
- AdditiveComplexity.E cf.rfind' = [true, true, true] ++ AdditiveComplexity.E cf
Instances For
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
- AdditiveComplexity.KE x = sInf {l : ℕ | ∃ (c : Nat.Partrec.Code), KolmogorovComplexity.Computes c x ∧ AdditiveComplexity.elen c = l}
Instances For
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.
The additive length law for pair (identical shape to E_len_comp).
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.
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.
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.
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
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.
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.
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.
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.
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
- AdditiveComplexity.tElens t x = {l : ℕ | ∃ (c : Nat.Partrec.Code), x ∈ Nat.Partrec.Code.evaln t c 0 ∧ AdditiveComplexity.elen c = l}
Instances For
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).