Documentation

CslibFrontier.Algorithms.WordRAM.Deduplicate.Count

Native counting of one adjacent run #

The counter tests the array bound before every read and stops at the first different word. No sorting or counting oracle is used. The mathematical end index is a proof parameter and does not occur in the code or a register.

Main definitions #

Main results #

@[reducible, inline]

Input length.

@[reducible, inline]

Sorted input array.

@[reducible, inline]

Unique-key output array.

@[reducible, inline]

Multiplicity output array.

@[reducible, inline]

Input cursor.

@[reducible, inline]

Number of completed output runs.

@[reducible, inline]

Current run key.

@[reducible, inline]

Current run multiplicity.

@[reducible, inline]

Loaded input word.

@[reducible, inline]

Address temporary.

@[reducible, inline]

Constant one.

@[reducible, inline]

Run-counting loop flag.

Read the next word only if the cursor is in bounds; count it or end the run.

Count from the current cursor, starting with zero count and flag one.

theorem Cslib.Algorithms.WordRAM.Deduplicate.Count.exec {w s n start stop k : ℕ} (x : WordRAM.Data 16) (hn : x.regs len = n) (hs : x.regs src = s) (hi : x.regs idx = start) (hk : x.regs key = k) (hc : x.regs count = 0) (ha : x.regs active = 1) (ho : x.regs one = 1) (hle : start ≤ stop) (hstop : stop ≤ n) (hmem : ∀ (j : ℕ), start ≤ j → j < stop → x.mem (s + j) = k) (hnext : stop < n → x.mem (s + stop) ≠ k) (hfit : WordRAM.Fits w (s + n)) :
∃ (y : WordRAM.Data 16), WordRAM.ExecWithin w code x y (8 * (stop - start) + 10) ∧ y.regs idx = stop ∧ y.regs count = stop - start ∧ y.mem = x.mem

Count a maximal adjacent run in 8c+10 instructions, including the terminating test. stop is a proof parameter: execution learns the boundary solely through charged comparisons and loads. The source memory is unchanged. Empty runs are also admitted by this kernel.