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.
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.
A variant of sum_range_succ
which pulls off the first term in the sum rather than the last.
A variant of prod_range_succ
which pulls off the first term in the product rather than the
last.
If elements of a list additively commute with each other, then their sum does not depend on the order of elements.
If elements of a list commute with each other, then their product does not depend on the order of elements.
A non-commutative variant of List.sum_reverse
A non-commutative variant of List.prod_reverse
This is the List.sum
version of add_neg
Cancellation of a telescoping sum.
Alternative version of List.sum_set
when the list is over a group
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
.
Summing the count of x
over a list filtered by some p
is just countP
applied to p
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.
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.
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
.
A morphism into the opposite monoid acts on the product by acting on the reversed elements.