Sums and products from lists #
This file provides basic definitions for 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_eq_foldr
{M : Type u_4}
[Monoid M]
{l : List M}
:
l.prod = List.foldr (fun (x1 x2 : M) => x1 * x2) 1 l
theorem
List.sum_eq_foldr
{M : Type u_4}
[AddMonoid M]
{l : List M}
:
l.sum = List.foldr (fun (x1 x2 : M) => x1 + x2) 0 l
@[simp]
theorem
List.prod_replicate
{M : Type u_4}
[Monoid M]
(n : ℕ)
(a : M)
:
(List.replicate n a).prod = a ^ n
@[simp]
theorem
List.sum_replicate
{M : Type u_4}
[AddMonoid M]
(n : ℕ)
(a : M)
:
(List.replicate n a).sum = n • a