Finite products and sums over types and sets #
We define products and sums over types and subsets of types, with no finiteness hypotheses.
All infinite products and sums are defined to be junk values (i.e. one or zero).
This approach is sometimes easier to use than finset.sum
,
when issues arise with finset
and fintype
being data.
Main definitions #
We use the following variables:
α
,β
- types with no structure;s
,t
- setsM
,N
- additive or multiplicative commutative monoidsf
,g
- functions
Definitions in this file:
-
finsum f : M
: the sum off x
asx
ranges over the support off
, if it's finite. Zero otherwise. -
finprod f : M
: the product off x
asx
ranges over the multiplicative support off
, if it's finite. One otherwise.
Notation #
This notation works for functions f : p → M
, where p : Prop
, so the following works:
∑ᶠ i ∈ s, f i
, wheref : α → M
,s : set α
: sum over the sets
;∑ᶠ n < 5, f n
, wheref : ℕ → M
: same asf 0 + f 1 + f 2 + f 3 + f 4
;∏ᶠ (n >= -2) (hn : n < 3), f n
, wheref : ℤ → M
: same asf (-2) * f (-1) * f 0 * f 1 * f 2
.
Implementation notes #
finsum
and finprod
is "yet another way of doing finite sums and products in Lean". However
experiments in the wild (e.g. with matroids) indicate that it is a helpful approach in settings
where the user is not interested in computability and wants to do reasoning without running into
typeclass diamonds caused by the constructive finiteness used in definitions such as finset
and
fintype
. By sticking solely to set.finite
we avoid these problems. We are aware that there are
other solutions but for beginner mathematicians this approach is easier in practice.
Another application is the construction of a partition of unity from a collection of “bump” function. In this case the finite set depends on the point and it's convenient to have a definition that does not mention the set explicitly.
The first arguments in all definitions and lemmas is the codomain of the function of the big
operator. This is necessary for the heuristic in @[to_additive]
.
See the documentation of to_additive.attr
for more information.
We did not add is_finite (X : Type) : Prop
, because it is simply nonempty (fintype X)
.
Tags #
finsum, finprod, finite sum, finite product
Definition and relation to finset.sum
and finset.prod
#
Sum of f x
as x
ranges over the elements of the support of f
, if it's finite. Zero
otherwise.
Equations
- finsum f = dite (function.support (f ∘ plift.down)).finite (λ (h : (function.support (f ∘ plift.down)).finite), ∑ (i : plift α) in h.to_finset, f i.down) (λ (h : ¬(function.support (f ∘ plift.down)).finite), 0)
Product of f x
as x
ranges over the elements of the multiplicative support of f
, if it's
finite. One otherwise.
Equations
- finprod f = dite (function.mul_support (f ∘ plift.down)).finite (λ (h : (function.mul_support (f ∘ plift.down)).finite), ∏ (i : plift α) in h.to_finset, f i.down) (λ (h : ¬(function.mul_support (f ∘ plift.down)).finite), 1)
To prove a property of a finite product, it suffices to prove that the property is multiplicative and holds on multipliers.
To prove a property of a finite sum, it suffices to prove that the property is additive and holds on summands.
Distributivity w.r.t. addition, subtraction, and (scalar) multiplication #
If the multiplicative supports of f
and g
are finite, then the product of f i * g i
equals
the product of f i
multiplied by the product over g i
.
If the multiplicative supports of f
and g
are finite, then the product of f i / g i
equals the product of f i
divided by the product over g i
.
A more general version of finprod_mem_mul_distrib
that requires s ∩ mul_support f
and
s ∩ mul_support g
instead of s
to be finite.
The product of constant one over any set equals one.
If a function f
equals one on a set s
, then the product of f i
over i ∈ s
equals one.
If the product of f i
over i ∈ s
is not equal to one, then there is some x ∈ s
such that f x ≠ 1
.
Given a finite set s
, the product of f i * g i
over i ∈ s
equals the product of f i
over i ∈ s
times the product of g i
over i ∈ s
.
A more general version of monoid_hom.map_finprod_mem
that requires s ∩ mul_support f
and
instead of s
to be finite.
Given a monoid homomorphism g : M →* N
, and a function f : α → M
, the value of g
at the
product of f i
over i ∈ s
equals the product of (g ∘ f) i
over s
.
Given a finite set s
, the product of f i / g i
over i ∈ s
equals the product of f i
over i ∈ s
divided by the product of g i
over i ∈ s
.
∏ᶠ x ∈ s, f x
and set operations #
The product of any function over an empty set is one.
A set s
is not empty if the product of some function over s
is not equal to one.
Given finite sets s
and t
, the product of f i
over i ∈ s ∪ t
times the product of
f i
over i ∈ s ∩ t
equals the product of f i
over i ∈ s
times the product of f i
over i ∈ t
.
A more general version of finprod_mem_union_inter
that requires s ∩ mul_support f
and
t ∩ mul_support f
instead of s
and t
to be finite.
A more general version of finprod_mem_union
that requires s ∩ mul_support f
and
t ∩ mul_support f
instead of s
and t
to be finite.
Given two finite disjoint sets s
and t
, the product of f i
over i ∈ s ∪ t
equals the
product of f i
over i ∈ s
times the product of f i
over i ∈ t
.
A more general version of finprod_mem_union'
that requires s ∩ mul_support f
and
t ∩ mul_support f
instead of s
and t
to be disjoint
The product of f i
over i ∈ {a}
equals f a
.
A more general version of finprod_mem_insert
that requires s ∩ mul_support f
instead of
s
to be finite.
Given a finite set s
and an element a ∉ s
, the product of f i
over i ∈ insert a s
equals
f a
times the product of f i
over i ∈ s
.
If f a = 1
for all a ∉ s
, then the product of f i
over i ∈ insert a s
equals the
product of f i
over i ∈ s
.
If f a = 1
, then the product of f i
over i ∈ insert a s
equals the product of f i
over
i ∈ s
.
If the multiplicative support of f
is finite, then for every x
in the domain of f
,
f x
divides finprod f
.
The product of f i
over i ∈ {a, b}
, a ≠ b
, is equal to f a * f b
.
The product of f y
over y ∈ g '' s
equals the product of f (g i)
over s
provided that g
is injective on s ∩ mul_support (f ∘ g)
.
The product of f y
over y ∈ g '' s
equals the product of f (g i)
over s
provided that g
is injective on s
.
The product of f y
over y ∈ set.range g
equals the product of f (g i)
over all i
provided that g
is injective on mul_support (f ∘ g)
.
The product of f y
over y ∈ set.range g
equals the product of f (g i)
over all i
provided that g
is injective.
The product of f i
over s : set α
is equal to the product of g j
over t : set β
if there exists a function e : α → β
such that e
is bijective from s
to t
and for all
x
in s
we have f x = g (e x)
.
See also finset.prod_bij
.
The product of f i
is equal to the product of g j
if there exists a bijective function
e : α → β
such that for all x
we have f x = g (e x)
.
See finprod_comp
, fintype.prod_bijective
and finset.prod_bij
Given a bijective function e
the product of g i
is equal to the product of g (e i)
.
See also finprod_eq_of_bijective
, fintype.prod_bijective
and finset.prod_bij
A more general version of finprod_mem_mul_diff
that requires t ∩ mul_support f
instead of
t
to be finite.
Given a finite set t
and a subset s
of t
, the product of f i
over i ∈ s
times the product of f i
over t \ s
equals the product of f i
over i ∈ t
.
Given a family of pairwise disjoint finite sets t i
indexed by a finite type,
the product of f a
over the union ⋃ i, t i
is equal to the product over all indexes i
of the products of f a
over a ∈ t i
.
Given a family of sets t : ι → set α
, a finite set I
in the index type such that all
sets t i
, i ∈ I
, are finite, if all t i
, i ∈ I
, are pairwise disjoint, then
the product of f a
over a ∈ ⋃ i ∈ I, t i
is equal to the product over i ∈ I
of the products of f a
over a ∈ t i
.
If t
is a finite set of pairwise disjoint finite sets, then the product of f a
over a ∈ ⋃₀ t
is the product over s ∈ t
of the products of f a
over a ∈ s
.
If s : set α
and t : set β
are finite sets, then the product over s
commutes
with the product over t
.
To prove a property of a finite product, it suffices to prove that the property is multiplicative and holds on multipliers.
Note that b ∈ (s.filter (λ ab, prod.fst ab = a)).image prod.snd
iff (a, b) ∈ s
so we can
simplify the right hand side of this lemma. However the form stated here is more useful for
iterating this lemma, e.g., if we have f : α × β × γ → M
.
See also finprod_mem_finset_product'
.