Documentation

Mathlib.Algebra.BigOperators.Group.List.Lemmas

Sums and products from lists #

This file provides further results about List.prod, List.sum, which calculate the product and sum of elements of a list and List.alternatingProd, List.alternatingSum, their alternating counterparts.

theorem List.prod_isUnit {M : Type u_4} [Monoid M] {L : List M} :
(โˆ€ m โˆˆ L, IsUnit m) โ†’ IsUnit L.prod
theorem List.sum_isAddUnit {M : Type u_4} [AddMonoid M] {L : List M} :
(โˆ€ m โˆˆ L, IsAddUnit m) โ†’ IsAddUnit L.sum
theorem List.prod_isUnit_iff {M : Type u_8} [CommMonoid M] {L : List M} :
IsUnit L.prod โ†” โˆ€ m โˆˆ L, IsUnit m
theorem List.sum_isAddUnit_iff {M : Type u_8} [AddCommMonoid M] {L : List M} :
IsAddUnit L.sum โ†” โˆ€ m โˆˆ L, IsAddUnit m
theorem List.Perm.prod_eq' {M : Type u_4} [Monoid M] {lโ‚ lโ‚‚ : List M} (h : lโ‚.Perm lโ‚‚) (hc : Pairwise Commute lโ‚) :
lโ‚.prod = lโ‚‚.prod

If elements of a list commute with each other, then their product does not depend on the order of elements.

theorem List.Perm.sum_eq' {M : Type u_4} [AddMonoid M] {lโ‚ lโ‚‚ : List M} (h : lโ‚.Perm lโ‚‚) (hc : Pairwise AddCommute lโ‚) :
lโ‚.sum = lโ‚‚.sum

If elements of a list additively commute with each other, then their sum does not depend on the order of elements.

theorem List.prod_rotate_eq_one_of_prod_eq_one {G : Type u_7} [Group G] {l : List G} :
l.prod = 1 โ†’ โˆ€ (n : โ„•), (l.rotate n).prod = 1
theorem List.sum_map_count_dedup_filter_eq_countP {ฮฑ : Type u_2} [DecidableEq ฮฑ] (p : ฮฑ โ†’ Bool) (l : List ฮฑ) :
(map (fun (x : ฮฑ) => count x l) (filter p l.dedup)).sum = countP p l

Summing the count of x over a list filtered by some p is just countP applied to p

theorem List.sum_map_count_dedup_eq_length {ฮฑ : Type u_2} [DecidableEq ฮฑ] (l : List ฮฑ) :
(map (fun (x : ฮฑ) => count x l) l.dedup).sum = l.length
theorem List.length_sigma {ฮฑ : Type u_2} {ฯƒ : ฮฑ โ†’ Type u_8} (lโ‚ : List ฮฑ) (lโ‚‚ : (a : ฮฑ) โ†’ List (ฯƒ a)) :
(lโ‚.sigma lโ‚‚).length = (map (fun (a : ฮฑ) => (lโ‚‚ a).length) lโ‚).sum
theorem List.ranges_nodup {l s : List โ„•} (hs : s โˆˆ l.ranges) :

The members of l.ranges have no duplicates

theorem List.mem_mem_ranges_iff_lt_sum (l : List โ„•) {n : โ„•} :
(โˆƒ s โˆˆ l.ranges, n โˆˆ s) โ†” n < l.sum

Any entry of any member of l.ranges is strictly smaller than l.sum.

theorem List.drop_take_succ_flatten_eq_getElem {ฮฑ : Type u_2} (L : List (List ฮฑ)) (i : โ„•) (h : i < L.length) :
drop (take i (map length L)).sum (take (take (i + 1) (map length L)).sum L.flatten) = L[i]

In a flatten of sublists, taking the slice between the indices A and B - 1 gives back the original sublist of index i if A is the sum of the lengths of sublists of index < i, and B is the sum of the lengths of sublists of index โ‰ค i.

If a product of integers is -1, then at least one factor must be -1.

theorem List.dvd_prod {M : Type u_4} [CommMonoid M] {a : M} {l : List M} (ha : a โˆˆ l) :
theorem List.Sublist.prod_dvd_prod {M : Type u_4} [CommMonoid M] {lโ‚ lโ‚‚ : List M} (h : lโ‚.Sublist lโ‚‚) :
lโ‚.prod โˆฃ lโ‚‚.prod
theorem List.alternatingProd_append {G : Type u_7} [CommGroup G] (lโ‚ lโ‚‚ : List G) :
(lโ‚ ++ lโ‚‚).alternatingProd = lโ‚.alternatingProd * lโ‚‚.alternatingProd ^ (-1) ^ lโ‚.length
theorem List.alternatingSum_append {G : Type u_7} [AddCommGroup G] (lโ‚ lโ‚‚ : List G) :
(lโ‚ ++ lโ‚‚).alternatingSum = lโ‚.alternatingSum + (-1) ^ lโ‚.length โ€ข lโ‚‚.alternatingSum

A morphism into the opposite monoid acts on the product by acting on the reversed elements.