Skip to content

Commit 6f417e4

Browse files
committed
feat(Data/Sym/Sym2): add Sym2.diagSet (leanprover-community#30559)
`Sym2.diagSet` is the set of elements on the diagonal.
1 parent 7b3642c commit 6f417e4

1 file changed

Lines changed: 42 additions & 5 deletions

File tree

Mathlib/Data/Sym/Sym2.lean

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -503,13 +503,34 @@ lemma isDiag_map (hf : Injective f) : (e.map f).IsDiag ↔ e.IsDiag :=
503503
theorem diag_isDiag (a : α) : IsDiag (diag a) :=
504504
Eq.refl a
505505

506-
theorem IsDiag.mem_range_diag {z : Sym2 α} : IsDiag z → z ∈ Set.range (@diag α) := by
507-
obtain ⟨x, y⟩ := z
508-
rintro (rfl : x = y)
509-
exact ⟨_, rfl⟩
506+
theorem isDiag_of_subsingleton [Subsingleton α] (z : Sym2 α) : z.IsDiag :=
507+
z.ind Subsingleton.elim
508+
509+
/-- The set of all `Sym2 α` elements on the diagonal. -/
510+
def diagSet : Set (Sym2 α) :=
511+
Set.range diag
512+
513+
@[simp]
514+
theorem mem_diagSet_iff_isDiag (z : Sym2 α) : z ∈ diagSet ↔ z.IsDiag :=
515+
fun ⟨_, h⟩ ↦ h ▸ rfl, z.ind fun a b (h : a = b) ↦ ⟨a, h ▸ rfl⟩⟩
510516

517+
@[deprecated (since := "2025-11-05")] alias ⟨_, IsDiag.mem_range_diag⟩ := mem_diagSet_iff_isDiag
518+
519+
@[deprecated mem_diagSet_iff_isDiag (since := "2025-11-05")]
511520
theorem isDiag_iff_mem_range_diag (z : Sym2 α) : IsDiag z ↔ z ∈ Set.range (@diag α) :=
512-
⟨IsDiag.mem_range_diag, fun ⟨i, hi⟩ => hi ▸ diag_isDiag i⟩
521+
z.mem_diagSet_iff_isDiag.symm
522+
523+
theorem mem_diagSet_iff_eq {a b : α} : s(a, b) ∈ diagSet ↔ a = b := by
524+
simp
525+
526+
theorem diagSet_eq_setOf_isDiag : diagSet = {z : Sym2 α | z.IsDiag} :=
527+
Set.ext mem_diagSet_iff_isDiag
528+
529+
theorem diagSet_compl_eq_setOf_not_isDiag : diagSetᶜ = {z : Sym2 α | ¬z.IsDiag} :=
530+
congrArg _ diagSet_eq_setOf_isDiag
531+
532+
theorem diagSet_eq_univ_of_subsingleton [Subsingleton α] : @diagSet α = Set.univ :=
533+
Set.ext fun z ↦ ⟨fun _ ↦ trivial, z.ind fun a b _ ↦ Subsingleton.elim a b ▸ ⟨_, rfl⟩⟩
513534

514535
instance IsDiag.decidablePred (α : Type u) [DecidableEq α] : DecidablePred (@IsDiag α) :=
515536
fun z => z.recOnSubsingleton fun a => decidable_of_iff' _ (isDiag_iff_proj_eq a)
@@ -564,6 +585,22 @@ theorem fromRel_top : fromRel (fun (_ _ : α) z => z : Symmetric ⊤) = Set.univ
564585
theorem fromRel_ne : fromRel (fun (_ _ : α) z => z.symm : Symmetric Ne) = {z | ¬IsDiag z} := by
565586
ext z; exact z.ind (by simp)
566587

588+
lemma diagSet_eq_fromRel_eq : diagSet = fromRel (α := α) eq_equivalence.symmetric := by
589+
ext z
590+
exact z.ind fun _ _ ↦ mem_diagSet_iff_eq
591+
592+
lemma diagSet_compl_eq_fromRel_ne : diagSetᶜ = fromRel (α := α) (r := Ne) (fun _ _ ↦ Ne.symm) := by
593+
ext z
594+
exact z.ind fun _ _ ↦ mem_diagSet_iff_eq.not
595+
596+
theorem reflexive_iff_diagSet_subset_fromRel (sym : Symmetric r) :
597+
Reflexive r ↔ diagSet ⊆ fromRel sym :=
598+
fun hr _ ⟨_, hd⟩ ↦ hd ▸ hr _, fun h _ ↦ h ⟨_, rfl⟩⟩
599+
600+
theorem irreflexive_iff_fromRel_subset_diagSet_compl (sym : Symmetric r) :
601+
Irreflexive r ↔ fromRel sym ⊆ diagSetᶜ :=
602+
fun hr _ hz ⟨_, hd⟩ ↦ hr _ <| fromRel_prop.mp <| hd ▸ hz, fun h _ ha ↦ h ha ⟨_, rfl⟩⟩
603+
567604
theorem fromRel_irreflexive {sym : Symmetric r} :
568605
Irreflexive r ↔ ∀ {z}, z ∈ fromRel sym → ¬IsDiag z :=
569606
{ mp := by intro h; apply Sym2.ind; aesop

0 commit comments

Comments
 (0)