Connections between finsupp
and alist
#
THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.
Main definitions #
finsupp.to_alist
alist.lookup_finsupp
: converts an association list into a finitely supported function viaalist.lookup
, sending absent keys to zero.
noncomputable
def
alist.lookup_finsupp
{α : Type u_1}
{M : Type u_2}
[has_zero M]
(l : alist (λ (x : α), M)) :
α →₀ M
Converts an association list into a finitely supported function via alist.lookup
, sending
absent keys to zero.
Equations
- l.lookup_finsupp = {support := (list.filter (λ (x : Σ (x : α), M), x.snd ≠ 0) l.entries).keys.to_finset, to_fun := λ (a : α), (alist.lookup a l).get_or_else 0, mem_support_to_fun := _}
@[simp]
theorem
alist.lookup_finsupp_apply
{α : Type u_1}
{M : Type u_2}
[has_zero M]
[decidable_eq α]
(l : alist (λ (x : α), M))
(a : α) :
⇑(l.lookup_finsupp) a = (alist.lookup a l).get_or_else 0
@[simp]
theorem
alist.lookup_finsupp_support
{α : Type u_1}
{M : Type u_2}
[has_zero M]
[decidable_eq α]
[decidable_eq M]
(l : alist (λ (x : α), M)) :
theorem
alist.lookup_finsupp_eq_iff_of_ne_zero
{α : Type u_1}
{M : Type u_2}
[has_zero M]
[decidable_eq α]
{l : alist (λ (x : α), M)}
{a : α}
{x : M}
(hx : x ≠ 0) :
⇑(l.lookup_finsupp) a = x ↔ x ∈ alist.lookup a l
theorem
alist.lookup_finsupp_eq_zero_iff
{α : Type u_1}
{M : Type u_2}
[has_zero M]
[decidable_eq α]
{l : alist (λ (x : α), M)}
{a : α} :
⇑(l.lookup_finsupp) a = 0 ↔ a ∉ l ∨ 0 ∈ alist.lookup a l
@[simp]
theorem
alist.empty_lookup_finsupp
{α : Type u_1}
{M : Type u_2}
[has_zero M] :
∅.lookup_finsupp = 0
@[simp]
theorem
alist.insert_lookup_finsupp
{α : Type u_1}
{M : Type u_2}
[has_zero M]
[decidable_eq α]
(l : alist (λ (x : α), M))
(a : α)
(m : M) :
(alist.insert a m l).lookup_finsupp = l.lookup_finsupp.update a m
@[simp]
theorem
alist.singleton_lookup_finsupp
{α : Type u_1}
{M : Type u_2}
[has_zero M]
(a : α)
(m : M) :
(alist.singleton a m).lookup_finsupp = finsupp.single a m
@[simp]
theorem
finsupp.to_alist_lookup_finsupp
{α : Type u_1}
{M : Type u_2}
[has_zero M]
(f : α →₀ M) :
f.to_alist.lookup_finsupp = f