Documentation

CslibFrontier.Algorithms.WordRAM.ThreeSum.ChanHe.CountPlace

A complete native counting and placement call #

This routine actually computes the residues and histogram before extracting a heavy array and placing the corresponding packed column. The histogram is not a premise of the execution contract. It also writes the compact output count to its caller-supplied descriptor cell.

Main definitions #

References #

This native composition is original and reuses the existing Chan–He mathematical definitions.

@[reducible, inline]

Input length (the selected third argument of the existing counting call).

@[reducible, inline]

Signed input base.

@[reducible, inline]

Unsigned residue workspace base.

@[reducible, inline]

Histogram workspace base.

@[reducible, inline]

Compact heavy output base.

@[reducible, inline]

Packed node array base.

@[reducible, inline]

Positive modulus, decoded unsigned.

@[reducible, inline]

Encoded positive tag.

@[reducible, inline]

Packed column.

@[reducible, inline]

Distance between the two stores.

@[reducible, inline]

Zero for X/Y, one for Z.

@[reducible, inline]

Cell in which the exact heavy count is stored.

Fixed embedding of the placement workspace below all caller parameters.

@[reducible, inline]

Input array base.

@[reducible, inline]

Unsigned residue array base.

@[reducible, inline]

Input length.

@[reducible, inline]

Histogram base.

@[reducible, inline]

Compact heavy output base.

@[reducible, inline]

Packed node output base.

@[reducible, inline]

Positive modulus, decoded unsigned.

@[reducible, inline]

Twice the positive tag added to a light integer.

@[reducible, inline]

Column in a four-cell group.

@[reducible, inline]

Distance to the second write: zero for X/Y, 4M for Z.

@[reducible, inline]

Zero for X/Y, one for Z.

@[reducible, inline]

Number of heavy integers already written.

All eleven runtime argument copies are real instructions.

Complete fixed native routine: no host histogram, heavy filter or output constructor.

Only the counting/placement workspace, the encoded modulus, and the discarded collision counter can change. All caller registers at least 46 are included in this frame.

Polynomial envelope for addresses, counters, encoded magnitudes and every scan intermediate.

def Cslib.Algorithms.WordRAM.ThreeSum.ChanHe.CountPlace.memory (mem : ℕ → ℕ) (values : ℕ → ℤ) (n M out dst col dist t scratch hist descriptor : ℕ) (neg : Bool) :
ℕ → ℕ

Exact memory, including actual residue/histogram construction and the descriptor write.

theorem Cslib.Algorithms.WordRAM.ThreeSum.ChanHe.CountPlace.exec {w M N U t : ℕ} (x : WordRAM.Data 64) (values : ℕ → ℤ) (neg : Bool) (hM : 0 < M) (hmod : GenericRAM.Signed.Fits w ↑M) (hmreg : x.regs modulus = M) (hN : 2 * M ≤ N) (ht : U ≤ t) (htag : x.regs tag = 2 * t) (hneg : x.regs negative = if neg = true then 1 else 0) (hc : x.regs column < 4) (hd : x.regs distance ≤ 4 * M) (hbdd : ∀ i < x.regs len, (values i).natAbs ≤ U) (hsigned : ∀ i < x.regs len, GenericRAM.Signed.Fits w (values i)) (hfit : WordRAM.Fits (w + 2) (budget x M N U t)) (hsh : x.regs src + x.regs len ≤ x.regs heavy) (hhp : x.regs heavy + x.regs len ≤ x.regs packed) (hpk : x.regs packed + 4 * N ≤ x.regs scratch) (hkh : x.regs scratch + x.regs len ≤ x.regs hist) (hinput : ∀ i < x.regs len, x.mem (x.regs src + i) = WordRAM.Signed.encode (values i)) (hinj : Set.InjOn values ↑(Finset.range (x.regs len))) :
∃ (y : WordRAM.Data 64), WordRAM.ExecWithin (w + 2) program x y (66 * x.regs len + 5 * M + 45) ∧ y.mem = memory x.mem values (x.regs len) M (x.regs heavy) (x.regs packed) (x.regs column) (x.regs distance) t (x.regs scratch) (x.regs hist) (x.regs descriptor) neg ∧ ∀ (i : Fin 64), 32 ≤ ↑i → i ≠ CountCall.modulus → i ≠ CountCall.result 2 → y.regs i = x.regs i

Complete native count/extract/place execution, charging modulus encoding, all subroutine argument/result copies and the final count write. The caller supplies actual signed input words; no histogram or light/heavy-output contract is assumed.