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. These are defined in Algebra.BigOperators.List.Defs
.
Equations
- ⋯ = ⋯
Instances For
A list with sum not zero must have positive length.
A list with product not one must have positive length.
A list with positive sum must have positive length.
A list with product greater than one must have positive length.
A list with negative sum must have positive length.
A list with product less than one must have positive length.
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.
If l₁
is a sublist of l₂
and all elements of l₂
are nonnegative,
then l₁.sum ≤ l₂.sum
.
One can prove a stronger version assuming ∀ a ∈ l₂.diff l₁, 0 ≤ a
instead of ∀ a ∈ l₂, 0 ≤ a
but this lemma is not yet in mathlib
.
If l₁
is a sublist of l₂
and all elements of l₂
are greater than or equal to one, then
l₁.prod ≤ l₂.prod
. One can prove a stronger version assuming ∀ a ∈ l₂.diff l₁, 1 ≤ a
instead
of ∀ a ∈ l₂, 1 ≤ a
but this lemma is not yet in mathlib
.
Equations
- ⋯ = ⋯
Instances For
If zero is an element of a list L
, then List.prod L = 0
. If the domain is a nontrivial
monoid with zero with no divisors, then this implication becomes an iff
, see
List.prod_eq_zero_iff
.
Product of elements of a list L
equals zero if and only if 0 ∈ L
. See also
List.prod_eq_zero
for an implication that needs weaker typeclass assumptions.
This is the List.prod
version of mul_inv_rev
Cancellation of a telescoping sum.
Alternative version of List.sum_set
when the list is over a group
Equations
- ⋯ = ⋯
Instances For
The product of a list of positive natural numbers is positive, and likewise for any nontrivial ordered semiring.
A variant of List.prod_pos
for CanonicallyOrderedCommSemiring
.
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
.