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.
The alternating sum of a list.
Equations
- List.alternatingSum [] = 0
- List.alternatingSum [g] = g
- List.alternatingSum (g :: h :: t) = g + -h + List.alternatingSum t
Instances For
The alternating product of a list.
Equations
- List.alternatingProd [] = 1
- List.alternatingProd [g] = g
- List.alternatingProd (g :: h :: t) = g * h⁻¹ * List.alternatingProd t
Instances For
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.
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.
This is the List.prod
version of mul_inv_rev
A non-commutative variant of List.sum_reverse
A non-commutative variant of List.prod_reverse
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
.
This relies on default ℕ = 0
.
This relies on default ℕ = 0
.
This relies on 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
.