-- Mathlib/Data/DFinsupp/Defs.lean
theorem filter_single (p : ι → Prop) [DecidablePred p] (i : ι) (x : β i) :
    (single i x).filter p = if p i then single i x else 0

Proof state:
case h
ι : Type u
β : ι → Type v
inst✝² : (i : ι) → Zero (β i)
inst✝¹ : DecidableEq ι
p : ι → Prop
inst✝ : DecidablePred p
i : ι
x : β i
j : ι
this : (if p i then single i x else 0) j = if p i then (single i x) j else 0
⊢ (filter p (single i x)) j = (if p i then single i x else 0) j

Tactic:
rw [filter_apply, this]

Result:
case h
ι : Type u
β : ι → Type v
inst✝² : (i : ι) → Zero (β i)
inst✝¹ : DecidableEq ι
p : ι → Prop
inst✝ : DecidablePred p
i : ι
x : β i
j : ι
this : (if p i then single i x else 0) j = if p i then (single i x) j else 0
⊢ (if p j then (single i x) j else 0) = if p i then (single i x) j else 0

Proof state:
case h
ι : Type u
β : ι → Type v
inst✝² : (i : ι) → Zero (β i)
inst✝¹ : DecidableEq ι
p : ι → Prop
inst✝ : DecidablePred p
i : ι
x : β i
j : ι
this : (if p i then single i x else 0) j = if p i then (single i x) j else 0
⊢ (if p j then (single i x) j else 0) = if p i then (single i x) j else 0

Tactic:
obtain rfl | hij := Decidable.eq_or_ne i j

Result:
case h.inl
ι : Type u
β : ι → Type v
inst✝² : (i : ι) → Zero (β i)
inst✝¹ : DecidableEq ι
p : ι → Prop
inst✝ : DecidablePred p
i : ι
x : β i
this : (if p i then single i x else 0) i = if p i then (single i x) i else 0
⊢ (if p i then (single i x) i else 0) = if p i then (single i x) i else 0

case h.inr
ι : Type u
β : ι → Type v
inst✝² : (i : ι) → Zero (β i)
inst✝¹ : DecidableEq ι
p : ι → Prop
inst✝ : DecidablePred p
i : ι
x : β i
j : ι
this : (if p i then single i x else 0) j = if p i then (single i x) j else 0
hij : i ≠ j
⊢ (if p j then (single i x) j else 0) = if p i then (single i x) j else 0

Proof state:
case h
ι : Type u
β : ι → Type v
inst✝² : (i : ι) → Zero (β i)
inst✝¹ : DecidableEq ι
p : ι → Prop
inst✝ : DecidablePred p
i : ι
x : β i
j : ι
this : (if p i then single i x else 0) j = if p i then (single i x) j else 0 j
⊢ (filter p (single i x)) j = (if p i then single i x else 0) j

Tactic:
dsimp at this

Result:
case h
ι : Type u
β : ι → Type v
inst✝² : (i : ι) → Zero (β i)
inst✝¹ : DecidableEq ι
p : ι → Prop
inst✝ : DecidablePred p
i : ι
x : β i
j : ι
this : (if p i then single i x else 0) j = if p i then (single i x) j else 0
⊢ (filter p (single i x)) j = (if p i then single i x else 0) j

Proof state:
case h
ι : Type u
β : ι → Type v
inst✝² : (i : ι) → Zero (β i)
inst✝¹ : DecidableEq ι
p : ι → Prop
inst✝ : DecidablePred p
i : ι
x : β i
j : ι
⊢ (filter p (single i x)) j = (if p i then single i x else 0) j

Tactic:
have := apply_ite (fun x : Π₀ i, β i => x j) (p i) (single i x) 0

Result:
case h
ι : Type u
β : ι → Type v
inst✝² : (i : ι) → Zero (β i)
inst✝¹ : DecidableEq ι
p : ι → Prop
inst✝ : DecidablePred p
i : ι
x : β i
j : ι
this : (if p i then single i x else 0) j = if p i then (single i x) j else 0 j
⊢ (filter p (single i x)) j = (if p i then single i x else 0) j

Proof state:
case h.inr
ι : Type u
β : ι → Type v
inst✝² : (i : ι) → Zero (β i)
inst✝¹ : DecidableEq ι
p : ι → Prop
inst✝ : DecidablePred p
i : ι
x : β i
j : ι
this : (if p i then single i x else 0) j = if p i then (single i x) j else 0
hij : i ≠ j
⊢ (if p j then (single i x) j else 0) = if p i then (single i x) j else 0

Tactic:
rw [single_eq_of_ne hij, ite_self, ite_self]

Result:
no goals

Proof state:
case h.inl
ι : Type u
β : ι → Type v
inst✝² : (i : ι) → Zero (β i)
inst✝¹ : DecidableEq ι
p : ι → Prop
inst✝ : DecidablePred p
i : ι
x : β i
this : (if p i then single i x else 0) i = if p i then (single i x) i else 0
⊢ (if p i then (single i x) i else 0) = if p i then (single i x) i else 0

Tactic:
rfl

Result:
no goals

Proof state:
ι : Type u
β : ι → Type v
inst✝² : (i : ι) → Zero (β i)
inst✝¹ : DecidableEq ι
p : ι → Prop
inst✝ : DecidablePred p
i : ι
x : β i
⊢ filter p (single i x) = if p i then single i x else 0

Tactic:
ext j

Result:
case h
ι : Type u
β : ι → Type v
inst✝² : (i : ι) → Zero (β i)
inst✝¹ : DecidableEq ι
p : ι → Prop
inst✝ : DecidablePred p
i : ι
x : β i
j : ι
⊢ (filter p (single i x)) j = (if p i then single i x else 0) j