Documentation

CslibFrontier.Algorithms.WordRAM.ExactTriangle.FixedPrime.Potential

Paying for the native catalogue traversal #

The remaining potential reserves one successful scan in total. A failed call consumes only its own distinct failed occurrences; a successful call consumes that reserve and terminates the traversal. These internal arithmetic lemmas do not provide an execution or cost oracle.

theorem Cslib.Algorithms.WordRAM.ExactTriangle.FixedPrime.pay_return {T base C scans failures flag restBase restFailures : ℕ} (hT : T + 2 ≤ base + C * scans) (hscans : scans ≤ failures + flag) (hflag : flag ≤ 1) :
T + 2 + (restBase + C * (restFailures + 1 - flag)) ≤ base + restBase + C * (failures + restFailures + 1)

One actual return consumes its failed occurrences and, only on success, the single reserve. The base charge includes this iteration's real call/controller/loop overhead.

theorem Cslib.Algorithms.WordRAM.ExactTriangle.FixedPrime.sum_prefix_le (charge : ℕ → ℕ) {i M : ℕ} (hi : i ≤ M) :
∑ j ∈ Finset.range i, charge j ≤ ∑ j ∈ Finset.range M, charge j

Nonnegative charges in a visited prefix are bounded by those in the complete range.

Reserve potential for a concrete finite sequence of base and failed-occurrence charges.

theorem Cslib.Algorithms.WordRAM.ExactTriangle.FixedPrime.remainingCharge_step {base failures : ℕ → ℕ} {C M i T scans flag : ℕ} (hi : i < M) (hT : T + 2 ≤ base i + C * scans) (hscans : scans ≤ failures i + flag) (hflag : flag ≤ 1) :
T + 2 + remainingCharge base failures C M (i + 1) flag ≤ remainingCharge base failures C M i 0

The actual per-call bound decreases the potential by the charged body and loop work. The loop invariant establishes zero prior success whenever its guard still holds.