Documentation

CslibFrontier.Algorithms.WordRAM.ExactTriangle.Instances

Native ExactTriangle instance preparation #

The input header is (D,g,n,p), followed by the three signed weight matrices. The program first computes the real class/chunk catalogue. It then visits each actual chunk and piece, reads that chunk's descriptor, computes the piece boundaries and writes its record and two zero/one matrices. The records share the already computed query arrays. Every visit uses the existing native InstancePair.program rather than assuming a matrix-preparation routine.

The output records and matrices occupy consecutive variable-size blocks. Register output names the first record, produced gives their actual number and heap is their final allocation end. Each block has six record words followed by 2nD matrix words. This module prepares instances; it does not choose a prime, evaluate their queried products or decide ExactTriangle.

Main definitions #

Main results #

PreparationInput supplies the initialized flat-program interface and derived width bounds; PreparationBounds proves the preparation time bound in the source's parameter regime. Code-stage definitions and single-visit invariants (pairInput, visit_preserves, budget_covers_loop) are exposed for interpreter and streaming clients; internal proof helpers are private.

References #

The matrix geometry follows the pinned Theorem 17 matrix construction. The native controller and resource proofs are original.

@[reducible, inline]

Outer matrix dimension.

@[reducible, inline]

Target padded middle dimension.

@[reducible, inline]

Residue modulus.

@[reducible, inline]

Computed maximum vertices per piece.

@[reducible, inline]

Computed number of pieces.

@[reducible, inline]

Actual number of nonempty query chunks.

@[reducible, inline]

Computed chunk-descriptor array.

@[reducible, inline]

First output record.

@[reducible, inline]

Number of completely written instance blocks.

@[reducible, inline]

Actual chunk count times piece count.

@[reducible, inline]

Next free output record.

@[reducible, inline]

Words per record and its two matrices.

@[reducible, inline]

Constant one.

@[reducible, inline]

Words per chunk descriptor.

@[reducible, inline]

Words per instance record.

@[reducible, inline]

Words in one matrix.

@[reducible, inline]

Original A–C residue matrix.

@[reducible, inline]

Original B–C residue matrix.

@[reducible, inline]

Descriptor/header address temporary.

@[reducible, inline]

Current chunk ordinal.

@[reducible, inline]

Current piece ordinal.

@[reducible, inline]

Residue loaded from the actual chunk descriptor.

@[reducible, inline]

Query pointer loaded from the actual chunk descriptor.

@[reducible, inline]

Query count loaded from the actual chunk descriptor.

@[reducible, inline]

First vertex of the current piece.

@[reducible, inline]

Actual length of the current piece.

@[reducible, inline]

Original weight-matrix area temporary.

Existing catalogue computation in the lower thirty-two registers.

Save the actual catalogue outputs and compute the allocation stride and residue bases.

Compute the chunk and piece ordinals, then load the real query reference and piece bounds.

Deliver every actual pointer, coordinate and count to the existing instance-pair ABI.

Advance only after the complete pair has been written.

One actual instance; every selection, argument-delivery and matrix instruction is native.

Prepare every actual chunk/piece pair after computing the catalogue.

The catalogue prefix, twenty-six setup instructions, each 40nD+66 visit and its two loop instructions, the two loop-exit instructions and the final halt are accounted separately.

Original-header bound for all arithmetic and allocated addresses. The conservative maximum p*n² chunk count and n pieces cover every actual catalogue entry. Signed weights have their separate magnitude fit premise; no layout information is supplied by the caller.

One bounded instruction graph with no word-size reads.

One instance visit preserves metadata except its heap and logical progress counters.

theorem Cslib.Algorithms.WordRAM.ExactTriangle.Instances.budget_covers_loop {n D g p K H B : ℕ} (hK : K ≤ p * (n * n)) (hH : H ≤ n) (hHB : H * B ≤ n * n) :
2 * (5 + 6 * (n * n) + p + 2 * (n * n) * p + 3 * K) + K * H * (6 + 2 * (n * D)) + 11 * (n * n) + 2 * p + n + H + H * B + K * H + 26 ≤ budget n D g p

The original input budget covers every visit using the actual chunk and piece bounds.

Specification of the delivered metadata, not a runtime layout input. Scratch registers are irrelevant: the pair arguments and record words read only registers 17–28.

theorem Cslib.Algorithms.WordRAM.ExactTriangle.Instances.exec_visit {w : ℕ} (x : WordRAM.Data 64) (L R : ℕ → ℕ) (ho : x.regs one = 1) (ht : x.regs three = 3) (hH : 0 < x.regs pieces) (hi : x.regs produced < x.regs chunks * x.regs pieces) (hstride : x.regs stride = 6 + 2 * (x.regs size * x.regs dimension)) (hstart : x.regs produced % x.regs pieces * x.regs pieceLength ≤ x.regs size) (hrho : x.mem (x.regs produced / x.regs pieces * 3 + x.regs descriptors) < x.regs modulus) (hL : ∀ i < x.regs size * x.regs size, L i < x.regs modulus) (hR : ∀ i < x.regs size * x.regs size, R i < x.regs modulus) (hleft : ∀ i < x.regs size * x.regs size, x.mem (x.regs srcLeft + i) = L i) (hright : ∀ i < x.regs size * x.regs size, x.mem (x.regs srcRight + i) = R i) (hsL : x.regs srcLeft + x.regs size * x.regs size ≤ x.regs heap) (hsR : x.regs srcRight + x.regs size * x.regs size ≤ x.regs heap) (hfit : WordRAM.Fits w (x.regs heap + x.regs stride + x.regs srcLeft + x.regs srcRight + 2 * (x.regs size * x.regs size) + 2 * x.regs modulus + x.regs descriptors + 3 * x.regs chunks + x.regs size + x.regs pieces + x.regs pieces * x.regs pieceLength + x.regs produced + 16)) :
have B := pairInput x; have M := x.regs size * x.regs dimension; ∃ (y : WordRAM.Data 64), WordRAM.ExecWithin w visit x y (40 * M + 66) ∧ y.regs produced = x.regs produced + 1 ∧ y.regs heap = x.regs heap + x.regs stride ∧ { base := x.regs heap, length := 6 }.Realizes y.mem (InstancePair.recordWords B) ∧ ({ base := (InstancePair.leftArgs B).dst, length := M }.Realizes y.mem fun (i : Fin { base := (InstancePair.leftArgs B).dst, length := M }.length) => WriteMatrices.entry false (InstancePair.leftArgs B) L ↑i) ∧ ({ base := (InstancePair.rightArgs B).dst, length := M }.Realizes y.mem fun (i : Fin { base := (InstancePair.rightArgs B).dst, length := M }.length) => WriteMatrices.entry true (InstancePair.rightArgs B) R ↑i) ∧ ∀ (a : ℕ), ¬(x.regs heap ≤ a ∧ a < x.regs heap + x.regs stride) → y.mem a = x.mem a

Execute one logical chunk/piece at the current heap pointer. Previous records and dirty scratch outside its destination span are unrestricted. All native argument delivery and both matrix calls are included in the charge.

def Cslib.Algorithms.WordRAM.ExactTriangle.Instances.Output (n D g p : ℕ) (values : ℕ → ℤ) (initial y : WordRAM.Data 64) :

Exact computed catalogue, record and raw zero/one matrix readback, with the complete input/output frame. The matrix predicates reuse the existing writer arguments and entry semantics.

theorem Cslib.Algorithms.WordRAM.ExactTriangle.Instances.exec_at_with_prefix {w : ℕ} (n D g p : ℕ) (values : ℕ → ℤ) (initial : WordRAM.Data 64) (hDHeader : initial.mem 1 = D) (hgHeader : initial.mem 2 = g) (hnHeader : initial.mem 3 = n) (hpHeader : initial.mem 4 = p) (hinput : ∀ q < 3 * (n * n), initial.mem (5 + q) = WordRAM.Signed.encode (values q)) (hD : 1 ≤ D) (hDn : D ≤ n) (hg : 1 ≤ g) (hp : 0 < p) (hmod : GenericRAM.Signed.Fits w ↑p) (hvalues : ∀ q < 3 * (n * n), GenericRAM.Signed.Fits w (values q)) (hbudget : WordRAM.Fits (w + 2) (budget n D g p)) :
have N := n * n; have R := fun (q : ℕ) => (values q % ↑p).toNat; have C := fun (rho : ℕ) => Nat.count (fun (q : ℕ) => R q = rho) N; have K := ChunkCatalogue.before C (ExactTriangle.queryCap n D) p; have H := ExactTriangle.numPieces n D g; ∃ (y : WordRAM.Data 64), WordRAM.ExecWithin (w + 2) program initial y (timeBound n D p K H - 1) ∧ Output n D g p values initial y ∧ ∃ (b : WordRAM.Data 64), WordRAM.ExecWithin (w + 2) (catalogue.seq setup) initial b (Catalogue.cost n D p + 26) ∧ b.regs size = n ∧ b.regs dimension = D ∧ b.regs modulus = p ∧ b.regs pieceLength = ExactTriangle.pieceSize D g ∧ b.regs pieces = ExactTriangle.numPieces n D g ∧ b.regs chunks = K ∧ b.regs descriptors = 5 + 6 * N + p + 2 * N * p ∧ b.regs output = y.regs output ∧ b.regs produced = 0 ∧ b.regs total = y.regs produced ∧ b.regs heap = b.regs output ∧ b.regs stride = 6 + 2 * (n * D) ∧ b.regs one = 1 ∧ b.regs three = 3 ∧ b.regs srcLeft = 5 + 5 * N ∧ b.regs srcRight = 5 + 4 * N ∧ Set.EqOn b.mem y.mem (Set.Iio (b.regs output)) ∧ ∀ (u : ℕ), u < 5 + 3 * N ∨ b.regs output ≤ u → b.mem u = initial.mem u

Execute the complete preparation from the real header and signed matrices. Every output record refers to the actual computed query chunk, followed by its raw zero/one matrix pair. The only resource premises concern the original signed values and the explicit numeric budget; neither a catalogue nor a layout or execution certificate is an input. The final halt is excluded here and added by the initialized flat-program client.

theorem Cslib.Algorithms.WordRAM.ExactTriangle.Instances.exec_at {w : ℕ} (n D g p : ℕ) (values : ℕ → ℤ) (initial : WordRAM.Data 64) (hDHeader : initial.mem 1 = D) (hgHeader : initial.mem 2 = g) (hnHeader : initial.mem 3 = n) (hpHeader : initial.mem 4 = p) (hinput : ∀ q < 3 * (n * n), initial.mem (5 + q) = WordRAM.Signed.encode (values q)) (hD : 1 ≤ D) (hDn : D ≤ n) (hg : 1 ≤ g) (hp : 0 < p) (hmod : GenericRAM.Signed.Fits w ↑p) (hvalues : ∀ q < 3 * (n * n), GenericRAM.Signed.Fits w (values q)) (hbudget : WordRAM.Fits (w + 2) (budget n D g p)) :
have N := n * n; have R := fun (q : ℕ) => (values q % ↑p).toNat; have C := fun (rho : ℕ) => Nat.count (fun (q : ℕ) => R q = rho) N; have K := ChunkCatalogue.before C (ExactTriangle.queryCap n D) p; have H := ExactTriangle.numPieces n D g; ∃ (y : WordRAM.Data 64), WordRAM.ExecWithin (w + 2) program initial y (timeBound n D p K H - 1) ∧ Output n D g p values initial y

Complete native preparation from the real original input, preserving the standalone all-record producer contract and halt-exclusive allowance.