Theorem: List.toFinsupp_append
File: Mathlib/Data/List/ToFinsupp.lean

tactic: ext n
state_before: M : Type ?u.10005
inst✝⁵ : Zero M
l : List M
inst✝⁴ : DecidablePred fun x => getD l x 0 ≠ 0
n : ℕ
R : Type u_1
inst✝³ : AddZeroClass R
l₁ l₂ : List R
inst✝² : DecidablePred fun x => getD (l₁ ++ l₂) x 0 ≠ 0
inst✝¹ : DecidablePred fun x => getD l₁ x 0 ≠ 0
inst✝ : DecidablePred fun x => getD l₂ x 0 ≠ 0
⊢ toFinsupp (l₁ ++ l₂) = toFinsupp l₁ + Finsupp.embDomain (addLeftEmbedding (length l₁)) (toFinsupp l₂)

tactic: simp only [toFinsupp_apply, Finsupp.add_apply]
state_before: case h
M : Type ?u.10005
inst✝⁵ : Zero M
l : List M
inst✝⁴ : DecidablePred fun x => getD l x 0 ≠ 0
n✝ : ℕ
R : Type u_1
inst✝³ : AddZeroClass R
l₁ l₂ : List R
inst✝² : DecidablePred fun x => getD (l₁ ++ l₂) x 0 ≠ 0
inst✝¹ : DecidablePred fun x => getD l₁ x 0 ≠ 0
inst✝ : DecidablePred fun x => getD l₂ x 0 ≠ 0
n : ℕ
⊢ ↑(toFinsupp (l₁ ++ l₂)) n = ↑(toFinsupp l₁ + Finsupp.embDomain (addLeftEmbedding (length l₁)) (toFinsupp l₂)) n

tactic: cases lt_or_le n l₁.length with
| inl h =>
  rw [getD_append _ _ _ _ h, Finsupp.embDomain_notin_range, add_zero]
  rintro ⟨k, rfl : length l₁ + k = n⟩
  exact h.not_le (self_le_add_right _ _)
| inr h =>
  rcases exists_add_of_le h with ⟨k, rfl⟩
  rw [getD_append_right _ _ _ _ h, add_tsub_cancel_left, getD_eq_default _ _ h, zero_add]
  exact Eq.symm (Finsupp.embDomain_apply _ _ _)
state_before: case h
M : Type ?u.10005
inst✝⁵ : Zero M
l : List M
inst✝⁴ : DecidablePred fun x => getD l x 0 ≠ 0
n✝ : ℕ
R : Type u_1
inst✝³ : AddZeroClass R
l₁ l₂ : List R
inst✝² : DecidablePred fun x => getD (l₁ ++ l₂) x 0 ≠ 0
inst✝¹ : DecidablePred fun x => getD l₁ x 0 ≠ 0
inst✝ : DecidablePred fun x => getD l₂ x 0 ≠ 0
n : ℕ
⊢ getD (l₁ ++ l₂) n 0 = getD l₁ n 0 + ↑(Finsupp.embDomain (addLeftEmbedding (length l₁)) (toFinsupp l₂)) n

tactic: rw [getD_append _ _ _ _ h, Finsupp.embDomain_notin_range, add_zero]
state_before: case h.inl
M : Type ?u.10005
inst✝⁵ : Zero M
l : List M
inst✝⁴ : DecidablePred fun x => getD l x 0 ≠ 0
n✝ : ℕ
R : Type u_1
inst✝³ : AddZeroClass R
l₁ l₂ : List R
inst✝² : DecidablePred fun x => getD (l₁ ++ l₂) x 0 ≠ 0
inst✝¹ : DecidablePred fun x => getD l₁ x 0 ≠ 0
inst✝ : DecidablePred fun x => getD l₂ x 0 ≠ 0
n : ℕ
h : n < length l₁
⊢ getD (l₁ ++ l₂) n 0 = getD l₁ n 0 + ↑(Finsupp.embDomain (addLeftEmbedding (length l₁)) (toFinsupp l₂)) n

tactic: rintro ⟨k, rfl : length l₁ + k = n⟩
state_before: case h.inl.h
M : Type ?u.10005
inst✝⁵ : Zero M
l : List M
inst✝⁴ : DecidablePred fun x => getD l x 0 ≠ 0
n✝ : ℕ
R : Type u_1
inst✝³ : AddZeroClass R
l₁ l₂ : List R
inst✝² : DecidablePred fun x => getD (l₁ ++ l₂) x 0 ≠ 0
inst✝¹ : DecidablePred fun x => getD l₁ x 0 ≠ 0
inst✝ : DecidablePred fun x => getD l₂ x 0 ≠ 0
n : ℕ
h : n < length l₁
⊢ ¬n ∈ Set.range ↑(addLeftEmbedding (length l₁))

tactic: exact h.not_le (self_le_add_right _ _)
state_before: case h.inl.h.intro
M : Type ?u.10005
inst✝⁵ : Zero M
l : List M
inst✝⁴ : DecidablePred fun x => getD l x 0 ≠ 0
n : ℕ
R : Type u_1
inst✝³ : AddZeroClass R
l₁ l₂ : List R
inst✝² : DecidablePred fun x => getD (l₁ ++ l₂) x 0 ≠ 0
inst✝¹ : DecidablePred fun x => getD l₁ x 0 ≠ 0
inst✝ : DecidablePred fun x => getD l₂ x 0 ≠ 0
k : ℕ
h : length l₁ + k < length l₁
⊢ False

tactic: rcases exists_add_of_le h with ⟨k, rfl⟩
state_before: case h.inr
M : Type ?u.10005
inst✝⁵ : Zero M
l : List M
inst✝⁴ : DecidablePred fun x => getD l x 0 ≠ 0
n✝ : ℕ
R : Type u_1
inst✝³ : AddZeroClass R
l₁ l₂ : List R
inst✝² : DecidablePred fun x => getD (l₁ ++ l₂) x 0 ≠ 0
inst✝¹ : DecidablePred fun x => getD l₁ x 0 ≠ 0
inst✝ : DecidablePred fun x => getD l₂ x 0 ≠ 0
n : ℕ
h : length l₁ ≤ n
⊢ getD (l₁ ++ l₂) n 0 = getD l₁ n 0 + ↑(Finsupp.embDomain (addLeftEmbedding (length l₁)) (toFinsupp l₂)) n

tactic: rw [getD_append_right _ _ _ _ h, add_tsub_cancel_left, getD_eq_default _ _ h, zero_add]
state_before: case h.inr.intro
M : Type ?u.10005
inst✝⁵ : Zero M
l : List M
inst✝⁴ : DecidablePred fun x => getD l x 0 ≠ 0
n : ℕ
R : Type u_1
inst✝³ : AddZeroClass R
l₁ l₂ : List R
inst✝² : DecidablePred fun x => getD (l₁ ++ l₂) x 0 ≠ 0
inst✝¹ : DecidablePred fun x => getD l₁ x 0 ≠ 0
inst✝ : DecidablePred fun x => getD l₂ x 0 ≠ 0
k : ℕ
h : length l₁ ≤ length l₁ + k
⊢ getD (l₁ ++ l₂) (length l₁ + k) 0 =
    getD l₁ (length l₁ + k) 0 + ↑(Finsupp.embDomain (addLeftEmbedding (length l₁)) (toFinsupp l₂)) (length l₁ + k)

tactic: exact Eq.symm (Finsupp.embDomain_apply _ _ _)
state_before: case h.inr.intro
M : Type ?u.10005
inst✝⁵ : Zero M
l : List M
inst✝⁴ : DecidablePred fun x => getD l x 0 ≠ 0
n : ℕ
R : Type u_1
inst✝³ : AddZeroClass R
l₁ l₂ : List R
inst✝² : DecidablePred fun x => getD (l₁ ++ l₂) x 0 ≠ 0
inst✝¹ : DecidablePred fun x => getD l₁ x 0 ≠ 0
inst✝ : DecidablePred fun x => getD l₂ x 0 ≠ 0
k : ℕ
h : length l₁ ≤ length l₁ + k
⊢ getD l₂ k 0 = ↑(Finsupp.embDomain (addLeftEmbedding (length l₁)) (toFinsupp l₂)) (length l₁ + k)