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.alternating_prod
, List.alternating_sum
, their alternating
counterparts. These are defined in Data.List.Defs
.
Equations
- List.sum_eq_foldr.match_1 motive x h_1 h_2 = List.casesOn x (h_1 ()) fun head tail => h_2 head tail
Instances For
Equations
- List.sum_isAddUnit.match_1 motive x x h_1 h_2 = List.casesOn M (fun x => (x_1 : ∀ (m : M), m ∈ x → IsAddUnit m) → motive x x_1) x (fun x => h_1 x) (fun head tail x => h_2 head tail x) x
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
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.
Equations
- List.sum_set.match_1 motive x x x h_1 h_2 h_3 = List.casesOn x (h_3 x x) fun head tail => Nat.casesOn x (h_1 head tail x) fun n => h_2 head tail n x
Instances For
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
- List.SublistForall₂.sum_le_sum.match_1 motive x h_1 = Exists.casesOn x fun w h => And.casesOn h fun left right => h_1 w left right
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
Counterpart to List.sum_take_succ
when we have a negation operation
Counterpart to List.prod_take_succ
when we have an inverse operation
Alternative version of List.sum_set
when the list is over a group
Alternative version of List.prod_set
when the list is over a group
Equations
- One or more equations did not get rendered due to their size.
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
.
Equations
- List.alternatingSum_cons'.match_1 motive x x h_1 h_2 = List.casesOn x (h_1 x) fun head tail => h_2 x head tail