File: Mathlib/Data/List/ToFinsupp.lean

full_name: List.toFinsupp
code: /-- 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.onFinset` construction.
-/
def toFinsupp : ℕ →₀ M 
goal: ℕ →₀ M

full_name: List.coe_toFinsupp
code: @[norm_cast]
theorem coe_toFinsupp : (l.toFinsupp : ℕ → M) = (l.getD · 0) 
goal: ⇑l.toFinsupp = fun x => l.getD x 0

full_name: List.toFinsupp_apply
code: @[simp, norm_cast]
theorem toFinsupp_apply (i : ℕ) : (l.toFinsupp : ℕ → M) i = l.getD i 0 
goal: l.toFinsupp i = l.getD i 0

full_name: List.toFinsupp_support
code: theorem toFinsupp_support :
    l.toFinsupp.support = (Finset.range l.length).filter (getD l · 0 ≠ 0) 
goal: l.toFinsupp.support = Finset.filter (fun x => l.getD x 0 ≠ 0) (Finset.range l.length)

full_name: List.toFinsupp_apply_lt
code: theorem toFinsupp_apply_lt (hn : n < l.length) : l.toFinsupp n = l.get ⟨n, hn⟩ 
goal: l.toFinsupp n = l.get ⟨n, hn⟩

full_name: List.toFinsupp_apply_fin
code: theorem toFinsupp_apply_fin (n : Fin l.length) : l.toFinsupp n = l.get n 
goal: l.toFinsupp ↑n = l.get n

full_name: List.toFinsupp_apply_lt'
code: @[deprecated (since := "2023-04-10")]
theorem toFinsupp_apply_lt' (hn : n < l.length) : l.toFinsupp n = l.nthLe n hn 
goal: l.toFinsupp n = l.nthLe n hn

full_name: List.toFinsupp_apply_le
code: theorem toFinsupp_apply_le (hn : l.length ≤ n) : l.toFinsupp n = 0 
goal: l.toFinsupp n = 0

full_name: List.toFinsupp_nil
code: @[simp]
theorem toFinsupp_nil [DecidablePred fun i => getD ([] : List M) i 0 ≠ 0] :
    toFinsupp ([] : List M) = 0 
goal: [].toFinsupp = 0

full_name: List.toFinsupp_singleton
code: theorem toFinsupp_singleton (x : M) [DecidablePred (getD [x] · 0 ≠ 0)] :
    toFinsupp [x] = Finsupp.single 0 x 
goal: [x].toFinsupp = Finsupp.single 0 x

full_name: List.toFinsupp_cons_apply_zero
code: @[deprecated "This lemma is unused, and can be proved by `simp`." (since := "2024-06-12")]
theorem toFinsupp_cons_apply_zero (x : M) (xs : List M)
    [DecidablePred (getD (x::xs) · 0 ≠ 0)] : (x::xs).toFinsupp 0 = x 
goal: (x :: xs).toFinsupp 0 = x

full_name: List.toFinsupp_cons_apply_succ
code: @[deprecated "This lemma is unused, and can be proved by `simp`." (since := "2024-06-12")]
theorem toFinsupp_cons_apply_succ (x : M) (xs : List M) (n : ℕ)
    [DecidablePred (getD (x::xs) · 0 ≠ 0)] [DecidablePred (getD xs · 0 ≠ 0)] :
    (x::xs).toFinsupp n.succ = xs.toFinsupp n 
goal: (x :: xs).toFinsupp n.succ = xs.toFinsupp n

full_name: List.toFinsupp_append
code: theorem toFinsupp_append {R : Type*} [AddZeroClass R] (l₁ l₂ : List R)
    [DecidablePred (getD (l₁ ++ l₂) · 0 ≠ 0)] [DecidablePred (getD l₁ · 0 ≠ 0)]
    [DecidablePred (getD l₂ · 0 ≠ 0)] :
    toFinsupp (l₁ ++ l₂) =
      toFinsupp l₁ + (toFinsupp l₂).embDomain (addLeftEmbedding l₁.length) 
goal: (l₁ ++ l₂).toFinsupp = l₁.toFinsupp + Finsupp.embDomain (addLeftEmbedding l₁.length) l₂.toFinsupp

full_name: List.toFinsupp_cons_eq_single_add_embDomain
code: theorem toFinsupp_cons_eq_single_add_embDomain {R : Type*} [AddZeroClass R] (x : R) (xs : List R)
    [DecidablePred (getD (x::xs) · 0 ≠ 0)] [DecidablePred (getD xs · 0 ≠ 0)] :
    toFinsupp (x::xs) =
      Finsupp.single 0 x + (toFinsupp xs).embDomain ⟨Nat.succ, Nat.succ_injective⟩ 
goal: (x :: xs).toFinsupp =
  Finsupp.single 0 x + Finsupp.embDomain { toFun := Nat.succ, inj' := Nat.succ_injective } xs.toFinsupp

full_name: List.toFinsupp_concat_eq_toFinsupp_add_single
code: theorem toFinsupp_concat_eq_toFinsupp_add_single {R : Type*} [AddZeroClass R] (x : R) (xs : List R)
    [DecidablePred fun i => getD (xs ++ [x]) i 0 ≠ 0] [DecidablePred fun i => getD xs i 0 ≠ 0] :
    toFinsupp (xs ++ [x]) = toFinsupp xs + Finsupp.single xs.length x 
goal: (xs ++ [x]).toFinsupp = xs.toFinsupp + Finsupp.single xs.length x

full_name: List.toFinsupp_eq_sum_map_enum_single
code: theorem toFinsupp_eq_sum_map_enum_single {R : Type*} [AddMonoid R] (l : List R)
    [DecidablePred (getD l · 0 ≠ 0)] :
    toFinsupp l = (l.enum.map fun nr : ℕ × R => Finsupp.single nr.1 nr.2).sum 
goal: l.toFinsupp = (List.map (fun nr => Finsupp.single nr.1 nr.2) l.enum).sum