The scan cost of a nodup list, summed over its elements, is the triangular number
ProvedScanSchemeDecoding.sum_succ_idxOfaether-catalogalgebra
The scan cost of a nodup list, summed over its elements, is the triangular number of its length. This is the list-level core of exact cost accounting.
theorem ScanSchemeDecoding.sum_succ_idxOf{γ : Type*} [DecidableEq γ] :
∀ (l : List γ), l.Nodup → ∑ x ∈ l.toFinset, (l.idxOf x + 1) = triangle l.length := by sorry
Formalization Note Transplanted verbatim from the Aether Catalog source Algebra/ScanSchemeDecoding/Core.lean; the statement is byte-identical to the source declaration, elaborated with autoImplicit disabled in the platform environment.
Preamble
-- Thm stub generated from Algebra/ScanSchemeDecoding/Core.lean
import Mathlib
import Definitions.Def_Algebra_ScanSchemeDecoding_Core
import Definitions.Def_Algebra_ScanSchemeDecoding_Triangle
/-!
# Scan schemes: honest uniqueness decoding and exact cost accounting
A **scan scheme** on a finite key type `α` with bucket labels in `β` is nothing but a
bucket map `bucket : α → β`. Decoding a key means scanning its bucket, in the
canonical (linear) order, until the key is found. Two things are then formalised
here, and both are *exact*, not asymptotic:
* **Honest uniqueness decoding** (`ScanScheme.honest_scanCode`,
`ScanScheme.decode_eq_some_iff`). The pair `encode x = (bucket x, idx x)`
— bucket label together with the *intra-bucket index* — decodes back to `x`, and
it is the **only** pair that does so. So `encode` is an injection into
`β × ℕ` whose decoding is unambiguous: no scheme-level ambiguity is hidden in the
cost model.
* **Exact cost accounting** (`ScanScheme.decodeCost_eq`). The total decoding cost
`∑ x, decodeCost x` equals `∑ b, triangle (fiber b).card` *on the nose*.
The two facts together turn the optimisation of scan schemes into the purely
arithmetic problem solved in `Algebra.ScanSchemeDecoding.Triangle`.
-/
open ScanSchemeDecoding
open Finset
variable {α β : Type*} [Fintype α] [LinearOrder α] [DecidableEq β]
open ScanScheme
variable (S : ScanScheme α β)Formal statement
theorem ScanSchemeDecoding.sum_succ_idxOf{γ : Type*} [DecidableEq γ] :
∀ (l : List γ), l.Nodup → ∑ x ∈ l.toFinset, (l.idxOf x + 1) = triangle l.length := by sorrySource