Documentation

CslibFrontier.Foundations.Data.List.SumIndicator

Sums of indicators over lists #

Indicator sums over List.range n reduce to the finite-sum indicator API through List.sum_map_range: the indicator of a single index sums to whether the index is in range (List.sum_map_range_ite_eq). A condition that does not depend on the element comes out of the sum (List.sum_map_ite_and).

Main results #

theorem List.sum_map_range_ite_eq {M : Type u_1} [AddCommMonoid M] (n i₀ : ℕ) (b : M) :
(map (fun (i : ℕ) => if i = i₀ then b else 0) (range n)).sum = if i₀ < n then b else 0

The indicator of a single index sums over List.range n to b when the index is below n, and to 0 otherwise.

theorem List.sum_map_ite_and {M : Type u_1} [AddCommMonoid M] {α : Type u_2} (l : List α) (P : Prop) [Decidable P] (Q : α → Prop) [DecidablePred Q] (b : M) :
(map (fun (a : α) => if P ∧ Q a then b else 0) l).sum = if P then (map (fun (a : α) => if Q a then b else 0) l).sum else 0

A conjunct of an indicator that does not depend on the element comes out of the sum.