Documentation

Complexitylib.Classes.PPoly.Uniform.Unrolling.Generator.Finalization

Direct-unrolling finalization generator #

This module exposes the verified acceptance, dead-padding, and terminal-copy phase of the executable direct-unrolling serializer. Padding is driven by the binary available counter and the precomputed closed frontier, so the routine uses logarithmic-width work values and performs no preliminary counting pass.

Preparing the two numeric acceptance references is sound.

The arithmetic preparation domain follows from its two reusable zero counters.

@[simp]

Exact pure endpoint of acceptance-reference preparation.

Saving and emitting the original acceptance gate is sound.

theorem Complexity.CircuitUnrolling.Serializer.DirectGenerator.emitAcceptance_requires {k : } (tm : TM k) (values : BinaryValues WorkCount) (hemit : values Work.emitCounter = 0) (hcopy : values Work.copyCounter = 0) (hadd : values Work.addCounter = 0) (hmultiply : values Work.multiplyCounter = 0) :

The acceptance phase's reusable-counter domain.

@[simp]

Exact pure endpoint after the original acceptance gate.

@[simp]

The acceptance phase emits exactly the numeric acceptance gate.

The dead-gate loop's controller and emission precondition.

theorem Complexity.CircuitUnrolling.Serializer.DirectGenerator.emitPadding_spaceBoundByWidth {initialSpace : } {values : BinaryValues WorkCount} {width : } (hfrontier : ∀ (inputLength : ), values inputLength Work.frontier width inputLength) (hreference : ∀ (inputLength : ), values inputLength Work.reference₀ width inputLength) :
emitPadding.SpaceBoundByWidthAt initialSpace values width

Padding retains a fixed-width pointwise space certificate whenever its closed frontier and preserved zero reference fit that width. The number of emitted dead gates does not contribute additively to auxiliary space.

From a zero reference, padding emits exactly the closed-frontier shortfall as constant-false raw gates.

The complete finalization phase is sound.

theorem Complexity.CircuitUnrolling.Serializer.DirectGenerator.finalization_requires {k : } (tm : TM k) (values : BinaryValues WorkCount) (hemit : values Work.emitCounter = 0) (hcopy : values Work.copyCounter = 0) (hadd : values Work.addCounter = 0) (hmultiply : values Work.multiplyCounter = 0) (hle : values Work.available + 1 values Work.frontier) :

Finalization is available whenever all reusable counters are zero and the acceptance gate still fits below the closed padding frontier.

theorem Complexity.CircuitUnrolling.Serializer.DirectGenerator.finalization_spaceBoundByPolynomial {k : } (tm : TM k) (p : Polynomial ) {initialSpace : } {values : BinaryValues WorkCount} (hvalues : ∀ (inputLength : ) (index : Fin WorkCount), values inputLength index Polynomial.eval inputLength p) :
∃ (width : Polynomial ), (finalization tm).SpaceBoundByWidthAt initialSpace values fun (x : ) => Polynomial.eval x width

If every incoming work value is bounded by one fixed polynomial, then the full acceptance, padding, terminal-copy, and cleanup phase has a pointwise polynomial-width auxiliary-space certificate.

theorem Complexity.CircuitUnrolling.Serializer.DirectGenerator.finalization_space_bigO_log {k : } (tm : TM k) (p : Polynomial ) {initialSpace : } {values : BinaryValues WorkCount} (hinitial : BigO initialSpace fun (inputLength : ) => Nat.log 2 inputLength) (hvalues : ∀ (inputLength : ) (index : Fin WorkCount), values inputLength index Polynomial.eval inputLength p) :
(finalization tm).SpaceBoundInLogAt initialSpace values

Polynomially bounded incoming work values make the complete finalization phase logarithmic-space, provided the incoming auxiliary-space budget is already logarithmic.

theorem Complexity.CircuitUnrolling.Serializer.DirectGenerator.finalization_emitted_eq_numericSchedule {k : } (tm : TM k) (values : BinaryValues WorkCount) (n originalRawGateCount closedBound T finalConfigBase : ) (hn : 0 < n) (havailable : values Work.available = n + originalRawGateCount - 1) (hfrontier : values Work.frontier = n + closedBound) (hhorizon : values Work.horizon = T) (hconfigBase : values Work.configBase = finalConfigBase) :
(finalization tm).emitted values = List.flatMap CircuitCode.RawGate.encode ([numericAcceptanceGate (Fintype.card tm.Q) (stateIndex tm.toNTM tm.qhalt) (k + 2) T finalConfigBase] ++ directFinalizationSuffix n originalRawGateCount closedBound)

Under the numeric tableau endpoint equations, finalization emits exactly the serializer's acceptance gate and padded suffix.