Documentation

Complexitylib.Models.TuringMachine.Experimental.BinaryRoutine.SpaceBounds

Compositional width bounds for binary routines #

This module exposes pointwise width certificates for routine leaves, sequential composition, fixed repetition, branches, and binary loops. Loop certificates collapse the recursive maximum in binaryForSpace to four local obligations, so the number of iterations does not appear additively in the resulting auxiliary-space bound. A final polynomial width bound converts the composed certificate to logarithmic space.

theorem Complexity.BinaryRoutine.values_update_le {n : } {values : BinaryValues n} {width value : } (index : Fin n) (hvalues : ∀ (current : Fin n), values current width) (hvalue : value width) (current : Fin n) :
Function.update values index value current width

Updating one binary register preserves a common pointwise upper bound when both the old vector and the replacement value satisfy that bound.

theorem Complexity.BinaryRoutine.SpaceBoundInLogAt.of_le {n : } {routine : BinaryRoutine n} {initialSpace : } {values : BinaryValues n} {bound : } (hle : ∀ (inputLength : ), routine.spaceBound (initialSpace inputLength) (values inputLength) bound inputLength) (hbound : BigO bound fun (inputLength : ) => Nat.log 2 inputLength) :
routine.SpaceBoundInLogAt initialSpace values

A pointwise logarithmic envelope proves logarithmic routine space along a fixed input-indexed trajectory.

theorem Complexity.BinaryRoutine.SpaceBoundInLogAt.restrict {n : } {routine : BinaryRoutine n} {requires : BinaryValues nProp} {initialSpace : } {values : BinaryValues n} (hspace : routine.SpaceBoundInLogAt initialSpace values) :
(routine.restrict requires).SpaceBoundInLogAt initialSpace values

Strengthening a precondition preserves an asymptotic space certificate.

theorem Complexity.BinaryRoutine.SpaceBoundInLogAt.seq {n : } {first second : BinaryRoutine n} {initialSpace : } {values : BinaryValues n} (hfirst : first.SpaceBoundInLogAt initialSpace values) (hsecond : second.SpaceBoundInLogAt initialSpace fun (inputLength : ) => first.effect (values inputLength)) :
(first.seq second).SpaceBoundInLogAt initialSpace values

Sequential phases preserve logarithmic space when the second certificate is stated along the first phase's exact pure effect.

theorem Complexity.BinaryRoutine.SpaceBoundInLogAt.branchZero {n : } {onZero onPositive : BinaryRoutine n} (idx : Fin n) {initialSpace : } {values : BinaryValues n} (hzero : onZero.SpaceBoundInLogAt initialSpace values) (hpositive : onPositive.SpaceBoundInLogAt initialSpace values) :
(BinaryRoutine.branchZero idx onZero onPositive).SpaceBoundInLogAt initialSpace values

Both branches sharing one logarithmic envelope make a zero branch logarithmic, independently of which branch is selected at each input.

theorem Complexity.BinaryRoutine.SpaceBoundInLogAt.binaryFor_of_envelope {n : } {body : BinaryRoutine n} {counterIdx limitIdx : Fin n} {initialSpace : } {values : BinaryValues n} {bound : } (henvelope : ∀ (inputLength : ), body.BinaryForSpaceEnvelope counterIdx limitIdx (initialSpace inputLength) (values inputLength) (bound inputLength)) (hbound : BigO bound fun (inputLength : ) => Nat.log 2 inputLength) :
(body.binaryFor counterIdx limitIdx).SpaceBoundInLogAt initialSpace values

A logarithmic pointwise envelope for all reachable comparisons, iterations, and successors proves logarithmic space for a binary loop.

theorem Complexity.BinaryRoutine.SpaceBoundByWidthAt.mono {n : } {routine : BinaryRoutine n} {initialSpace : } {values : BinaryValues n} {width width' : } (hspace : routine.SpaceBoundByWidthAt initialSpace values width) (hle : ∀ (inputLength : ), width inputLength width' inputLength) :
routine.SpaceBoundByWidthAt initialSpace values width'

Enlarging the controlling value preserves a pointwise width certificate.

theorem Complexity.BinaryRoutine.SpaceBoundByWidthAt.restrict {n : } {routine : BinaryRoutine n} {requires : BinaryValues nProp} {initialSpace : } {values : BinaryValues n} {width : } (hspace : routine.SpaceBoundByWidthAt initialSpace values width) :
(routine.restrict requires).SpaceBoundByWidthAt initialSpace values width

Strengthening a precondition preserves a pointwise width certificate.

theorem Complexity.BinaryRoutine.SpaceBoundByWidthAt.emitBits {n : } (word : List Bool) {initialSpace : } {values : BinaryValues n} {width : } :
(BinaryRoutine.emitBits word).SpaceBoundByWidthAt initialSpace values width

Fixed-word emission has a pointwise width certificate for every input trajectory.

theorem Complexity.BinaryRoutine.SpaceBoundByWidthAt.identity {n : } {initialSpace : } {values : BinaryValues n} {width : } :

The routine identity has a pointwise width certificate.

theorem Complexity.BinaryRoutine.SpaceBoundByWidthAt.clear {n : } (idx : Fin n) {initialSpace : } {values : BinaryValues n} {width : } (hvalue : ∀ (inputLength : ), values inputLength idx width inputLength) :
(BinaryRoutine.clear idx).SpaceBoundByWidthAt initialSpace values width

Clearing a value bounded by the controlling width has a pointwise width certificate.

theorem Complexity.BinaryRoutine.SpaceBoundByWidthAt.binarySucc {n : } (idx : Fin n) {initialSpace : } {values : BinaryValues n} {width : } (hvalue : ∀ (inputLength : ), values inputLength idx width inputLength) :
(BinaryRoutine.binarySucc idx).SpaceBoundByWidthAt initialSpace values width

Successor on a value bounded by the controlling width has a pointwise width certificate.

theorem Complexity.BinaryRoutine.SpaceBoundByWidthAt.binaryPred {n : } (idx : Fin n) {initialSpace : } {values : BinaryValues n} {width : } (hvalue : ∀ (inputLength : ), values inputLength idx - 1 + 1 width inputLength) :
(BinaryRoutine.binaryPred idx).SpaceBoundByWidthAt initialSpace values width

Predecessor has a pointwise width certificate when its exact positive space argument is bounded by the controlling value.

theorem Complexity.BinaryRoutine.SpaceBoundByWidthAt.binaryCopy {n : } (srcIdx dstIdx counterIdx : Fin n) {initialSpace : } {values : BinaryValues n} {width : } (hsrc : ∀ (inputLength : ), values inputLength srcIdx width inputLength) (hdst : ∀ (inputLength : ), values inputLength dstIdx width inputLength) :
(BinaryRoutine.binaryCopy srcIdx dstIdx counterIdx).SpaceBoundByWidthAt initialSpace values width

Copying two width-bounded values has a pointwise width certificate.

theorem Complexity.BinaryRoutine.SpaceBoundByWidthAt.addConst {n : } (idx : Fin n) (constant : ) {initialSpace : } {values : BinaryValues n} {width : } (hvalue : ∀ (inputLength : ), values inputLength idx + constant width inputLength) :
(BinaryRoutine.addConst idx constant).SpaceBoundByWidthAt initialSpace values width

Fixed addition has a pointwise width certificate when its result is bounded by the controlling value.

theorem Complexity.BinaryRoutine.SpaceBoundByWidthAt.set {n : } (idx : Fin n) (value : ) {initialSpace : } {values : BinaryValues n} {width : } (hcurrent : ∀ (inputLength : ), values inputLength idx width inputLength) (hvalue : ∀ (inputLength : ), value width inputLength) :
(BinaryRoutine.set idx value).SpaceBoundByWidthAt initialSpace values width

Setting a width-bounded value to another width-bounded value has a pointwise width certificate.

theorem Complexity.BinaryRoutine.SpaceBoundByWidthAt.add {n : } (srcIdx dstIdx counterIdx : Fin n) {initialSpace : } {values : BinaryValues n} {width : } (hsrc : ∀ (inputLength : ), values inputLength srcIdx width inputLength) (hsum : ∀ (inputLength : ), values inputLength dstIdx + values inputLength srcIdx width inputLength) :
(BinaryRoutine.add srcIdx dstIdx counterIdx).SpaceBoundByWidthAt initialSpace values width

Preserved-source addition has a pointwise width certificate when its source and result are bounded by the controlling value.

theorem Complexity.BinaryRoutine.SpaceBoundByWidthAt.mulAdd {n : } (leftIdx rightIdx accIdx mulCounterIdx addCounterIdx : Fin n) {initialSpace : } {values : BinaryValues n} {width : } (hleft : ∀ (inputLength : ), values inputLength leftIdx width inputLength) (hright : ∀ (inputLength : ), values inputLength rightIdx width inputLength) (htotal : ∀ (inputLength : ), values inputLength accIdx + values inputLength leftIdx * values inputLength rightIdx + values inputLength leftIdx width inputLength) :
(BinaryRoutine.mulAdd leftIdx rightIdx accIdx mulCounterIdx addCounterIdx).SpaceBoundByWidthAt initialSpace values width

Multiply-add has a pointwise width certificate when both factors and the largest addition intermediate are width-bounded.

theorem Complexity.BinaryRoutine.SpaceBoundByWidthAt.evalPolynomial {n : } (inputIdx resultIdx scratchIdx mulCounterIdx addCounterIdx : Fin n) (p : Polynomial ) {initialSpace : } {values : BinaryValues n} {width : } (hvalue : ∀ (inputLength : ), 2 * TM.binaryPolynomialValueCap p (values inputLength inputIdx) width inputLength) :
(BinaryRoutine.evalPolynomial inputIdx resultIdx scratchIdx mulCounterIdx addCounterIdx p).SpaceBoundByWidthAt initialSpace values width

Fixed-polynomial evaluation has a pointwise width certificate when its explicit Horner-prefix cap is width-bounded.

theorem Complexity.BinaryRoutine.SpaceBoundByWidthAt.emitNatCode {n : } (counterIdx valueIdx : Fin n) {initialSpace : } {values : BinaryValues n} {width : } (hvalue : ∀ (inputLength : ), values inputLength valueIdx width inputLength) :
(BinaryRoutine.emitNatCode counterIdx valueIdx).SpaceBoundByWidthAt initialSpace values width

Natural-code emission of a width-bounded value has a pointwise width certificate.

theorem Complexity.BinaryRoutine.SpaceBoundByWidthAt.emitRawGate {n : } (op : AndOrOp) (negated₀ negated₁ : Bool) (emitCounterIdx input₀Idx input₁Idx : Fin n) {initialSpace : } {values : BinaryValues n} {width : } (hinput₀ : ∀ (inputLength : ), values inputLength input₀Idx width inputLength) (hinput₁ : ∀ (inputLength : ), values inputLength input₁Idx width inputLength) :
(BinaryRoutine.emitRawGate op negated₀ negated₁ emitCounterIdx input₀Idx input₁Idx).SpaceBoundByWidthAt initialSpace values width

Raw-gate emission from two width-bounded references has a pointwise width certificate.

theorem Complexity.BinaryRoutine.SpaceBoundByWidthAt.emitRawGateStep {n : } (op : AndOrOp) (negated₀ negated₁ : Bool) (emitCounterIdx availableIdx input₀Idx input₁Idx : Fin n) {initialSpace : } {values : BinaryValues n} {width : } (havailable : ∀ (inputLength : ), values inputLength availableIdx width inputLength) (hinput₀ : ∀ (inputLength : ), values inputLength input₀Idx width inputLength) (hinput₁ : ∀ (inputLength : ), values inputLength input₁Idx width inputLength) :
(BinaryRoutine.emitRawGateStep op negated₀ negated₁ emitCounterIdx availableIdx input₀Idx input₁Idx).SpaceBoundByWidthAt initialSpace values width

Emitting and advancing one gate from width-bounded references and a width-bounded frontier has a pointwise width certificate.

theorem Complexity.BinaryRoutine.SpaceBoundByWidthAt.seq {n : } {first second : BinaryRoutine n} {initialSpace : } {values : BinaryValues n} {width : } (hfirst : first.SpaceBoundByWidthAt initialSpace values width) (hsecond : second.SpaceBoundByWidthAt initialSpace (fun (inputLength : ) => first.effect (values inputLength)) width) :
(first.seq second).SpaceBoundByWidthAt initialSpace values width

Sequential pointwise width certificates compose along the first phase's exact pure effect.

theorem Complexity.BinaryRoutine.SpaceBoundByWidthAt.seqList {n : } (routines : List (BinaryRoutine n)) {initialSpace : } {values : BinaryValues n} {width : } (hspace : SeqListSpaceBoundByWidthAt routines initialSpace values width) :
(BinaryRoutine.seqList routines).SpaceBoundByWidthAt initialSpace values width

A list of pointwise width certificates composes along its exact pure prefix effects.

theorem Complexity.BinaryRoutine.SeqListSpaceBoundByWidthAt.append {n : } (first second : List (BinaryRoutine n)) {initialSpace : } {values : BinaryValues n} {width : } (hfirst : SeqListSpaceBoundByWidthAt first initialSpace values width) (hsecond : SeqListSpaceBoundByWidthAt second initialSpace (fun (inputLength : ) => (seqList first).effect (values inputLength)) width) :
SeqListSpaceBoundByWidthAt (first ++ second) initialSpace values width

Width certificates for two routine lists compose when the second list is certified along the first list's exact pure effect.

theorem Complexity.BinaryRoutine.SpaceBoundByWidthAt.repeatRoutine_of_invariant {n : } (count : ) (routine : BinaryRoutine n) (invariant : BinaryValues nProp) {initialSpace : } {values : BinaryValues n} {width : } (hvalues : ∀ (inputLength : ), invariant (values inputLength)) (hspace : ∀ (trajectory : BinaryValues n), (∀ (inputLength : ), invariant (trajectory inputLength))routine.SpaceBoundByWidthAt initialSpace trajectory width) (heffect : ∀ (current : BinaryValues n), invariant currentinvariant (routine.effect current)) :
(repeatRoutine count routine).SpaceBoundByWidthAt initialSpace values width

Fixed repetition has a pointwise width certificate when one invariant both supplies the body certificate and is preserved by its pure effect.

theorem Complexity.BinaryRoutine.SpaceBoundByWidthAt.branchZero {n : } {onZero onPositive : BinaryRoutine n} (idx : Fin n) {initialSpace : } {values : BinaryValues n} {width : } (hzero : onZero.SpaceBoundByWidthAt initialSpace values width) (hpositive : onPositive.SpaceBoundByWidthAt initialSpace values width) :
(BinaryRoutine.branchZero idx onZero onPositive).SpaceBoundByWidthAt initialSpace values width

Pointwise width certificates for both branches certify a zero branch.

theorem Complexity.BinaryRoutine.SpaceBoundByWidthAt.to_log {n : } {routine : BinaryRoutine n} {initialSpace : } {values : BinaryValues n} {width : } (hspace : routine.SpaceBoundByWidthAt initialSpace values width) (hinitial : BigO initialSpace fun (inputLength : ) => Nat.log 2 inputLength) (p : Polynomial ) (hwidth : ∀ (inputLength : ), width inputLength Polynomial.eval inputLength p) :
routine.SpaceBoundInLogAt initialSpace values

A polynomial upper bound on the controlling value turns a pointwise width certificate into logarithmic space.

theorem Complexity.BinaryRoutine.SpaceBoundInLogAt.emitBits {n : } (word : List Bool) {initialSpace : } {values : BinaryValues n} (hinitial : BigO initialSpace fun (inputLength : ) => Nat.log 2 inputLength) :
(BinaryRoutine.emitBits word).SpaceBoundInLogAt initialSpace values

Fixed-word emission preserves logarithmic incoming space.

theorem Complexity.BinaryRoutine.SpaceBoundInLogAt.identity {n : } {initialSpace : } {values : BinaryValues n} (hinitial : BigO initialSpace fun (inputLength : ) => Nat.log 2 inputLength) :

The routine identity preserves logarithmic incoming space.

theorem Complexity.BinaryRoutine.SpaceBoundByWidthAt.binaryFor_of_envelope {n : } {body : BinaryRoutine n} {counterIdx limitIdx : Fin n} {initialSpace : } {values : BinaryValues n} {width : } (constant : ) (henvelope : ∀ (inputLength : ), body.BinaryForSpaceEnvelope counterIdx limitIdx (initialSpace inputLength) (values inputLength) (initialSpace inputLength + constant * (width inputLength).size + constant)) :
(body.binaryFor counterIdx limitIdx).SpaceBoundByWidthAt initialSpace values width

A pointwise loop envelope of the standard width-controlled form certifies the complete binary loop without exposing its recursive maximum.

theorem Complexity.BinaryRoutine.SpaceBoundByWidthAt.binaryFor_of_clamped_body {n : } {body : BinaryRoutine n} {counterIdx limitIdx : Fin n} {initialSpace : } {values : BinaryValues n} {width : } (hlimit : ∀ (inputLength : ), values inputLength limitIdx width inputLength) (hcounter : ∀ (inputLength count : ), count < binaryForCount counterIdx limitIdx (values inputLength)body.binaryForValues counterIdx (values inputLength) count counterIdx width inputLength) (hbody : body.SpaceBoundByWidthAt (fun (code : ) => initialSpace (Nat.unpair code).1) (body.binaryForClampedValues counterIdx limitIdx values) fun (code : ) => width (Nat.unpair code).1) :
(body.binaryFor counterIdx limitIdx).SpaceBoundByWidthAt initialSpace values width

A width certificate over the canonical paired-and-clamped body trajectory lifts to the complete binary loop. The limit and every reachable counter value must fit the same width; the resulting constant is uniform in both the input index and the loop iteration.

theorem Complexity.BinaryRoutine.BinaryForSpaceEnvelope.iterationSpaceMax_le {n : } {body : BinaryRoutine n} {counterIdx limitIdx : Fin n} {initialSpace : } {initial : BinaryValues n} {bound : } (envelope : body.BinaryForSpaceEnvelope counterIdx limitIdx initialSpace initial bound) :
body.binaryForIterationSpaceMax counterIdx initialSpace initial (binaryForCount counterIdx limitIdx initial) bound

A pointwise envelope bounds the recursive maximum over all reachable iterations.

theorem Complexity.BinaryRoutine.BinaryForSpaceEnvelope.binaryForSpace_le {n : } {body : BinaryRoutine n} {counterIdx limitIdx : Fin n} {initialSpace : } {initial : BinaryValues n} {bound : } (envelope : body.BinaryForSpaceEnvelope counterIdx limitIdx initialSpace initial bound) :
body.binaryForSpace counterIdx limitIdx initialSpace initial bound

A pointwise envelope bounds the complete comparison-plus-iteration space formula of a binary count-up loop.

theorem Complexity.BinaryRoutine.BinaryForSpaceEnvelope.spaceBound_le {n : } {body : BinaryRoutine n} {counterIdx limitIdx : Fin n} {initialSpace : } {initial : BinaryValues n} {bound : } (envelope : body.BinaryForSpaceEnvelope counterIdx limitIdx initialSpace initial bound) :
(body.binaryFor counterIdx limitIdx).spaceBound initialSpace initial bound

A pointwise envelope directly bounds the advertised space budget of the corresponding proof-carrying binary loop.