Documentation

CslibFrontier.Algorithms.WordRAM.ThreeSum.Frontend.Layout

Native frontend descriptor layout #

Descriptors have six words, three consecutive (length,pointer) pairs. Arrays occupy disjoint blocks of capacity n+1; unused capacity is outside the compact enumeration. The first four n-word blocks remain reserved for radix sorting and full multiplicities.

Main definitions #

Concrete layout at input length n and runtime label-bit budget Λ.

  • n : ℕ

    Input length.

  • digits : ℕ

    Number of label bits.

Total descriptor count, including the two multiplicity triples.

Capacity allows singleton zero even when the original input is empty.

Descriptor table follows all four radix buffers.

Payload blocks follow the complete descriptor table.

One-past-end address of all allocated blocks.

Payload pointers advance by the full reserved capacity.

Payload blocks occur in allocation order.

Every descriptor word precedes every payload block.

Selection mode for a physical array slot.

Bit coordinates of a physical slot in the split part of the table.

Bit coordinates of a physical slot in the split part of the table.

Bit coordinates of a physical slot in the split part of the table.

Compact encoded list for one physical array slot.

theorem Cslib.Algorithms.WordRAM.ThreeSum.Frontend.Math.select_extra (U β β' v mode : ℕ) (rs : List (ℕ × ℕ)) (hm : 3 ≤ mode) :
select U β β' v mode rs = select U 0 0 0 mode rs

The two bit coordinates are irrelevant in the three nonsplitting scan modes.

theorem Cslib.Algorithms.WordRAM.ThreeSum.Frontend.Math.array_split (U Λ : ℕ) (rs : List (ℕ × ℕ)) (t s : ℕ) (ht : t < 2 * Λ ^ 2) (hs : s < 3) :
array U Λ rs (3 * t + s) = select U (t / 2 / Λ) (t / 2 % Λ) (t % 2) s rs

Physical array slots within a split triple follow A, B₀, B₁ order.

Read the three array specifications belonging to a descriptor.

theorem Cslib.Algorithms.WordRAM.ThreeSum.Frontend.Math.root_split (U Λ : ℕ) (rs : List (ℕ × ℕ)) (t : ℕ) (ht : t < 2 * Λ ^ 2) :
root U Λ rs t = { first := select U (t / 2 / Λ) (t / 2 % Λ) (t % 2) 0 rs, second := select U (t / 2 / Λ) (t / 2 % Λ) (t % 2) 1 rs, third := select U (t / 2 / Λ) (t / 2 % Λ) (t % 2) 2 rs }

A descriptor in the split prefix has exactly the requested three compact selections.

theorem Cslib.Algorithms.WordRAM.ThreeSum.Frontend.Math.root_extras (U Λ : ℕ) (rs : List (ℕ × ℕ)) :
root U Λ rs (2 * Λ ^ 2) = { first := select U 0 0 0 3 rs, second := [0], third := select U 0 0 0 5 rs } ∧ root U Λ rs (2 * Λ ^ 2 + 1) = { first := select U 0 0 0 4 rs, second := [0], third := [0] }

The two final descriptors retain their singleton zeros and exact multiplicity scans.

Every array fits in its n+1 capacity, including empty-input singleton zeros.

Every descriptor represents an injective enumeration.

theorem Cslib.Algorithms.WordRAM.ThreeSum.Frontend.Math.array_values {input : List ℤ} {rs : List (ℕ × ℕ)} (hkeys : ∀ (k : ℕ), k ∈ List.map Prod.fst rs ↔ k ∈ List.map WordRAM.Signed.encode input) (U Λ j u : ℕ) (hu : u ∈ array U Λ rs j) :
u = 0 ∨ ∃ z ∈ input, u = WordRAM.Signed.encode z ∨ u = WordRAM.Signed.encode (2 * z)

Each output word is canonical zero, an original input key, or the key of twice an input.

Every compact output word is a canonical signed encoding.

Injectivity holds for the represented integer array, as well as its native keys.

theorem Cslib.Algorithms.WordRAM.ThreeSum.Frontend.Math.array_magnitude {input : List ℤ} {rs : List (ℕ × ℕ)} {U : ℕ} (hkeys : ∀ (k : ℕ), k ∈ List.map Prod.fst rs ↔ k ∈ List.map WordRAM.Signed.encode input) (hvalues : ∀ z ∈ input, |z| ≤ ↑U) (Λ j u : ℕ) (hu : u ∈ array U Λ rs j) :

Every decoded payload integer has the exact reduction's common magnitude bound 2U.

The compact root lists before their native layout is assigned.

Decode a compact triple to the finite sets used by the existing reduction.

theorem Cslib.Algorithms.WordRAM.ThreeSum.Frontend.Math.roots_decoded {input : List ℤ} {rs : List (ℕ × ℕ)} {U : ℕ} (hkeys : ∀ (k : ℕ), k ∈ List.map Prod.fst rs ↔ k ∈ List.map WordRAM.Signed.encode input) (hcounts : ∀ p ∈ rs, List.count p.1 (List.map WordRAM.Signed.encode input) = p.2) (hvalues : ∀ z ∈ input, |z| ≤ ↑U) :
List.map decodeRoot (roots U rs) = ThreeSum.inputs U fun (i : Fin input.length) => input[i]

Exact list equality with ThreeSum.inputs, preserving root order and every empty array.

theorem Cslib.Algorithms.WordRAM.ThreeSum.Frontend.Math.roots_indexed (U : ℕ) (rs : List (ℕ × ℕ)) :
have Λ := ThreeSum.labelBits (2 * U); List.map (root U Λ rs) (List.range (2 * Λ ^ 2 + 2)) = roots U rs

Physical descriptor indices have exactly the nested order of the finite root list.

Exact descriptor and compact payload readback. Unused capacity is unrestricted.

Follow one (length,pointer) pair in native memory. This is output interpretation, not an instruction or an assumed computation by the frontend.

Follow all six-word descriptors in order and decode their represented sets.

theorem Cslib.Algorithms.WordRAM.ThreeSum.Frontend.Output.read_array {l : Layout} {U : ℕ} {rs : List (ℕ × ℕ)} {mem : ℕ → ℕ} (h : Output l U rs mem) {j : ℕ} (hj : j < l.arrays) :
readArray mem (l.descriptors + 2 * j) = Math.array U l.digits rs j

Exact slot readback includes zero-length arrays and ignores unused capacity.

theorem Cslib.Algorithms.WordRAM.ThreeSum.Frontend.Output.readback {n U : ℕ} {input : List ℤ} {rs : List (ℕ × ℕ)} {mem : ℕ → ℕ} (h : Output { n := n, digits := ThreeSum.labelBits (2 * U) } U rs mem) (hkeys : ∀ (k : ℕ), k ∈ List.map Prod.fst rs ↔ k ∈ List.map WordRAM.Signed.encode input) (hcounts : ∀ p ∈ rs, List.count p.1 (List.map WordRAM.Signed.encode input) = p.2) (hvalues : ∀ z ∈ input, |z| ≤ ↑U) :
readRoots { n := n, digits := ThreeSum.labelBits (2 * U) } mem = ThreeSum.inputs U fun (i : Fin input.length) => input[i]

The descriptor table reads back as exactly the existing finite frontend list, in order.