Documentation

CodeLayer.BinaryConstant

Length-efficient binary constant bconst #

Extends CodeLayer/AdditiveComplexity.lean (E, elen, KE).

Status: PROVED. eval_bconst and elen_bconst_le (with κ = 15 + elen dbl) are proved and CI-guarded in CodeLayer/AxiomAudit.lean; both depend only on [propext, Classical.choice, Quot.sound] (Classical.choice genuinely used — dbl is extracted from universality).

Why a new constant (the gate) #

AdditiveComplexity documents that Mathlib's Code.const is a unary tower (const (n+1) = comp succ (const n)), so elen (Code.const n) = Θ(n) — exponential in bit-length. Both the O(log T) bound of the time-bounded description and the invariance bound KE(x) ≤ K_d(x) + c_d need a constant whose additive length is O(Nat.size n) (linear in bits). bconst builds n in Horner (binary) form: a fixed doubling code dbl (x ↦ 2x, via universality) plus one succ/id per bit, so the AST has O(Nat.size n) nodes.

What this file establishes #

theorem AdditiveComplexity.size_succ_div_two (n : ℕ) :
(n + 1).size = ((n + 1) / 2).size + 1

The binary-length recursion Nat.size (n+1) = Nat.size ((n+1)/2) + 1. Mathlib has no direct size (n/2) lemma; derive it from Nat.size_bit + Nat.bit_bodd_div2 + Nat.div2_val.

theorem AdditiveComplexity.partrec_dbl :
Nat.Partrec fun (x : ℕ) => ↑(some (2 * x))

x ↦ 2x is partial recursive. Bridge chain: Primrec.nat_mul → Primrec (2 * ·) → Primrec.to_comp → Computable → Computable.partrec → _root_.Partrec → Partrec.nat_iff.mp → Nat.Partrec.

A fixed doubling code, extracted from universality (exists_code). Noncomputable — Classical.choose picks an arbitrary such code; its elen is a fixed (uncontrolled) constant elen dbl.

Equations
Instances For

    The doubling code's evaluation law: eval dbl x = 2x. From Classical.choose_spec (eval dbl = ↑(fun x => 2*x)), applied pointwise.

    @[irreducible]

    Length-efficient binary constant: bconst n computes n from any input, with O(Nat.size n) AST nodes (vs Θ(n) for Code.const). Horner form: n+1 = 2·((n+1)/2) + (n+1)%2, so double the code for (n+1)/2 and add the low bit via succ (odd) or id (even).

    Equations
    Instances For

      Correctness: bconst n outputs n from any input (the constant ignores its argument).

      The gate deliverable: bconst's additive length is O(Nat.size n) — linear in the number of bits of n, not in n. The explicit constant κ = 15 + elen dbl (per-step: two comps = 6, one succ/id ≤ 9, plus the fixed elen dbl), induction mirroring the n ↦ (n+1)/2 recursion via Nat.size_bit.

      Payoffs: a time-bounded description bound and multiplicative optimality #

      theorem AdditiveComplexity.prop_2_2_core (coll cR : Nat.Partrec.Code) (n T y : ℕ) (h : y ∈ Nat.Partrec.Code.evaln T (coll.comp (cR.comp (bconst n))) 0) :
      KE_t T y ≤ ↑(elen cR + (15 + elen dbl) * n.size + (6 + elen coll + (15 + elen dbl)))

      Time-bounded description bound: the length-n trajectory y produced within budget T by comp coll (comp cR (bconst n)) (rule code cR, elen cR = r; collector coll) has time-bounded additive complexity S_T ≤ r + O(log n). The O(log n) is κ · Nat.size n (κ = 15 + elen dbl) — logarithmic in the horizon because bconst is binary, not the Θ(n) of Code.const. Modeled premise: the assembled code computes y within T steps.

      theorem AdditiveComplexity.invariance_general (d : Nat.Partrec.Code) (p x : ℕ) (h : d.eval p = Part.some x) :
      KE x ≤ elen d + (15 + elen dbl) * p.size + (3 + (15 + elen dbl))

      Multiplicative optimality of KE: for any number-input description method d with d.eval p = x, KE x ≤ elen d + κ · Nat.size p + (3 + κ) (κ = 15 + elen dbl). Hardcode the program p as data via the binary constant bconst p (whose additive length is O(Nat.size p), not Θ(p)), then comp d (bconst p) computes x — the + O(log p) model-bridge the encodeCode measures cannot give additively.