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 #
dbl,eval_dbl: a fixed doubling code and its eval law (from universality +choose_spec).bconst,eval_bconst: the binary constant and its correctnesseval (bconst n) m = n.elen_bconst_le: theO(Nat.size n)length bound — the gate deliverable.size_succ_div_two: the binary-length recursion the length bound runs on. Thecompeval law it is used with,eval_comp_some, comes fromCodeLayer.Code.EvalLaws.
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.
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.
Instances For
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
- AdditiveComplexity.bconst 0 = Nat.Partrec.Code.zero
- AdditiveComplexity.bconst n.succ = (if (n + 1) % 2 = 0 then Nat.Partrec.Code.id else Nat.Partrec.Code.succ).comp (AdditiveComplexity.dbl.comp (AdditiveComplexity.bconst ((n + 1) / 2)))
Instances For
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 #
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.
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.