Dynamic prefix sums #
The abstract state is a list over an additive commutative monoid. add pos δ increments one
entry; out-of-range positions leave the list unchanged. sum len returns the sum of the first
len entries; a length beyond the end sums the whole list. Every operation is admissible, and
the length of the list never changes. The module chooses no representation and charges no cost;
an implementation with machine bounds, such as a word-fit condition, restricts spec.valid.
Main definitions #
Cslib.DataStructure.PrefixSums.addAt: point increment on a list.Cslib.DataStructure.PrefixSums.Op,Cslib.DataStructure.PrefixSums.step,Cslib.DataStructure.PrefixSums.spec: typed operations and their list semantics.
Main results #
Cslib.DataStructure.PrefixSums.length_addAt,Cslib.DataStructure.PrefixSums.getD_addAt,Cslib.DataStructure.PrefixSums.addAt_of_length_le: the point increment changes one entry.Cslib.DataStructure.PrefixSums.addAt_append: a point increment of a concatenation updates the part containing the position.Cslib.DataStructure.PrefixSums.length_stepFn: every operation preserves the length.
References #
def Cslib.DataStructure.PrefixSums.addAt {α : Type u_1} [AddZeroClass α] (s : List α) (pos : ℕ) (δ : α) :
List α
Point increment on a list at 0-based index pos (no-op when s.length ≤ pos).
@[simp]
theorem Cslib.DataStructure.PrefixSums.length_addAt {α : Type u_1} [AddZeroClass α] (s : List α) (pos : ℕ) (δ : α) :
theorem Cslib.DataStructure.PrefixSums.addAt_of_length_le {α : Type u_1} [AddZeroClass α] {s : List α} {pos : ℕ} (δ : α) (h : s.length ≤ pos) :
theorem Cslib.DataStructure.PrefixSums.addAt_append {α : Type u_1} [AddZeroClass α] (s t : List α) (pos : ℕ) (δ : α) :
A point increment of a concatenation updates the part containing the position.
@[instance_reducible]
instance Cslib.DataStructure.PrefixSums.instDecidableEqOp {α✝ : Type} [DecidableEq α✝] :
DecidableEq (Op α✝)
def Cslib.DataStructure.PrefixSums.instDecidableEqOp.decEq {α✝ : Type} [DecidableEq α✝] (x✝ x✝¹ : Op α✝) :
Pure transition function of dynamic prefix sums on List α.
@[simp]
theorem Cslib.DataStructure.PrefixSums.length_stepFn {α : Type} [AddCommMonoid α] (s : List α) (o : Op α) :
Every operation preserves the length of the list.