Documentation

Mathlib.Algebra.BigOperators.List.Basic

Sums and products from lists #

This file provides basic 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.

def List.sum {α : Type u_11} [Add α] [Zero α] :
List αα

Sum of a list.

List.sum [a, b, c] = ((0 + a) + b) + c

Equations
Instances For
    def List.prod {α : Type u_11} [Mul α] [One α] :
    List αα

    Product of a list.

    List.prod [a, b, c] = ((1 * a) * b) * c

    Equations
    Instances For
      def List.alternatingSum {G : Type u_11} [Zero G] [Add G] [Neg G] :
      List GG

      The alternating sum of a list.

      Equations
      Instances For
        def List.alternatingProd {G : Type u_11} [One G] [Mul G] [Inv G] :
        List GG

        The alternating product of a list.

        Equations
        Instances For
          @[simp]
          theorem List.sum_nil {M : Type u_5} [AddZeroClass M] :
          List.sum [] = 0
          @[simp]
          theorem List.prod_nil {M : Type u_5} [MulOneClass M] :
          theorem List.sum_singleton {M : Type u_5} [AddZeroClass M] {a : M} :
          List.sum [a] = a
          theorem List.prod_singleton {M : Type u_5} [MulOneClass M] {a : M} :
          List.prod [a] = a
          @[simp]
          theorem List.sum_zero_cons {M : Type u_5} [AddZeroClass M] {l : List M} :
          @[simp]
          theorem List.prod_one_cons {M : Type u_5} [MulOneClass M] {l : List M} :
          theorem List.sum_map_zero {ι : Type u_1} {M : Type u_5} [AddZeroClass M] {l : List ι} :
          List.sum (List.map (fun (x : ι) => 0) l) = 0
          theorem List.prod_map_one {ι : Type u_1} {M : Type u_5} [MulOneClass M] {l : List ι} :
          List.prod (List.map (fun (x : ι) => 1) l) = 1
          @[simp]
          theorem List.sum_cons {M : Type u_5} [AddMonoid M] {l : List M} {a : M} :
          List.sum (a :: l) = a + List.sum l
          @[simp]
          theorem List.prod_cons {M : Type u_5} [Monoid M] {l : List M} {a : M} :
          theorem List.sum_induction {M : Type u_5} [AddMonoid M] {l : List M} (p : MProp) (hom : ∀ (a b : M), p ap bp (a + b)) (unit : p 0) (base : xl, p x) :
          p (List.sum l)
          theorem List.prod_induction {M : Type u_5} [Monoid M] {l : List M} (p : MProp) (hom : ∀ (a b : M), p ap bp (a * b)) (unit : p 1) (base : xl, p x) :
          p (List.prod l)
          @[simp]
          theorem List.sum_append {M : Type u_5} [AddMonoid M] {l₁ : List M} {l₂ : List M} :
          List.sum (l₁ ++ l₂) = List.sum l₁ + List.sum l₂
          @[simp]
          theorem List.prod_append {M : Type u_5} [Monoid M] {l₁ : List M} {l₂ : List M} :
          List.prod (l₁ ++ l₂) = List.prod l₁ * List.prod l₂
          theorem List.sum_concat {M : Type u_5} [AddMonoid M] {l : List M} {a : M} :
          theorem List.prod_concat {M : Type u_5} [Monoid M] {l : List M} {a : M} :
          @[simp]
          theorem List.sum_join {M : Type u_5} [AddMonoid M] {l : List (List M)} :
          @[simp]
          theorem List.prod_join {M : Type u_5} [Monoid M] {l : List (List M)} :
          theorem List.sum_eq_foldr {M : Type u_5} [AddMonoid M] {l : List M} :
          List.sum l = List.foldr (fun (x x_1 : M) => x + x_1) 0 l
          abbrev List.sum_eq_foldr.match_1 {M : Type u_1} (motive : List MProp) :
          ∀ (x : List M), (Unitmotive [])(∀ (a : M) (l : List M), motive (a :: l))motive x
          Equations
          • =
          Instances For
            theorem List.prod_eq_foldr {M : Type u_5} [Monoid M] {l : List M} :
            List.prod l = List.foldr (fun (x x_1 : M) => x * x_1) 1 l
            @[simp]
            theorem List.sum_replicate {M : Type u_5} [AddMonoid M] (n : ) (a : M) :
            @[simp]
            theorem List.prod_replicate {M : Type u_5} [Monoid M] (n : ) (a : M) :
            theorem List.sum_eq_card_nsmul {M : Type u_5} [AddMonoid M] (l : List M) (m : M) (h : xl, x = m) :
            theorem List.prod_eq_pow_card {M : Type u_5} [Monoid M] (l : List M) (m : M) (h : xl, x = m) :
            theorem List.sum_hom_rel {ι : Type u_1} {M : Type u_5} {N : Type u_6} [AddMonoid M] [AddMonoid N] (l : List ι) {r : MNProp} {f : ιM} {g : ιN} (h₁ : r 0 0) (h₂ : ∀ ⦃i : ι⦄ ⦃a : M⦄ ⦃b : N⦄, r a br (f i + a) (g i + b)) :
            theorem List.prod_hom_rel {ι : Type u_1} {M : Type u_5} {N : Type u_6} [Monoid M] [Monoid N] (l : List ι) {r : MNProp} {f : ιM} {g : ιN} (h₁ : r 1 1) (h₂ : ∀ ⦃i : ι⦄ ⦃a : M⦄ ⦃b : N⦄, r a br (f i * a) (g i * b)) :
            theorem List.rel_sum {M : Type u_5} {N : Type u_6} [AddMonoid M] [AddMonoid N] {R : MNProp} (h : R 0 0) (hf : (R R R) (fun (x x_1 : M) => x + x_1) fun (x x_1 : N) => x + x_1) :
            (List.Forall₂ R R) List.sum List.sum
            theorem List.rel_prod {M : Type u_5} {N : Type u_6} [Monoid M] [Monoid N] {R : MNProp} (h : R 1 1) (hf : (R R R) (fun (x x_1 : M) => x * x_1) fun (x x_1 : N) => x * x_1) :
            (List.Forall₂ R R) List.prod List.prod
            theorem List.sum_hom {M : Type u_5} {N : Type u_6} [AddMonoid M] [AddMonoid N] (l : List M) {F : Type u_11} [FunLike F M N] [AddMonoidHomClass F M N] (f : F) :
            List.sum (List.map (f) l) = f (List.sum l)
            theorem List.prod_hom {M : Type u_5} {N : Type u_6} [Monoid M] [Monoid N] (l : List M) {F : Type u_11} [FunLike F M N] [MonoidHomClass F M N] (f : F) :
            List.prod (List.map (f) l) = f (List.prod l)
            theorem List.sum_hom₂ {ι : Type u_1} {M : Type u_5} {N : Type u_6} {P : Type u_7} [AddMonoid M] [AddMonoid N] [AddMonoid P] (l : List ι) (f : MNP) (hf : ∀ (a b : M) (c d : N), f (a + b) (c + d) = f a c + f b d) (hf' : f 0 0 = 0) (f₁ : ιM) (f₂ : ιN) :
            List.sum (List.map (fun (i : ι) => f (f₁ i) (f₂ i)) l) = f (List.sum (List.map f₁ l)) (List.sum (List.map f₂ l))
            theorem List.prod_hom₂ {ι : Type u_1} {M : Type u_5} {N : Type u_6} {P : Type u_7} [Monoid M] [Monoid N] [Monoid P] (l : List ι) (f : MNP) (hf : ∀ (a b : M) (c d : N), f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ιM) (f₂ : ιN) :
            List.prod (List.map (fun (i : ι) => f (f₁ i) (f₂ i)) l) = f (List.prod (List.map f₁ l)) (List.prod (List.map f₂ l))
            @[simp]
            theorem List.sum_map_add {ι : Type u_1} {α : Type u_11} [AddCommMonoid α] {l : List ι} {f : ια} {g : ια} :
            List.sum (List.map (fun (i : ι) => f i + g i) l) = List.sum (List.map f l) + List.sum (List.map g l)
            @[simp]
            theorem List.prod_map_mul {ι : Type u_1} {α : Type u_11} [CommMonoid α] {l : List ι} {f : ια} {g : ια} :
            List.prod (List.map (fun (i : ι) => f i * g i) l) = List.prod (List.map f l) * List.prod (List.map g l)
            @[simp]
            theorem List.prod_map_neg {M : Type u_5} [Monoid M] [HasDistribNeg M] (l : List M) :
            List.prod (List.map Neg.neg l) = (-1) ^ List.length l * List.prod l
            theorem List.sum_map_hom {ι : Type u_1} {M : Type u_5} {N : Type u_6} [AddMonoid M] [AddMonoid N] (L : List ι) (f : ιM) {G : Type u_11} [FunLike G M N] [AddMonoidHomClass G M N] (g : G) :
            List.sum (List.map (g f) L) = g (List.sum (List.map f L))
            theorem List.prod_map_hom {ι : Type u_1} {M : Type u_5} {N : Type u_6} [Monoid M] [Monoid N] (L : List ι) (f : ιM) {G : Type u_11} [FunLike G M N] [MonoidHomClass G M N] (g : G) :
            List.prod (List.map (g f) L) = g (List.prod (List.map f L))
            theorem List.sum_isAddUnit {M : Type u_5} [AddMonoid M] {L : List M} :
            (mL, IsAddUnit m)IsAddUnit (List.sum L)
            abbrev List.sum_isAddUnit.match_1 {M : Type u_1} [AddMonoid M] (motive : (x : List M) → (mx, IsAddUnit m)Prop) :
            ∀ (x : List M) (x_1 : mx, IsAddUnit m), (∀ (x : m[], IsAddUnit m), motive [] x)(∀ (h : M) (t : List M) (u : mh :: t, IsAddUnit m), motive (h :: t) u)motive x x_1
            Equations
            • =
            Instances For
              theorem List.prod_isUnit {M : Type u_5} [Monoid M] {L : List M} :
              (mL, IsUnit m)IsUnit (List.prod L)
              theorem List.sum_isAddUnit_iff {α : Type u_11} [AddCommMonoid α] {L : List α} :
              IsAddUnit (List.sum L) mL, IsAddUnit m
              theorem List.prod_isUnit_iff {α : Type u_11} [CommMonoid α] {L : List α} :
              IsUnit (List.prod L) mL, IsUnit m
              abbrev List.sum_take_add_sum_drop.match_1 {M : Type u_1} (motive : List MProp) :
              ∀ (x : List M) (x_1 : ), (∀ (i : ), motive [] i)(∀ (L : List M), motive L 0)(∀ (h : M) (t : List M) (n : ), motive (h :: t) (Nat.succ n))motive x x_1
              Equations
              • =
              Instances For
                @[simp]
                theorem List.sum_take_add_sum_drop {M : Type u_5} [AddMonoid M] (L : List M) (i : ) :
                @[simp]
                theorem List.prod_take_mul_prod_drop {M : Type u_5} [Monoid M] (L : List M) (i : ) :
                @[simp]
                theorem List.sum_take_succ {M : Type u_5} [AddMonoid M] (L : List M) (i : ) (p : i < List.length L) :
                List.sum (List.take (i + 1) L) = List.sum (List.take i L) + List.get L { val := i, isLt := p }
                abbrev List.sum_take_succ.match_1 {M : Type u_1} (motive : (x : List M) → (x_1 : ) → x_1 < List.length xProp) :
                ∀ (x : List M) (x_1 : ) (x_2 : x_1 < List.length x), (∀ (i : ) (p : i < List.length []), motive [] i p)(∀ (h : M) (t : List M) (x : 0 < List.length (h :: t)), motive (h :: t) 0 x)(∀ (h : M) (t : List M) (n : ) (p : n + 1 < List.length (h :: t)), motive (h :: t) (Nat.succ n) p)motive x x_1 x_2
                Equations
                • =
                Instances For
                  @[simp]
                  theorem List.prod_take_succ {M : Type u_5} [Monoid M] (L : List M) (i : ) (p : i < List.length L) :
                  List.prod (List.take (i + 1) L) = List.prod (List.take i L) * List.get L { val := i, isLt := p }
                  theorem List.length_pos_of_sum_ne_zero {M : Type u_5} [AddMonoid M] (L : List M) (h : List.sum L 0) :

                  A list with sum not zero must have positive length.

                  theorem List.length_pos_of_prod_ne_one {M : Type u_5} [Monoid M] (L : List M) (h : List.prod L 1) :

                  A list with product not one must have positive length.

                  theorem List.length_pos_of_sum_pos {M : Type u_5} [AddMonoid M] [Preorder M] (L : List M) (h : 0 < List.sum L) :

                  A list with positive sum must have positive length.

                  theorem List.length_pos_of_one_lt_prod {M : Type u_5} [Monoid M] [Preorder M] (L : List M) (h : 1 < List.prod L) :

                  A list with product greater than one must have positive length.

                  theorem List.length_pos_of_sum_neg {M : Type u_5} [AddMonoid M] [Preorder M] (L : List M) (h : List.sum L < 0) :

                  A list with negative sum must have positive length.

                  theorem List.length_pos_of_prod_lt_one {M : Type u_5} [Monoid M] [Preorder M] (L : List M) (h : List.prod L < 1) :

                  A list with product less than one must have positive length.

                  abbrev List.sum_set.match_1 {M : Type u_1} (motive : List MMProp) :
                  ∀ (x : List M) (x_1 : ) (x_2 : M), (∀ (x : M) (xs : List M) (a : M), motive (x :: xs) 0 a)(∀ (x : M) (xs : List M) (i : ) (a : M), motive (x :: xs) (Nat.succ i) a)(∀ (x : ) (x_3 : M), motive [] x x_3)motive x x_1 x_2
                  Equations
                  • =
                  Instances For
                    theorem List.sum_set {M : Type u_5} [AddMonoid M] (L : List M) (n : ) (a : M) :
                    List.sum (List.set L n a) = (List.sum (List.take n L) + if n < List.length L then a else 0) + List.sum (List.drop (n + 1) L)
                    theorem List.prod_set {M : Type u_5} [Monoid M] (L : List M) (n : ) (a : M) :
                    List.prod (List.set L n a) = (List.prod (List.take n L) * if n < List.length L then a else 1) * List.prod (List.drop (n + 1) L)

                    We'd like to state this as L.headI + L.tail.sum = L.sum, but because L.headI relies on an inhabited instance to return a garbage value on the empty list, this is not possible. Instead, we write the statement in terms of (L.get? 0).getD 0.

                    We'd like to state this as L.headI * L.tail.prod = L.prod, but because L.headI relies on an inhabited instance to return a garbage value on the empty list, this is not possible. Instead, we write the statement in terms of (L.get? 0).getD 1.

                    Same as get?_zero_add_tail_sum, but avoiding the List.headI garbage complication by requiring the list to be nonempty.

                    Same as get?_zero_mul_tail_prod, but avoiding the List.headI garbage complication by requiring the list to be nonempty.

                    theorem AddCommute.list_sum_right {M : Type u_5} [AddMonoid M] (l : List M) (y : M) (h : xl, AddCommute y x) :
                    theorem Commute.list_prod_right {M : Type u_5} [Monoid M] (l : List M) (y : M) (h : xl, Commute y x) :
                    theorem AddCommute.list_sum_left {M : Type u_5} [AddMonoid M] (l : List M) (y : M) (h : xl, AddCommute x y) :
                    theorem Commute.list_prod_left {M : Type u_5} [Monoid M] (l : List M) (y : M) (h : xl, Commute x y) :
                    theorem List.sum_range_succ {M : Type u_5} [AddMonoid M] (f : M) (n : ) :
                    theorem List.prod_range_succ {M : Type u_5} [Monoid M] (f : M) (n : ) :
                    theorem List.sum_range_succ' {M : Type u_5} [AddMonoid M] (f : M) (n : ) :
                    List.sum (List.map f (List.range (Nat.succ n))) = f 0 + List.sum (List.map (fun (i : ) => f (Nat.succ i)) (List.range n))

                    A variant of sum_range_succ which pulls off the first term in the sum rather than the last.

                    theorem List.prod_range_succ' {M : Type u_5} [Monoid M] (f : M) (n : ) :
                    List.prod (List.map f (List.range (Nat.succ n))) = f 0 * List.prod (List.map (fun (i : ) => f (Nat.succ i)) (List.range n))

                    A variant of prod_range_succ which pulls off the first term in the product rather than the last.

                    theorem List.sum_eq_zero {M : Type u_5} [AddMonoid M] {l : List M} (hl : xl, x = 0) :
                    theorem List.prod_eq_one {M : Type u_5} [Monoid M] {l : List M} (hl : xl, x = 1) :
                    theorem List.exists_mem_ne_zero_of_sum_ne_zero {M : Type u_5} [AddMonoid M] {l : List M} (h : List.sum l 0) :
                    ∃ x ∈ l, x 0
                    theorem List.exists_mem_ne_one_of_prod_ne_one {M : Type u_5} [Monoid M] {l : List M} (h : List.prod l 1) :
                    ∃ x ∈ l, x 1
                    theorem List.sum_erase_of_comm {M : Type u_5} [AddMonoid M] {l : List M} {a : M} [DecidableEq M] (ha : a l) (comm : xl, yl, x + y = y + x) :
                    theorem List.prod_erase_of_comm {M : Type u_5} [Monoid M] {l : List M} {a : M} [DecidableEq M] (ha : a l) (comm : xl, yl, x * y = y * x) :
                    theorem List.sum_map_eq_nsmul_single {α : Type u_2} {M : Type u_5} [AddMonoid M] [DecidableEq α] {l : List α} (a : α) (f : αM) (hf : ∀ (a' : α), a' aa' lf a' = 0) :
                    theorem List.prod_map_eq_pow_single {α : Type u_2} {M : Type u_5} [Monoid M] [DecidableEq α] {l : List α} (a : α) (f : αM) (hf : ∀ (a' : α), a' aa' lf a' = 1) :
                    theorem List.sum_eq_nsmul_single {M : Type u_5} [AddMonoid M] {l : List M} [DecidableEq M] (a : M) (h : ∀ (a' : M), a' aa' la' = 0) :
                    theorem List.prod_eq_pow_single {M : Type u_5} [Monoid M] {l : List M} [DecidableEq M] (a : M) (h : ∀ (a' : M), a' aa' la' = 1) :
                    theorem List.Perm.sum_eq' {M : Type u_5} [AddMonoid M] {l₁ : List M} {l₂ : List M} (h : List.Perm l₁ l₂) (hc : List.Pairwise AddCommute l₁) :
                    List.sum l₁ = List.sum l₂

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

                    theorem List.Perm.prod_eq' {M : Type u_5} [Monoid M] {l₁ : List M} {l₂ : List M} (h : List.Perm l₁ l₂) (hc : List.Pairwise Commute l₁) :

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

                    @[simp]
                    theorem List.sum_erase {M : Type u_5} [AddCommMonoid M] {a : M} {l : List M} [DecidableEq M] (ha : a l) :
                    @[simp]
                    theorem List.prod_erase {M : Type u_5} [CommMonoid M] {a : M} {l : List M} [DecidableEq M] (ha : a l) :
                    abbrev List.sum_map_erase.match_1 {α : Type u_1} {a : α} (motive : (x : List α) → a xProp) :
                    ∀ (x : List α) (x_1 : a x), (∀ (b : α) (l : List α) (h : a b :: l), motive (b :: l) h)motive x x_1
                    Equations
                    • =
                    Instances For
                      @[simp]
                      theorem List.sum_map_erase {α : Type u_2} {M : Type u_5} [AddCommMonoid M] [DecidableEq α] (f : αM) {a : α} {l : List α} :
                      a lf a + List.sum (List.map f (List.erase l a)) = List.sum (List.map f l)
                      @[simp]
                      theorem List.prod_map_erase {α : Type u_2} {M : Type u_5} [CommMonoid M] [DecidableEq α] (f : αM) {a : α} {l : List α} :
                      a lf a * List.prod (List.map f (List.erase l a)) = List.prod (List.map f l)
                      theorem List.Perm.sum_eq {M : Type u_5} [AddCommMonoid M] {l₁ : List M} {l₂ : List M} (h : List.Perm l₁ l₂) :
                      List.sum l₁ = List.sum l₂
                      theorem List.Perm.prod_eq {M : Type u_5} [CommMonoid M] {l₁ : List M} {l₂ : List M} (h : List.Perm l₁ l₂) :
                      abbrev List.sum_add_sum_eq_sum_zipWith_add_sum_drop.match_1 {M : Type u_1} (motive : List MList MProp) :
                      ∀ (x x_1 : List M), (∀ (ys : List M), motive [] ys)(∀ (xs : List M), motive xs [])(∀ (x : M) (xs : List M) (y : M) (ys : List M), motive (x :: xs) (y :: ys))motive x x_1
                      Equations
                      • =
                      Instances For
                        theorem List.sum_add_sum_eq_sum_zipWith_add_sum_drop {M : Type u_5} [AddCommMonoid M] (l : List M) (l' : List M) :
                        List.sum l + List.sum l' = List.sum (List.zipWith (fun (x x_1 : M) => x + x_1) l l') + List.sum (List.drop (List.length l') l) + List.sum (List.drop (List.length l) l')
                        theorem List.sum_add_sum_eq_sum_zipWith_of_length_eq {M : Type u_5} [AddCommMonoid M] (l : List M) (l' : List M) (h : List.length l = List.length l') :
                        List.sum l + List.sum l' = List.sum (List.zipWith (fun (x x_1 : M) => x + x_1) l l')
                        theorem List.prod_mul_prod_eq_prod_zipWith_of_length_eq {M : Type u_5} [CommMonoid M] (l : List M) (l' : List M) (h : List.length l = List.length l') :
                        List.prod l * List.prod l' = List.prod (List.zipWith (fun (x x_1 : M) => x * x_1) l l')
                        theorem List.eq_of_sum_take_eq {M : Type u_5} [AddLeftCancelMonoid M] {L : List M} {L' : List M} (h : List.length L = List.length L') (h' : iList.length L, List.sum (List.take i L) = List.sum (List.take i L')) :
                        L = L'
                        theorem List.eq_of_prod_take_eq {M : Type u_5} [LeftCancelMonoid M] {L : List M} {L' : List M} (h : List.length L = List.length L') (h' : iList.length L, List.prod (List.take i L) = List.prod (List.take i L')) :
                        L = L'
                        theorem List.sum_neg_reverse {G : Type u_9} [AddGroup G] (L : List G) :
                        -List.sum L = List.sum (List.reverse (List.map (fun (x : G) => -x) L))

                        This is the List.sum version of add_neg_rev

                        theorem List.prod_inv_reverse {G : Type u_9} [Group G] (L : List G) :
                        (List.prod L)⁻¹ = List.prod (List.reverse (List.map (fun (x : G) => x⁻¹) L))

                        This is the List.prod version of mul_inv_rev

                        theorem List.sum_reverse_noncomm {G : Type u_9} [AddGroup G] (L : List G) :
                        List.sum (List.reverse L) = -List.sum (List.map (fun (x : G) => -x) L)

                        A non-commutative variant of List.sum_reverse

                        theorem List.prod_reverse_noncomm {G : Type u_9} [Group G] (L : List G) :
                        List.prod (List.reverse L) = (List.prod (List.map (fun (x : G) => x⁻¹) L))⁻¹

                        A non-commutative variant of List.prod_reverse

                        @[simp]
                        theorem List.sum_drop_succ {G : Type u_9} [AddGroup G] (L : List G) (i : ) (p : i < List.length L) :
                        List.sum (List.drop (i + 1) L) = -List.get L { val := i, isLt := p } + List.sum (List.drop i L)

                        Counterpart to List.sum_take_succ when we have a negation operation

                        @[simp]
                        theorem List.prod_drop_succ {G : Type u_9} [Group G] (L : List G) (i : ) (p : i < List.length L) :
                        List.prod (List.drop (i + 1) L) = (List.get L { val := i, isLt := p })⁻¹ * List.prod (List.drop i L)

                        Counterpart to List.prod_take_succ when we have an inverse operation

                        theorem List.sum_range_sub' {G : Type u_9} [AddGroup G] (n : ) (f : G) :
                        List.sum (List.map (fun (k : ) => f k - f (k + 1)) (List.range n)) = f 0 - f n

                        Cancellation of a telescoping sum.

                        theorem List.prod_range_div' {G : Type u_9} [Group G] (n : ) (f : G) :
                        List.prod (List.map (fun (k : ) => f k / f (k + 1)) (List.range n)) = f 0 / f n

                        Cancellation of a telescoping product.

                        theorem List.prod_rotate_eq_one_of_prod_eq_one {G : Type u_9} [Group G] {l : List G} :
                        List.prod l = 1∀ (n : ), List.prod (List.rotate l n) = 1
                        theorem List.sum_neg {G : Type u_9} [AddCommGroup G] (L : List G) :
                        -List.sum L = List.sum (List.map (fun (x : G) => -x) L)

                        This is the List.sum version of add_neg

                        theorem List.prod_inv {G : Type u_9} [CommGroup G] (L : List G) :
                        (List.prod L)⁻¹ = List.prod (List.map (fun (x : G) => x⁻¹) L)

                        This is the List.prod version of mul_inv

                        theorem List.sum_range_sub {G : Type u_9} [AddCommGroup G] (n : ) (f : G) :
                        List.sum (List.map (fun (k : ) => f (k + 1) - f k) (List.range n)) = f n - f 0

                        Cancellation of a telescoping sum.

                        theorem List.prod_range_div {G : Type u_9} [CommGroup G] (n : ) (f : G) :
                        List.prod (List.map (fun (k : ) => f (k + 1) / f k) (List.range n)) = f n / f 0

                        Cancellation of a telescoping product.

                        theorem List.sum_set' {G : Type u_9} [AddCommGroup G] (L : List G) (n : ) (a : G) :
                        List.sum (List.set L n a) = List.sum L + if hn : n < List.length L then -List.get L { val := n, isLt := hn } + a else 0

                        Alternative version of List.sum_set when the list is over a group

                        theorem List.prod_set' {G : Type u_9} [CommGroup G] (L : List G) (n : ) (a : G) :
                        List.prod (List.set L n a) = List.prod L * if hn : n < List.length L then (List.get L { val := n, isLt := hn })⁻¹ * a else 1

                        Alternative version of List.prod_set when the list is over a group

                        @[simp]
                        theorem List.sum_zipWith_distrib_left {α : Type u_2} {β : Type u_3} {γ : Type u_4} [Semiring γ] (f : αβγ) (n : γ) (l : List α) (l' : List β) :
                        List.sum (List.zipWith (fun (x : α) (y : β) => n * f x y) l l') = n * List.sum (List.zipWith f l l')
                        theorem List.sum_const_nat (m : ) (n : ) :

                        Several lemmas about sum/head/tail for List. These are hard to generalize well, as they rely on the fact that default ℕ = 0. If desired, we could add a class stating that default = 0.

                        This relies on default ℕ = 0.

                        This relies on default ℕ = 0.

                        This relies on default ℕ = 0.

                        @[simp]
                        theorem List.alternatingSum_nil {α : Type u_2} [Zero α] [Add α] [Neg α] :
                        @[simp]
                        theorem List.alternatingProd_nil {α : Type u_2} [One α] [Mul α] [Inv α] :
                        @[simp]
                        theorem List.alternatingSum_singleton {α : Type u_2} [Zero α] [Add α] [Neg α] (a : α) :
                        @[simp]
                        theorem List.alternatingProd_singleton {α : Type u_2} [One α] [Mul α] [Inv α] (a : α) :
                        theorem List.alternatingSum_cons_cons' {α : Type u_2} [Zero α] [Add α] [Neg α] (a : α) (b : α) (l : List α) :
                        theorem List.alternatingProd_cons_cons' {α : Type u_2} [One α] [Mul α] [Inv α] (a : α) (b : α) (l : List α) :
                        theorem List.alternatingSum_cons_cons {α : Type u_2} [SubNegMonoid α] (a : α) (b : α) (l : List α) :
                        theorem List.alternatingProd_cons_cons {α : Type u_2} [DivInvMonoid α] (a : α) (b : α) (l : List α) :
                        abbrev List.alternatingSum_cons'.match_1 {α : Type u_1} (motive : αList αProp) :
                        ∀ (x : α) (x_1 : List α), (∀ (a : α), motive a [])(∀ (a b : α) (l : List α), motive a (b :: l))motive x x_1
                        Equations
                        • =
                        Instances For
                          @[simp]
                          theorem List.alternatingSum_cons {α : Type u_2} [AddCommGroup α] (a : α) (l : List α) :
                          @[simp]
                          theorem List.alternatingProd_cons {α : Type u_2} [CommGroup α] (a : α) (l : List α) :
                          theorem List.sum_nat_mod (l : List ) (n : ) :
                          List.sum l % n = List.sum (List.map (fun (x : ) => x % n) l) % n
                          theorem List.prod_nat_mod (l : List ) (n : ) :
                          List.prod l % n = List.prod (List.map (fun (x : ) => x % n) l) % n
                          theorem List.sum_int_mod (l : List ) (n : ) :
                          List.sum l % n = List.sum (List.map (fun (x : ) => x % n) l) % n
                          theorem List.prod_int_mod (l : List ) (n : ) :
                          List.prod l % n = List.prod (List.map (fun (x : ) => x % n) l) % n
                          theorem List.sum_map_count_dedup_filter_eq_countP {α : Type u_2} [DecidableEq α] (p : αBool) (l : List α) :
                          List.sum (List.map (fun (x : α) => List.count x l) (List.filter p (List.dedup l))) = List.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 α) :
                          List.sum (List.map (fun (x : α) => List.count x l) (List.dedup l)) = List.length l
                          theorem map_list_sum {M : Type u_5} {N : Type u_6} [AddMonoid M] [AddMonoid N] {F : Type u_11} [FunLike F M N] [AddMonoidHomClass F M N] (f : F) (l : List M) :
                          f (List.sum l) = List.sum (List.map (f) l)
                          theorem map_list_prod {M : Type u_5} {N : Type u_6} [Monoid M] [Monoid N] {F : Type u_11} [FunLike F M N] [MonoidHomClass F M N] (f : F) (l : List M) :
                          f (List.prod l) = List.prod (List.map (f) l)
                          theorem AddMonoidHom.map_list_sum {M : Type u_5} {N : Type u_6} [AddMonoid M] [AddMonoid N] (f : M →+ N) (l : List M) :
                          f (List.sum l) = List.sum (List.map (f) l)

                          Deprecated, use _root_.map_list_sum instead.

                          theorem MonoidHom.map_list_prod {M : Type u_5} {N : Type u_6} [Monoid M] [Monoid N] (f : M →* N) (l : List M) :
                          f (List.prod l) = List.prod (List.map (f) l)

                          Deprecated, use _root_.map_list_prod instead.

                          @[simp]
                          theorem List.length_sigma {α : Type u_2} {σ : αType u_11} (l₁ : List α) (l₂ : (a : α) → List (σ a)) :
                          List.length (List.sigma l₁ l₂) = List.sum (List.map (fun (a : α) => List.length (l₂ a)) l₁)
                          theorem List.mem_mem_ranges_iff_lt_sum (l : List ) {n : } :
                          (∃ s ∈ List.ranges l, n s) n < List.sum l

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

                          @[simp]
                          theorem List.length_join {α : Type u_2} (L : List (List α)) :
                          theorem List.countP_join {α : Type u_2} (p : αBool) (L : List (List α)) :
                          theorem List.count_join {α : Type u_2} [BEq α] (L : List (List α)) (a : α) :
                          @[simp]
                          theorem List.length_bind {α : Type u_2} {β : Type u_3} (l : List α) (f : αList β) :
                          List.length (List.bind l f) = List.sum (List.map (List.length f) l)
                          theorem List.countP_bind {α : Type u_2} {β : Type u_3} (p : βBool) (l : List α) (f : αList β) :
                          theorem List.count_bind {α : Type u_2} {β : Type u_3} [BEq β] (l : List α) (f : αList β) (x : β) :
                          theorem List.take_sum_join {α : Type u_2} (L : List (List α)) (i : ) :

                          In a join, taking the first elements up to an index which is the sum of the lengths of the first i sublists, is the same as taking the join of the first i sublists.

                          theorem List.drop_sum_join {α : Type u_2} (L : List (List α)) (i : ) :

                          In a join, dropping all the elements up to an index which is the sum of the lengths of the first i sublists, is the same as taking the join after dropping the first i sublists.

                          theorem List.drop_take_succ_join_eq_get {α : Type u_2} (L : List (List α)) (i : Fin (List.length L)) :
                          List.drop (List.sum (List.take (i) (List.map List.length L))) (List.take (List.sum (List.take (i + 1) (List.map List.length L))) (List.join L)) = List.get L i

                          In a join 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.