Skip to content

Commit 35186be

Browse files
BryceT233WenrongZou
andcommitted
feat(Data/Finsupp): add computational lemmas for cons and single (leanprover-community#35329)
This PR introduces `cons_injective2`, `cons_eq_single_zero_iff` and `cons_eq_single_succ_iff`, which are helper lemmas designed to facilitate calculations (or simplification) of equalities involving `Finsupp.cons` and `Finsupp.single`. Co-authored-by: Wenrong Zou <141128015+WenrongZou@users.noreply.github.com>
1 parent 5948832 commit 35186be

1 file changed

Lines changed: 24 additions & 8 deletions

File tree

Mathlib/Data/Finsupp/Fin.lean

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,16 @@ theorem cons_tail : cons (t 0) (tail t) = t := by
6565
· rw [c_a, cons_zero]
6666
· rw [← Fin.succ_pred a c_a, cons_succ, ← tail_apply]
6767

68+
lemma cons_zero_eq_single_zero : cons y (0 : Fin n →₀ M) = single 0 y := by
69+
ext j
70+
cases j using Fin.cases <;> simp
71+
72+
lemma cons_zero_single_eq_single_succ : cons 0 (single i y) = single i.succ y := by
73+
ext j
74+
cases j using Fin.cases <;> simp [single_apply]
75+
6876
@[simp]
69-
theorem cons_zero_zero : cons 0 (0 : Fin n →₀ M) = 0 := by
70-
ext a
71-
by_cases c : a = 0
72-
· simp [c]
73-
· rw [← Fin.succ_pred a c, cons_succ]
74-
simp
77+
theorem cons_zero_zero : cons 0 (0 : Fin n →₀ M) = 0 := by simp [cons_zero_eq_single_zero]
7578

7679
variable {s} {y}
7780

@@ -96,8 +99,21 @@ lemma cons_support : (s.cons y).support ⊆ insert 0 (s.support.map (Fin.succEmb
9699
rintro i rfl
97100
simpa [Finsupp.mem_support_iff] using hi
98101

99-
lemma cons_right_injective {n : ℕ} {M : Type*} [Zero M] (y : M) :
100-
Injective (Finsupp.cons y : (Fin n →₀ M) → Fin (n + 1) →₀ M) :=
102+
variable (y) in
103+
lemma cons_right_injective : Injective (Finsupp.cons y : (Fin n →₀ M) → Fin (n + 1) →₀ M) :=
101104
(equivFunOnFinite.symm.injective.comp ((Fin.cons_right_injective _).comp DFunLike.coe_injective))
102105

106+
/-- As a binary function, `Finsupp.cons` is injective. -/
107+
theorem cons_injective2 : Function.Injective2 (cons (n := n) (M := M)) := by
108+
refine fun x₀ y₀ x y h ↦ ?_
109+
have := DFunLike.congr_fun h 0
110+
simp only [cons_zero] at this
111+
exact ⟨this, cons_right_injective y₀ (this ▸ h)⟩
112+
113+
lemma cons_eq_single_zero_iff {x : M} : s.cons x = single 0 y ↔ s = 0 ∧ x = y := by
114+
rw [← cons_zero_eq_single_zero, cons_injective2.eq_iff, and_comm]
115+
116+
lemma cons_eq_single_succ_iff {x : M} : s.cons x = single i.succ y ↔ s = single i y ∧ x = 0 := by
117+
rw [← cons_zero_single_eq_single_succ, cons_injective2.eq_iff, and_comm]
118+
103119
end Finsupp

0 commit comments

Comments
 (0)