Lists as finsupp #
THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.
Main definitions #
list.to_finsupp
: Interpret a list as a finitely supported function, where the indexing type isℕ
, and the values are either the elements of the list (accessing by indexing) or0
outside of the list.
Main theorems #
list.to_finsupp_eq_sum_map_enum_single
: Al : list M
overM
anadd_monoid
, when interpreted as a finitely supported function, is equal to the sum offinsupp.single
produced by mapping overlist.enum l
.
Implementation details #
The functions defined here rely on a decidability predicate that each element in the list
can be decidably determined to be not equal to zero or that one can decide one is out of the
bounds of a list. For concretely defined lists that are made up of elements of decidable terms,
this holds. More work will be needed to support lists over non-dec-eq types like ℝ
, where the
elements are beyond the dec-eq terms of casted values from ℕ, ℤ, ℚ
.
Indexing into a l : list M
, as a finitely-supported function,
where the support are all the indices within the length of the list
that index to a non-zero value. Indices beyond the end of the list are sent to 0.
This is a computable version of the finsupp.on_finset
construction.
Equations
- l.to_finsupp = {support := finset.filter (λ (i : ℕ), l.nthd i 0 ≠ 0) (finset.range l.length), to_fun := λ (i : ℕ), l.nthd i 0, mem_support_to_fun := _}