Documentation

CslibFrontier.Algorithms.WordRAM.ExactTriangle.WriteMatrices

Native zero/one matrices for an Exact Triangle instance #

The input contains ordinary unsigned residues. Each output cell computes its row, middle vertex and label through charged division/remainder instructions. Cells outside the selected piece are zero; all other cells test the required modular adjacency. The same seventeen registers serve the left n×D and right D×n matrices, with no supplied indexing table.

The X/Y output entries are raw unsigned words 0 and 1. A consumer using canonical Signed.encode matrix entries must double each entry while copying it into that input and charge the conversion instruction. Scalar headers, pointers and query coordinates remain raw unsigned words.

This directly adapts the adjacency formulas in the pinned Theorem 17 instance builder. The native implementation visits each output cell once; the source clears and then marks cells.

Main definitions #

Main results #

Runtime arguments of one matrix-building call.

  • src : ℕ

    Residue matrix base.

  • dst : ℕ

    Output matrix base.

  • n : ℕ

    Number of vertices in each outer part.

  • D : ℕ

    Padded middle dimension.

  • p : ℕ

    Positive modulus.

  • first : ℕ

    First vertex of the selected piece.

  • length : ℕ

    Number of vertices in the piece.

  • rho : ℕ

    A–B query residue.

Raw unsigned zero/one row-major adjacency. A true side chooses the right D×n matrix; false chooses the left n×D matrix. The source residue matrix has shape n×n. A signed-matrix consumer encodes these entries by doubling them.

theorem Cslib.Algorithms.WordRAM.ExactTriangle.WriteMatrices.entry_le_one (side : Bool) (A : Args) (R : ℕ → ℕ) (q : ℕ) :
entry side A R q ≤ 1

Every raw adjacency entry is a zero/one word, including padding.

@[reducible, inline]

Residue input pointer.

@[reducible, inline]

Output matrix pointer.

@[reducible, inline]

Outer dimension.

@[reducible, inline]

Middle dimension.

@[reducible, inline]

First vertex of the piece.

@[reducible, inline]

Query residue.

@[reducible, inline]

Flat output cursor.

@[reducible, inline]

Number of output cells.

@[reducible, inline]

Selected source row.

@[reducible, inline]

Selected vertex within the piece.

@[reducible, inline]

Middle label.

@[reducible, inline]

Address temporary.

@[reducible, inline]

Residue and output value temporary.

@[reducible, inline]

Constant zero.

@[reducible, inline]

Constant one.

The eight runtime arguments occupy registers 0–7.

Compute the source row and decode the middle label using actual arithmetic instructions.

Read the selected residue and form its required label.

Write one zero/one cell and increment the flat cursor.

The complete builder initializes constants and visits all output positions once.

The instruction graph has fixed size and never reads the physical word width.

theorem Cslib.Algorithms.WordRAM.ExactTriangle.WriteMatrices.exec {w : ℕ} (side : Bool) (A : Args) (R : ℕ → ℕ) (x : WordRAM.Data 17) (hx : Entry A x) (hrho : A.rho < A.p) (hpiece : A.first + A.length ≤ A.n) (hR : ∀ i < A.n * A.n, R i < A.p) (hinput : ∀ i < A.n * A.n, x.mem (A.src + i) = R i) (hsrc : WordRAM.Fits w (A.src + A.n * A.n)) (hdst : WordRAM.Fits w (A.dst + A.n * A.D)) (hmod : WordRAM.Fits w (2 * A.p)) (hdisj : A.src + A.n * A.n ≤ A.dst) :
∃ (y : WordRAM.Data 17), WordRAM.ExecWithin w (program side) x y (20 * (A.n * A.D) + 6) ∧ Entry A y ∧ y.regs idx = A.n * A.D ∧ ({ base := A.dst, length := A.n * A.D }.Realizes y.mem fun (i : Fin { base := A.dst, length := A.n * A.D }.length) => entry side A R ↑i) ∧ ∀ (a : ℕ), ¬{ base := A.dst, length := A.n * A.D }.Owns a → y.mem a = x.mem a

Construct every entry of a left or right instance matrix in 20nD+6 native instructions, excluding the halt. The source is an actual residue array below the output. All cells outside the output block and all eight arguments are preserved. No adjacency table is supplied.