Documentation

CslibFrontier.Algorithms.WordRAM.ThreeSum.Frontend.Scan

Compact native frontend scans #

Each pass reads both canonical keys and their full multiplicities. It appends only selected keys to a disjoint destination. The singleton-zero arrays are written separately, so empty input needs no exceptional semantics.

Main definitions #

@[reducible, inline]

Key pointer, count pointer and number of distinct keys.

@[reducible, inline]

Key pointer, count pointer and number of distinct keys.

@[reducible, inline]

Key pointer, count pointer and number of distinct keys.

@[reducible, inline]

Output pointer, input cursor and output length.

@[reducible, inline]

Output pointer, input cursor and output length.

@[reducible, inline]

Output pointer, input cursor and output length.

@[reducible, inline]

Address scratch.

Load one full key/count pair, compute its selection, optionally append, and advance.

theorem Cslib.Algorithms.WordRAM.ThreeSum.Frontend.Scan.step {w : ℕ} (x : WordRAM.Data 48) (hz : x.regs Select.zero = 0) (h1 : x.regs Select.one = 1) (h2 : x.regs Select.two = 2) (h3 : x.regs Select.three = 3) (h4 : x.regs Select.four = 4) (h5 : x.regs Select.five = 5) (hsmall : WordRAM.Fits w 5) (hkaddr : WordRAM.Fits w (x.regs keys + x.regs idx)) (hcaddr : WordRAM.Fits w (x.regs counts + x.regs idx)) (hdaddr : WordRAM.Fits w (x.regs dst + x.regs out)) (hi : WordRAM.Fits w (x.regs idx + 1)) (ho : WordRAM.Fits w (x.regs out + 1)) (hkey : WordRAM.Fits w (x.mem (x.regs keys + x.regs idx))) (habs : x.mem (x.regs keys + x.regs idx) / 2 ≤ 2 * x.regs Select.magnitude) (hfit : WordRAM.Fits w (4 * x.regs Select.magnitude + 2)) (hdouble : WordRAM.Fits w (2 * x.mem (x.regs keys + x.regs idx))) :

One charged compacting iteration.

theorem Cslib.Algorithms.WordRAM.ThreeSum.Frontend.Scan.exec {w : ℕ} (rs : List (ℕ × ℕ)) (x : WordRAM.Data 48) (hn : x.regs len = rs.length) (hz : x.regs Select.zero = 0) (h1 : x.regs Select.one = 1) (h2 : x.regs Select.two = 2) (h3 : x.regs Select.three = 3) (h4 : x.regs Select.four = 4) (h5 : x.regs Select.five = 5) (hk : WordRAM.Block.HoldsList (x.regs keys) (List.map Prod.fst rs) x.mem) (hc : WordRAM.Block.HoldsList (x.regs counts) (List.map Prod.snd rs) x.mem) (hkey : ∀ p ∈ rs, WordRAM.Fits w p.1) (habs : ∀ p ∈ rs, p.1 / 2 ≤ 2 * x.regs Select.magnitude) (hdouble : ∀ p ∈ rs, WordRAM.Fits w (2 * p.1)) (hfit : WordRAM.Fits w (4 * x.regs Select.magnitude + 2)) (hsmall : WordRAM.Fits w 5) (hka : WordRAM.Fits w (x.regs keys + rs.length)) (hca : WordRAM.Fits w (x.regs counts + rs.length)) (hda : WordRAM.Fits w (x.regs dst + rs.length + 1)) (hkd : x.regs keys + rs.length ≤ x.regs dst) (hcd : x.regs counts + rs.length ≤ x.regs dst) :

Complete compact scan, with arbitrary old output/scratch memory and an exact memory frame. The source key/count blocks precede the output; their contents and all caller registers that the body does not write are retained.